mpd/src/lib/xiph/OggStreamState.hxx

94 lines
2.1 KiB
C++
Raw Normal View History

/*
2020-01-18 19:22:19 +01:00
* Copyright 2003-2020 The Music Player Daemon Project
* 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.
*/
#ifndef MPD_OGG_STREAM_STATE_HXX
#define MPD_OGG_STREAM_STATE_HXX
#include <ogg/ogg.h>
#include <cassert>
#include <cstdint>
#include <string.h>
class OggStreamState {
ogg_stream_state state;
public:
2017-11-12 18:35:49 +01:00
explicit OggStreamState(int serialno) noexcept {
ogg_stream_init(&state, serialno);
}
/**
* Initialize a decoding #ogg_stream_state with the first
* page.
*/
2017-11-12 18:35:49 +01:00
explicit OggStreamState(ogg_page &page) noexcept {
ogg_stream_init(&state, ogg_page_serialno(&page));
PageIn(page);
}
2017-11-12 18:35:49 +01:00
~OggStreamState() noexcept {
ogg_stream_clear(&state);
}
2017-11-12 18:35:49 +01:00
operator ogg_stream_state &() noexcept {
return state;
}
2017-11-12 18:35:49 +01:00
void Reinitialize(int serialno) noexcept {
ogg_stream_reset_serialno(&state, serialno);
}
2017-11-12 18:35:49 +01:00
long GetSerialNo() const noexcept {
return state.serialno;
}
2017-11-12 18:35:49 +01:00
void Reset() noexcept {
ogg_stream_reset(&state);
}
/* encoding */
2017-11-12 18:35:49 +01:00
void PacketIn(const ogg_packet &packet) noexcept {
ogg_stream_packetin(&state,
const_cast<ogg_packet *>(&packet));
}
2017-11-12 18:35:49 +01:00
bool PageOut(ogg_page &page) noexcept {
return ogg_stream_pageout(&state, &page) != 0;
}
2017-11-12 18:35:49 +01:00
bool Flush(ogg_page &page) noexcept {
return ogg_stream_flush(&state, &page) != 0;
}
/* decoding */
2017-11-12 18:35:49 +01:00
bool PageIn(ogg_page &page) noexcept {
return ogg_stream_pagein(&state, &page) == 0;
}
2017-11-12 18:35:49 +01:00
int PacketOut(ogg_packet &packet) noexcept {
return ogg_stream_packetout(&state, &packet);
}
};
#endif