DecoderBuffer: export the struct

Eliminates the functions _new() and _free().
This commit is contained in:
Max Kellermann 2014-09-22 08:18:58 +02:00
parent 13b66a77c7
commit 3ae0d6f421
3 changed files with 27 additions and 57 deletions

View File

@ -21,38 +21,9 @@
#include "DecoderBuffer.hxx" #include "DecoderBuffer.hxx"
#include "DecoderAPI.hxx" #include "DecoderAPI.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "util/DynamicFifoBuffer.hxx"
#include <assert.h> #include <assert.h>
struct DecoderBuffer {
Decoder *const decoder;
InputStream &is;
DynamicFifoBuffer<uint8_t> buffer;
DecoderBuffer(Decoder *_decoder, InputStream &_is,
size_t _size)
:decoder(_decoder), is(_is), buffer(_size) {}
};
DecoderBuffer *
decoder_buffer_new(Decoder *decoder, InputStream &is,
size_t size)
{
assert(size > 0);
return new DecoderBuffer(decoder, is, size);
}
void
decoder_buffer_free(DecoderBuffer *buffer)
{
assert(buffer != nullptr);
delete buffer;
}
const InputStream & const InputStream &
decoder_buffer_get_stream(const DecoderBuffer *buffer) decoder_buffer_get_stream(const DecoderBuffer *buffer)
{ {

View File

@ -21,38 +21,37 @@
#define MPD_DECODER_BUFFER_HXX #define MPD_DECODER_BUFFER_HXX
#include "Compiler.h" #include "Compiler.h"
#include "util/DynamicFifoBuffer.hxx"
#include <stddef.h> #include <stddef.h>
struct Decoder;
class InputStream;
template<typename T> struct ConstBuffer;
/** /**
* This objects handles buffered reads in decoder plugins easily. You * This objects handles buffered reads in decoder plugins easily. You
* 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 DecoderBuffer; struct DecoderBuffer {
Decoder *const decoder;
InputStream &is;
struct Decoder; DynamicFifoBuffer<uint8_t> buffer;
class InputStream;
template<typename T> struct ConstBuffer;
/** /**
* Creates a new buffer. * Creates a new buffer.
* *
* @param decoder the decoder object, used for decoder_read(), may be nullptr * @param _decoder the decoder object, used for decoder_read(),
* @param is the input stream object where we should read from * may be nullptr
* @param size the maximum size of the buffer * @param _is the input stream object where we should read from
* @return the new decoder_buffer object * @param _size the maximum size of the buffer
*/ */
DecoderBuffer * DecoderBuffer(Decoder *_decoder, InputStream &_is,
decoder_buffer_new(Decoder *decoder, InputStream &is, size_t _size)
size_t size); :decoder(_decoder), is(_is), buffer(_size) {}
};
/**
* Frees resources used by the decoder_buffer object.
*/
void
decoder_buffer_free(DecoderBuffer *buffer);
gcc_pure gcc_pure
const InputStream & const InputStream &

View File

@ -308,7 +308,7 @@ static std::pair<bool, SignedSongTime>
faad_get_file_time(InputStream &is) faad_get_file_time(InputStream &is)
{ {
DecoderBuffer *buffer = DecoderBuffer *buffer =
decoder_buffer_new(nullptr, is, new DecoderBuffer(nullptr, is,
FAAD_MIN_STREAMSIZE * MAX_CHANNELS); FAAD_MIN_STREAMSIZE * MAX_CHANNELS);
auto duration = faad_song_duration(buffer, is); auto duration = faad_song_duration(buffer, is);
bool recognized = !duration.IsNegative(); bool recognized = !duration.IsNegative();
@ -326,7 +326,7 @@ faad_get_file_time(InputStream &is)
NeAACDecClose(decoder); NeAACDecClose(decoder);
} }
decoder_buffer_free(buffer); delete buffer;
return std::make_pair(recognized, duration); return std::make_pair(recognized, duration);
} }
@ -415,7 +415,7 @@ static void
faad_stream_decode(Decoder &mpd_decoder, InputStream &is) faad_stream_decode(Decoder &mpd_decoder, InputStream &is)
{ {
DecoderBuffer *buffer = DecoderBuffer *buffer =
decoder_buffer_new(&mpd_decoder, is, new DecoderBuffer(&mpd_decoder, is,
FAAD_MIN_STREAMSIZE * MAX_CHANNELS); FAAD_MIN_STREAMSIZE * MAX_CHANNELS);
/* create the libfaad decoder */ /* create the libfaad decoder */
@ -427,7 +427,7 @@ faad_stream_decode(Decoder &mpd_decoder, InputStream &is)
/* cleanup */ /* cleanup */
NeAACDecClose(decoder); NeAACDecClose(decoder);
decoder_buffer_free(buffer); delete buffer;
} }
static bool static bool