asffile.cpp

来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 548 行 · 第 1/2 页

CPP
548
字号
/**************************************************************************    copyright            : (C) 2005-2007 by Lukáš Lalinský    email                : lalinsky@gmail.com **************************************************************************//*************************************************************************** *   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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  * *   USA                                                                   * ***************************************************************************/#include <tbytevectorlist.h>#include <tstring.h>#include "asffile.h"#include "asftag.h"#include "asfproperties.h"using namespace TagLib;class ASF::File::FilePrivate{public:  FilePrivate():    size(0),    tag(0),    properties(0),    contentDescriptionObject(0),    extendedContentDescriptionObject(0),    headerExtensionObject(0),    metadataObject(0),    metadataLibraryObject(0) {}  unsigned long long size;  ASF::Tag *tag;  ASF::Properties *properties;  List<ASF::File::BaseObject *> objects;  ASF::File::ContentDescriptionObject *contentDescriptionObject;  ASF::File::ExtendedContentDescriptionObject *extendedContentDescriptionObject;  ASF::File::HeaderExtensionObject *headerExtensionObject;  ASF::File::MetadataObject *metadataObject;  ASF::File::MetadataLibraryObject *metadataLibraryObject;};static ByteVector headerGuid("\x30\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C", 16);static ByteVector filePropertiesGuid("\xA1\xDC\xAB\x8C\x47\xA9\xCF\x11\x8E\xE4\x00\xC0\x0C\x20\x53\x65", 16);static ByteVector streamPropertiesGuid("\x91\x07\xDC\xB7\xB7\xA9\xCF\x11\x8E\xE6\x00\xC0\x0C\x20\x53\x65", 16);static ByteVector contentDescriptionGuid("\x33\x26\xB2\x75\x8E\x66\xCF\x11\xA6\xD9\x00\xAA\x00\x62\xCE\x6C", 16);static ByteVector extendedContentDescriptionGuid("\x40\xA4\xD0\xD2\x07\xE3\xD2\x11\x97\xF0\x00\xA0\xC9\x5E\xA8\x50", 16);static ByteVector headerExtensionGuid("\xb5\x03\xbf_.\xa9\xcf\x11\x8e\xe3\x00\xc0\x0c Se", 16);static ByteVector metadataGuid("\xEA\xCB\xF8\xC5\xAF[wH\204g\xAA\214D\xFAL\xCA", 16);static ByteVector metadataLibraryGuid("\224\034#D\230\224\321I\241A\x1d\x13NEpT", 16);class ASF::File::BaseObject{public:  ByteVector data;  virtual ~BaseObject() {}  virtual ByteVector guid() = 0;  virtual void parse(ASF::File *file, unsigned int size);  virtual ByteVector render(ASF::File *file);};class ASF::File::UnknownObject : public ASF::File::BaseObject{  ByteVector myGuid;public:  UnknownObject(const ByteVector &guid);  ByteVector guid();};class ASF::File::FilePropertiesObject : public ASF::File::BaseObject{public:  ByteVector guid();  void parse(ASF::File *file, uint size);};class ASF::File::StreamPropertiesObject : public ASF::File::BaseObject{public:  ByteVector guid();  void parse(ASF::File *file, uint size);};class ASF::File::ContentDescriptionObject : public ASF::File::BaseObject{public:  ByteVector guid();  void parse(ASF::File *file, uint size);  ByteVector render(ASF::File *file);};class ASF::File::ExtendedContentDescriptionObject : public ASF::File::BaseObject{public:  ByteVectorList attributeData;  ByteVector guid();  void parse(ASF::File *file, uint size);  ByteVector render(ASF::File *file);};class ASF::File::MetadataObject : public ASF::File::BaseObject{public:  ByteVectorList attributeData;  ByteVector guid();  void parse(ASF::File *file, uint size);  ByteVector render(ASF::File *file);};class ASF::File::MetadataLibraryObject : public ASF::File::BaseObject{public:  ByteVectorList attributeData;  ByteVector guid();  void parse(ASF::File *file, uint size);  ByteVector render(ASF::File *file);};class ASF::File::HeaderExtensionObject : public ASF::File::BaseObject{public:  List<ASF::File::BaseObject *> objects;  ByteVector guid();  void parse(ASF::File *file, uint size);  ByteVector render(ASF::File *file);};voidASF::File::BaseObject::parse(ASF::File *file, unsigned int size){  data = file->readBlock(size - 24);}ByteVectorASF::File::BaseObject::render(ASF::File * /*file*/){  return guid() + ByteVector::fromLongLong(data.size() + 24, false) + data;}ASF::File::UnknownObject::UnknownObject(const ByteVector &guid) : myGuid(guid){}ByteVectorASF::File::UnknownObject::guid(){  return myGuid;}ByteVectorASF::File::FilePropertiesObject::guid(){  return filePropertiesGuid;}voidASF::File::FilePropertiesObject::parse(ASF::File *file, uint size){  BaseObject::parse(file, size);  file->d->properties->setLength((int)(data.mid(40, 8).toLongLong(false) / 10000000L - data.mid(56, 8).toLongLong(false) / 1000L));}ByteVectorASF::File::StreamPropertiesObject::guid(){  return streamPropertiesGuid;}voidASF::File::StreamPropertiesObject::parse(ASF::File *file, uint size){  BaseObject::parse(file, size);  file->d->properties->setChannels(data.mid(56, 2).toShort(false));  file->d->properties->setSampleRate(data.mid(58, 4).toUInt(false));  file->d->properties->setBitrate(data.mid(62, 4).toUInt(false) * 8 / 1000);}ByteVectorASF::File::ContentDescriptionObject::guid(){  return contentDescriptionGuid;}voidASF::File::ContentDescriptionObject::parse(ASF::File *file, uint /*size*/){  file->d->contentDescriptionObject = this;  int titleLength = file->readWORD();  int artistLength = file->readWORD();  int copyrightLength = file->readWORD();  int commentLength = file->readWORD();  int ratingLength = file->readWORD();  file->d->tag->setTitle(file->readString(titleLength));  file->d->tag->setArtist(file->readString(artistLength));  file->d->tag->setCopyright(file->readString(copyrightLength));  file->d->tag->setComment(file->readString(commentLength));  file->d->tag->setRating(file->readString(ratingLength));}ByteVectorASF::File::ContentDescriptionObject::render(ASF::File *file){  ByteVector v1 = file->renderString(file->d->tag->title());  ByteVector v2 = file->renderString(file->d->tag->artist());  ByteVector v3 = file->renderString(file->d->tag->copyright());  ByteVector v4 = file->renderString(file->d->tag->comment());  ByteVector v5 = file->renderString(file->d->tag->rating());  data.clear();  data.append(ByteVector::fromShort(v1.size(), false));  data.append(ByteVector::fromShort(v2.size(), false));  data.append(ByteVector::fromShort(v3.size(), false));  data.append(ByteVector::fromShort(v4.size(), false));  data.append(ByteVector::fromShort(v5.size(), false));  data.append(v1);  data.append(v2);  data.append(v3);  data.append(v4);  data.append(v5);  return BaseObject::render(file);}ByteVectorASF::File::ExtendedContentDescriptionObject::guid(){  return extendedContentDescriptionGuid;}voidASF::File::ExtendedContentDescriptionObject::parse(ASF::File *file, uint /*size*/){  file->d->extendedContentDescriptionObject = this;  int count = file->readWORD();  while(count--) {    ASF::Attribute attribute;    String name = attribute.parse(*file);    file->d->tag->addAttribute(name, attribute);  }}ByteVectorASF::File::ExtendedContentDescriptionObject::render(ASF::File *file){  data.clear();  data.append(ByteVector::fromShort(attributeData.size(), false));  data.append(attributeData.toByteVector(ByteVector::null));  return BaseObject::render(file);}ByteVectorASF::File::MetadataObject::guid(){  return metadataGuid;}voidASF::File::MetadataObject::parse(ASF::File *file, uint /*size*/){  file->d->metadataObject = this;  int count = file->readWORD();  while(count--) {    ASF::Attribute attribute;    String name = attribute.parse(*file, 1);    file->d->tag->addAttribute(name, attribute);  }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?