{de,en}coder/{vorbis,flac,opus}: move several libraries to lib/xiph/
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "OggFind.hxx"
|
||||
#include "OggSyncState.hxx"
|
||||
#include "lib/xiph/OggSyncState.hxx"
|
||||
#include "input/InputStream.hxx"
|
||||
#include "util/Error.hxx"
|
||||
|
||||
|
@@ -1,77 +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_SYNC_STATE_HXX
|
||||
#define MPD_OGG_SYNC_STATE_HXX
|
||||
|
||||
#include "check.h"
|
||||
#include "OggUtil.hxx"
|
||||
|
||||
#include <ogg/ogg.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
* Wrapper for an ogg_sync_state.
|
||||
*/
|
||||
class OggSyncState {
|
||||
ogg_sync_state oy;
|
||||
|
||||
Reader &reader;
|
||||
|
||||
public:
|
||||
explicit OggSyncState(Reader &_reader)
|
||||
:reader(_reader) {
|
||||
ogg_sync_init(&oy);
|
||||
}
|
||||
|
||||
~OggSyncState() {
|
||||
ogg_sync_clear(&oy);
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
ogg_sync_reset(&oy);
|
||||
}
|
||||
|
||||
bool Feed(size_t size) {
|
||||
return OggFeed(oy, reader, size);
|
||||
}
|
||||
|
||||
bool ExpectPage(ogg_page &page) {
|
||||
return OggExpectPage(oy, page, reader);
|
||||
}
|
||||
|
||||
bool ExpectFirstPage(ogg_stream_state &os) {
|
||||
return OggExpectFirstPage(oy, os, reader);
|
||||
}
|
||||
|
||||
bool ExpectPageIn(ogg_stream_state &os) {
|
||||
return OggExpectPageIn(oy, os, reader);
|
||||
}
|
||||
|
||||
bool ExpectPageSeek(ogg_page &page) {
|
||||
return OggExpectPageSeek(oy, page, reader);
|
||||
}
|
||||
|
||||
bool ExpectPageSeekIn(ogg_stream_state &os) {
|
||||
return OggExpectPageSeekIn(oy, os, reader);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@@ -1,111 +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.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "OggUtil.hxx"
|
||||
#include "fs/io/Reader.hxx"
|
||||
|
||||
bool
|
||||
OggFeed(ogg_sync_state &oy, Reader &reader, size_t size)
|
||||
{
|
||||
char *buffer = ogg_sync_buffer(&oy, size);
|
||||
if (buffer == nullptr)
|
||||
return false;
|
||||
|
||||
size_t nbytes = reader.Read(buffer, size);
|
||||
if (nbytes == 0)
|
||||
return false;
|
||||
|
||||
ogg_sync_wrote(&oy, nbytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
OggExpectPage(ogg_sync_state &oy, ogg_page &page, Reader &reader)
|
||||
{
|
||||
while (true) {
|
||||
int r = ogg_sync_pageout(&oy, &page);
|
||||
if (r != 0)
|
||||
return r > 0;
|
||||
|
||||
if (!OggFeed(oy, reader, 1024))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader)
|
||||
{
|
||||
ogg_page page;
|
||||
if (!OggExpectPage(oy, page, reader))
|
||||
return false;
|
||||
|
||||
ogg_stream_init(&os, ogg_page_serialno(&page));
|
||||
ogg_stream_pagein(&os, &page);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader)
|
||||
{
|
||||
ogg_page page;
|
||||
if (!OggExpectPage(oy, page, reader))
|
||||
return false;
|
||||
|
||||
ogg_stream_pagein(&os, &page);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page, Reader &reader)
|
||||
{
|
||||
size_t remaining_skipped = 32768;
|
||||
|
||||
while (true) {
|
||||
int r = ogg_sync_pageseek(&oy, &page);
|
||||
if (r > 0)
|
||||
return true;
|
||||
|
||||
if (r < 0) {
|
||||
/* skipped -r bytes */
|
||||
size_t nbytes = -r;
|
||||
if (nbytes > remaining_skipped)
|
||||
/* still no ogg page - we lost our
|
||||
patience, abort */
|
||||
return false;
|
||||
|
||||
remaining_skipped -= nbytes;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!OggFeed(oy, reader, 1024))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os, Reader &reader)
|
||||
{
|
||||
ogg_page page;
|
||||
if (!OggExpectPageSeek(oy, page, reader))
|
||||
return false;
|
||||
|
||||
ogg_stream_pagein(&os, &page);
|
||||
return true;
|
||||
}
|
@@ -1,80 +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(), ogg_stream_init() and
|
||||
* ogg_stream_pagein().
|
||||
*
|
||||
* @return true if the stream was initialized and the first page was
|
||||
* delivered to it
|
||||
*/
|
||||
bool
|
||||
OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os, 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
|
@@ -23,7 +23,7 @@
|
||||
#include "OpusHead.hxx"
|
||||
#include "OpusTags.hxx"
|
||||
#include "OggFind.hxx"
|
||||
#include "OggSyncState.hxx"
|
||||
#include "lib/xiph/OggSyncState.hxx"
|
||||
#include "../DecoderAPI.hxx"
|
||||
#include "decoder/Reader.hxx"
|
||||
#include "input/Reader.hxx"
|
||||
|
@@ -1,110 +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.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "VorbisComments.hxx"
|
||||
#include "lib/xiph/XiphTags.hxx"
|
||||
#include "tag/TagTable.hxx"
|
||||
#include "tag/TagHandler.hxx"
|
||||
#include "tag/TagBuilder.hxx"
|
||||
#include "tag/VorbisComment.hxx"
|
||||
#include "tag/ReplayGain.hxx"
|
||||
#include "ReplayGainInfo.hxx"
|
||||
#include "util/DivideString.hxx"
|
||||
|
||||
bool
|
||||
vorbis_comments_to_replay_gain(ReplayGainInfo &rgi, char **comments)
|
||||
{
|
||||
rgi.Clear();
|
||||
|
||||
bool found = false;
|
||||
|
||||
while (*comments) {
|
||||
if (ParseReplayGainVorbis(rgi, *comments))
|
||||
found = true;
|
||||
|
||||
comments++;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the comment's name equals the passed name, and if so, copy
|
||||
* the comment value into the tag.
|
||||
*/
|
||||
static bool
|
||||
vorbis_copy_comment(const char *comment,
|
||||
const char *name, TagType tag_type,
|
||||
const TagHandler &handler, void *handler_ctx)
|
||||
{
|
||||
const char *value;
|
||||
|
||||
value = vorbis_comment_value(comment, name);
|
||||
if (value != nullptr) {
|
||||
tag_handler_invoke_tag(handler, handler_ctx, tag_type, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
vorbis_scan_comment(const char *comment,
|
||||
const TagHandler &handler, void *handler_ctx)
|
||||
{
|
||||
if (handler.pair != nullptr) {
|
||||
const DivideString split(comment, '=');
|
||||
if (split.IsDefined() && !split.IsEmpty())
|
||||
tag_handler_invoke_pair(handler, handler_ctx,
|
||||
split.GetFirst(),
|
||||
split.GetSecond());
|
||||
}
|
||||
|
||||
for (const struct tag_table *i = xiph_tags; i->name != nullptr; ++i)
|
||||
if (vorbis_copy_comment(comment, i->name, i->type,
|
||||
handler, handler_ctx))
|
||||
return;
|
||||
|
||||
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
||||
if (vorbis_copy_comment(comment,
|
||||
tag_item_names[i], TagType(i),
|
||||
handler, handler_ctx))
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
vorbis_comments_scan(char **comments,
|
||||
const TagHandler &handler, void *handler_ctx)
|
||||
{
|
||||
while (*comments)
|
||||
vorbis_scan_comment(*comments++,
|
||||
handler, handler_ctx);
|
||||
|
||||
}
|
||||
|
||||
Tag *
|
||||
vorbis_comments_to_tag(char **comments)
|
||||
{
|
||||
TagBuilder tag_builder;
|
||||
vorbis_comments_scan(comments, add_tag_handler, &tag_builder);
|
||||
return tag_builder.IsEmpty()
|
||||
? nullptr
|
||||
: tag_builder.CommitNew();
|
||||
}
|
@@ -1,39 +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_VORBIS_COMMENTS_HXX
|
||||
#define MPD_VORBIS_COMMENTS_HXX
|
||||
|
||||
#include "check.h"
|
||||
|
||||
struct ReplayGainInfo;
|
||||
struct TagHandler;
|
||||
struct Tag;
|
||||
|
||||
bool
|
||||
vorbis_comments_to_replay_gain(ReplayGainInfo &rgi, char **comments);
|
||||
|
||||
void
|
||||
vorbis_comments_scan(char **comments,
|
||||
const TagHandler &handler, void *handler_ctx);
|
||||
|
||||
Tag *
|
||||
vorbis_comments_to_tag(char **comments);
|
||||
|
||||
#endif
|
@@ -19,7 +19,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "VorbisDecoderPlugin.h"
|
||||
#include "VorbisComments.hxx"
|
||||
#include "lib/xiph/VorbisComments.hxx"
|
||||
#include "VorbisDomain.hxx"
|
||||
#include "../DecoderAPI.hxx"
|
||||
#include "input/InputStream.hxx"
|
||||
|
Reference in New Issue
Block a user