encoder/vorbis: add wrapper class for vorbis_comment
This commit is contained in:
parent
99d32dc0b4
commit
215213fc2c
@ -585,6 +585,7 @@ if HAVE_XIPH
|
||||
noinst_LIBRARIES += libxiph.a
|
||||
|
||||
libxiph_a_SOURCES = \
|
||||
src/lib/xiph/VorbisComment.hxx \
|
||||
src/lib/xiph/VorbisComments.cxx src/lib/xiph/VorbisComments.hxx \
|
||||
src/lib/xiph/XiphTags.cxx src/lib/xiph/XiphTags.hxx
|
||||
libxiph_a_CPPFLAGS = $(AM_CPPFLAGS) \
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "config.h"
|
||||
#include "VorbisEncoderPlugin.hxx"
|
||||
#include "OggEncoder.hxx"
|
||||
#include "lib/xiph/VorbisComment.hxx"
|
||||
#include "AudioFormat.hxx"
|
||||
#include "config/ConfigError.hxx"
|
||||
#include "util/StringUtil.hxx"
|
||||
@ -202,11 +203,8 @@ VorbisEncoder::HeaderOut(vorbis_comment &vc)
|
||||
void
|
||||
VorbisEncoder::SendHeader()
|
||||
{
|
||||
vorbis_comment vc;
|
||||
|
||||
vorbis_comment_init(&vc);
|
||||
VorbisComment vc;
|
||||
HeaderOut(vc);
|
||||
vorbis_comment_clear(&vc);
|
||||
}
|
||||
|
||||
Encoder *
|
||||
@ -260,24 +258,22 @@ VorbisEncoder::PreTag(gcc_unused Error &error)
|
||||
}
|
||||
|
||||
static void
|
||||
copy_tag_to_vorbis_comment(vorbis_comment *vc, const Tag &tag)
|
||||
copy_tag_to_vorbis_comment(VorbisComment &vc, const Tag &tag)
|
||||
{
|
||||
for (const auto &item : tag) {
|
||||
char name[64];
|
||||
ToUpperASCII(name, tag_item_names[item.type], sizeof(name));
|
||||
vorbis_comment_add_tag(vc, name, item.value);
|
||||
vc.AddTag(name, item.value);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
VorbisEncoder::SendTag(const Tag &tag, gcc_unused Error &error)
|
||||
{
|
||||
vorbis_comment comment;
|
||||
|
||||
/* write the vorbis_comment object */
|
||||
|
||||
vorbis_comment_init(&comment);
|
||||
copy_tag_to_vorbis_comment(&comment, tag);
|
||||
VorbisComment comment;
|
||||
copy_tag_to_vorbis_comment(comment, tag);
|
||||
|
||||
/* reset ogg_stream_state and begin a new stream */
|
||||
|
||||
@ -286,7 +282,6 @@ VorbisEncoder::SendTag(const Tag &tag, gcc_unused Error &error)
|
||||
/* send that vorbis_comment to the ogg_stream_state */
|
||||
|
||||
HeaderOut(comment);
|
||||
vorbis_comment_clear(&comment);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
58
src/lib/xiph/VorbisComment.hxx
Normal file
58
src/lib/xiph/VorbisComment.hxx
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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_COMMENT_HXX
|
||||
#define MPD_VORBIS_COMMENT_HXX
|
||||
|
||||
#include "check.h"
|
||||
|
||||
#include <vorbis/codec.h>
|
||||
|
||||
/**
|
||||
* OO wrapper for a #vorbis_comment instance.
|
||||
*/
|
||||
class VorbisComment {
|
||||
vorbis_comment vc;
|
||||
|
||||
public:
|
||||
VorbisComment() {
|
||||
vorbis_comment_init(&vc);
|
||||
}
|
||||
|
||||
~VorbisComment() {
|
||||
vorbis_comment_clear(&vc);
|
||||
}
|
||||
|
||||
VorbisComment(const VorbisComment &) = delete;
|
||||
VorbisComment &operator=(const VorbisComment &) = delete;
|
||||
|
||||
operator vorbis_comment &() {
|
||||
return vc;
|
||||
}
|
||||
|
||||
operator vorbis_comment *() {
|
||||
return &vc;
|
||||
}
|
||||
|
||||
void AddTag(const char *tag, const char *contents) {
|
||||
vorbis_comment_add_tag(&vc, tag, contents);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user