lib/xiph/OggUtil: move code into class OggSyncState

This commit is contained in:
Max Kellermann 2016-05-09 16:29:04 +02:00
parent 675e8667c2
commit f26159a0e3
4 changed files with 18 additions and 98 deletions

View File

@ -594,8 +594,7 @@ libxiph_a_CPPFLAGS = $(AM_CPPFLAGS) \
if HAVE_OGG
libxiph_a_SOURCES += \
src/lib/xiph/OggSerial.cxx src/lib/xiph/OggSerial.hxx \
src/lib/xiph/OggUtil.cxx src/lib/xiph/OggUtil.hxx \
src/lib/xiph/OggSyncState.hxx \
src/lib/xiph/OggSyncState.cxx src/lib/xiph/OggSyncState.hxx \
src/lib/xiph/OggPage.hxx \
src/lib/xiph/OggStreamState.hxx
endif

View File

@ -18,11 +18,11 @@
*/
#include "config.h"
#include "OggUtil.hxx"
#include "OggSyncState.hxx"
#include "fs/io/Reader.hxx"
bool
OggFeed(ogg_sync_state &oy, Reader &reader, size_t size)
OggSyncState::Feed(size_t size)
{
char *buffer = ogg_sync_buffer(&oy, size);
if (buffer == nullptr)
@ -37,23 +37,23 @@ OggFeed(ogg_sync_state &oy, Reader &reader, size_t size)
}
bool
OggExpectPage(ogg_sync_state &oy, ogg_page &page, Reader &reader)
OggSyncState::ExpectPage(ogg_page &page)
{
while (true) {
int r = ogg_sync_pageout(&oy, &page);
if (r != 0)
return r > 0;
if (!OggFeed(oy, reader, 1024))
if (!Feed(1024))
return false;
}
}
bool
OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader)
OggSyncState::ExpectPageIn(ogg_stream_state &os)
{
ogg_page page;
if (!OggExpectPage(oy, page, reader))
if (!ExpectPage(page))
return false;
ogg_stream_pagein(&os, &page);
@ -61,7 +61,7 @@ OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader)
}
bool
OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, Reader &reader)
OggSyncState::ExpectPageSeek(ogg_page &page)
{
size_t remaining_skipped = 32768;
@ -82,16 +82,16 @@ OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, Reader &reader)
continue;
}
if (!OggFeed(oy, reader, 1024))
if (!Feed(1024))
return false;
}
}
bool
OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader)
OggSyncState::ExpectPageSeekIn(ogg_stream_state &os)
{
ogg_page page;
if (!OggExpectPageSeek(oy, page, reader))
if (!ExpectPageSeek(page))
return false;
ogg_stream_pagein(&os, &page);

View File

@ -21,12 +21,13 @@
#define MPD_OGG_SYNC_STATE_HXX
#include "check.h"
#include "OggUtil.hxx"
#include <ogg/ogg.h>
#include <stddef.h>
class Reader;
/**
* Wrapper for an ogg_sync_state.
*/
@ -52,25 +53,15 @@ public:
ogg_sync_reset(&oy);
}
bool Feed(size_t size) {
return OggFeed(oy, reader, size);
}
bool Feed(size_t size);
bool ExpectPage(ogg_page &page) {
return OggExpectPage(oy, page, reader);
}
bool ExpectPage(ogg_page &page);
bool ExpectPageIn(ogg_stream_state &os) {
return OggExpectPageIn(oy, os, reader);
}
bool ExpectPageIn(ogg_stream_state &os);
bool ExpectPageSeek(ogg_page &page) {
return OggExpectPageSeek(oy, page, reader);
}
bool ExpectPageSeek(ogg_page &page);
bool ExpectPageSeekIn(ogg_stream_state &os) {
return OggExpectPageSeekIn(oy, os, reader);
}
bool ExpectPageSeekIn(ogg_stream_state &os);
};
#endif

View File

@ -1,70 +0,0 @@
/*
* Copyright 2003-2016 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_UTIL_HXX
#define MPD_OGG_UTIL_HXX
#include "check.h"
#include <ogg/ogg.h>
#include <stddef.h>
class Reader;
/**
* Feed data from the #InputStream into the #ogg_sync_state.
*
* @return false on error or end-of-file
*/
bool
OggFeed(ogg_sync_state &oy, Reader &reader, size_t size);
/**
* Feed into the #ogg_sync_state until a page gets available. Garbage
* data at the beginning is considered a fatal error.
*
* @return true if a page is available
*/
bool
OggExpectPage(ogg_sync_state &oy, ogg_page &page, Reader &reader);
/**
* Combines OggExpectPage() and ogg_stream_pagein().
*
* @return true if a page was delivered to the stream
*/
bool
OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader);
/**
* Like OggExpectPage(), but allow skipping garbage (after seeking).
*/
bool
OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, Reader &reader);
/**
* Combines OggExpectPageSeek() and ogg_stream_pagein().
*
* @return true if a page was delivered to the stream
*/
bool
OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader);
#endif