NullEncoderPlugin.cxx 2.41 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2015 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

20
#include "config.h"
21
#include "NullEncoderPlugin.hxx"
22
#include "../EncoderAPI.hxx"
23 24
#include "util/Manual.hxx"
#include "util/DynamicFifoBuffer.hxx"
25
#include "Compiler.h"
26

27 28
#include <assert.h>

29
struct NullEncoder final {
30
	Encoder encoder;
31

32
	Manual<DynamicFifoBuffer<uint8_t>> buffer;
33

34 35
	NullEncoder()
		:encoder(null_encoder_plugin) {}
36
};
37

38
static Encoder *
39
null_encoder_init(gcc_unused const ConfigBlock &block,
40
		  gcc_unused Error &error)
41
{
42
	NullEncoder *encoder = new NullEncoder();
43 44 45 46
	return &encoder->encoder;
}

static void
47
null_encoder_finish(Encoder *_encoder)
48
{
49
	NullEncoder *encoder = (NullEncoder *)_encoder;
50

51
	delete encoder;
52 53
}

54
static void
55
null_encoder_close(Encoder *_encoder)
56
{
57
	NullEncoder *encoder = (NullEncoder *)_encoder;
58

59
	encoder->buffer.Destruct();
60 61 62
}


63
static bool
64
null_encoder_open(Encoder *_encoder,
65
		  gcc_unused AudioFormat &audio_format,
66
		  gcc_unused Error &error)
67
{
68
	NullEncoder *encoder = (NullEncoder *)_encoder;
69
	encoder->buffer.Construct(8192);
70 71 72 73
	return true;
}

static bool
74
null_encoder_write(Encoder *_encoder,
75
		   const void *data, size_t length,
76
		   gcc_unused Error &error)
77
{
78
	NullEncoder *encoder = (NullEncoder *)_encoder;
79

80
	encoder->buffer->Append((const uint8_t *)data, length);
81
	return length;
82 83 84
}

static size_t
85
null_encoder_read(Encoder *_encoder, void *dest, size_t length)
86
{
87
	NullEncoder *encoder = (NullEncoder *)_encoder;
88

89
	return encoder->buffer->Read((uint8_t *)dest, length);
90 91
}

92
const EncoderPlugin null_encoder_plugin = {
93 94 95 96 97 98 99 100 101 102 103 104
	"null",
	null_encoder_init,
	null_encoder_finish,
	null_encoder_open,
	null_encoder_close,
	nullptr,
	nullptr,
	nullptr,
	nullptr,
	null_encoder_write,
	null_encoder_read,
	nullptr,
105
};