MPD: encoder/plugins/OggEncoder.hxx Source File

MPD 0.20.18

OggEncoder.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_OGG_ENCODER_HXX
21 #define MPD_OGG_ENCODER_HXX
22
23 #include "config.h"
24 #include "../EncoderAPI.hxx"
25 #include "lib/xiph/OggStreamState.hxx"
26 #include "lib/xiph/OggPage.hxx"
27 #include "lib/xiph/OggSerial.hxx"
28
29 #include <ogg/ogg.h>
30
35 class OggEncoder : public Encoder {
36 /* initialize "flush" to true, so the caller gets the full
37 headers on the first read */
38 bool flush = true;
39
40 protected:
41 OggStreamState stream;
42
43 public:
44 OggEncoder(bool _implements_tag)
45 :Encoder(_implements_tag),
46 stream(GenerateOggSerial()) {
47 }
48
49 /* virtual methods from class Encoder */
50 void Flush() final {
51 flush = true;
52 }
53
54 size_t Read(void *dest, size_t length) override {
55 ogg_page page;
56 bool success = stream.PageOut(page);
57 if (!success) {
58 if (flush) {
59 flush = false;
60 success = stream.Flush(page);
61 }
62
63 if (!success)
64 return 0;
65 }
66
67 return ReadPage(page, dest, length);
68 }
69 };
70
71 #endif
OggSerial.hxx
ReadPage
static size_t ReadPage(const ogg_page &page, void *_buffer, size_t size)
Definition: OggPage.hxx:32
config.h
OggPage.hxx
OggStreamState::PageOut
bool PageOut(ogg_page &page)
Definition: OggStreamState.hxx:75
OggEncoder::stream
OggStreamState stream
Definition: OggEncoder.hxx:41
Encoder
Definition: EncoderInterface.hxx:32
OggStreamState
Definition: OggStreamState.hxx:31
OggStreamState.hxx
OggEncoder
An abstract base class which contains code common to all encoders with Ogg container output...
Definition: OggEncoder.hxx:35
OggEncoder::Read
size_t Read(void *dest, size_t length) override
Reads encoded data from the encoder.
Definition: OggEncoder.hxx:54
OggEncoder::Flush
void Flush() final
Flushes an encoder object, make everything which might currently be buffered available by Read()...
Definition: OggEncoder.hxx:50
OggStreamState::Flush
bool Flush(ogg_page &page)
Definition: OggStreamState.hxx:79
OggEncoder::OggEncoder
OggEncoder(bool _implements_tag)
Definition: OggEncoder.hxx:44
GenerateOggSerial
int GenerateOggSerial()
Generate the next pseudo-random Ogg serial.