Audio file detection by content
This commit is contained in:
311
3rdparty/taglib/ogg/flac/oggflacfile.cpp
vendored
Normal file
311
3rdparty/taglib/ogg/flac/oggflacfile.cpp
vendored
Normal file
@@ -0,0 +1,311 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2004-2005 by Allan Sandfeld Jensen
|
||||
email : kde@carewolf.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <tbytevector.h>
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
#include <tpropertymap.h>
|
||||
#include <tagutils.h>
|
||||
|
||||
#include <xiphcomment.h>
|
||||
#include "oggflacfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
using TagLib::FLAC::Properties;
|
||||
|
||||
class Ogg::FLAC::File::FilePrivate
|
||||
{
|
||||
public:
|
||||
FilePrivate() :
|
||||
comment(0),
|
||||
properties(0),
|
||||
streamStart(0),
|
||||
streamLength(0),
|
||||
scanned(false),
|
||||
hasXiphComment(false),
|
||||
commentPacket(0) {}
|
||||
|
||||
~FilePrivate()
|
||||
{
|
||||
delete comment;
|
||||
delete properties;
|
||||
}
|
||||
|
||||
Ogg::XiphComment *comment;
|
||||
|
||||
Properties *properties;
|
||||
ByteVector streamInfoData;
|
||||
ByteVector xiphCommentData;
|
||||
long streamStart;
|
||||
long streamLength;
|
||||
bool scanned;
|
||||
|
||||
bool hasXiphComment;
|
||||
int commentPacket;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// static members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Ogg::FLAC::File::isSupported(IOStream *stream)
|
||||
{
|
||||
// An Ogg FLAC file has IDs "OggS" and "fLaC" somewhere.
|
||||
|
||||
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), false);
|
||||
return (buffer.find("OggS") >= 0 && buffer.find("fLaC") >= 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Ogg::FLAC::File::File(FileName file, bool readProperties,
|
||||
Properties::ReadStyle propertiesStyle) :
|
||||
Ogg::File(file),
|
||||
d(new FilePrivate())
|
||||
{
|
||||
if(isOpen())
|
||||
read(readProperties, propertiesStyle);
|
||||
}
|
||||
|
||||
Ogg::FLAC::File::File(IOStream *stream, bool readProperties,
|
||||
Properties::ReadStyle propertiesStyle) :
|
||||
Ogg::File(stream),
|
||||
d(new FilePrivate())
|
||||
{
|
||||
if(isOpen())
|
||||
read(readProperties, propertiesStyle);
|
||||
}
|
||||
|
||||
Ogg::FLAC::File::~File()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
Ogg::XiphComment *Ogg::FLAC::File::tag() const
|
||||
{
|
||||
return d->comment;
|
||||
}
|
||||
|
||||
PropertyMap Ogg::FLAC::File::properties() const
|
||||
{
|
||||
return d->comment->properties();
|
||||
}
|
||||
|
||||
PropertyMap Ogg::FLAC::File::setProperties(const PropertyMap &properties)
|
||||
{
|
||||
return d->comment->setProperties(properties);
|
||||
}
|
||||
|
||||
Properties *Ogg::FLAC::File::audioProperties() const
|
||||
{
|
||||
return d->properties;
|
||||
}
|
||||
|
||||
|
||||
bool Ogg::FLAC::File::save()
|
||||
{
|
||||
d->xiphCommentData = d->comment->render(false);
|
||||
|
||||
// Create FLAC metadata-block:
|
||||
|
||||
// Put the size in the first 32 bit (I assume no more than 24 bit are used)
|
||||
|
||||
ByteVector v = ByteVector::fromUInt(d->xiphCommentData.size());
|
||||
|
||||
// Set the type of the metadata-block to be a Xiph / Vorbis comment
|
||||
|
||||
v[0] = 4;
|
||||
|
||||
// Append the comment-data after the 32 bit header
|
||||
|
||||
v.append(d->xiphCommentData);
|
||||
|
||||
// Save the packet at the old spot
|
||||
// FIXME: Use padding if size is increasing
|
||||
|
||||
setPacket(d->commentPacket, v);
|
||||
|
||||
return Ogg::File::save();
|
||||
}
|
||||
|
||||
bool Ogg::FLAC::File::hasXiphComment() const
|
||||
{
|
||||
return d->hasXiphComment;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Ogg::FLAC::File::read(bool readProperties, Properties::ReadStyle propertiesStyle)
|
||||
{
|
||||
// Sanity: Check if we really have an Ogg/FLAC file
|
||||
|
||||
/*
|
||||
ByteVector oggHeader = packet(0);
|
||||
|
||||
if (oggHeader.mid(28,4) != "fLaC") {
|
||||
debug("Ogg::FLAC::File::read() -- Not an Ogg/FLAC file");
|
||||
setValid(false);
|
||||
return;
|
||||
}*/
|
||||
|
||||
// Look for FLAC metadata, including vorbis comments
|
||||
|
||||
scan();
|
||||
|
||||
if (!d->scanned) {
|
||||
setValid(false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(d->hasXiphComment)
|
||||
d->comment = new Ogg::XiphComment(xiphCommentData());
|
||||
else
|
||||
d->comment = new Ogg::XiphComment();
|
||||
|
||||
|
||||
if(readProperties)
|
||||
d->properties = new Properties(streamInfoData(), streamLength(), propertiesStyle);
|
||||
}
|
||||
|
||||
ByteVector Ogg::FLAC::File::streamInfoData()
|
||||
{
|
||||
scan();
|
||||
return d->streamInfoData;
|
||||
}
|
||||
|
||||
ByteVector Ogg::FLAC::File::xiphCommentData()
|
||||
{
|
||||
scan();
|
||||
return d->xiphCommentData;
|
||||
}
|
||||
|
||||
long Ogg::FLAC::File::streamLength()
|
||||
{
|
||||
scan();
|
||||
return d->streamLength;
|
||||
}
|
||||
|
||||
void Ogg::FLAC::File::scan()
|
||||
{
|
||||
// Scan the metadata pages
|
||||
|
||||
if(d->scanned)
|
||||
return;
|
||||
|
||||
if(!isValid())
|
||||
return;
|
||||
|
||||
int ipacket = 0;
|
||||
long overhead = 0;
|
||||
|
||||
ByteVector metadataHeader = packet(ipacket);
|
||||
if(metadataHeader.isEmpty())
|
||||
return;
|
||||
|
||||
if(!metadataHeader.startsWith("fLaC")) {
|
||||
// FLAC 1.1.2+
|
||||
if(metadataHeader.mid(1, 4) != "FLAC")
|
||||
return;
|
||||
|
||||
if(metadataHeader[5] != 1)
|
||||
return; // not version 1
|
||||
|
||||
metadataHeader = metadataHeader.mid(13);
|
||||
}
|
||||
else {
|
||||
// FLAC 1.1.0 & 1.1.1
|
||||
metadataHeader = packet(++ipacket);
|
||||
}
|
||||
|
||||
ByteVector header = metadataHeader.mid(0, 4);
|
||||
if(header.size() != 4) {
|
||||
debug("Ogg::FLAC::File::scan() -- Invalid Ogg/FLAC metadata header");
|
||||
return;
|
||||
}
|
||||
|
||||
// Header format (from spec):
|
||||
// <1> Last-metadata-block flag
|
||||
// <7> BLOCK_TYPE
|
||||
// 0 : STREAMINFO
|
||||
// 1 : PADDING
|
||||
// ..
|
||||
// 4 : VORBIS_COMMENT
|
||||
// ..
|
||||
// <24> Length of metadata to follow
|
||||
|
||||
char blockType = header[0] & 0x7f;
|
||||
bool lastBlock = (header[0] & 0x80) != 0;
|
||||
unsigned int length = header.toUInt(1, 3, true);
|
||||
overhead += length;
|
||||
|
||||
// Sanity: First block should be the stream_info metadata
|
||||
|
||||
if(blockType != 0) {
|
||||
debug("Ogg::FLAC::File::scan() -- Invalid Ogg/FLAC stream");
|
||||
return;
|
||||
}
|
||||
|
||||
d->streamInfoData = metadataHeader.mid(4, length);
|
||||
|
||||
// Search through the remaining metadata
|
||||
|
||||
while(!lastBlock) {
|
||||
metadataHeader = packet(++ipacket);
|
||||
header = metadataHeader.mid(0, 4);
|
||||
if(header.size() != 4) {
|
||||
debug("Ogg::FLAC::File::scan() -- Invalid Ogg/FLAC metadata header");
|
||||
return;
|
||||
}
|
||||
|
||||
blockType = header[0] & 0x7f;
|
||||
lastBlock = (header[0] & 0x80) != 0;
|
||||
length = header.toUInt(1, 3, true);
|
||||
overhead += length;
|
||||
|
||||
if(blockType == 1) {
|
||||
// debug("Ogg::FLAC::File::scan() -- Padding found");
|
||||
}
|
||||
else if(blockType == 4) {
|
||||
// debug("Ogg::FLAC::File::scan() -- Vorbis-comments found");
|
||||
d->xiphCommentData = metadataHeader.mid(4, length);
|
||||
d->hasXiphComment = true;
|
||||
d->commentPacket = ipacket;
|
||||
}
|
||||
else if(blockType > 5) {
|
||||
debug("Ogg::FLAC::File::scan() -- Unknown metadata block");
|
||||
}
|
||||
}
|
||||
|
||||
// End of metadata, now comes the datastream
|
||||
d->streamStart = overhead;
|
||||
d->streamLength = File::length() - d->streamStart;
|
||||
|
||||
d->scanned = true;
|
||||
}
|
||||
170
3rdparty/taglib/ogg/flac/oggflacfile.h
vendored
Normal file
170
3rdparty/taglib/ogg/flac/oggflacfile.h
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2004 by Allan Sandfeld Jensen
|
||||
email : kde@carewolf.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_OGGFLACFILE_H
|
||||
#define TAGLIB_OGGFLACFILE_H
|
||||
|
||||
#include "taglib_export.h"
|
||||
#include "oggfile.h"
|
||||
#include "xiphcomment.h"
|
||||
|
||||
#include "flacproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
class Tag;
|
||||
|
||||
namespace Ogg {
|
||||
|
||||
//! An implementation of Ogg FLAC metadata
|
||||
|
||||
/*!
|
||||
* This is implementation of FLAC metadata for Ogg FLAC files. For "pure"
|
||||
* FLAC files look under the FLAC hierarchy.
|
||||
*
|
||||
* Unlike "pure" FLAC-files, Ogg FLAC only supports Xiph-comments,
|
||||
* while the audio-properties are the same.
|
||||
*/
|
||||
namespace FLAC {
|
||||
|
||||
using TagLib::FLAC::Properties;
|
||||
|
||||
//! An implementation of TagLib::File with Ogg/FLAC specific methods
|
||||
|
||||
/*!
|
||||
* This implements and provides an interface for Ogg/FLAC files to the
|
||||
* TagLib::Tag and TagLib::AudioProperties interfaces by way of implementing
|
||||
* the abstract TagLib::File API as well as providing some additional
|
||||
* information specific to Ogg FLAC files.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT File : public Ogg::File
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Constructs an Ogg/FLAC file from \a file. If \a readProperties is true
|
||||
* the file's audio properties will also be read.
|
||||
*
|
||||
* \note In the current implementation, \a propertiesStyle is ignored.
|
||||
*/
|
||||
File(FileName file, bool readProperties = true,
|
||||
Properties::ReadStyle propertiesStyle = Properties::Average);
|
||||
|
||||
/*!
|
||||
* Constructs an Ogg/FLAC file from \a stream. If \a readProperties is true
|
||||
* the file's audio properties will also be read.
|
||||
*
|
||||
* \note TagLib will *not* take ownership of the stream, the caller is
|
||||
* responsible for deleting it after the File object.
|
||||
*
|
||||
* \note In the current implementation, \a propertiesStyle is ignored.
|
||||
*/
|
||||
File(IOStream *stream, bool readProperties = true,
|
||||
Properties::ReadStyle propertiesStyle = Properties::Average);
|
||||
|
||||
/*!
|
||||
* Destroys this instance of the File.
|
||||
*/
|
||||
virtual ~File();
|
||||
|
||||
/*!
|
||||
* Returns the Tag for this file. This will always be a XiphComment.
|
||||
*
|
||||
* \note This always returns a valid pointer regardless of whether or not
|
||||
* the file on disk has a XiphComment. Use hasXiphComment() to check if
|
||||
* the file on disk actually has a XiphComment.
|
||||
*
|
||||
* \note The Tag <b>is still</b> owned by the FLAC::File and should not be
|
||||
* deleted by the user. It will be deleted when the file (object) is
|
||||
* destroyed.
|
||||
*
|
||||
* \see hasXiphComment()
|
||||
*/
|
||||
virtual XiphComment *tag() const;
|
||||
|
||||
/*!
|
||||
* Returns the FLAC::Properties for this file. If no audio properties
|
||||
* were read then this will return a null pointer.
|
||||
*/
|
||||
virtual Properties *audioProperties() const;
|
||||
|
||||
|
||||
/*!
|
||||
* Implements the unified property interface -- export function.
|
||||
* This forwards directly to XiphComment::properties().
|
||||
*/
|
||||
PropertyMap properties() const;
|
||||
|
||||
/*!
|
||||
* Implements the unified tag dictionary interface -- import function.
|
||||
* Like properties(), this is a forwarder to the file's XiphComment.
|
||||
*/
|
||||
PropertyMap setProperties(const PropertyMap &);
|
||||
|
||||
|
||||
/*!
|
||||
* Save the file. This will primarily save and update the XiphComment.
|
||||
* Returns true if the save is successful.
|
||||
*/
|
||||
virtual bool save();
|
||||
|
||||
/*!
|
||||
* Returns the length of the audio-stream, used by FLAC::Properties for
|
||||
* calculating the bitrate.
|
||||
*/
|
||||
long streamLength();
|
||||
|
||||
/*!
|
||||
* Returns whether or not the file on disk actually has a XiphComment.
|
||||
*
|
||||
* \see tag()
|
||||
*/
|
||||
bool hasXiphComment() const;
|
||||
|
||||
/*!
|
||||
* Check if the given \a stream can be opened as an Ogg FLAC file.
|
||||
*
|
||||
* \note This method is designed to do a quick check. The result may
|
||||
* not necessarily be correct.
|
||||
*/
|
||||
static bool isSupported(IOStream *stream);
|
||||
|
||||
private:
|
||||
File(const File &);
|
||||
File &operator=(const File &);
|
||||
|
||||
void read(bool readProperties, Properties::ReadStyle propertiesStyle);
|
||||
void scan();
|
||||
ByteVector streamInfoData();
|
||||
ByteVector xiphCommentData();
|
||||
|
||||
class FilePrivate;
|
||||
FilePrivate *d;
|
||||
};
|
||||
} // namespace FLAC
|
||||
} // namespace Ogg
|
||||
} // namespace TagLib
|
||||
|
||||
#endif
|
||||
313
3rdparty/taglib/ogg/oggfile.cpp
vendored
Normal file
313
3rdparty/taglib/ogg/oggfile.cpp
vendored
Normal file
@@ -0,0 +1,313 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <tbytevectorlist.h>
|
||||
#include <tmap.h>
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
|
||||
#include "oggfile.h"
|
||||
#include "oggpage.h"
|
||||
#include "oggpageheader.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
namespace
|
||||
{
|
||||
// Returns the first packet index of the right next page to the given one.
|
||||
unsigned int nextPacketIndex(const Ogg::Page *page)
|
||||
{
|
||||
if(page->header()->lastPacketCompleted())
|
||||
return page->firstPacketIndex() + page->packetCount();
|
||||
else
|
||||
return page->firstPacketIndex() + page->packetCount() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
class Ogg::File::FilePrivate
|
||||
{
|
||||
public:
|
||||
FilePrivate() :
|
||||
firstPageHeader(0),
|
||||
lastPageHeader(0)
|
||||
{
|
||||
pages.setAutoDelete(true);
|
||||
}
|
||||
|
||||
~FilePrivate()
|
||||
{
|
||||
delete firstPageHeader;
|
||||
delete lastPageHeader;
|
||||
}
|
||||
|
||||
unsigned int streamSerialNumber;
|
||||
List<Page *> pages;
|
||||
PageHeader *firstPageHeader;
|
||||
PageHeader *lastPageHeader;
|
||||
Map<unsigned int, ByteVector> dirtyPackets;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Ogg::File::~File()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
ByteVector Ogg::File::packet(unsigned int i)
|
||||
{
|
||||
// Check to see if we're called setPacket() for this packet since the last
|
||||
// save:
|
||||
|
||||
if(d->dirtyPackets.contains(i))
|
||||
return d->dirtyPackets[i];
|
||||
|
||||
// If we haven't indexed the page where the packet we're interested in starts,
|
||||
// begin reading pages until we have.
|
||||
|
||||
if(!readPages(i)) {
|
||||
debug("Ogg::File::packet() -- Could not find the requested packet.");
|
||||
return ByteVector();
|
||||
}
|
||||
|
||||
// Look for the first page in which the requested packet starts.
|
||||
|
||||
List<Page *>::ConstIterator it = d->pages.begin();
|
||||
while((*it)->containsPacket(i) == Page::DoesNotContainPacket)
|
||||
++it;
|
||||
|
||||
// If the packet is completely contained in the first page that it's in.
|
||||
|
||||
// If the packet is *not* completely contained in the first page that it's a
|
||||
// part of then that packet trails off the end of the page. Continue appending
|
||||
// the pages' packet data until we hit a page that either does not end with the
|
||||
// packet that we're fetching or where the last packet is complete.
|
||||
|
||||
ByteVector packet = (*it)->packets()[i - (*it)->firstPacketIndex()];
|
||||
|
||||
while(nextPacketIndex(*it) <= i) {
|
||||
++it;
|
||||
packet.append((*it)->packets().front());
|
||||
}
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
void Ogg::File::setPacket(unsigned int i, const ByteVector &p)
|
||||
{
|
||||
if(!readPages(i)) {
|
||||
debug("Ogg::File::setPacket() -- Could not set the requested packet.");
|
||||
return;
|
||||
}
|
||||
|
||||
d->dirtyPackets[i] = p;
|
||||
}
|
||||
|
||||
const Ogg::PageHeader *Ogg::File::firstPageHeader()
|
||||
{
|
||||
if(!d->firstPageHeader) {
|
||||
const long firstPageHeaderOffset = find("OggS");
|
||||
if(firstPageHeaderOffset < 0)
|
||||
return 0;
|
||||
|
||||
d->firstPageHeader = new PageHeader(this, firstPageHeaderOffset);
|
||||
}
|
||||
|
||||
return d->firstPageHeader->isValid() ? d->firstPageHeader : 0;
|
||||
}
|
||||
|
||||
const Ogg::PageHeader *Ogg::File::lastPageHeader()
|
||||
{
|
||||
if(!d->lastPageHeader) {
|
||||
const long lastPageHeaderOffset = rfind("OggS");
|
||||
if(lastPageHeaderOffset < 0)
|
||||
return 0;
|
||||
|
||||
d->lastPageHeader = new PageHeader(this, lastPageHeaderOffset);
|
||||
}
|
||||
|
||||
return d->lastPageHeader->isValid() ? d->lastPageHeader : 0;
|
||||
}
|
||||
|
||||
bool Ogg::File::save()
|
||||
{
|
||||
if(readOnly()) {
|
||||
debug("Ogg::File::save() - Cannot save to a read only file.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<unsigned int, ByteVector>::ConstIterator it;
|
||||
for(it = d->dirtyPackets.begin(); it != d->dirtyPackets.end(); ++it)
|
||||
writePacket(it->first, it->second);
|
||||
|
||||
d->dirtyPackets.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// protected members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Ogg::File::File(FileName file) :
|
||||
TagLib::File(file),
|
||||
d(new FilePrivate())
|
||||
{
|
||||
}
|
||||
|
||||
Ogg::File::File(IOStream *stream) :
|
||||
TagLib::File(stream),
|
||||
d(new FilePrivate())
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Ogg::File::readPages(unsigned int i)
|
||||
{
|
||||
while(true) {
|
||||
unsigned int packetIndex;
|
||||
long offset;
|
||||
|
||||
if(d->pages.isEmpty()) {
|
||||
packetIndex = 0;
|
||||
offset = find("OggS");
|
||||
if(offset < 0)
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
const Page *page = d->pages.back();
|
||||
packetIndex = nextPacketIndex(page);
|
||||
offset = page->fileOffset() + page->size();
|
||||
}
|
||||
|
||||
// Enough pages have been fetched.
|
||||
|
||||
if(packetIndex > i)
|
||||
return true;
|
||||
|
||||
// Read the next page and add it to the page list.
|
||||
|
||||
Page *nextPage = new Page(this, offset);
|
||||
if(!nextPage->header()->isValid()) {
|
||||
delete nextPage;
|
||||
return false;
|
||||
}
|
||||
|
||||
nextPage->setFirstPacketIndex(packetIndex);
|
||||
d->pages.append(nextPage);
|
||||
|
||||
if(nextPage->header()->lastPageOfStream())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Ogg::File::writePacket(unsigned int i, const ByteVector &packet)
|
||||
{
|
||||
if(!readPages(i)) {
|
||||
debug("Ogg::File::writePacket() -- Could not find the requested packet.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Look for the pages where the requested packet should belong to.
|
||||
|
||||
List<Page *>::ConstIterator it = d->pages.begin();
|
||||
while((*it)->containsPacket(i) == Page::DoesNotContainPacket)
|
||||
++it;
|
||||
|
||||
const Page *firstPage = *it;
|
||||
|
||||
while(nextPacketIndex(*it) <= i)
|
||||
++it;
|
||||
|
||||
const Page *lastPage = *it;
|
||||
|
||||
// Replace the requested packet and create new pages to replace the located pages.
|
||||
|
||||
ByteVectorList packets = firstPage->packets();
|
||||
packets[i - firstPage->firstPacketIndex()] = packet;
|
||||
|
||||
if(firstPage != lastPage && lastPage->packetCount() > 1) {
|
||||
ByteVectorList lastPagePackets = lastPage->packets();
|
||||
lastPagePackets.erase(lastPagePackets.begin());
|
||||
packets.append(lastPagePackets);
|
||||
}
|
||||
|
||||
// TODO: This pagination method isn't accurate for what's being done here.
|
||||
// This should account for real possibilities like non-aligned packets and such.
|
||||
|
||||
List<Page *> pages = Page::paginate(packets,
|
||||
Page::SinglePagePerGroup,
|
||||
firstPage->header()->streamSerialNumber(),
|
||||
firstPage->pageSequenceNumber(),
|
||||
firstPage->header()->firstPacketContinued(),
|
||||
lastPage->header()->lastPacketCompleted());
|
||||
pages.setAutoDelete(true);
|
||||
|
||||
// Write the pages.
|
||||
|
||||
ByteVector data;
|
||||
for(it = pages.begin(); it != pages.end(); ++it)
|
||||
data.append((*it)->render());
|
||||
|
||||
const unsigned long originalOffset = firstPage->fileOffset();
|
||||
const unsigned long originalLength = lastPage->fileOffset() + lastPage->size() - originalOffset;
|
||||
|
||||
insert(data, originalOffset, originalLength);
|
||||
|
||||
// Renumber the following pages if the pages have been split or merged.
|
||||
|
||||
const int numberOfNewPages
|
||||
= pages.back()->pageSequenceNumber() - lastPage->pageSequenceNumber();
|
||||
|
||||
if(numberOfNewPages != 0) {
|
||||
long pageOffset = originalOffset + data.size();
|
||||
|
||||
while(true) {
|
||||
Page page(this, pageOffset);
|
||||
if(!page.header()->isValid())
|
||||
break;
|
||||
|
||||
page.setPageSequenceNumber(page.pageSequenceNumber() + numberOfNewPages);
|
||||
const ByteVector data = page.render();
|
||||
|
||||
seek(pageOffset + 18);
|
||||
writeBlock(data.mid(18, 8));
|
||||
|
||||
if(page.header()->lastPageOfStream())
|
||||
break;
|
||||
|
||||
pageOffset += page.size();
|
||||
}
|
||||
}
|
||||
|
||||
// Discard all the pages to keep them up-to-date by fetching them again.
|
||||
|
||||
d->pages.clear();
|
||||
}
|
||||
127
3rdparty/taglib/ogg/oggfile.h
vendored
Normal file
127
3rdparty/taglib/ogg/oggfile.h
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include "taglib_export.h"
|
||||
#include "tfile.h"
|
||||
#include "tbytevectorlist.h"
|
||||
|
||||
#ifndef TAGLIB_OGGFILE_H
|
||||
#define TAGLIB_OGGFILE_H
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
//! A namespace for the classes used by Ogg-based metadata files
|
||||
|
||||
namespace Ogg {
|
||||
|
||||
class PageHeader;
|
||||
|
||||
//! An implementation of TagLib::File with some helpers for Ogg based formats
|
||||
|
||||
/*!
|
||||
* This is an implementation of Ogg file page and packet rendering and is of
|
||||
* use to Ogg based formats. While the API is small this handles the
|
||||
* non-trivial details of breaking up an Ogg stream into packets and makes
|
||||
* these available (via subclassing) to the codec meta data implementations.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT File : public TagLib::File
|
||||
{
|
||||
public:
|
||||
virtual ~File();
|
||||
|
||||
/*!
|
||||
* Returns the packet contents for the i-th packet (starting from zero)
|
||||
* in the Ogg bitstream.
|
||||
*
|
||||
* \warning This requires reading at least the packet header for every page
|
||||
* up to the requested page.
|
||||
*/
|
||||
ByteVector packet(unsigned int i);
|
||||
|
||||
/*!
|
||||
* Sets the packet with index \a i to the value \a p.
|
||||
*/
|
||||
void setPacket(unsigned int i, const ByteVector &p);
|
||||
|
||||
/*!
|
||||
* Returns a pointer to the PageHeader for the first page in the stream or
|
||||
* null if the page could not be found.
|
||||
*/
|
||||
const PageHeader *firstPageHeader();
|
||||
|
||||
/*!
|
||||
* Returns a pointer to the PageHeader for the last page in the stream or
|
||||
* null if the page could not be found.
|
||||
*/
|
||||
const PageHeader *lastPageHeader();
|
||||
|
||||
virtual bool save();
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* Constructs an Ogg file from \a file.
|
||||
*
|
||||
* \note This constructor is protected since Ogg::File shouldn't be
|
||||
* instantiated directly but rather should be used through the codec
|
||||
* specific subclasses.
|
||||
*/
|
||||
File(FileName file);
|
||||
|
||||
/*!
|
||||
* Constructs an Ogg file from \a stream.
|
||||
*
|
||||
* \note This constructor is protected since Ogg::File shouldn't be
|
||||
* instantiated directly but rather should be used through the codec
|
||||
* specific subclasses.
|
||||
*
|
||||
* \note TagLib will *not* take ownership of the stream, the caller is
|
||||
* responsible for deleting it after the File object.
|
||||
*/
|
||||
File(IOStream *stream);
|
||||
|
||||
private:
|
||||
File(const File &);
|
||||
File &operator=(const File &);
|
||||
|
||||
/*!
|
||||
* Reads the pages from the beginning of the file until enough to compose
|
||||
* the requested packet.
|
||||
*/
|
||||
bool readPages(unsigned int i);
|
||||
|
||||
/*!
|
||||
* Writes the requested packet to the file.
|
||||
*/
|
||||
void writePacket(unsigned int i, const ByteVector &packet);
|
||||
|
||||
class FilePrivate;
|
||||
FilePrivate *d;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
308
3rdparty/taglib/ogg/oggpage.cpp
vendored
Normal file
308
3rdparty/taglib/ogg/oggpage.cpp
vendored
Normal file
@@ -0,0 +1,308 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
|
||||
#include "oggpage.h"
|
||||
#include "oggpageheader.h"
|
||||
#include "oggfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
class Ogg::Page::PagePrivate
|
||||
{
|
||||
public:
|
||||
PagePrivate(File *f = 0, long pageOffset = -1) :
|
||||
file(f),
|
||||
fileOffset(pageOffset),
|
||||
header(f, pageOffset),
|
||||
firstPacketIndex(-1) {}
|
||||
|
||||
File *file;
|
||||
long fileOffset;
|
||||
PageHeader header;
|
||||
int firstPacketIndex;
|
||||
ByteVectorList packets;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Ogg::Page::Page(Ogg::File *file, long pageOffset) :
|
||||
d(new PagePrivate(file, pageOffset))
|
||||
{
|
||||
}
|
||||
|
||||
Ogg::Page::~Page()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
long Ogg::Page::fileOffset() const
|
||||
{
|
||||
return d->fileOffset;
|
||||
}
|
||||
|
||||
const Ogg::PageHeader *Ogg::Page::header() const
|
||||
{
|
||||
return &d->header;
|
||||
}
|
||||
|
||||
int Ogg::Page::pageSequenceNumber() const
|
||||
{
|
||||
return d->header.pageSequenceNumber();
|
||||
}
|
||||
|
||||
void Ogg::Page::setPageSequenceNumber(int sequenceNumber)
|
||||
{
|
||||
d->header.setPageSequenceNumber(sequenceNumber);
|
||||
}
|
||||
|
||||
int Ogg::Page::firstPacketIndex() const
|
||||
{
|
||||
return d->firstPacketIndex;
|
||||
}
|
||||
|
||||
void Ogg::Page::setFirstPacketIndex(int index)
|
||||
{
|
||||
d->firstPacketIndex = index;
|
||||
}
|
||||
|
||||
Ogg::Page::ContainsPacketFlags Ogg::Page::containsPacket(int index) const
|
||||
{
|
||||
const int lastPacketIndex = d->firstPacketIndex + packetCount() - 1;
|
||||
if(index < d->firstPacketIndex || index > lastPacketIndex)
|
||||
return DoesNotContainPacket;
|
||||
|
||||
ContainsPacketFlags flags = DoesNotContainPacket;
|
||||
|
||||
if(index == d->firstPacketIndex)
|
||||
flags = ContainsPacketFlags(flags | BeginsWithPacket);
|
||||
|
||||
if(index == lastPacketIndex)
|
||||
flags = ContainsPacketFlags(flags | EndsWithPacket);
|
||||
|
||||
// If there's only one page and it's complete:
|
||||
|
||||
if(packetCount() == 1 &&
|
||||
!d->header.firstPacketContinued() &&
|
||||
d->header.lastPacketCompleted())
|
||||
{
|
||||
flags = ContainsPacketFlags(flags | CompletePacket);
|
||||
}
|
||||
|
||||
// Or if there is more than one page and the page is
|
||||
// (a) the first page and it's complete or
|
||||
// (b) the last page and it's complete or
|
||||
// (c) a page in the middle.
|
||||
else if(packetCount() > 1 &&
|
||||
((flags & BeginsWithPacket && !d->header.firstPacketContinued()) ||
|
||||
(flags & EndsWithPacket && d->header.lastPacketCompleted()) ||
|
||||
(!(flags & BeginsWithPacket) && !(flags & EndsWithPacket))))
|
||||
{
|
||||
flags = ContainsPacketFlags(flags | CompletePacket);
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
unsigned int Ogg::Page::packetCount() const
|
||||
{
|
||||
return d->header.packetSizes().size();
|
||||
}
|
||||
|
||||
ByteVectorList Ogg::Page::packets() const
|
||||
{
|
||||
if(!d->packets.isEmpty())
|
||||
return d->packets;
|
||||
|
||||
ByteVectorList l;
|
||||
|
||||
if(d->file && d->header.isValid()) {
|
||||
|
||||
d->file->seek(d->fileOffset + d->header.size());
|
||||
|
||||
List<int> packetSizes = d->header.packetSizes();
|
||||
|
||||
List<int>::ConstIterator it = packetSizes.begin();
|
||||
for(; it != packetSizes.end(); ++it)
|
||||
l.append(d->file->readBlock(*it));
|
||||
}
|
||||
else
|
||||
debug("Ogg::Page::packets() -- attempting to read packets from an invalid page.");
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
int Ogg::Page::size() const
|
||||
{
|
||||
return d->header.size() + d->header.dataSize();
|
||||
}
|
||||
|
||||
ByteVector Ogg::Page::render() const
|
||||
{
|
||||
ByteVector data;
|
||||
|
||||
data.append(d->header.render());
|
||||
|
||||
if(d->packets.isEmpty()) {
|
||||
if(d->file) {
|
||||
d->file->seek(d->fileOffset + d->header.size());
|
||||
data.append(d->file->readBlock(d->header.dataSize()));
|
||||
}
|
||||
else
|
||||
debug("Ogg::Page::render() -- this page is empty!");
|
||||
}
|
||||
else {
|
||||
ByteVectorList::ConstIterator it = d->packets.begin();
|
||||
for(; it != d->packets.end(); ++it)
|
||||
data.append(*it);
|
||||
}
|
||||
|
||||
// Compute and set the checksum for the Ogg page. The checksum is taken over
|
||||
// the entire page with the 4 bytes reserved for the checksum zeroed and then
|
||||
// inserted in bytes 22-25 of the page header.
|
||||
|
||||
const ByteVector checksum = ByteVector::fromUInt(data.checksum(), false);
|
||||
std::copy(checksum.begin(), checksum.end(), data.begin() + 22);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
List<Ogg::Page *> Ogg::Page::paginate(const ByteVectorList &packets,
|
||||
PaginationStrategy strategy,
|
||||
unsigned int streamSerialNumber,
|
||||
int firstPage,
|
||||
bool firstPacketContinued,
|
||||
bool lastPacketCompleted,
|
||||
bool containsLastPacket)
|
||||
{
|
||||
// SplitSize must be a multiple of 255 in order to get the lacing values right
|
||||
// create pages of about 8KB each
|
||||
|
||||
static const unsigned int SplitSize = 32 * 255;
|
||||
|
||||
// Force repagination if the segment table will exceed the size limit.
|
||||
|
||||
if(strategy != Repaginate) {
|
||||
|
||||
size_t tableSize = 0;
|
||||
for(ByteVectorList::ConstIterator it = packets.begin(); it != packets.end(); ++it)
|
||||
tableSize += it->size() / 255 + 1;
|
||||
|
||||
if(tableSize > 255)
|
||||
strategy = Repaginate;
|
||||
}
|
||||
|
||||
List<Page *> l;
|
||||
|
||||
// Handle creation of multiple pages with appropriate pagination.
|
||||
|
||||
if(strategy == Repaginate) {
|
||||
|
||||
int pageIndex = firstPage;
|
||||
|
||||
for(ByteVectorList::ConstIterator it = packets.begin(); it != packets.end(); ++it) {
|
||||
|
||||
const bool lastPacketInList = (it == --packets.end());
|
||||
|
||||
// mark very first packet?
|
||||
|
||||
bool continued = (firstPacketContinued && it == packets.begin());
|
||||
unsigned int pos = 0;
|
||||
|
||||
while(pos < it->size()) {
|
||||
|
||||
const bool lastSplit = (pos + SplitSize >= it->size());
|
||||
|
||||
ByteVectorList packetList;
|
||||
packetList.append(it->mid(pos, SplitSize));
|
||||
|
||||
l.append(new Page(packetList,
|
||||
streamSerialNumber,
|
||||
pageIndex,
|
||||
continued,
|
||||
lastSplit && (lastPacketInList ? lastPacketCompleted : true),
|
||||
lastSplit && (containsLastPacket && lastPacketInList)));
|
||||
pageIndex++;
|
||||
continued = true;
|
||||
|
||||
pos += SplitSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
l.append(new Page(packets,
|
||||
streamSerialNumber,
|
||||
firstPage,
|
||||
firstPacketContinued,
|
||||
lastPacketCompleted,
|
||||
containsLastPacket));
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
Ogg::Page* Ogg::Page::getCopyWithNewPageSequenceNumber(int /*sequenceNumber*/)
|
||||
{
|
||||
debug("Ogg::Page::getCopyWithNewPageSequenceNumber() -- This function is obsolete. Returning null.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// protected members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Ogg::Page::Page(const ByteVectorList &packets,
|
||||
unsigned int streamSerialNumber,
|
||||
int pageNumber,
|
||||
bool firstPacketContinued,
|
||||
bool lastPacketCompleted,
|
||||
bool containsLastPacket) :
|
||||
d(new PagePrivate())
|
||||
{
|
||||
d->header.setFirstPageOfStream(pageNumber == 0 && !firstPacketContinued);
|
||||
d->header.setLastPageOfStream(containsLastPacket);
|
||||
d->header.setFirstPacketContinued(firstPacketContinued);
|
||||
d->header.setLastPacketCompleted(lastPacketCompleted);
|
||||
d->header.setStreamSerialNumber(streamSerialNumber);
|
||||
d->header.setPageSequenceNumber(pageNumber);
|
||||
|
||||
// Build a page from the list of packets.
|
||||
|
||||
ByteVector data;
|
||||
List<int> packetSizes;
|
||||
|
||||
for(ByteVectorList::ConstIterator it = packets.begin(); it != packets.end(); ++it) {
|
||||
packetSizes.append((*it).size());
|
||||
data.append(*it);
|
||||
}
|
||||
d->packets = packets;
|
||||
d->header.setPacketSizes(packetSizes);
|
||||
}
|
||||
228
3rdparty/taglib/ogg/oggpage.h
vendored
Normal file
228
3rdparty/taglib/ogg/oggpage.h
vendored
Normal file
@@ -0,0 +1,228 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_OGGPAGE_H
|
||||
#define TAGLIB_OGGPAGE_H
|
||||
|
||||
#include "taglib_export.h"
|
||||
#include "tbytevectorlist.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace Ogg {
|
||||
|
||||
class File;
|
||||
class PageHeader;
|
||||
|
||||
//! An implementation of Ogg pages
|
||||
|
||||
/*!
|
||||
* This is an implementation of the pages that make up an Ogg stream.
|
||||
* This handles parsing pages and breaking them down into packets and handles
|
||||
* the details of packets spanning multiple pages and pages that contain
|
||||
* multiple packets.
|
||||
*
|
||||
* In most Xiph.org formats the comments are found in the first few packets,
|
||||
* this however is a reasonably complete implementation of Ogg pages that
|
||||
* could potentially be useful for non-meta data purposes.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT Page
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Read an Ogg page from the \a file at the position \a pageOffset.
|
||||
*/
|
||||
Page(File *file, long pageOffset);
|
||||
|
||||
virtual ~Page();
|
||||
|
||||
/*!
|
||||
* Returns the page's position within the file (in bytes).
|
||||
*/
|
||||
long fileOffset() const;
|
||||
|
||||
/*!
|
||||
* Returns a pointer to the header for this page. This pointer will become
|
||||
* invalid when the page is deleted.
|
||||
*/
|
||||
const PageHeader *header() const;
|
||||
|
||||
/*!
|
||||
* Returns the index of the page within the Ogg stream. This helps make it
|
||||
* possible to determine if pages have been lost.
|
||||
*
|
||||
* \see setPageSequenceNumber()
|
||||
*/
|
||||
int pageSequenceNumber() const;
|
||||
|
||||
/*!
|
||||
* Sets the page's position in the stream to \a sequenceNumber.
|
||||
*
|
||||
* \see pageSequenceNumber()
|
||||
*/
|
||||
void setPageSequenceNumber(int sequenceNumber);
|
||||
|
||||
/*!
|
||||
* Returns a copy of the page with \a sequenceNumber set as sequence number.
|
||||
*
|
||||
* \see header()
|
||||
* \see PageHeader::setPageSequenceNumber()
|
||||
*
|
||||
* \deprecated Always returns null.
|
||||
*/
|
||||
Page* getCopyWithNewPageSequenceNumber(int sequenceNumber);
|
||||
|
||||
/*!
|
||||
* Returns the index of the first packet wholly or partially contained in
|
||||
* this page.
|
||||
*
|
||||
* \see setFirstPacketIndex()
|
||||
*/
|
||||
int firstPacketIndex() const;
|
||||
|
||||
/*!
|
||||
* Sets the index of the first packet in the page.
|
||||
*
|
||||
* \see firstPacketIndex()
|
||||
*/
|
||||
void setFirstPacketIndex(int index);
|
||||
|
||||
/*!
|
||||
* When checking to see if a page contains a given packet this set of flags
|
||||
* represents the possible values for that packets status in the page.
|
||||
*
|
||||
* \see containsPacket()
|
||||
*/
|
||||
enum ContainsPacketFlags {
|
||||
//! No part of the packet is contained in the page
|
||||
DoesNotContainPacket = 0x0000,
|
||||
//! The packet is wholly contained in the page
|
||||
CompletePacket = 0x0001,
|
||||
//! The page starts with the given packet
|
||||
BeginsWithPacket = 0x0002,
|
||||
//! The page ends with the given packet
|
||||
EndsWithPacket = 0x0004
|
||||
};
|
||||
|
||||
/*!
|
||||
* Checks to see if the specified \a packet is contained in the current
|
||||
* page.
|
||||
*
|
||||
* \see ContainsPacketFlags
|
||||
*/
|
||||
ContainsPacketFlags containsPacket(int index) const;
|
||||
|
||||
/*!
|
||||
* Returns the number of packets (whole or partial) in this page.
|
||||
*/
|
||||
unsigned int packetCount() const;
|
||||
|
||||
/*!
|
||||
* Returns a list of the packets in this page.
|
||||
*
|
||||
* \note Either or both the first and last packets may be only partial.
|
||||
* \see PageHeader::firstPacketContinued()
|
||||
*/
|
||||
ByteVectorList packets() const;
|
||||
|
||||
/*!
|
||||
* Returns the size of the page in bytes.
|
||||
*/
|
||||
int size() const;
|
||||
|
||||
ByteVector render() const;
|
||||
|
||||
/*!
|
||||
* Defines a strategy for pagination, or grouping pages into Ogg packets,
|
||||
* for use with pagination methods.
|
||||
*
|
||||
* \note Yes, I'm aware that this is not a canonical "Strategy Pattern",
|
||||
* the term was simply convenient.
|
||||
*/
|
||||
enum PaginationStrategy {
|
||||
/*!
|
||||
* Attempt to put the specified set of packets into a single Ogg packet.
|
||||
* If the sum of the packet data is greater than will fit into a single
|
||||
* Ogg page -- 65280 bytes -- this will fall back to repagination using
|
||||
* the recommended page sizes.
|
||||
*/
|
||||
SinglePagePerGroup,
|
||||
/*!
|
||||
* Split the packet or group of packets into pages that conform to the
|
||||
* sizes recommended in the Ogg standard.
|
||||
*/
|
||||
Repaginate
|
||||
};
|
||||
|
||||
/*!
|
||||
* Pack \a packets into Ogg pages using the \a strategy for pagination.
|
||||
* The page number indicator inside of the rendered packets will start
|
||||
* with \a firstPage and be incremented for each page rendered.
|
||||
* \a containsLastPacket should be set to true if \a packets contains the
|
||||
* last page in the stream and will set the appropriate flag in the last
|
||||
* rendered Ogg page's header. \a streamSerialNumber should be set to
|
||||
* the serial number for this stream.
|
||||
*
|
||||
* \note The "absolute granule position" is currently always zeroed using
|
||||
* this method as this suffices for the comment headers.
|
||||
*
|
||||
* \warning The pages returned by this method must be deleted by the user.
|
||||
* You can use List<T>::setAutoDelete(true) to set these pages to be
|
||||
* automatically deleted when this list passes out of scope.
|
||||
*
|
||||
* \see PaginationStrategy
|
||||
* \see List::setAutoDelete()
|
||||
*/
|
||||
static List<Page *> paginate(const ByteVectorList &packets,
|
||||
PaginationStrategy strategy,
|
||||
unsigned int streamSerialNumber,
|
||||
int firstPage,
|
||||
bool firstPacketContinued = false,
|
||||
bool lastPacketCompleted = true,
|
||||
bool containsLastPacket = false);
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* Creates an Ogg packet based on the data in \a packets. The page number
|
||||
* for each page will be set to \a pageNumber.
|
||||
*/
|
||||
Page(const ByteVectorList &packets,
|
||||
unsigned int streamSerialNumber,
|
||||
int pageNumber,
|
||||
bool firstPacketContinued = false,
|
||||
bool lastPacketCompleted = true,
|
||||
bool containsLastPacket = false);
|
||||
|
||||
private:
|
||||
Page(const Page &);
|
||||
Page &operator=(const Page &);
|
||||
|
||||
class PagePrivate;
|
||||
PagePrivate *d;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
312
3rdparty/taglib/ogg/oggpageheader.cpp
vendored
Normal file
312
3rdparty/taglib/ogg/oggpageheader.cpp
vendored
Normal file
@@ -0,0 +1,312 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <bitset>
|
||||
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
#include <taglib.h>
|
||||
|
||||
#include "oggpageheader.h"
|
||||
#include "oggfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
class Ogg::PageHeader::PageHeaderPrivate
|
||||
{
|
||||
public:
|
||||
PageHeaderPrivate() :
|
||||
isValid(false),
|
||||
firstPacketContinued(false),
|
||||
lastPacketCompleted(false),
|
||||
firstPageOfStream(false),
|
||||
lastPageOfStream(false),
|
||||
absoluteGranularPosition(0),
|
||||
streamSerialNumber(0),
|
||||
pageSequenceNumber(-1),
|
||||
size(0),
|
||||
dataSize(0) {}
|
||||
|
||||
bool isValid;
|
||||
List<int> packetSizes;
|
||||
bool firstPacketContinued;
|
||||
bool lastPacketCompleted;
|
||||
bool firstPageOfStream;
|
||||
bool lastPageOfStream;
|
||||
long long absoluteGranularPosition;
|
||||
unsigned int streamSerialNumber;
|
||||
int pageSequenceNumber;
|
||||
int size;
|
||||
int dataSize;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Ogg::PageHeader::PageHeader(Ogg::File *file, long pageOffset) :
|
||||
d(new PageHeaderPrivate())
|
||||
{
|
||||
if(file && pageOffset >= 0)
|
||||
read(file, pageOffset);
|
||||
}
|
||||
|
||||
Ogg::PageHeader::~PageHeader()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool Ogg::PageHeader::isValid() const
|
||||
{
|
||||
return d->isValid;
|
||||
}
|
||||
|
||||
List<int> Ogg::PageHeader::packetSizes() const
|
||||
{
|
||||
return d->packetSizes;
|
||||
}
|
||||
|
||||
void Ogg::PageHeader::setPacketSizes(const List<int> &sizes)
|
||||
{
|
||||
d->packetSizes = sizes;
|
||||
}
|
||||
|
||||
bool Ogg::PageHeader::firstPacketContinued() const
|
||||
{
|
||||
return d->firstPacketContinued;
|
||||
}
|
||||
|
||||
void Ogg::PageHeader::setFirstPacketContinued(bool continued)
|
||||
{
|
||||
d->firstPacketContinued = continued;
|
||||
}
|
||||
|
||||
bool Ogg::PageHeader::lastPacketCompleted() const
|
||||
{
|
||||
return d->lastPacketCompleted;
|
||||
}
|
||||
|
||||
void Ogg::PageHeader::setLastPacketCompleted(bool completed)
|
||||
{
|
||||
d->lastPacketCompleted = completed;
|
||||
}
|
||||
|
||||
bool Ogg::PageHeader::firstPageOfStream() const
|
||||
{
|
||||
return d->firstPageOfStream;
|
||||
}
|
||||
|
||||
void Ogg::PageHeader::setFirstPageOfStream(bool first)
|
||||
{
|
||||
d->firstPageOfStream = first;
|
||||
}
|
||||
|
||||
bool Ogg::PageHeader::lastPageOfStream() const
|
||||
{
|
||||
return d->lastPageOfStream;
|
||||
}
|
||||
|
||||
void Ogg::PageHeader::setLastPageOfStream(bool last)
|
||||
{
|
||||
d->lastPageOfStream = last;
|
||||
}
|
||||
|
||||
long long Ogg::PageHeader::absoluteGranularPosition() const
|
||||
{
|
||||
return d->absoluteGranularPosition;
|
||||
}
|
||||
|
||||
void Ogg::PageHeader::setAbsoluteGranularPosition(long long agp)
|
||||
{
|
||||
d->absoluteGranularPosition = agp;
|
||||
}
|
||||
|
||||
int Ogg::PageHeader::pageSequenceNumber() const
|
||||
{
|
||||
return d->pageSequenceNumber;
|
||||
}
|
||||
|
||||
void Ogg::PageHeader::setPageSequenceNumber(int sequenceNumber)
|
||||
{
|
||||
d->pageSequenceNumber = sequenceNumber;
|
||||
}
|
||||
|
||||
unsigned int Ogg::PageHeader::streamSerialNumber() const
|
||||
{
|
||||
return d->streamSerialNumber;
|
||||
}
|
||||
|
||||
void Ogg::PageHeader::setStreamSerialNumber(unsigned int n)
|
||||
{
|
||||
d->streamSerialNumber = n;
|
||||
}
|
||||
|
||||
int Ogg::PageHeader::size() const
|
||||
{
|
||||
return d->size;
|
||||
}
|
||||
|
||||
int Ogg::PageHeader::dataSize() const
|
||||
{
|
||||
return d->dataSize;
|
||||
}
|
||||
|
||||
ByteVector Ogg::PageHeader::render() const
|
||||
{
|
||||
ByteVector data;
|
||||
|
||||
// capture pattern
|
||||
|
||||
data.append("OggS");
|
||||
|
||||
// stream structure version
|
||||
|
||||
data.append(char(0));
|
||||
|
||||
// header type flag
|
||||
|
||||
std::bitset<8> flags;
|
||||
flags[0] = d->firstPacketContinued;
|
||||
flags[1] = d->pageSequenceNumber == 0;
|
||||
flags[2] = d->lastPageOfStream;
|
||||
|
||||
data.append(char(flags.to_ulong()));
|
||||
|
||||
// absolute granular position
|
||||
|
||||
data.append(ByteVector::fromLongLong(d->absoluteGranularPosition, false));
|
||||
|
||||
// stream serial number
|
||||
|
||||
data.append(ByteVector::fromUInt(d->streamSerialNumber, false));
|
||||
|
||||
// page sequence number
|
||||
|
||||
data.append(ByteVector::fromUInt(d->pageSequenceNumber, false));
|
||||
|
||||
// checksum -- this is left empty and should be filled in by the Ogg::Page
|
||||
// class
|
||||
|
||||
data.append(ByteVector(4, 0));
|
||||
|
||||
// page segment count and page segment table
|
||||
|
||||
ByteVector pageSegments = lacingValues();
|
||||
|
||||
data.append(static_cast<unsigned char>(pageSegments.size()));
|
||||
data.append(pageSegments);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Ogg::PageHeader::read(Ogg::File *file, long pageOffset)
|
||||
{
|
||||
file->seek(pageOffset);
|
||||
|
||||
// An Ogg page header is at least 27 bytes, so we'll go ahead and read that
|
||||
// much and then get the rest when we're ready for it.
|
||||
|
||||
const ByteVector data = file->readBlock(27);
|
||||
|
||||
// Sanity check -- make sure that we were in fact able to read as much data as
|
||||
// we asked for and that the page begins with "OggS".
|
||||
|
||||
if(data.size() != 27 || !data.startsWith("OggS")) {
|
||||
debug("Ogg::PageHeader::read() -- error reading page header");
|
||||
return;
|
||||
}
|
||||
|
||||
const std::bitset<8> flags(data[5]);
|
||||
|
||||
d->firstPacketContinued = flags.test(0);
|
||||
d->firstPageOfStream = flags.test(1);
|
||||
d->lastPageOfStream = flags.test(2);
|
||||
|
||||
d->absoluteGranularPosition = data.toLongLong(6, false);
|
||||
d->streamSerialNumber = data.toUInt(14, false);
|
||||
d->pageSequenceNumber = data.toUInt(18, false);
|
||||
|
||||
// Byte number 27 is the number of page segments, which is the only variable
|
||||
// length portion of the page header. After reading the number of page
|
||||
// segments we'll then read in the corresponding data for this count.
|
||||
|
||||
int pageSegmentCount = static_cast<unsigned char>(data[26]);
|
||||
|
||||
const ByteVector pageSegments = file->readBlock(pageSegmentCount);
|
||||
|
||||
// Another sanity check.
|
||||
|
||||
if(pageSegmentCount < 1 || int(pageSegments.size()) != pageSegmentCount)
|
||||
return;
|
||||
|
||||
// The base size of an Ogg page 27 bytes plus the number of lacing values.
|
||||
|
||||
d->size = 27 + pageSegmentCount;
|
||||
|
||||
int packetSize = 0;
|
||||
|
||||
for(int i = 0; i < pageSegmentCount; i++) {
|
||||
d->dataSize += static_cast<unsigned char>(pageSegments[i]);
|
||||
packetSize += static_cast<unsigned char>(pageSegments[i]);
|
||||
|
||||
if(static_cast<unsigned char>(pageSegments[i]) < 255) {
|
||||
d->packetSizes.append(packetSize);
|
||||
packetSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(packetSize > 0) {
|
||||
d->packetSizes.append(packetSize);
|
||||
d->lastPacketCompleted = false;
|
||||
}
|
||||
else
|
||||
d->lastPacketCompleted = true;
|
||||
|
||||
d->isValid = true;
|
||||
}
|
||||
|
||||
ByteVector Ogg::PageHeader::lacingValues() const
|
||||
{
|
||||
ByteVector data;
|
||||
|
||||
for(List<int>::ConstIterator it = d->packetSizes.begin(); it != d->packetSizes.end(); ++it) {
|
||||
|
||||
// The size of a packet in an Ogg page is indicated by a series of "lacing
|
||||
// values" where the sum of the values is the packet size in bytes. Each of
|
||||
// these values is a byte. A value of less than 255 (0xff) indicates the end
|
||||
// of the packet.
|
||||
|
||||
data.resize(data.size() + (*it / 255), '\xff');
|
||||
|
||||
if(it != --d->packetSizes.end() || d->lastPacketCompleted)
|
||||
data.append(static_cast<unsigned char>(*it % 255));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
232
3rdparty/taglib/ogg/oggpageheader.h
vendored
Normal file
232
3rdparty/taglib/ogg/oggpageheader.h
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_OGGPAGEHEADER_H
|
||||
#define TAGLIB_OGGPAGEHEADER_H
|
||||
|
||||
#include "tlist.h"
|
||||
#include "tbytevector.h"
|
||||
#include "taglib_export.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace Ogg {
|
||||
|
||||
class File;
|
||||
|
||||
//! An implementation of the page headers associated with each Ogg::Page
|
||||
|
||||
/*!
|
||||
* This class implements Ogg page headers which contain the information
|
||||
* about Ogg pages needed to break them into packets which can be passed on
|
||||
* to the codecs.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT PageHeader
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Reads a PageHeader from \a file starting at \a pageOffset. The defaults
|
||||
* create a page with no (and as such, invalid) data that must be set
|
||||
* later.
|
||||
*/
|
||||
PageHeader(File *file = 0, long pageOffset = -1);
|
||||
|
||||
/*!
|
||||
* Deletes this instance of the PageHeader.
|
||||
*/
|
||||
virtual ~PageHeader();
|
||||
|
||||
/*!
|
||||
* Returns true if the header parsed properly and is valid.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/*!
|
||||
* Ogg pages contain a list of packets (which are used by the contained
|
||||
* codecs). The sizes of these pages is encoded in the page header. This
|
||||
* returns a list of the packet sizes in bytes.
|
||||
*
|
||||
* \see setPacketSizes()
|
||||
*/
|
||||
List<int> packetSizes() const;
|
||||
|
||||
/*!
|
||||
* Sets the sizes of the packets in this page to \a sizes. Internally this
|
||||
* updates the lacing values in the header.
|
||||
*
|
||||
* \see packetSizes()
|
||||
*/
|
||||
void setPacketSizes(const List<int> &sizes);
|
||||
|
||||
/*!
|
||||
* Some packets can be <i>continued</i> across multiple pages. If the
|
||||
* first packet in the current page is a continuation this will return
|
||||
* true. If this is page starts with a new packet this will return false.
|
||||
*
|
||||
* \see lastPacketCompleted()
|
||||
* \see setFirstPacketContinued()
|
||||
*/
|
||||
bool firstPacketContinued() const;
|
||||
|
||||
/*!
|
||||
* Sets the internal flag indicating if the first packet in this page is
|
||||
* continued to \a continued.
|
||||
*
|
||||
* \see firstPacketContinued()
|
||||
*/
|
||||
void setFirstPacketContinued(bool continued);
|
||||
|
||||
/*!
|
||||
* Returns true if the last packet of this page is completely contained in
|
||||
* this page.
|
||||
*
|
||||
* \see firstPacketContinued()
|
||||
* \see setLastPacketCompleted()
|
||||
*/
|
||||
bool lastPacketCompleted() const;
|
||||
|
||||
/*!
|
||||
* Sets the internal flag indicating if the last packet in this page is
|
||||
* complete to \a completed.
|
||||
*
|
||||
* \see lastPacketCompleted()
|
||||
*/
|
||||
void setLastPacketCompleted(bool completed);
|
||||
|
||||
/*!
|
||||
* This returns true if this is the first page of the Ogg (logical) stream.
|
||||
*
|
||||
* \see setFirstPageOfStream()
|
||||
*/
|
||||
bool firstPageOfStream() const;
|
||||
|
||||
/*!
|
||||
* Marks this page as the first page of the Ogg stream.
|
||||
*
|
||||
* \see firstPageOfStream()
|
||||
*/
|
||||
void setFirstPageOfStream(bool first);
|
||||
|
||||
/*!
|
||||
* This returns true if this is the last page of the Ogg (logical) stream.
|
||||
*
|
||||
* \see setLastPageOfStream()
|
||||
*/
|
||||
bool lastPageOfStream() const;
|
||||
|
||||
/*!
|
||||
* Marks this page as the last page of the Ogg stream.
|
||||
*
|
||||
* \see lastPageOfStream()
|
||||
*/
|
||||
void setLastPageOfStream(bool last);
|
||||
|
||||
/*!
|
||||
* A special value of containing the position of the packet to be
|
||||
* interpreted by the codec. In the case of Vorbis this contains the PCM
|
||||
* value and is used to calculate the length of the stream.
|
||||
*
|
||||
* \see setAbsoluteGranularPosition()
|
||||
*/
|
||||
long long absoluteGranularPosition() const;
|
||||
|
||||
/*!
|
||||
* A special value of containing the position of the packet to be
|
||||
* interpreted by the codec. It is only supported here so that it may be
|
||||
* coppied from one page to another.
|
||||
*
|
||||
* \see absoluteGranularPosition()
|
||||
*/
|
||||
void setAbsoluteGranularPosition(long long agp);
|
||||
|
||||
/*!
|
||||
* Every Ogg logical stream is given a random serial number which is common
|
||||
* to every page in that logical stream. This returns the serial number of
|
||||
* the stream associated with this packet.
|
||||
*
|
||||
* \see setStreamSerialNumber()
|
||||
*/
|
||||
unsigned int streamSerialNumber() const;
|
||||
|
||||
/*!
|
||||
* Every Ogg logical stream is given a random serial number which is common
|
||||
* to every page in that logical stream. This sets this pages serial
|
||||
* number. This method should be used when adding new pages to a logical
|
||||
* stream.
|
||||
*
|
||||
* \see streamSerialNumber()
|
||||
*/
|
||||
void setStreamSerialNumber(unsigned int n);
|
||||
|
||||
/*!
|
||||
* Returns the index of the page within the Ogg stream. This helps make it
|
||||
* possible to determine if pages have been lost.
|
||||
*
|
||||
* \see setPageSequenceNumber()
|
||||
*/
|
||||
int pageSequenceNumber() const;
|
||||
|
||||
/*!
|
||||
* Sets the page's position in the stream to \a sequenceNumber.
|
||||
*
|
||||
* \see pageSequenceNumber()
|
||||
*/
|
||||
void setPageSequenceNumber(int sequenceNumber);
|
||||
|
||||
/*!
|
||||
* Returns the complete header size.
|
||||
*/
|
||||
int size() const;
|
||||
|
||||
/*!
|
||||
* Returns the size of the data portion of the page -- i.e. the size of the
|
||||
* page less the header size.
|
||||
*/
|
||||
int dataSize() const;
|
||||
|
||||
/*!
|
||||
* Render the page header to binary data.
|
||||
*
|
||||
* \note The checksum -- bytes 22 - 25 -- will be left empty and must be
|
||||
* filled in when rendering the entire page.
|
||||
*/
|
||||
ByteVector render() const;
|
||||
|
||||
private:
|
||||
PageHeader(const PageHeader &);
|
||||
PageHeader &operator=(const PageHeader &);
|
||||
|
||||
void read(Ogg::File *file, long pageOffset);
|
||||
ByteVector lacingValues() const;
|
||||
|
||||
class PageHeaderPrivate;
|
||||
PageHeaderPrivate *d;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
150
3rdparty/taglib/ogg/opus/opusfile.cpp
vendored
Normal file
150
3rdparty/taglib/ogg/opus/opusfile.cpp
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2012 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
(original Vorbis implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
#include <tpropertymap.h>
|
||||
#include <tagutils.h>
|
||||
|
||||
#include "opusfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
using namespace TagLib::Ogg;
|
||||
|
||||
class Opus::File::FilePrivate
|
||||
{
|
||||
public:
|
||||
FilePrivate() :
|
||||
comment(0),
|
||||
properties(0) {}
|
||||
|
||||
~FilePrivate()
|
||||
{
|
||||
delete comment;
|
||||
delete properties;
|
||||
}
|
||||
|
||||
Ogg::XiphComment *comment;
|
||||
Properties *properties;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// static members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Ogg::Opus::File::isSupported(IOStream *stream)
|
||||
{
|
||||
// An Opus file has IDs "OggS" and "OpusHead" somewhere.
|
||||
|
||||
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), false);
|
||||
return (buffer.find("OggS") >= 0 && buffer.find("OpusHead") >= 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Opus::File::File(FileName file, bool readProperties, Properties::ReadStyle) :
|
||||
Ogg::File(file),
|
||||
d(new FilePrivate())
|
||||
{
|
||||
if(isOpen())
|
||||
read(readProperties);
|
||||
}
|
||||
|
||||
Opus::File::File(IOStream *stream, bool readProperties, Properties::ReadStyle) :
|
||||
Ogg::File(stream),
|
||||
d(new FilePrivate())
|
||||
{
|
||||
if(isOpen())
|
||||
read(readProperties);
|
||||
}
|
||||
|
||||
Opus::File::~File()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
Ogg::XiphComment *Opus::File::tag() const
|
||||
{
|
||||
return d->comment;
|
||||
}
|
||||
|
||||
PropertyMap Opus::File::properties() const
|
||||
{
|
||||
return d->comment->properties();
|
||||
}
|
||||
|
||||
PropertyMap Opus::File::setProperties(const PropertyMap &properties)
|
||||
{
|
||||
return d->comment->setProperties(properties);
|
||||
}
|
||||
|
||||
Opus::Properties *Opus::File::audioProperties() const
|
||||
{
|
||||
return d->properties;
|
||||
}
|
||||
|
||||
bool Opus::File::save()
|
||||
{
|
||||
if(!d->comment)
|
||||
d->comment = new Ogg::XiphComment();
|
||||
|
||||
setPacket(1, ByteVector("OpusTags", 8) + d->comment->render(false));
|
||||
|
||||
return Ogg::File::save();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Opus::File::read(bool readProperties)
|
||||
{
|
||||
ByteVector opusHeaderData = packet(0);
|
||||
|
||||
if(!opusHeaderData.startsWith("OpusHead")) {
|
||||
setValid(false);
|
||||
debug("Opus::File::read() -- invalid Opus identification header");
|
||||
return;
|
||||
}
|
||||
|
||||
ByteVector commentHeaderData = packet(1);
|
||||
|
||||
if(!commentHeaderData.startsWith("OpusTags")) {
|
||||
setValid(false);
|
||||
debug("Opus::File::read() -- invalid Opus tags header");
|
||||
return;
|
||||
}
|
||||
|
||||
d->comment = new Ogg::XiphComment(commentHeaderData.mid(8));
|
||||
|
||||
if(readProperties)
|
||||
d->properties = new Properties(this);
|
||||
}
|
||||
138
3rdparty/taglib/ogg/opus/opusfile.h
vendored
Normal file
138
3rdparty/taglib/ogg/opus/opusfile.h
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2012 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
(original Vorbis implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_OPUSFILE_H
|
||||
#define TAGLIB_OPUSFILE_H
|
||||
|
||||
#include "oggfile.h"
|
||||
#include "xiphcomment.h"
|
||||
|
||||
#include "opusproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace Ogg {
|
||||
|
||||
//! A namespace containing classes for Opus metadata
|
||||
|
||||
namespace Opus {
|
||||
|
||||
//! An implementation of Ogg::File with Opus specific methods
|
||||
|
||||
/*!
|
||||
* This is the central class in the Ogg Opus metadata processing collection
|
||||
* of classes. It's built upon Ogg::File which handles processing of the Ogg
|
||||
* logical bitstream and breaking it down into pages which are handled by
|
||||
* the codec implementations, in this case Opus specifically.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT File : public Ogg::File
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Constructs an Opus file from \a file. If \a readProperties is true the
|
||||
* file's audio properties will also be read.
|
||||
*
|
||||
* \note In the current implementation, \a propertiesStyle is ignored.
|
||||
*/
|
||||
File(FileName file, bool readProperties = true,
|
||||
Properties::ReadStyle propertiesStyle = Properties::Average);
|
||||
|
||||
/*!
|
||||
* Constructs an Opus file from \a stream. If \a readProperties is true the
|
||||
* file's audio properties will also be read.
|
||||
*
|
||||
* \note TagLib will *not* take ownership of the stream, the caller is
|
||||
* responsible for deleting it after the File object.
|
||||
*
|
||||
* \note In the current implementation, \a propertiesStyle is ignored.
|
||||
*/
|
||||
File(IOStream *stream, bool readProperties = true,
|
||||
Properties::ReadStyle propertiesStyle = Properties::Average);
|
||||
|
||||
/*!
|
||||
* Destroys this instance of the File.
|
||||
*/
|
||||
virtual ~File();
|
||||
|
||||
/*!
|
||||
* Returns the XiphComment for this file. XiphComment implements the tag
|
||||
* interface, so this serves as the reimplementation of
|
||||
* TagLib::File::tag().
|
||||
*/
|
||||
virtual Ogg::XiphComment *tag() const;
|
||||
|
||||
/*!
|
||||
* Implements the unified property interface -- export function.
|
||||
* This forwards directly to XiphComment::properties().
|
||||
*/
|
||||
PropertyMap properties() const;
|
||||
|
||||
/*!
|
||||
* Implements the unified tag dictionary interface -- import function.
|
||||
* Like properties(), this is a forwarder to the file's XiphComment.
|
||||
*/
|
||||
PropertyMap setProperties(const PropertyMap &);
|
||||
|
||||
/*!
|
||||
* Returns the Opus::Properties for this file. If no audio properties
|
||||
* were read then this will return a null pointer.
|
||||
*/
|
||||
virtual Properties *audioProperties() const;
|
||||
|
||||
/*!
|
||||
* Save the file.
|
||||
*
|
||||
* This returns true if the save was successful.
|
||||
*/
|
||||
virtual bool save();
|
||||
|
||||
/*!
|
||||
* Returns whether or not the given \a stream can be opened as an Opus
|
||||
* file.
|
||||
*
|
||||
* \note This method is designed to do a quick check. The result may
|
||||
* not necessarily be correct.
|
||||
*/
|
||||
static bool isSupported(IOStream *stream);
|
||||
|
||||
private:
|
||||
File(const File &);
|
||||
File &operator=(const File &);
|
||||
|
||||
void read(bool readProperties);
|
||||
|
||||
class FilePrivate;
|
||||
FilePrivate *d;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
177
3rdparty/taglib/ogg/opus/opusproperties.cpp
vendored
Normal file
177
3rdparty/taglib/ogg/opus/opusproperties.cpp
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2012 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
(original Vorbis implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
|
||||
#include <oggpageheader.h>
|
||||
|
||||
#include "opusproperties.h"
|
||||
#include "opusfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
using namespace TagLib::Ogg;
|
||||
|
||||
class Opus::Properties::PropertiesPrivate
|
||||
{
|
||||
public:
|
||||
PropertiesPrivate() :
|
||||
length(0),
|
||||
bitrate(0),
|
||||
inputSampleRate(0),
|
||||
channels(0),
|
||||
opusVersion(0) {}
|
||||
|
||||
int length;
|
||||
int bitrate;
|
||||
int inputSampleRate;
|
||||
int channels;
|
||||
int opusVersion;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Opus::Properties::Properties(File *file, ReadStyle style) :
|
||||
AudioProperties(style),
|
||||
d(new PropertiesPrivate())
|
||||
{
|
||||
read(file);
|
||||
}
|
||||
|
||||
Opus::Properties::~Properties()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
int Opus::Properties::length() const
|
||||
{
|
||||
return lengthInSeconds();
|
||||
}
|
||||
|
||||
int Ogg::Opus::Properties::lengthInSeconds() const
|
||||
{
|
||||
return d->length / 1000;
|
||||
}
|
||||
|
||||
int Ogg::Opus::Properties::lengthInMilliseconds() const
|
||||
{
|
||||
return d->length;
|
||||
}
|
||||
|
||||
int Opus::Properties::bitrate() const
|
||||
{
|
||||
return d->bitrate;
|
||||
}
|
||||
|
||||
int Opus::Properties::sampleRate() const
|
||||
{
|
||||
// Opus can decode any stream at a sample rate of 8, 12, 16, 24, or 48 kHz,
|
||||
// so there is no single sample rate. Let's assume it's the highest
|
||||
// possible.
|
||||
return 48000;
|
||||
}
|
||||
|
||||
int Opus::Properties::channels() const
|
||||
{
|
||||
return d->channels;
|
||||
}
|
||||
|
||||
int Opus::Properties::inputSampleRate() const
|
||||
{
|
||||
return d->inputSampleRate;
|
||||
}
|
||||
|
||||
int Opus::Properties::opusVersion() const
|
||||
{
|
||||
return d->opusVersion;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Opus::Properties::read(File *file)
|
||||
{
|
||||
// Get the identification header from the Ogg implementation.
|
||||
|
||||
// http://tools.ietf.org/html/draft-terriberry-oggopus-01#section-5.1
|
||||
|
||||
const ByteVector data = file->packet(0);
|
||||
|
||||
// *Magic Signature*
|
||||
unsigned int pos = 8;
|
||||
|
||||
// *Version* (8 bits, unsigned)
|
||||
d->opusVersion = static_cast<unsigned char>(data.at(pos));
|
||||
pos += 1;
|
||||
|
||||
// *Output Channel Count* 'C' (8 bits, unsigned)
|
||||
d->channels = static_cast<unsigned char>(data.at(pos));
|
||||
pos += 1;
|
||||
|
||||
// *Pre-skip* (16 bits, unsigned, little endian)
|
||||
const unsigned short preSkip = data.toUShort(pos, false);
|
||||
pos += 2;
|
||||
|
||||
// *Input Sample Rate* (32 bits, unsigned, little endian)
|
||||
d->inputSampleRate = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
// *Output Gain* (16 bits, signed, little endian)
|
||||
pos += 2;
|
||||
|
||||
// *Channel Mapping Family* (8 bits, unsigned)
|
||||
pos += 1;
|
||||
|
||||
const Ogg::PageHeader *first = file->firstPageHeader();
|
||||
const Ogg::PageHeader *last = file->lastPageHeader();
|
||||
|
||||
if(first && last) {
|
||||
const long long start = first->absoluteGranularPosition();
|
||||
const long long end = last->absoluteGranularPosition();
|
||||
|
||||
if(start >= 0 && end >= 0) {
|
||||
const long long frameCount = (end - start - preSkip);
|
||||
|
||||
if(frameCount > 0) {
|
||||
const double length = frameCount * 1000.0 / 48000.0;
|
||||
d->length = static_cast<int>(length + 0.5);
|
||||
d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
|
||||
}
|
||||
}
|
||||
else {
|
||||
debug("Opus::Properties::read() -- The PCM values for the start or "
|
||||
"end of this file was incorrect.");
|
||||
}
|
||||
}
|
||||
else
|
||||
debug("Opus::Properties::read() -- Could not find valid first and last Ogg pages.");
|
||||
}
|
||||
134
3rdparty/taglib/ogg/opus/opusproperties.h
vendored
Normal file
134
3rdparty/taglib/ogg/opus/opusproperties.h
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2012 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
(original Vorbis implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_OPUSPROPERTIES_H
|
||||
#define TAGLIB_OPUSPROPERTIES_H
|
||||
|
||||
#include "audioproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace Ogg {
|
||||
|
||||
namespace Opus {
|
||||
|
||||
class File;
|
||||
|
||||
//! An implementation of audio property reading for Ogg Opus
|
||||
|
||||
/*!
|
||||
* This reads the data from an Ogg Opus stream found in the AudioProperties
|
||||
* API.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT Properties : public AudioProperties
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Create an instance of Opus::Properties with the data read from the
|
||||
* Opus::File \a file.
|
||||
*/
|
||||
Properties(File *file, ReadStyle style = Average);
|
||||
|
||||
/*!
|
||||
* Destroys this Opus::Properties instance.
|
||||
*/
|
||||
virtual ~Properties();
|
||||
|
||||
/*!
|
||||
* Returns the length of the file in seconds. The length is rounded down to
|
||||
* the nearest whole second.
|
||||
*
|
||||
* \note This method is just an alias of lengthInSeconds().
|
||||
*
|
||||
* \deprecated
|
||||
*/
|
||||
virtual int length() const;
|
||||
|
||||
/*!
|
||||
* Returns the length of the file in seconds. The length is rounded down to
|
||||
* the nearest whole second.
|
||||
*
|
||||
* \see lengthInMilliseconds()
|
||||
*/
|
||||
// BIC: make virtual
|
||||
int lengthInSeconds() const;
|
||||
|
||||
/*!
|
||||
* Returns the length of the file in milliseconds.
|
||||
*
|
||||
* \see lengthInSeconds()
|
||||
*/
|
||||
// BIC: make virtual
|
||||
int lengthInMilliseconds() const;
|
||||
|
||||
/*!
|
||||
* Returns the average bit rate of the file in kb/s.
|
||||
*/
|
||||
virtual int bitrate() const;
|
||||
|
||||
/*!
|
||||
* Returns the sample rate in Hz.
|
||||
*
|
||||
* \note Always returns 48000, because Opus can decode any stream at a
|
||||
* sample rate of 8, 12, 16, 24, or 48 kHz,
|
||||
*/
|
||||
virtual int sampleRate() const;
|
||||
|
||||
/*!
|
||||
* Returns the number of audio channels.
|
||||
*/
|
||||
virtual int channels() const;
|
||||
|
||||
/*!
|
||||
* The Opus codec supports decoding at multiple sample rates, there is no
|
||||
* single sample rate of the encoded stream. This returns the sample rate
|
||||
* of the original audio stream.
|
||||
*/
|
||||
int inputSampleRate() const;
|
||||
|
||||
/*!
|
||||
* Returns the Opus version, in the range 0...255.
|
||||
*/
|
||||
int opusVersion() const;
|
||||
|
||||
private:
|
||||
Properties(const Properties &);
|
||||
Properties &operator=(const Properties &);
|
||||
|
||||
void read(File *file);
|
||||
|
||||
class PropertiesPrivate;
|
||||
PropertiesPrivate *d;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
143
3rdparty/taglib/ogg/speex/speexfile.cpp
vendored
Normal file
143
3rdparty/taglib/ogg/speex/speexfile.cpp
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2006 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
(original Vorbis implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
#include <tpropertymap.h>
|
||||
#include <tagutils.h>
|
||||
|
||||
#include "speexfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
using namespace TagLib::Ogg;
|
||||
|
||||
class Speex::File::FilePrivate
|
||||
{
|
||||
public:
|
||||
FilePrivate() :
|
||||
comment(0),
|
||||
properties(0) {}
|
||||
|
||||
~FilePrivate()
|
||||
{
|
||||
delete comment;
|
||||
delete properties;
|
||||
}
|
||||
|
||||
Ogg::XiphComment *comment;
|
||||
Properties *properties;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// static members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Ogg::Speex::File::isSupported(IOStream *stream)
|
||||
{
|
||||
// A Speex file has IDs "OggS" and "Speex " somewhere.
|
||||
|
||||
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), false);
|
||||
return (buffer.find("OggS") >= 0 && buffer.find("Speex ") >= 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Speex::File::File(FileName file, bool readProperties, Properties::ReadStyle) :
|
||||
Ogg::File(file),
|
||||
d(new FilePrivate())
|
||||
{
|
||||
if(isOpen())
|
||||
read(readProperties);
|
||||
}
|
||||
|
||||
Speex::File::File(IOStream *stream, bool readProperties, Properties::ReadStyle) :
|
||||
Ogg::File(stream),
|
||||
d(new FilePrivate())
|
||||
{
|
||||
if(isOpen())
|
||||
read(readProperties);
|
||||
}
|
||||
|
||||
Speex::File::~File()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
Ogg::XiphComment *Speex::File::tag() const
|
||||
{
|
||||
return d->comment;
|
||||
}
|
||||
|
||||
PropertyMap Speex::File::properties() const
|
||||
{
|
||||
return d->comment->properties();
|
||||
}
|
||||
|
||||
PropertyMap Speex::File::setProperties(const PropertyMap &properties)
|
||||
{
|
||||
return d->comment->setProperties(properties);
|
||||
}
|
||||
|
||||
Speex::Properties *Speex::File::audioProperties() const
|
||||
{
|
||||
return d->properties;
|
||||
}
|
||||
|
||||
bool Speex::File::save()
|
||||
{
|
||||
if(!d->comment)
|
||||
d->comment = new Ogg::XiphComment();
|
||||
|
||||
setPacket(1, d->comment->render());
|
||||
|
||||
return Ogg::File::save();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Speex::File::read(bool readProperties)
|
||||
{
|
||||
ByteVector speexHeaderData = packet(0);
|
||||
|
||||
if(!speexHeaderData.startsWith("Speex ")) {
|
||||
debug("Speex::File::read() -- invalid Speex identification header");
|
||||
return;
|
||||
}
|
||||
|
||||
ByteVector commentHeaderData = packet(1);
|
||||
|
||||
d->comment = new Ogg::XiphComment(commentHeaderData);
|
||||
|
||||
if(readProperties)
|
||||
d->properties = new Properties(this);
|
||||
}
|
||||
138
3rdparty/taglib/ogg/speex/speexfile.h
vendored
Normal file
138
3rdparty/taglib/ogg/speex/speexfile.h
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2006 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
(original Vorbis implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_SPEEXFILE_H
|
||||
#define TAGLIB_SPEEXFILE_H
|
||||
|
||||
#include "oggfile.h"
|
||||
#include "xiphcomment.h"
|
||||
|
||||
#include "speexproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace Ogg {
|
||||
|
||||
//! A namespace containing classes for Speex metadata
|
||||
|
||||
namespace Speex {
|
||||
|
||||
//! An implementation of Ogg::File with Speex specific methods
|
||||
|
||||
/*!
|
||||
* This is the central class in the Ogg Speex metadata processing collection
|
||||
* of classes. It's built upon Ogg::File which handles processing of the Ogg
|
||||
* logical bitstream and breaking it down into pages which are handled by
|
||||
* the codec implementations, in this case Speex specifically.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT File : public Ogg::File
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Constructs a Speex file from \a file. If \a readProperties is true the
|
||||
* file's audio properties will also be read.
|
||||
*
|
||||
* \note In the current implementation, \a propertiesStyle is ignored.
|
||||
*/
|
||||
File(FileName file, bool readProperties = true,
|
||||
Properties::ReadStyle propertiesStyle = Properties::Average);
|
||||
|
||||
/*!
|
||||
* Constructs a Speex file from \a stream. If \a readProperties is true the
|
||||
* file's audio properties will also be read.
|
||||
*
|
||||
* \note TagLib will *not* take ownership of the stream, the caller is
|
||||
* responsible for deleting it after the File object.
|
||||
*
|
||||
* \note In the current implementation, \a propertiesStyle is ignored.
|
||||
*/
|
||||
File(IOStream *stream, bool readProperties = true,
|
||||
Properties::ReadStyle propertiesStyle = Properties::Average);
|
||||
|
||||
/*!
|
||||
* Destroys this instance of the File.
|
||||
*/
|
||||
virtual ~File();
|
||||
|
||||
/*!
|
||||
* Returns the XiphComment for this file. XiphComment implements the tag
|
||||
* interface, so this serves as the reimplementation of
|
||||
* TagLib::File::tag().
|
||||
*/
|
||||
virtual Ogg::XiphComment *tag() const;
|
||||
|
||||
/*!
|
||||
* Implements the unified property interface -- export function.
|
||||
* This forwards directly to XiphComment::properties().
|
||||
*/
|
||||
PropertyMap properties() const;
|
||||
|
||||
/*!
|
||||
* Implements the unified tag dictionary interface -- import function.
|
||||
* Like properties(), this is a forwarder to the file's XiphComment.
|
||||
*/
|
||||
PropertyMap setProperties(const PropertyMap &);
|
||||
|
||||
/*!
|
||||
* Returns the Speex::Properties for this file. If no audio properties
|
||||
* were read then this will return a null pointer.
|
||||
*/
|
||||
virtual Properties *audioProperties() const;
|
||||
|
||||
/*!
|
||||
* Save the file.
|
||||
*
|
||||
* This returns true if the save was successful.
|
||||
*/
|
||||
virtual bool save();
|
||||
|
||||
/*!
|
||||
* Returns whether or not the given \a stream can be opened as a Speex
|
||||
* file.
|
||||
*
|
||||
* \note This method is designed to do a quick check. The result may
|
||||
* not necessarily be correct.
|
||||
*/
|
||||
static bool isSupported(IOStream *stream);
|
||||
|
||||
private:
|
||||
File(const File &);
|
||||
File &operator=(const File &);
|
||||
|
||||
void read(bool readProperties);
|
||||
|
||||
class FilePrivate;
|
||||
FilePrivate *d;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
201
3rdparty/taglib/ogg/speex/speexproperties.cpp
vendored
Normal file
201
3rdparty/taglib/ogg/speex/speexproperties.cpp
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2006 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
(original Vorbis implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
|
||||
#include <oggpageheader.h>
|
||||
|
||||
#include "speexproperties.h"
|
||||
#include "speexfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
using namespace TagLib::Ogg;
|
||||
|
||||
class Speex::Properties::PropertiesPrivate
|
||||
{
|
||||
public:
|
||||
PropertiesPrivate() :
|
||||
length(0),
|
||||
bitrate(0),
|
||||
bitrateNominal(0),
|
||||
sampleRate(0),
|
||||
channels(0),
|
||||
speexVersion(0),
|
||||
vbr(false),
|
||||
mode(0) {}
|
||||
|
||||
int length;
|
||||
int bitrate;
|
||||
int bitrateNominal;
|
||||
int sampleRate;
|
||||
int channels;
|
||||
int speexVersion;
|
||||
bool vbr;
|
||||
int mode;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Speex::Properties::Properties(File *file, ReadStyle style) :
|
||||
AudioProperties(style),
|
||||
d(new PropertiesPrivate())
|
||||
{
|
||||
read(file);
|
||||
}
|
||||
|
||||
Speex::Properties::~Properties()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
int Speex::Properties::length() const
|
||||
{
|
||||
return lengthInSeconds();
|
||||
}
|
||||
|
||||
int Speex::Properties::lengthInSeconds() const
|
||||
{
|
||||
return d->length / 1000;
|
||||
}
|
||||
|
||||
int Speex::Properties::lengthInMilliseconds() const
|
||||
{
|
||||
return d->length;
|
||||
}
|
||||
|
||||
int Speex::Properties::bitrate() const
|
||||
{
|
||||
return d->bitrate;
|
||||
}
|
||||
|
||||
int Speex::Properties::bitrateNominal() const
|
||||
{
|
||||
return d->bitrateNominal;
|
||||
}
|
||||
|
||||
int Speex::Properties::sampleRate() const
|
||||
{
|
||||
return d->sampleRate;
|
||||
}
|
||||
|
||||
int Speex::Properties::channels() const
|
||||
{
|
||||
return d->channels;
|
||||
}
|
||||
|
||||
int Speex::Properties::speexVersion() const
|
||||
{
|
||||
return d->speexVersion;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Speex::Properties::read(File *file)
|
||||
{
|
||||
// Get the identification header from the Ogg implementation.
|
||||
|
||||
const ByteVector data = file->packet(0);
|
||||
if(data.size() < 64) {
|
||||
debug("Speex::Properties::read() -- data is too short.");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int pos = 28;
|
||||
|
||||
// speex_version_id; /**< Version for Speex (for checking compatibility) */
|
||||
d->speexVersion = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
// header_size; /**< Total size of the header ( sizeof(SpeexHeader) ) */
|
||||
pos += 4;
|
||||
|
||||
// rate; /**< Sampling rate used */
|
||||
d->sampleRate = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
// mode; /**< Mode used (0 for narrowband, 1 for wideband) */
|
||||
d->mode = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
// mode_bitstream_version; /**< Version ID of the bit-stream */
|
||||
pos += 4;
|
||||
|
||||
// nb_channels; /**< Number of channels encoded */
|
||||
d->channels = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
// bitrate; /**< Bit-rate used */
|
||||
d->bitrateNominal = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
// frame_size; /**< Size of frames */
|
||||
// unsigned int frameSize = data.mid(pos, 4).toUInt(false);
|
||||
pos += 4;
|
||||
|
||||
// vbr; /**< 1 for a VBR encoding, 0 otherwise */
|
||||
d->vbr = data.toUInt(pos, false) == 1;
|
||||
pos += 4;
|
||||
|
||||
// frames_per_packet; /**< Number of frames stored per Ogg packet */
|
||||
// unsigned int framesPerPacket = data.mid(pos, 4).toUInt(false);
|
||||
|
||||
const Ogg::PageHeader *first = file->firstPageHeader();
|
||||
const Ogg::PageHeader *last = file->lastPageHeader();
|
||||
|
||||
if(first && last) {
|
||||
const long long start = first->absoluteGranularPosition();
|
||||
const long long end = last->absoluteGranularPosition();
|
||||
|
||||
if(start >= 0 && end >= 0 && d->sampleRate > 0) {
|
||||
const long long frameCount = end - start;
|
||||
|
||||
if(frameCount > 0) {
|
||||
const double length = frameCount * 1000.0 / d->sampleRate;
|
||||
d->length = static_cast<int>(length + 0.5);
|
||||
d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
|
||||
}
|
||||
}
|
||||
else {
|
||||
debug("Speex::Properties::read() -- Either the PCM values for the start or "
|
||||
"end of this file was incorrect or the sample rate is zero.");
|
||||
}
|
||||
}
|
||||
else
|
||||
debug("Speex::Properties::read() -- Could not find valid first and last Ogg pages.");
|
||||
|
||||
// Alternative to the actual average bitrate.
|
||||
|
||||
if(d->bitrate == 0 && d->bitrateNominal > 0)
|
||||
d->bitrate = static_cast<int>(d->bitrateNominal / 1000.0 + 0.5);
|
||||
}
|
||||
129
3rdparty/taglib/ogg/speex/speexproperties.h
vendored
Normal file
129
3rdparty/taglib/ogg/speex/speexproperties.h
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2006 by Lukáš Lalinský
|
||||
email : lalinsky@gmail.com
|
||||
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
(original Vorbis implementation)
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_SPEEXPROPERTIES_H
|
||||
#define TAGLIB_SPEEXPROPERTIES_H
|
||||
|
||||
#include "audioproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace Ogg {
|
||||
|
||||
namespace Speex {
|
||||
|
||||
class File;
|
||||
|
||||
//! An implementation of audio property reading for Ogg Speex
|
||||
|
||||
/*!
|
||||
* This reads the data from an Ogg Speex stream found in the AudioProperties
|
||||
* API.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT Properties : public AudioProperties
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Create an instance of Speex::Properties with the data read from the
|
||||
* Speex::File \a file.
|
||||
*/
|
||||
Properties(File *file, ReadStyle style = Average);
|
||||
|
||||
/*!
|
||||
* Destroys this Speex::Properties instance.
|
||||
*/
|
||||
virtual ~Properties();
|
||||
|
||||
/*!
|
||||
* Returns the length of the file in seconds. The length is rounded down to
|
||||
* the nearest whole second.
|
||||
*
|
||||
* \note This method is just an alias of lengthInSeconds().
|
||||
*
|
||||
* \deprecated
|
||||
*/
|
||||
virtual int length() const;
|
||||
|
||||
/*!
|
||||
* Returns the length of the file in seconds. The length is rounded down to
|
||||
* the nearest whole second.
|
||||
*
|
||||
* \see lengthInMilliseconds()
|
||||
*/
|
||||
// BIC: make virtual
|
||||
int lengthInSeconds() const;
|
||||
|
||||
/*!
|
||||
* Returns the length of the file in milliseconds.
|
||||
*
|
||||
* \see lengthInSeconds()
|
||||
*/
|
||||
// BIC: make virtual
|
||||
int lengthInMilliseconds() const;
|
||||
|
||||
/*!
|
||||
* Returns the average bit rate of the file in kb/s.
|
||||
*/
|
||||
virtual int bitrate() const;
|
||||
|
||||
/*!
|
||||
* Returns the nominal bit rate as read from the Speex header in kb/s.
|
||||
*/
|
||||
int bitrateNominal() const;
|
||||
|
||||
/*!
|
||||
* Returns the sample rate in Hz.
|
||||
*/
|
||||
virtual int sampleRate() const;
|
||||
|
||||
/*!
|
||||
* Returns the number of audio channels.
|
||||
*/
|
||||
virtual int channels() const;
|
||||
|
||||
/*!
|
||||
* Returns the Speex version, currently "0" (as specified by the spec).
|
||||
*/
|
||||
int speexVersion() const;
|
||||
|
||||
private:
|
||||
Properties(const Properties &);
|
||||
Properties &operator=(const Properties &);
|
||||
|
||||
void read(File *file);
|
||||
|
||||
class PropertiesPrivate;
|
||||
PropertiesPrivate *d;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
150
3rdparty/taglib/ogg/vorbis/vorbisfile.cpp
vendored
Normal file
150
3rdparty/taglib/ogg/vorbis/vorbisfile.cpp
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <bitset>
|
||||
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
#include <tpropertymap.h>
|
||||
#include <tagutils.h>
|
||||
|
||||
#include "vorbisfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
class Vorbis::File::FilePrivate
|
||||
{
|
||||
public:
|
||||
FilePrivate() :
|
||||
comment(0),
|
||||
properties(0) {}
|
||||
|
||||
~FilePrivate()
|
||||
{
|
||||
delete comment;
|
||||
delete properties;
|
||||
}
|
||||
|
||||
Ogg::XiphComment *comment;
|
||||
Properties *properties;
|
||||
};
|
||||
|
||||
namespace TagLib {
|
||||
/*!
|
||||
* Vorbis headers can be found with one type ID byte and the string "vorbis" in
|
||||
* an Ogg stream. 0x03 indicates the comment header.
|
||||
*/
|
||||
static const char vorbisCommentHeaderID[] = { 0x03, 'v', 'o', 'r', 'b', 'i', 's', 0 };
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// static members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool Vorbis::File::isSupported(IOStream *stream)
|
||||
{
|
||||
// An Ogg Vorbis file has IDs "OggS" and "\x01vorbis" somewhere.
|
||||
|
||||
const ByteVector buffer = Utils::readHeader(stream, bufferSize(), false);
|
||||
return (buffer.find("OggS") >= 0 && buffer.find("\x01vorbis") >= 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Vorbis::File::File(FileName file, bool readProperties, Properties::ReadStyle) :
|
||||
Ogg::File(file),
|
||||
d(new FilePrivate())
|
||||
{
|
||||
if(isOpen())
|
||||
read(readProperties);
|
||||
}
|
||||
|
||||
Vorbis::File::File(IOStream *stream, bool readProperties, Properties::ReadStyle) :
|
||||
Ogg::File(stream),
|
||||
d(new FilePrivate())
|
||||
{
|
||||
if(isOpen())
|
||||
read(readProperties);
|
||||
}
|
||||
|
||||
Vorbis::File::~File()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
Ogg::XiphComment *Vorbis::File::tag() const
|
||||
{
|
||||
return d->comment;
|
||||
}
|
||||
|
||||
PropertyMap Vorbis::File::properties() const
|
||||
{
|
||||
return d->comment->properties();
|
||||
}
|
||||
|
||||
PropertyMap Vorbis::File::setProperties(const PropertyMap &properties)
|
||||
{
|
||||
return d->comment->setProperties(properties);
|
||||
}
|
||||
|
||||
Vorbis::Properties *Vorbis::File::audioProperties() const
|
||||
{
|
||||
return d->properties;
|
||||
}
|
||||
|
||||
bool Vorbis::File::save()
|
||||
{
|
||||
ByteVector v(vorbisCommentHeaderID);
|
||||
|
||||
if(!d->comment)
|
||||
d->comment = new Ogg::XiphComment();
|
||||
v.append(d->comment->render());
|
||||
|
||||
setPacket(1, v);
|
||||
|
||||
return Ogg::File::save();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Vorbis::File::read(bool readProperties)
|
||||
{
|
||||
ByteVector commentHeaderData = packet(1);
|
||||
|
||||
if(commentHeaderData.mid(0, 7) != vorbisCommentHeaderID) {
|
||||
debug("Vorbis::File::read() - Could not find the Vorbis comment header.");
|
||||
setValid(false);
|
||||
return;
|
||||
}
|
||||
|
||||
d->comment = new Ogg::XiphComment(commentHeaderData.mid(7));
|
||||
|
||||
if(readProperties)
|
||||
d->properties = new Properties(this);
|
||||
}
|
||||
157
3rdparty/taglib/ogg/vorbis/vorbisfile.h
vendored
Normal file
157
3rdparty/taglib/ogg/vorbis/vorbisfile.h
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_VORBISFILE_H
|
||||
#define TAGLIB_VORBISFILE_H
|
||||
|
||||
#include "taglib_export.h"
|
||||
#include "oggfile.h"
|
||||
#include "xiphcomment.h"
|
||||
|
||||
#include "vorbisproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
/*
|
||||
* This is just to make this appear to be in the Ogg namespace in the
|
||||
* documentation. The typedef below will make this work with the current code.
|
||||
* In the next BIC version of TagLib this will be really moved into the Ogg
|
||||
* namespace.
|
||||
*/
|
||||
|
||||
#ifdef DOXYGEN
|
||||
namespace Ogg {
|
||||
#endif
|
||||
|
||||
//! A namespace containing classes for Vorbis metadata
|
||||
|
||||
namespace Vorbis {
|
||||
|
||||
|
||||
//! An implementation of Ogg::File with Vorbis specific methods
|
||||
|
||||
/*!
|
||||
* This is the central class in the Ogg Vorbis metadata processing collection
|
||||
* of classes. It's built upon Ogg::File which handles processing of the Ogg
|
||||
* logical bitstream and breaking it down into pages which are handled by
|
||||
* the codec implementations, in this case Vorbis specifically.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT File : public Ogg::File
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Constructs a Vorbis file from \a file. If \a readProperties is true the
|
||||
* file's audio properties will also be read.
|
||||
*
|
||||
* \note In the current implementation, \a propertiesStyle is ignored.
|
||||
*/
|
||||
File(FileName file, bool readProperties = true,
|
||||
Properties::ReadStyle propertiesStyle = Properties::Average);
|
||||
|
||||
/*!
|
||||
* Constructs a Vorbis file from \a stream. If \a readProperties is true the
|
||||
* file's audio properties will also be read.
|
||||
*
|
||||
* \note TagLib will *not* take ownership of the stream, the caller is
|
||||
* responsible for deleting it after the File object.
|
||||
*
|
||||
* \note In the current implementation, \a propertiesStyle is ignored.
|
||||
*/
|
||||
File(IOStream *stream, bool readProperties = true,
|
||||
Properties::ReadStyle propertiesStyle = Properties::Average);
|
||||
|
||||
/*!
|
||||
* Destroys this instance of the File.
|
||||
*/
|
||||
virtual ~File();
|
||||
|
||||
/*!
|
||||
* Returns the XiphComment for this file. XiphComment implements the tag
|
||||
* interface, so this serves as the reimplementation of
|
||||
* TagLib::File::tag().
|
||||
*/
|
||||
virtual Ogg::XiphComment *tag() const;
|
||||
|
||||
|
||||
/*!
|
||||
* Implements the unified property interface -- export function.
|
||||
* This forwards directly to XiphComment::properties().
|
||||
*/
|
||||
PropertyMap properties() const;
|
||||
|
||||
/*!
|
||||
* Implements the unified tag dictionary interface -- import function.
|
||||
* Like properties(), this is a forwarder to the file's XiphComment.
|
||||
*/
|
||||
PropertyMap setProperties(const PropertyMap &);
|
||||
|
||||
/*!
|
||||
* Returns the Vorbis::Properties for this file. If no audio properties
|
||||
* were read then this will return a null pointer.
|
||||
*/
|
||||
virtual Properties *audioProperties() const;
|
||||
|
||||
/*!
|
||||
* Save the file.
|
||||
*
|
||||
* This returns true if the save was successful.
|
||||
*/
|
||||
virtual bool save();
|
||||
|
||||
/*!
|
||||
* Check if the given \a stream can be opened as an Ogg Vorbis file.
|
||||
*
|
||||
* \note This method is designed to do a quick check. The result may
|
||||
* not necessarily be correct.
|
||||
*/
|
||||
static bool isSupported(IOStream *stream);
|
||||
|
||||
private:
|
||||
File(const File &);
|
||||
File &operator=(const File &);
|
||||
|
||||
void read(bool readProperties);
|
||||
|
||||
class FilePrivate;
|
||||
FilePrivate *d;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* To keep compatibility with the current version put Vorbis in the Ogg namespace
|
||||
* only in the docs and provide a typedef to make it work. In the next BIC
|
||||
* version this will be removed and it will only exist in the Ogg namespace.
|
||||
*/
|
||||
|
||||
#ifdef DOXYGEN
|
||||
}
|
||||
#else
|
||||
namespace Ogg { namespace Vorbis { typedef TagLib::Vorbis::File File; } }
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
206
3rdparty/taglib/ogg/vorbis/vorbisproperties.cpp
vendored
Normal file
206
3rdparty/taglib/ogg/vorbis/vorbisproperties.cpp
vendored
Normal file
@@ -0,0 +1,206 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <tstring.h>
|
||||
#include <tdebug.h>
|
||||
|
||||
#include <oggpageheader.h>
|
||||
|
||||
#include "vorbisproperties.h"
|
||||
#include "vorbisfile.h"
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
class Vorbis::Properties::PropertiesPrivate
|
||||
{
|
||||
public:
|
||||
PropertiesPrivate() :
|
||||
length(0),
|
||||
bitrate(0),
|
||||
sampleRate(0),
|
||||
channels(0),
|
||||
vorbisVersion(0),
|
||||
bitrateMaximum(0),
|
||||
bitrateNominal(0),
|
||||
bitrateMinimum(0) {}
|
||||
|
||||
int length;
|
||||
int bitrate;
|
||||
int sampleRate;
|
||||
int channels;
|
||||
int vorbisVersion;
|
||||
int bitrateMaximum;
|
||||
int bitrateNominal;
|
||||
int bitrateMinimum;
|
||||
};
|
||||
|
||||
namespace TagLib {
|
||||
/*!
|
||||
* Vorbis headers can be found with one type ID byte and the string "vorbis" in
|
||||
* an Ogg stream. 0x01 indicates the setup header.
|
||||
*/
|
||||
static const char vorbisSetupHeaderID[] = { 0x01, 'v', 'o', 'r', 'b', 'i', 's', 0 };
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Vorbis::Properties::Properties(File *file, ReadStyle style) :
|
||||
AudioProperties(style),
|
||||
d(new PropertiesPrivate())
|
||||
{
|
||||
read(file);
|
||||
}
|
||||
|
||||
Vorbis::Properties::~Properties()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
int Vorbis::Properties::length() const
|
||||
{
|
||||
return lengthInSeconds();
|
||||
}
|
||||
|
||||
int Vorbis::Properties::lengthInSeconds() const
|
||||
{
|
||||
return d->length / 1000;
|
||||
}
|
||||
|
||||
int Vorbis::Properties::lengthInMilliseconds() const
|
||||
{
|
||||
return d->length;
|
||||
}
|
||||
|
||||
int Vorbis::Properties::bitrate() const
|
||||
{
|
||||
return d->bitrate;
|
||||
}
|
||||
|
||||
int Vorbis::Properties::sampleRate() const
|
||||
{
|
||||
return d->sampleRate;
|
||||
}
|
||||
|
||||
int Vorbis::Properties::channels() const
|
||||
{
|
||||
return d->channels;
|
||||
}
|
||||
|
||||
int Vorbis::Properties::vorbisVersion() const
|
||||
{
|
||||
return d->vorbisVersion;
|
||||
}
|
||||
|
||||
int Vorbis::Properties::bitrateMaximum() const
|
||||
{
|
||||
return d->bitrateMaximum;
|
||||
}
|
||||
|
||||
int Vorbis::Properties::bitrateNominal() const
|
||||
{
|
||||
return d->bitrateNominal;
|
||||
}
|
||||
|
||||
int Vorbis::Properties::bitrateMinimum() const
|
||||
{
|
||||
return d->bitrateMinimum;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// private members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Vorbis::Properties::read(File *file)
|
||||
{
|
||||
// Get the identification header from the Ogg implementation.
|
||||
|
||||
const ByteVector data = file->packet(0);
|
||||
if(data.size() < 28) {
|
||||
debug("Vorbis::Properties::read() -- data is too short.");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int pos = 0;
|
||||
|
||||
if(data.mid(pos, 7) != vorbisSetupHeaderID) {
|
||||
debug("Vorbis::Properties::read() -- invalid Vorbis identification header");
|
||||
return;
|
||||
}
|
||||
|
||||
pos += 7;
|
||||
|
||||
d->vorbisVersion = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
d->channels = static_cast<unsigned char>(data[pos]);
|
||||
pos += 1;
|
||||
|
||||
d->sampleRate = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
d->bitrateMaximum = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
d->bitrateNominal = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
d->bitrateMinimum = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
// Find the length of the file. See http://wiki.xiph.org/VorbisStreamLength/
|
||||
// for my notes on the topic.
|
||||
|
||||
const Ogg::PageHeader *first = file->firstPageHeader();
|
||||
const Ogg::PageHeader *last = file->lastPageHeader();
|
||||
|
||||
if(first && last) {
|
||||
const long long start = first->absoluteGranularPosition();
|
||||
const long long end = last->absoluteGranularPosition();
|
||||
|
||||
if(start >= 0 && end >= 0 && d->sampleRate > 0) {
|
||||
const long long frameCount = end - start;
|
||||
|
||||
if(frameCount > 0) {
|
||||
const double length = frameCount * 1000.0 / d->sampleRate;
|
||||
|
||||
d->length = static_cast<int>(length + 0.5);
|
||||
d->bitrate = static_cast<int>(file->length() * 8.0 / length + 0.5);
|
||||
}
|
||||
}
|
||||
else {
|
||||
debug("Vorbis::Properties::read() -- Either the PCM values for the start or "
|
||||
"end of this file was incorrect or the sample rate is zero.");
|
||||
}
|
||||
}
|
||||
else
|
||||
debug("Vorbis::Properties::read() -- Could not find valid first and last Ogg pages.");
|
||||
|
||||
// Alternative to the actual average bitrate.
|
||||
|
||||
if(d->bitrate == 0 && d->bitrateNominal > 0)
|
||||
d->bitrate = static_cast<int>(d->bitrateNominal / 1000.0 + 0.5);
|
||||
}
|
||||
160
3rdparty/taglib/ogg/vorbis/vorbisproperties.h
vendored
Normal file
160
3rdparty/taglib/ogg/vorbis/vorbisproperties.h
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_VORBISPROPERTIES_H
|
||||
#define TAGLIB_VORBISPROPERTIES_H
|
||||
|
||||
#include "taglib_export.h"
|
||||
#include "audioproperties.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
/*
|
||||
* This is just to make this appear to be in the Ogg namespace in the
|
||||
* documentation. The typedef below will make this work with the current code.
|
||||
* In the next BIC version of TagLib this will be really moved into the Ogg
|
||||
* namespace.
|
||||
*/
|
||||
|
||||
#ifdef DOXYGEN
|
||||
namespace Ogg {
|
||||
#endif
|
||||
|
||||
namespace Vorbis {
|
||||
|
||||
class File;
|
||||
|
||||
//! An implementation of audio property reading for Ogg Vorbis
|
||||
|
||||
/*!
|
||||
* This reads the data from an Ogg Vorbis stream found in the AudioProperties
|
||||
* API.
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT Properties : public AudioProperties
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Create an instance of Vorbis::Properties with the data read from the
|
||||
* Vorbis::File \a file.
|
||||
*/
|
||||
Properties(File *file, ReadStyle style = Average);
|
||||
|
||||
/*!
|
||||
* Destroys this VorbisProperties instance.
|
||||
*/
|
||||
virtual ~Properties();
|
||||
|
||||
/*!
|
||||
* Returns the length of the file in seconds. The length is rounded down to
|
||||
* the nearest whole second.
|
||||
*
|
||||
* \note This method is just an alias of lengthInSeconds().
|
||||
*
|
||||
* \deprecated
|
||||
*/
|
||||
virtual int length() const;
|
||||
|
||||
/*!
|
||||
* Returns the length of the file in seconds. The length is rounded down to
|
||||
* the nearest whole second.
|
||||
*
|
||||
* \see lengthInMilliseconds()
|
||||
*/
|
||||
// BIC: make virtual
|
||||
int lengthInSeconds() const;
|
||||
|
||||
/*!
|
||||
* Returns the length of the file in milliseconds.
|
||||
*
|
||||
* \see lengthInSeconds()
|
||||
*/
|
||||
// BIC: make virtual
|
||||
int lengthInMilliseconds() const;
|
||||
|
||||
/*!
|
||||
* Returns the average bit rate of the file in kb/s.
|
||||
*/
|
||||
virtual int bitrate() const;
|
||||
|
||||
/*!
|
||||
* Returns the sample rate in Hz.
|
||||
*/
|
||||
virtual int sampleRate() const;
|
||||
|
||||
/*!
|
||||
* Returns the number of audio channels.
|
||||
*/
|
||||
virtual int channels() const;
|
||||
|
||||
/*!
|
||||
* Returns the Vorbis version, currently "0" (as specified by the spec).
|
||||
*/
|
||||
int vorbisVersion() const;
|
||||
|
||||
/*!
|
||||
* Returns the maximum bitrate as read from the Vorbis identification
|
||||
* header.
|
||||
*/
|
||||
int bitrateMaximum() const;
|
||||
|
||||
/*!
|
||||
* Returns the nominal bitrate as read from the Vorbis identification
|
||||
* header.
|
||||
*/
|
||||
int bitrateNominal() const;
|
||||
|
||||
/*!
|
||||
* Returns the minimum bitrate as read from the Vorbis identification
|
||||
* header.
|
||||
*/
|
||||
int bitrateMinimum() const;
|
||||
|
||||
private:
|
||||
Properties(const Properties &);
|
||||
Properties &operator=(const Properties &);
|
||||
|
||||
void read(File *file);
|
||||
|
||||
class PropertiesPrivate;
|
||||
PropertiesPrivate *d;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* To keep compatibility with the current version put Vorbis in the Ogg namespace
|
||||
* only in the docs and provide a typedef to make it work. In the next BIC
|
||||
* version this will be removed and it will only exist in the Ogg namespace.
|
||||
*/
|
||||
|
||||
#ifdef DOXYGEN
|
||||
}
|
||||
#else
|
||||
namespace Ogg { namespace Vorbis { typedef TagLib::AudioProperties AudioProperties; } }
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
515
3rdparty/taglib/ogg/xiphcomment.cpp
vendored
Normal file
515
3rdparty/taglib/ogg/xiphcomment.cpp
vendored
Normal file
@@ -0,0 +1,515 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#include <tbytevector.h>
|
||||
#include <tdebug.h>
|
||||
|
||||
#include <flacpicture.h>
|
||||
#include <xiphcomment.h>
|
||||
#include <tpropertymap.h>
|
||||
|
||||
using namespace TagLib;
|
||||
|
||||
namespace
|
||||
{
|
||||
typedef Ogg::FieldListMap::Iterator FieldIterator;
|
||||
typedef Ogg::FieldListMap::ConstIterator FieldConstIterator;
|
||||
|
||||
typedef List<FLAC::Picture *> PictureList;
|
||||
typedef PictureList::Iterator PictureIterator;
|
||||
typedef PictureList::Iterator PictureConstIterator;
|
||||
}
|
||||
|
||||
class Ogg::XiphComment::XiphCommentPrivate
|
||||
{
|
||||
public:
|
||||
XiphCommentPrivate()
|
||||
{
|
||||
pictureList.setAutoDelete(true);
|
||||
}
|
||||
|
||||
FieldListMap fieldListMap;
|
||||
String vendorID;
|
||||
String commentField;
|
||||
PictureList pictureList;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// public members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Ogg::XiphComment::XiphComment() :
|
||||
TagLib::Tag(),
|
||||
d(new XiphCommentPrivate())
|
||||
{
|
||||
}
|
||||
|
||||
Ogg::XiphComment::XiphComment(const ByteVector &data) :
|
||||
TagLib::Tag(),
|
||||
d(new XiphCommentPrivate())
|
||||
{
|
||||
parse(data);
|
||||
}
|
||||
|
||||
Ogg::XiphComment::~XiphComment()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
String Ogg::XiphComment::title() const
|
||||
{
|
||||
if(d->fieldListMap["TITLE"].isEmpty())
|
||||
return String();
|
||||
return d->fieldListMap["TITLE"].toString();
|
||||
}
|
||||
|
||||
String Ogg::XiphComment::artist() const
|
||||
{
|
||||
if(d->fieldListMap["ARTIST"].isEmpty())
|
||||
return String();
|
||||
return d->fieldListMap["ARTIST"].toString();
|
||||
}
|
||||
|
||||
String Ogg::XiphComment::album() const
|
||||
{
|
||||
if(d->fieldListMap["ALBUM"].isEmpty())
|
||||
return String();
|
||||
return d->fieldListMap["ALBUM"].toString();
|
||||
}
|
||||
|
||||
String Ogg::XiphComment::comment() const
|
||||
{
|
||||
if(!d->fieldListMap["DESCRIPTION"].isEmpty()) {
|
||||
d->commentField = "DESCRIPTION";
|
||||
return d->fieldListMap["DESCRIPTION"].toString();
|
||||
}
|
||||
|
||||
if(!d->fieldListMap["COMMENT"].isEmpty()) {
|
||||
d->commentField = "COMMENT";
|
||||
return d->fieldListMap["COMMENT"].toString();
|
||||
}
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
String Ogg::XiphComment::genre() const
|
||||
{
|
||||
if(d->fieldListMap["GENRE"].isEmpty())
|
||||
return String();
|
||||
return d->fieldListMap["GENRE"].toString();
|
||||
}
|
||||
|
||||
unsigned int Ogg::XiphComment::year() const
|
||||
{
|
||||
if(!d->fieldListMap["DATE"].isEmpty())
|
||||
return d->fieldListMap["DATE"].front().toInt();
|
||||
if(!d->fieldListMap["YEAR"].isEmpty())
|
||||
return d->fieldListMap["YEAR"].front().toInt();
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int Ogg::XiphComment::track() const
|
||||
{
|
||||
if(!d->fieldListMap["TRACKNUMBER"].isEmpty())
|
||||
return d->fieldListMap["TRACKNUMBER"].front().toInt();
|
||||
if(!d->fieldListMap["TRACKNUM"].isEmpty())
|
||||
return d->fieldListMap["TRACKNUM"].front().toInt();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::setTitle(const String &s)
|
||||
{
|
||||
addField("TITLE", s);
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::setArtist(const String &s)
|
||||
{
|
||||
addField("ARTIST", s);
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::setAlbum(const String &s)
|
||||
{
|
||||
addField("ALBUM", s);
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::setComment(const String &s)
|
||||
{
|
||||
if(d->commentField.isEmpty()) {
|
||||
if(!d->fieldListMap["DESCRIPTION"].isEmpty())
|
||||
d->commentField = "DESCRIPTION";
|
||||
else
|
||||
d->commentField = "COMMENT";
|
||||
}
|
||||
|
||||
addField(d->commentField, s);
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::setGenre(const String &s)
|
||||
{
|
||||
addField("GENRE", s);
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::setYear(unsigned int i)
|
||||
{
|
||||
removeFields("YEAR");
|
||||
if(i == 0)
|
||||
removeFields("DATE");
|
||||
else
|
||||
addField("DATE", String::number(i));
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::setTrack(unsigned int i)
|
||||
{
|
||||
removeFields("TRACKNUM");
|
||||
if(i == 0)
|
||||
removeFields("TRACKNUMBER");
|
||||
else
|
||||
addField("TRACKNUMBER", String::number(i));
|
||||
}
|
||||
|
||||
bool Ogg::XiphComment::isEmpty() const
|
||||
{
|
||||
for(FieldConstIterator it = d->fieldListMap.begin(); it != d->fieldListMap.end(); ++it) {
|
||||
if(!(*it).second.isEmpty())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int Ogg::XiphComment::fieldCount() const
|
||||
{
|
||||
unsigned int count = 0;
|
||||
|
||||
for(FieldConstIterator it = d->fieldListMap.begin(); it != d->fieldListMap.end(); ++it)
|
||||
count += (*it).second.size();
|
||||
|
||||
count += d->pictureList.size();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
const Ogg::FieldListMap &Ogg::XiphComment::fieldListMap() const
|
||||
{
|
||||
return d->fieldListMap;
|
||||
}
|
||||
|
||||
PropertyMap Ogg::XiphComment::properties() const
|
||||
{
|
||||
return d->fieldListMap;
|
||||
}
|
||||
|
||||
PropertyMap Ogg::XiphComment::setProperties(const PropertyMap &properties)
|
||||
{
|
||||
// check which keys are to be deleted
|
||||
StringList toRemove;
|
||||
for(FieldConstIterator it = d->fieldListMap.begin(); it != d->fieldListMap.end(); ++it)
|
||||
if (!properties.contains(it->first))
|
||||
toRemove.append(it->first);
|
||||
|
||||
for(StringList::ConstIterator it = toRemove.begin(); it != toRemove.end(); ++it)
|
||||
removeFields(*it);
|
||||
|
||||
// now go through keys in \a properties and check that the values match those in the xiph comment
|
||||
PropertyMap invalid;
|
||||
PropertyMap::ConstIterator it = properties.begin();
|
||||
for(; it != properties.end(); ++it)
|
||||
{
|
||||
if(!checkKey(it->first))
|
||||
invalid.insert(it->first, it->second);
|
||||
else if(!d->fieldListMap.contains(it->first) || !(it->second == d->fieldListMap[it->first])) {
|
||||
const StringList &sl = it->second;
|
||||
if(sl.isEmpty())
|
||||
// zero size string list -> remove the tag with all values
|
||||
removeFields(it->first);
|
||||
else {
|
||||
// replace all strings in the list for the tag
|
||||
StringList::ConstIterator valueIterator = sl.begin();
|
||||
addField(it->first, *valueIterator, true);
|
||||
++valueIterator;
|
||||
for(; valueIterator != sl.end(); ++valueIterator)
|
||||
addField(it->first, *valueIterator, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return invalid;
|
||||
}
|
||||
|
||||
bool Ogg::XiphComment::checkKey(const String &key)
|
||||
{
|
||||
if(key.size() < 1)
|
||||
return false;
|
||||
|
||||
// A key may consist of ASCII 0x20 through 0x7D, 0x3D ('=') excluded.
|
||||
|
||||
for(String::ConstIterator it = key.begin(); it != key.end(); it++) {
|
||||
if(*it < 0x20 || *it > 0x7D || *it == 0x3D)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
String Ogg::XiphComment::vendorID() const
|
||||
{
|
||||
return d->vendorID;
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::addField(const String &key, const String &value, bool replace)
|
||||
{
|
||||
if(!checkKey(key)) {
|
||||
debug("Ogg::XiphComment::addField() - Invalid key. Field not added.");
|
||||
return;
|
||||
}
|
||||
|
||||
const String upperKey = key.upper();
|
||||
|
||||
if(replace)
|
||||
removeFields(upperKey);
|
||||
|
||||
if(!key.isEmpty() && !value.isEmpty())
|
||||
d->fieldListMap[upperKey].append(value);
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::removeField(const String &key, const String &value)
|
||||
{
|
||||
if(!value.isNull())
|
||||
removeFields(key, value);
|
||||
else
|
||||
removeFields(key);
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::removeFields(const String &key)
|
||||
{
|
||||
d->fieldListMap.erase(key.upper());
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::removeFields(const String &key, const String &value)
|
||||
{
|
||||
StringList &fields = d->fieldListMap[key.upper()];
|
||||
for(StringList::Iterator it = fields.begin(); it != fields.end(); ) {
|
||||
if(*it == value)
|
||||
it = fields.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::removeAllFields()
|
||||
{
|
||||
d->fieldListMap.clear();
|
||||
}
|
||||
|
||||
bool Ogg::XiphComment::contains(const String &key) const
|
||||
{
|
||||
return !d->fieldListMap[key.upper()].isEmpty();
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::removePicture(FLAC::Picture *picture, bool del)
|
||||
{
|
||||
PictureIterator it = d->pictureList.find(picture);
|
||||
if(it != d->pictureList.end())
|
||||
d->pictureList.erase(it);
|
||||
|
||||
if(del)
|
||||
delete picture;
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::removeAllPictures()
|
||||
{
|
||||
d->pictureList.clear();
|
||||
}
|
||||
|
||||
void Ogg::XiphComment::addPicture(FLAC::Picture * picture)
|
||||
{
|
||||
d->pictureList.append(picture);
|
||||
}
|
||||
|
||||
List<FLAC::Picture *> Ogg::XiphComment::pictureList()
|
||||
{
|
||||
return d->pictureList;
|
||||
}
|
||||
|
||||
ByteVector Ogg::XiphComment::render() const
|
||||
{
|
||||
return render(true);
|
||||
}
|
||||
|
||||
ByteVector Ogg::XiphComment::render(bool addFramingBit) const
|
||||
{
|
||||
ByteVector data;
|
||||
|
||||
// Add the vendor ID length and the vendor ID. It's important to use the
|
||||
// length of the data(String::UTF8) rather than the length of the the string
|
||||
// since this is UTF8 text and there may be more characters in the data than
|
||||
// in the UTF16 string.
|
||||
|
||||
ByteVector vendorData = d->vendorID.data(String::UTF8);
|
||||
|
||||
data.append(ByteVector::fromUInt(vendorData.size(), false));
|
||||
data.append(vendorData);
|
||||
|
||||
// Add the number of fields.
|
||||
|
||||
data.append(ByteVector::fromUInt(fieldCount(), false));
|
||||
|
||||
// Iterate over the the field lists. Our iterator returns a
|
||||
// std::pair<String, StringList> where the first String is the field name and
|
||||
// the StringList is the values associated with that field.
|
||||
|
||||
FieldListMap::ConstIterator it = d->fieldListMap.begin();
|
||||
for(; it != d->fieldListMap.end(); ++it) {
|
||||
|
||||
// And now iterate over the values of the current list.
|
||||
|
||||
String fieldName = (*it).first;
|
||||
StringList values = (*it).second;
|
||||
|
||||
StringList::ConstIterator valuesIt = values.begin();
|
||||
for(; valuesIt != values.end(); ++valuesIt) {
|
||||
ByteVector fieldData = fieldName.data(String::UTF8);
|
||||
fieldData.append('=');
|
||||
fieldData.append((*valuesIt).data(String::UTF8));
|
||||
|
||||
data.append(ByteVector::fromUInt(fieldData.size(), false));
|
||||
data.append(fieldData);
|
||||
}
|
||||
}
|
||||
|
||||
for(PictureConstIterator it = d->pictureList.begin(); it != d->pictureList.end(); ++it) {
|
||||
ByteVector picture = (*it)->render().toBase64();
|
||||
data.append(ByteVector::fromUInt(picture.size() + 23, false));
|
||||
data.append("METADATA_BLOCK_PICTURE=");
|
||||
data.append(picture);
|
||||
}
|
||||
|
||||
// Append the "framing bit".
|
||||
|
||||
if(addFramingBit)
|
||||
data.append(char(1));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// protected members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Ogg::XiphComment::parse(const ByteVector &data)
|
||||
{
|
||||
// The first thing in the comment data is the vendor ID length, followed by a
|
||||
// UTF8 string with the vendor ID.
|
||||
|
||||
unsigned int pos = 0;
|
||||
|
||||
const unsigned int vendorLength = data.toUInt(0, false);
|
||||
pos += 4;
|
||||
|
||||
d->vendorID = String(data.mid(pos, vendorLength), String::UTF8);
|
||||
pos += vendorLength;
|
||||
|
||||
// Next the number of fields in the comment vector.
|
||||
|
||||
const unsigned int commentFields = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
if(commentFields > (data.size() - 8) / 4) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(unsigned int i = 0; i < commentFields; i++) {
|
||||
|
||||
// Each comment field is in the format "KEY=value" in a UTF8 string and has
|
||||
// 4 bytes before the text starts that gives the length.
|
||||
|
||||
const unsigned int commentLength = data.toUInt(pos, false);
|
||||
pos += 4;
|
||||
|
||||
const ByteVector entry = data.mid(pos, commentLength);
|
||||
pos += commentLength;
|
||||
|
||||
// Don't go past data end
|
||||
|
||||
if(pos > data.size())
|
||||
break;
|
||||
|
||||
// Check for field separator
|
||||
|
||||
const int sep = entry.find('=');
|
||||
if(sep < 1) {
|
||||
debug("Ogg::XiphComment::parse() - Discarding a field. Separator not found.");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Parse the key
|
||||
|
||||
const String key = String(entry.mid(0, sep), String::UTF8).upper();
|
||||
if(!checkKey(key)) {
|
||||
debug("Ogg::XiphComment::parse() - Discarding a field. Invalid key.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key == "METADATA_BLOCK_PICTURE" || key == "COVERART") {
|
||||
|
||||
// Handle Pictures separately
|
||||
|
||||
const ByteVector picturedata = ByteVector::fromBase64(entry.mid(sep + 1));
|
||||
if(picturedata.isEmpty()) {
|
||||
debug("Ogg::XiphComment::parse() - Discarding a field. Invalid base64 data");
|
||||
continue;
|
||||
}
|
||||
|
||||
if(key[0] == L'M') {
|
||||
|
||||
// Decode FLAC Picture
|
||||
|
||||
FLAC::Picture * picture = new FLAC::Picture();
|
||||
if(picture->parse(picturedata)) {
|
||||
d->pictureList.append(picture);
|
||||
}
|
||||
else {
|
||||
delete picture;
|
||||
debug("Ogg::XiphComment::parse() - Failed to decode FLAC Picture block");
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// Assume it's some type of image file
|
||||
|
||||
FLAC::Picture * picture = new FLAC::Picture();
|
||||
picture->setData(picturedata);
|
||||
picture->setMimeType("image/");
|
||||
picture->setType(FLAC::Picture::Other);
|
||||
d->pictureList.append(picture);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
// Parse the text
|
||||
|
||||
addField(key, String(entry.mid(sep + 1), String::UTF8), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
275
3rdparty/taglib/ogg/xiphcomment.h
vendored
Normal file
275
3rdparty/taglib/ogg/xiphcomment.h
vendored
Normal file
@@ -0,0 +1,275 @@
|
||||
/***************************************************************************
|
||||
copyright : (C) 2002 - 2008 by Scott Wheeler
|
||||
email : wheeler@kde.org
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* This library is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Lesser General Public License version *
|
||||
* 2.1 as published by the Free Software Foundation. *
|
||||
* *
|
||||
* This library 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
|
||||
* 02110-1301 USA *
|
||||
* *
|
||||
* Alternatively, this file is available under the Mozilla Public *
|
||||
* License Version 1.1. You may obtain a copy of the License at *
|
||||
* http://www.mozilla.org/MPL/ *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TAGLIB_VORBISCOMMENT_H
|
||||
#define TAGLIB_VORBISCOMMENT_H
|
||||
|
||||
#include "tag.h"
|
||||
#include "tlist.h"
|
||||
#include "tmap.h"
|
||||
#include "tstring.h"
|
||||
#include "tstringlist.h"
|
||||
#include "tbytevector.h"
|
||||
#include "flacpicture.h"
|
||||
#include "taglib_export.h"
|
||||
|
||||
namespace TagLib {
|
||||
|
||||
namespace Ogg {
|
||||
|
||||
/*!
|
||||
* A mapping between a list of field names, or keys, and a list of values
|
||||
* associated with that field.
|
||||
*
|
||||
* \see XiphComment::fieldListMap()
|
||||
*/
|
||||
typedef Map<String, StringList> FieldListMap;
|
||||
|
||||
//! Ogg Vorbis comment implementation
|
||||
|
||||
/*!
|
||||
* This class is an implementation of the Ogg Vorbis comment specification,
|
||||
* to be found in section 5 of the Ogg Vorbis specification. Because this
|
||||
* format is also used in other (currently unsupported) Xiph.org formats, it
|
||||
* has been made part of a generic implementation rather than being limited
|
||||
* to strictly Vorbis.
|
||||
*
|
||||
* Vorbis comments are a simple vector of keys and values, called fields.
|
||||
* Multiple values for a given key are supported.
|
||||
*
|
||||
* \see fieldListMap()
|
||||
*/
|
||||
|
||||
class TAGLIB_EXPORT XiphComment : public TagLib::Tag
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* Constructs an empty Vorbis comment.
|
||||
*/
|
||||
XiphComment();
|
||||
|
||||
/*!
|
||||
* Constructs a Vorbis comment from \a data.
|
||||
*/
|
||||
XiphComment(const ByteVector &data);
|
||||
|
||||
/*!
|
||||
* Destroys this instance of the XiphComment.
|
||||
*/
|
||||
virtual ~XiphComment();
|
||||
|
||||
virtual String title() const;
|
||||
virtual String artist() const;
|
||||
virtual String album() const;
|
||||
virtual String comment() const;
|
||||
virtual String genre() const;
|
||||
virtual unsigned int year() const;
|
||||
virtual unsigned int track() const;
|
||||
|
||||
virtual void setTitle(const String &s);
|
||||
virtual void setArtist(const String &s);
|
||||
virtual void setAlbum(const String &s);
|
||||
virtual void setComment(const String &s);
|
||||
virtual void setGenre(const String &s);
|
||||
virtual void setYear(unsigned int i);
|
||||
virtual void setTrack(unsigned int i);
|
||||
|
||||
virtual bool isEmpty() const;
|
||||
|
||||
/*!
|
||||
* Returns the number of fields present in the comment.
|
||||
*/
|
||||
unsigned int fieldCount() const;
|
||||
|
||||
/*!
|
||||
* Returns a reference to the map of field lists. Because Xiph comments
|
||||
* support multiple fields with the same key, a pure Map would not work.
|
||||
* As such this is a Map of string lists, keyed on the comment field name.
|
||||
*
|
||||
* The standard set of Xiph/Vorbis fields (which may or may not be
|
||||
* contained in any specific comment) is:
|
||||
*
|
||||
* <ul>
|
||||
* <li>TITLE</li>
|
||||
* <li>VERSION</li>
|
||||
* <li>ALBUM</li>
|
||||
* <li>ARTIST</li>
|
||||
* <li>PERFORMER</li>
|
||||
* <li>COPYRIGHT</li>
|
||||
* <li>ORGANIZATION</li>
|
||||
* <li>DESCRIPTION</li>
|
||||
* <li>GENRE</li>
|
||||
* <li>DATE</li>
|
||||
* <li>LOCATION</li>
|
||||
* <li>CONTACT</li>
|
||||
* <li>ISRC</li>
|
||||
* </ul>
|
||||
*
|
||||
* For a more detailed description of these fields, please see the Ogg
|
||||
* Vorbis specification, section 5.2.2.1.
|
||||
*
|
||||
* \note The Ogg Vorbis comment specification does allow these key values
|
||||
* to be either upper or lower case. However, it is conventional for them
|
||||
* to be upper case. As such, TagLib, when parsing a Xiph/Vorbis comment,
|
||||
* converts all fields to uppercase. When you are using this data
|
||||
* structure, you will need to specify the field name in upper case.
|
||||
*
|
||||
* \warning You should not modify this data structure directly, instead
|
||||
* use addField() and removeField().
|
||||
*/
|
||||
const FieldListMap &fieldListMap() const;
|
||||
|
||||
/*!
|
||||
* Implements the unified property interface -- export function.
|
||||
* The result is a one-to-one match of the Xiph comment, since it is
|
||||
* completely compatible with the property interface (in fact, a Xiph
|
||||
* comment is nothing more than a map from tag names to list of values,
|
||||
* as is the dict interface).
|
||||
*/
|
||||
PropertyMap properties() const;
|
||||
|
||||
/*!
|
||||
* Implements the unified property interface -- import function.
|
||||
* The tags from the given map will be stored one-to-one in the file,
|
||||
* except for invalid keys (less than one character, non-ASCII, or
|
||||
* containing '=' or '~') in which case the according values will
|
||||
* be contained in the returned PropertyMap.
|
||||
*/
|
||||
PropertyMap setProperties(const PropertyMap&);
|
||||
|
||||
/*!
|
||||
* Check if the given String is a valid Xiph comment key.
|
||||
*/
|
||||
static bool checkKey(const String&);
|
||||
|
||||
/*!
|
||||
* Returns the vendor ID of the Ogg Vorbis encoder. libvorbis 1.0 as the
|
||||
* most common case always returns "Xiph.Org libVorbis I 20020717".
|
||||
*/
|
||||
String vendorID() const;
|
||||
|
||||
/*!
|
||||
* Add the field specified by \a key with the data \a value. If \a replace
|
||||
* is true, then all of the other fields with the same key will be removed
|
||||
* first.
|
||||
*
|
||||
* If the field value is empty, the field will be removed.
|
||||
*/
|
||||
void addField(const String &key, const String &value, bool replace = true);
|
||||
|
||||
/*!
|
||||
* Remove the field specified by \a key with the data \a value. If
|
||||
* \a value is null, all of the fields with the given key will be removed.
|
||||
*
|
||||
* \deprecated Using this method may lead to a linkage error.
|
||||
*/
|
||||
// BIC: remove and merge with below
|
||||
void removeField(const String &key, const String &value = String::null);
|
||||
|
||||
/*!
|
||||
* Remove all the fields specified by \a key.
|
||||
*
|
||||
* \see removeAllFields()
|
||||
*/
|
||||
void removeFields(const String &key);
|
||||
|
||||
/*!
|
||||
* Remove all the fields specified by \a key with the data \a value.
|
||||
*
|
||||
* \see removeAllFields()
|
||||
*/
|
||||
void removeFields(const String &key, const String &value);
|
||||
|
||||
/*!
|
||||
* Remove all the fields in the comment.
|
||||
*
|
||||
* \see removeFields()
|
||||
*/
|
||||
void removeAllFields();
|
||||
|
||||
/*!
|
||||
* Returns true if the field is contained within the comment.
|
||||
*
|
||||
* \note This is safer than checking for membership in the FieldListMap.
|
||||
*/
|
||||
bool contains(const String &key) const;
|
||||
|
||||
/*!
|
||||
* Renders the comment to a ByteVector suitable for inserting into a file.
|
||||
*/
|
||||
ByteVector render() const; // BIC: remove and merge with below
|
||||
|
||||
/*!
|
||||
* Renders the comment to a ByteVector suitable for inserting into a file.
|
||||
*
|
||||
* If \a addFramingBit is true the standard Vorbis comment framing bit will
|
||||
* be appended. However some formats (notably FLAC) do not work with this
|
||||
* in place.
|
||||
*/
|
||||
ByteVector render(bool addFramingBit) const;
|
||||
|
||||
|
||||
/*!
|
||||
* Returns a list of pictures attached to the xiph comment.
|
||||
*/
|
||||
List<FLAC::Picture *> pictureList();
|
||||
|
||||
/*!
|
||||
* Removes an picture. If \a del is true the picture's memory
|
||||
* will be freed; if it is false, it must be deleted by the user.
|
||||
*/
|
||||
void removePicture(FLAC::Picture *picture, bool del = true);
|
||||
|
||||
/*!
|
||||
* Remove all pictures.
|
||||
*/
|
||||
void removeAllPictures();
|
||||
|
||||
/*!
|
||||
* Add a new picture to the comment block. The comment block takes ownership of the
|
||||
* picture and will handle freeing its memory.
|
||||
*
|
||||
* \note The file will be saved only after calling save().
|
||||
*/
|
||||
void addPicture(FLAC::Picture *picture);
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* Reads the tag from the file specified in the constructor and fills the
|
||||
* FieldListMap.
|
||||
*/
|
||||
void parse(const ByteVector &data);
|
||||
|
||||
private:
|
||||
XiphComment(const XiphComment &);
|
||||
XiphComment &operator=(const XiphComment &);
|
||||
|
||||
class XiphCommentPrivate;
|
||||
XiphCommentPrivate *d;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user