MPD: lib/xiph/OggStreamState.hxx Source File

MPD 0.20.18

OggStreamState.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_STREAM_STATE_HXX
21 #define MPD_OGG_STREAM_STATE_HXX
22
23 #include "check.h"
24
25 #include <ogg/ogg.h>
26
27 #include <assert.h>
28 #include <string.h>
29 #include <stdint.h>
30
31 class OggStreamState {
32 ogg_stream_state state;
33
34 public:
35 explicit OggStreamState(int serialno) {
36 ogg_stream_init(&state, serialno);
37 }
38
43 explicit OggStreamState(ogg_page &page) {
44 ogg_stream_init(&state, ogg_page_serialno(&page));
45 PageIn(page);
46 }
47
48 ~OggStreamState() {
49 ogg_stream_clear(&state);
50 }
51
52 operator ogg_stream_state &() {
53 return state;
54 }
55
56 void Reinitialize(int serialno) {
57 ogg_stream_reset_serialno(&state, serialno);
58 }
59
60 long GetSerialNo() const {
61 return state.serialno;
62 }
63
64 void Reset() {
65 ogg_stream_reset(&state);
66 }
67
68 /* encoding */
69
70 void PacketIn(const ogg_packet &packet) {
71 ogg_stream_packetin(&state,
72 const_cast<ogg_packet *>(&packet));
73 }
74
75 bool PageOut(ogg_page &page) {
76 return ogg_stream_pageout(&state, &page) != 0;
77 }
78
79 bool Flush(ogg_page &page) {
80 return ogg_stream_flush(&state, &page) != 0;
81 }
82
83 /* decoding */
84
85 bool PageIn(ogg_page &page) {
86 return ogg_stream_pagein(&state, &page) == 0;
87 }
88
89 int PacketOut(ogg_packet &packet) {
90 return ogg_stream_packetout(&state, &packet);
91 }
92 };
93
94 #endif
check.h
OggStreamState::~OggStreamState
~OggStreamState()
Definition: OggStreamState.hxx:48
OggStreamState::PageOut
bool PageOut(ogg_page &page)
Definition: OggStreamState.hxx:75
OggStreamState::PacketIn
void PacketIn(const ogg_packet &packet)
Definition: OggStreamState.hxx:70
OggStreamState
Definition: OggStreamState.hxx:31
OggStreamState::Reinitialize
void Reinitialize(int serialno)
Definition: OggStreamState.hxx:56
OggStreamState::PageIn
bool PageIn(ogg_page &page)
Definition: OggStreamState.hxx:85
OggStreamState::Reset
void Reset()
Definition: OggStreamState.hxx:64
OggStreamState::PacketOut
int PacketOut(ogg_packet &packet)
Definition: OggStreamState.hxx:89
OggStreamState::Flush
bool Flush(ogg_page &page)
Definition: OggStreamState.hxx:79
OggStreamState::OggStreamState
OggStreamState(int serialno)
Definition: OggStreamState.hxx:35
OggStreamState::OggStreamState
OggStreamState(ogg_page &page)
Initialize a decoding #ogg_stream_state with the first page.
Definition: OggStreamState.hxx:43
OggStreamState::GetSerialNo
long GetSerialNo() const
Definition: OggStreamState.hxx:60