Commit abaabe92 authored by Max Kellermann's avatar Max Kellermann

decoder_buffer: convert to C++

parent 257b42b8
...@@ -60,7 +60,6 @@ mpd_headers = \ ...@@ -60,7 +60,6 @@ mpd_headers = \
src/conf.h \ src/conf.h \
src/decoder_plugin.h \ src/decoder_plugin.h \
src/decoder_command.h \ src/decoder_command.h \
src/decoder_buffer.h \
src/decoder_api.h \ src/decoder_api.h \
src/decoder_plugin.h \ src/decoder_plugin.h \
src/encoder_plugin.h \ src/encoder_plugin.h \
...@@ -455,7 +454,7 @@ libdecoder_plugins_a_SOURCES = \ ...@@ -455,7 +454,7 @@ libdecoder_plugins_a_SOURCES = \
src/decoder/dsf_decoder_plugin.h \ src/decoder/dsf_decoder_plugin.h \
src/decoder/dsdlib.c \ src/decoder/dsdlib.c \
src/decoder/dsdlib.h \ src/decoder/dsdlib.h \
src/decoder_buffer.c \ src/DecoderBuffer.cxx src/DecoderBuffer.hxx \
src/DecoderPlugin.cxx \ src/DecoderPlugin.cxx \
src/DecoderList.cxx src/DecoderList.hxx src/DecoderList.cxx src/DecoderList.hxx
libdecoder_plugins_a_CPPFLAGS = $(AM_CPPFLAGS) \ libdecoder_plugins_a_CPPFLAGS = $(AM_CPPFLAGS) \
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -18,14 +18,14 @@ ...@@ -18,14 +18,14 @@
*/ */
#include "config.h" #include "config.h"
#include "decoder_buffer.h" #include "DecoderBuffer.hxx"
#include "decoder_api.h" #include "decoder_api.h"
#include <glib.h> #include <glib.h>
#include <assert.h> #include <assert.h>
struct decoder_buffer { struct DecoderBuffer {
struct decoder *decoder; struct decoder *decoder;
struct input_stream *is; struct input_stream *is;
...@@ -43,14 +43,14 @@ struct decoder_buffer { ...@@ -43,14 +43,14 @@ struct decoder_buffer {
unsigned char data[sizeof(size_t)]; unsigned char data[sizeof(size_t)];
}; };
struct decoder_buffer * DecoderBuffer *
decoder_buffer_new(struct decoder *decoder, struct input_stream *is, decoder_buffer_new(struct decoder *decoder, struct input_stream *is,
size_t size) size_t size)
{ {
struct decoder_buffer *buffer = DecoderBuffer *buffer = (DecoderBuffer *)
g_malloc(sizeof(*buffer) - sizeof(buffer->data) + size); g_malloc(sizeof(*buffer) - sizeof(buffer->data) + size);
assert(is != NULL); assert(is != nullptr);
assert(size > 0); assert(size > 0);
buffer->decoder = decoder; buffer->decoder = decoder;
...@@ -63,27 +63,27 @@ decoder_buffer_new(struct decoder *decoder, struct input_stream *is, ...@@ -63,27 +63,27 @@ decoder_buffer_new(struct decoder *decoder, struct input_stream *is,
} }
void void
decoder_buffer_free(struct decoder_buffer *buffer) decoder_buffer_free(DecoderBuffer *buffer)
{ {
assert(buffer != NULL); assert(buffer != nullptr);
g_free(buffer); g_free(buffer);
} }
bool bool
decoder_buffer_is_empty(const struct decoder_buffer *buffer) decoder_buffer_is_empty(const DecoderBuffer *buffer)
{ {
return buffer->consumed == buffer->length; return buffer->consumed == buffer->length;
} }
bool bool
decoder_buffer_is_full(const struct decoder_buffer *buffer) decoder_buffer_is_full(const DecoderBuffer *buffer)
{ {
return buffer->consumed == 0 && buffer->length == buffer->size; return buffer->consumed == 0 && buffer->length == buffer->size;
} }
static void static void
decoder_buffer_shift(struct decoder_buffer *buffer) decoder_buffer_shift(DecoderBuffer *buffer)
{ {
assert(buffer->consumed > 0); assert(buffer->consumed > 0);
...@@ -93,7 +93,7 @@ decoder_buffer_shift(struct decoder_buffer *buffer) ...@@ -93,7 +93,7 @@ decoder_buffer_shift(struct decoder_buffer *buffer)
} }
bool bool
decoder_buffer_fill(struct decoder_buffer *buffer) decoder_buffer_fill(DecoderBuffer *buffer)
{ {
size_t nbytes; size_t nbytes;
...@@ -119,18 +119,18 @@ decoder_buffer_fill(struct decoder_buffer *buffer) ...@@ -119,18 +119,18 @@ decoder_buffer_fill(struct decoder_buffer *buffer)
} }
const void * const void *
decoder_buffer_read(const struct decoder_buffer *buffer, size_t *length_r) decoder_buffer_read(const DecoderBuffer *buffer, size_t *length_r)
{ {
if (buffer->consumed >= buffer->length) if (buffer->consumed >= buffer->length)
/* buffer is empty */ /* buffer is empty */
return NULL; return nullptr;
*length_r = buffer->length - buffer->consumed; *length_r = buffer->length - buffer->consumed;
return buffer->data + buffer->consumed; return buffer->data + buffer->consumed;
} }
void void
decoder_buffer_consume(struct decoder_buffer *buffer, size_t nbytes) decoder_buffer_consume(DecoderBuffer *buffer, size_t nbytes)
{ {
/* just move the "consumed" pointer - decoder_buffer_shift() /* just move the "consumed" pointer - decoder_buffer_shift()
will do the real work later (called by will do the real work later (called by
...@@ -141,7 +141,7 @@ decoder_buffer_consume(struct decoder_buffer *buffer, size_t nbytes) ...@@ -141,7 +141,7 @@ decoder_buffer_consume(struct decoder_buffer *buffer, size_t nbytes)
} }
bool bool
decoder_buffer_skip(struct decoder_buffer *buffer, size_t nbytes) decoder_buffer_skip(DecoderBuffer *buffer, size_t nbytes)
{ {
size_t length; size_t length;
const void *data; const void *data;
...@@ -151,7 +151,7 @@ decoder_buffer_skip(struct decoder_buffer *buffer, size_t nbytes) ...@@ -151,7 +151,7 @@ decoder_buffer_skip(struct decoder_buffer *buffer, size_t nbytes)
while (true) { while (true) {
data = decoder_buffer_read(buffer, &length); data = decoder_buffer_read(buffer, &length);
if (data != NULL) { if (data != nullptr) {
if (length > nbytes) if (length > nbytes)
length = nbytes; length = nbytes;
decoder_buffer_consume(buffer, length); decoder_buffer_consume(buffer, length);
......
/* /*
* Copyright (C) 2003-2011 The Music Player Daemon Project * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -17,10 +17,9 @@ ...@@ -17,10 +17,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_DECODER_BUFFER_H #ifndef MPD_DECODER_BUFFER_HXX
#define MPD_DECODER_BUFFER_H #define MPD_DECODER_BUFFER_HXX
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
/** /**
...@@ -28,7 +27,7 @@ ...@@ -28,7 +27,7 @@
* create a buffer object, and use its high-level methods to fill and * create a buffer object, and use its high-level methods to fill and
* read it. It will automatically handle shifting the buffer. * read it. It will automatically handle shifting the buffer.
*/ */
struct decoder_buffer; struct DecoderBuffer;
struct decoder; struct decoder;
struct input_stream; struct input_stream;
...@@ -41,7 +40,7 @@ struct input_stream; ...@@ -41,7 +40,7 @@ struct input_stream;
* @param size the maximum size of the buffer * @param size the maximum size of the buffer
* @return the new decoder_buffer object * @return the new decoder_buffer object
*/ */
struct decoder_buffer * DecoderBuffer *
decoder_buffer_new(struct decoder *decoder, struct input_stream *is, decoder_buffer_new(struct decoder *decoder, struct input_stream *is,
size_t size); size_t size);
...@@ -49,13 +48,13 @@ decoder_buffer_new(struct decoder *decoder, struct input_stream *is, ...@@ -49,13 +48,13 @@ decoder_buffer_new(struct decoder *decoder, struct input_stream *is,
* Frees resources used by the decoder_buffer object. * Frees resources used by the decoder_buffer object.
*/ */
void void
decoder_buffer_free(struct decoder_buffer *buffer); decoder_buffer_free(DecoderBuffer *buffer);
bool bool
decoder_buffer_is_empty(const struct decoder_buffer *buffer); decoder_buffer_is_empty(const DecoderBuffer *buffer);
bool bool
decoder_buffer_is_full(const struct decoder_buffer *buffer); decoder_buffer_is_full(const DecoderBuffer *buffer);
/** /**
* Read data from the input_stream and append it to the buffer. * Read data from the input_stream and append it to the buffer.
...@@ -65,7 +64,7 @@ decoder_buffer_is_full(const struct decoder_buffer *buffer); ...@@ -65,7 +64,7 @@ decoder_buffer_is_full(const struct decoder_buffer *buffer);
* received * received
*/ */
bool bool
decoder_buffer_fill(struct decoder_buffer *buffer); decoder_buffer_fill(DecoderBuffer *buffer);
/** /**
* Reads data from the buffer. This data is not yet consumed, you * Reads data from the buffer. This data is not yet consumed, you
...@@ -80,7 +79,7 @@ decoder_buffer_fill(struct decoder_buffer *buffer); ...@@ -80,7 +79,7 @@ decoder_buffer_fill(struct decoder_buffer *buffer);
* available * available
*/ */
const void * const void *
decoder_buffer_read(const struct decoder_buffer *buffer, size_t *length_r); decoder_buffer_read(const DecoderBuffer *buffer, size_t *length_r);
/** /**
* Consume (delete, invalidate) a part of the buffer. The "nbytes" * Consume (delete, invalidate) a part of the buffer. The "nbytes"
...@@ -91,7 +90,7 @@ decoder_buffer_read(const struct decoder_buffer *buffer, size_t *length_r); ...@@ -91,7 +90,7 @@ decoder_buffer_read(const struct decoder_buffer *buffer, size_t *length_r);
* @param nbytes the number of bytes to consume * @param nbytes the number of bytes to consume
*/ */
void void
decoder_buffer_consume(struct decoder_buffer *buffer, size_t nbytes); decoder_buffer_consume(DecoderBuffer *buffer, size_t nbytes);
/** /**
* Skips the specified number of bytes, discarding its data. * Skips the specified number of bytes, discarding its data.
...@@ -101,6 +100,6 @@ decoder_buffer_consume(struct decoder_buffer *buffer, size_t nbytes); ...@@ -101,6 +100,6 @@ decoder_buffer_consume(struct decoder_buffer *buffer, size_t nbytes);
* @return true on success, false on error * @return true on success, false on error
*/ */
bool bool
decoder_buffer_skip(struct decoder_buffer *buffer, size_t nbytes); decoder_buffer_skip(DecoderBuffer *buffer, size_t nbytes);
#endif #endif
...@@ -20,9 +20,7 @@ ...@@ -20,9 +20,7 @@
#include "config.h" #include "config.h"
#include "FaadDecoderPlugin.hxx" #include "FaadDecoderPlugin.hxx"
#include "decoder_api.h" #include "decoder_api.h"
extern "C" { #include "DecoderBuffer.hxx"
#include "decoder_buffer.h"
}
#include "audio_check.h" #include "audio_check.h"
#include "tag_handler.h" #include "tag_handler.h"
...@@ -73,7 +71,7 @@ adts_check_frame(const unsigned char *data) ...@@ -73,7 +71,7 @@ adts_check_frame(const unsigned char *data)
* found or if not enough data is available. * found or if not enough data is available.
*/ */
static size_t static size_t
adts_find_frame(struct decoder_buffer *buffer) adts_find_frame(DecoderBuffer *buffer)
{ {
size_t length, frame_length; size_t length, frame_length;
bool ret; bool ret;
...@@ -138,7 +136,7 @@ adts_find_frame(struct decoder_buffer *buffer) ...@@ -138,7 +136,7 @@ adts_find_frame(struct decoder_buffer *buffer)
} }
static float static float
adts_song_duration(struct decoder_buffer *buffer) adts_song_duration(DecoderBuffer *buffer)
{ {
unsigned int frames, frame_length; unsigned int frames, frame_length;
unsigned sample_rate = 0; unsigned sample_rate = 0;
...@@ -172,7 +170,7 @@ adts_song_duration(struct decoder_buffer *buffer) ...@@ -172,7 +170,7 @@ adts_song_duration(struct decoder_buffer *buffer)
} }
static float static float
faad_song_duration(struct decoder_buffer *buffer, struct input_stream *is) faad_song_duration(DecoderBuffer *buffer, struct input_stream *is)
{ {
size_t fileread; size_t fileread;
size_t tagsize; size_t tagsize;
...@@ -248,7 +246,7 @@ faad_song_duration(struct decoder_buffer *buffer, struct input_stream *is) ...@@ -248,7 +246,7 @@ faad_song_duration(struct decoder_buffer *buffer, struct input_stream *is)
* inconsistencies in libfaad. * inconsistencies in libfaad.
*/ */
static bool static bool
faad_decoder_init(NeAACDecHandle decoder, struct decoder_buffer *buffer, faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer *buffer,
struct audio_format *audio_format, GError **error_r) struct audio_format *audio_format, GError **error_r)
{ {
int32_t nbytes; int32_t nbytes;
...@@ -294,7 +292,7 @@ faad_decoder_init(NeAACDecHandle decoder, struct decoder_buffer *buffer, ...@@ -294,7 +292,7 @@ faad_decoder_init(NeAACDecHandle decoder, struct decoder_buffer *buffer,
* inconsistencies in libfaad. * inconsistencies in libfaad.
*/ */
static const void * static const void *
faad_decoder_decode(NeAACDecHandle decoder, struct decoder_buffer *buffer, faad_decoder_decode(NeAACDecHandle decoder, DecoderBuffer *buffer,
NeAACDecFrameInfo *frame_info) NeAACDecFrameInfo *frame_info)
{ {
size_t length; size_t length;
...@@ -317,7 +315,7 @@ faad_decoder_decode(NeAACDecHandle decoder, struct decoder_buffer *buffer, ...@@ -317,7 +315,7 @@ faad_decoder_decode(NeAACDecHandle decoder, struct decoder_buffer *buffer,
static float static float
faad_get_file_time_float(struct input_stream *is) faad_get_file_time_float(struct input_stream *is)
{ {
struct decoder_buffer *buffer; DecoderBuffer *buffer;
float length; float length;
buffer = decoder_buffer_new(nullptr, is, buffer = decoder_buffer_new(nullptr, is,
...@@ -374,7 +372,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is) ...@@ -374,7 +372,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
struct audio_format audio_format; struct audio_format audio_format;
bool ret; bool ret;
uint16_t bit_rate = 0; uint16_t bit_rate = 0;
struct decoder_buffer *buffer; DecoderBuffer *buffer;
enum decoder_command cmd; enum decoder_command cmd;
buffer = decoder_buffer_new(mpd_decoder, is, buffer = decoder_buffer_new(mpd_decoder, is,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment