2013-01-07 23:06:02 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2013 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "OggFind.hxx"
|
2013-01-08 11:04:14 +01:00
|
|
|
#include "OggSyncState.hxx"
|
2013-10-24 20:33:12 +02:00
|
|
|
#include "InputStream.hxx"
|
|
|
|
#include "util/Error.hxx"
|
2013-01-07 23:06:02 +01:00
|
|
|
|
|
|
|
bool
|
2013-01-08 11:04:14 +01:00
|
|
|
OggFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet)
|
2013-01-07 23:06:02 +01:00
|
|
|
{
|
|
|
|
while (true) {
|
|
|
|
int r = ogg_stream_packetout(&os, &packet);
|
|
|
|
if (r == 0) {
|
2013-01-08 11:04:14 +01:00
|
|
|
if (!oy.ExpectPageIn(os))
|
2013-01-07 23:06:02 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
} else if (r > 0 && packet.e_o_s)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-10-24 20:33:12 +02:00
|
|
|
|
2013-10-24 20:40:23 +02:00
|
|
|
static bool
|
|
|
|
OggSeekPageAtOffset(OggSyncState &oy, ogg_stream_state &os, InputStream &is,
|
|
|
|
InputStream::offset_type offset, int whence)
|
|
|
|
{
|
|
|
|
oy.Reset();
|
|
|
|
|
2013-10-24 23:23:23 +02:00
|
|
|
/* reset the stream to clear any previous partial packet
|
|
|
|
data */
|
|
|
|
ogg_stream_reset(&os);
|
|
|
|
|
2013-10-24 20:40:23 +02:00
|
|
|
return is.LockSeek(offset, whence, IgnoreError()) &&
|
|
|
|
oy.ExpectPageSeekIn(os);
|
|
|
|
}
|
|
|
|
|
2013-10-24 20:33:12 +02:00
|
|
|
bool
|
|
|
|
OggSeekFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet,
|
|
|
|
InputStream &is)
|
|
|
|
{
|
|
|
|
if (is.size > 0 && is.size - is.offset < 65536)
|
|
|
|
return OggFindEOS(oy, os, packet);
|
|
|
|
|
|
|
|
if (!is.CheapSeeking())
|
|
|
|
return false;
|
|
|
|
|
2013-10-24 20:40:23 +02:00
|
|
|
return OggSeekPageAtOffset(oy, os, is, -65536, SEEK_END) &&
|
2013-10-24 20:33:12 +02:00
|
|
|
OggFindEOS(oy, os, packet);
|
|
|
|
}
|