⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 metadata.cpp

📁 tcpmp.src.0.72RC1 优秀的多媒体播放器TCPMP的源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* libFLAC++ - Free Lossless Audio Codec library * Copyright (C) 2002,2003,2004,2005  Josh Coalson * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of the Xiph.org Foundation nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */#include "FLAC++/metadata.h"#include "FLAC/assert.h"#include <stdlib.h> // for malloc(), free()#include <string.h> // for memcpy() etc.#ifdef _MSC_VER// warning C4800: 'int' : forcing to bool 'true' or 'false' (performance warning)#pragma warning ( disable : 4800 )#endifnamespace FLAC {	namespace Metadata {		// local utility routines		namespace local {			Prototype *construct_block(::FLAC__StreamMetadata *object)			{				Prototype *ret = 0;				switch(object->type) {					case FLAC__METADATA_TYPE_STREAMINFO:						ret = new StreamInfo(object, /*copy=*/false);						break;					case FLAC__METADATA_TYPE_PADDING:						ret = new Padding(object, /*copy=*/false);						break;					case FLAC__METADATA_TYPE_APPLICATION:						ret = new Application(object, /*copy=*/false);						break;					case FLAC__METADATA_TYPE_SEEKTABLE:						ret = new SeekTable(object, /*copy=*/false);						break;					case FLAC__METADATA_TYPE_VORBIS_COMMENT:						ret = new VorbisComment(object, /*copy=*/false);						break;					case FLAC__METADATA_TYPE_CUESHEET:						ret = new CueSheet(object, /*copy=*/false);						break;					default:						ret = new Unknown(object, /*copy=*/false);						break;				}				return ret;			}		}		FLACPP_API Prototype *clone(const Prototype *object)		{			FLAC__ASSERT(0 != object);			const StreamInfo *streaminfo = dynamic_cast<const StreamInfo *>(object);			const Padding *padding = dynamic_cast<const Padding *>(object);			const Application *application = dynamic_cast<const Application *>(object);			const SeekTable *seektable = dynamic_cast<const SeekTable *>(object);			const VorbisComment *vorbiscomment = dynamic_cast<const VorbisComment *>(object);			const CueSheet *cuesheet = dynamic_cast<const CueSheet *>(object);			const Unknown *unknown = dynamic_cast<const Unknown *>(object);			if(0 != streaminfo)				return new StreamInfo(*streaminfo);			else if(0 != padding)				return new Padding(*padding);			else if(0 != application)				return new Application(*application);			else if(0 != seektable)				return new SeekTable(*seektable);			else if(0 != vorbiscomment)				return new VorbisComment(*vorbiscomment);			else if(0 != cuesheet)				return new CueSheet(*cuesheet);			else if(0 != unknown)				return new Unknown(*unknown);			else {				FLAC__ASSERT(0);				return 0;			}		}		//		// Prototype		//		Prototype::Prototype(const Prototype &object):		object_(::FLAC__metadata_object_clone(object.object_)),		is_reference_(false)		{			FLAC__ASSERT(object.is_valid());		}		Prototype::Prototype(const ::FLAC__StreamMetadata &object):		object_(::FLAC__metadata_object_clone(&object)),		is_reference_(false)		{		}		Prototype::Prototype(const ::FLAC__StreamMetadata *object):		object_(::FLAC__metadata_object_clone(object)),		is_reference_(false)		{			FLAC__ASSERT(0 != object);		}		Prototype::Prototype(::FLAC__StreamMetadata *object, bool copy):		object_(copy? ::FLAC__metadata_object_clone(object) : object),		is_reference_(false)		{			FLAC__ASSERT(0 != object);		}		Prototype::~Prototype()		{			clear();		}		void Prototype::clear()		{			if(0 != object_ && !is_reference_)				FLAC__metadata_object_delete(object_);			object_ = 0;		}		Prototype &Prototype::operator=(const Prototype &object)		{			FLAC__ASSERT(object.is_valid());			clear();			is_reference_ = false;			object_ = ::FLAC__metadata_object_clone(object.object_);			return *this;		}		Prototype &Prototype::operator=(const ::FLAC__StreamMetadata &object)		{			clear();			is_reference_ = false;			object_ = ::FLAC__metadata_object_clone(&object);			return *this;		}		Prototype &Prototype::operator=(const ::FLAC__StreamMetadata *object)		{			FLAC__ASSERT(0 != object);			clear();			is_reference_ = false;			object_ = ::FLAC__metadata_object_clone(object);			return *this;		}		Prototype &Prototype::assign_object(::FLAC__StreamMetadata *object, bool copy)		{			FLAC__ASSERT(0 != object);			clear();			object_ = (copy? ::FLAC__metadata_object_clone(object) : object);			is_reference_ = false;			return *this;		}		bool Prototype::get_is_last() const		{			FLAC__ASSERT(is_valid());			return (bool)object_->is_last;		}		FLAC__MetadataType Prototype::get_type() const		{			FLAC__ASSERT(is_valid());			return object_->type;		}		unsigned Prototype::get_length() const		{			FLAC__ASSERT(is_valid());			return object_->length;		}		void Prototype::set_is_last(bool value)		{			FLAC__ASSERT(is_valid());			object_->is_last = value;		}		//		// StreamInfo		//		StreamInfo::StreamInfo():		Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_STREAMINFO), /*copy=*/false)		{ }		StreamInfo::~StreamInfo()		{ }		unsigned StreamInfo::get_min_blocksize() const		{			FLAC__ASSERT(is_valid());			return object_->data.stream_info.min_blocksize;		}		unsigned StreamInfo::get_max_blocksize() const		{			FLAC__ASSERT(is_valid());			return object_->data.stream_info.max_blocksize;		}		unsigned StreamInfo::get_min_framesize() const		{			FLAC__ASSERT(is_valid());			return object_->data.stream_info.min_framesize;		}		unsigned StreamInfo::get_max_framesize() const		{			FLAC__ASSERT(is_valid());			return object_->data.stream_info.max_framesize;		}		unsigned StreamInfo::get_sample_rate() const		{			FLAC__ASSERT(is_valid());			return object_->data.stream_info.sample_rate;		}		unsigned StreamInfo::get_channels() const		{			FLAC__ASSERT(is_valid());			return object_->data.stream_info.channels;		}		unsigned StreamInfo::get_bits_per_sample() const		{			FLAC__ASSERT(is_valid());			return object_->data.stream_info.bits_per_sample;		}		FLAC__uint64 StreamInfo::get_total_samples() const		{			FLAC__ASSERT(is_valid());			return object_->data.stream_info.total_samples;		}		const FLAC__byte *StreamInfo::get_md5sum() const		{			FLAC__ASSERT(is_valid());			return object_->data.stream_info.md5sum;		}		void StreamInfo::set_min_blocksize(unsigned value)		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(value >= FLAC__MIN_BLOCK_SIZE);			FLAC__ASSERT(value <= FLAC__MAX_BLOCK_SIZE);			object_->data.stream_info.min_blocksize = value;		}		void StreamInfo::set_max_blocksize(unsigned value)		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(value >= FLAC__MIN_BLOCK_SIZE);			FLAC__ASSERT(value <= FLAC__MAX_BLOCK_SIZE);			object_->data.stream_info.max_blocksize = value;		}		void StreamInfo::set_min_framesize(unsigned value)		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(value < (1u < FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));			object_->data.stream_info.min_framesize = value;		}		void StreamInfo::set_max_framesize(unsigned value)		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(value < (1u < FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));			object_->data.stream_info.max_framesize = value;		}		void StreamInfo::set_sample_rate(unsigned value)		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(FLAC__format_sample_rate_is_valid(value));			object_->data.stream_info.sample_rate = value;		}		void StreamInfo::set_channels(unsigned value)		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(value > 0);			FLAC__ASSERT(value <= FLAC__MAX_CHANNELS);			object_->data.stream_info.channels = value;		}		void StreamInfo::set_bits_per_sample(unsigned value)		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(value >= FLAC__MIN_BITS_PER_SAMPLE);			FLAC__ASSERT(value <= FLAC__MAX_BITS_PER_SAMPLE);			object_->data.stream_info.bits_per_sample = value;		}		void StreamInfo::set_total_samples(FLAC__uint64 value)		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(value < (1u << FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN));			object_->data.stream_info.total_samples = value;		}		void StreamInfo::set_md5sum(const FLAC__byte value[16])		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(0 != value);			memcpy(object_->data.stream_info.md5sum, value, 16);		}		//		// Padding		//		Padding::Padding():		Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING), /*copy=*/false)		{ }		Padding::~Padding()		{ }		void Padding::set_length(unsigned length)		{			FLAC__ASSERT(is_valid());			object_->length = length;		}		//		// Application		//		Application::Application():		Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_APPLICATION), /*copy=*/false)		{ }		Application::~Application()		{ }		const FLAC__byte *Application::get_id() const		{			FLAC__ASSERT(is_valid());			return object_->data.application.id;		}		const FLAC__byte *Application::get_data() const		{			FLAC__ASSERT(is_valid());			return object_->data.application.data;		}		void Application::set_id(const FLAC__byte value[4])		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(0 != value);			memcpy(object_->data.application.id, value, 4);		}		bool Application::set_data(const FLAC__byte *data, unsigned length)		{			FLAC__ASSERT(is_valid());			return (bool)::FLAC__metadata_object_application_set_data(object_, (FLAC__byte*)data, length, true);		}		bool Application::set_data(FLAC__byte *data, unsigned length, bool copy)		{			FLAC__ASSERT(is_valid());			return (bool)::FLAC__metadata_object_application_set_data(object_, data, length, copy);		}		//		// SeekTable		//		SeekTable::SeekTable():		Prototype(FLAC__metadata_object_new(FLAC__METADATA_TYPE_SEEKTABLE), /*copy=*/false)		{ }		SeekTable::~SeekTable()		{ }		unsigned SeekTable::get_num_points() const		{			FLAC__ASSERT(is_valid());			return object_->data.seek_table.num_points;		}		::FLAC__StreamMetadata_SeekPoint SeekTable::get_point(unsigned index) const		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(index < object_->data.seek_table.num_points);			return object_->data.seek_table.points[index];		}		void SeekTable::set_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point)		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(index < object_->data.seek_table.num_points);			::FLAC__metadata_object_seektable_set_point(object_, index, point);		}		bool SeekTable::insert_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point)		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(index <= object_->data.seek_table.num_points);			return (bool)::FLAC__metadata_object_seektable_insert_point(object_, index, point);		}		bool SeekTable::delete_point(unsigned index)		{			FLAC__ASSERT(is_valid());			FLAC__ASSERT(index < object_->data.seek_table.num_points);			return (bool)::FLAC__metadata_object_seektable_delete_point(object_, index);		}		bool SeekTable::is_legal() const		{

⌨️ 快捷键说明

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