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