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

📄 decoders.cpp

📁 tcpmp.src.0.72RC1 优秀的多媒体播放器TCPMP的源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	printf("OK\n");	printf("testing set_metadata_ignore_application(of app block #1)... ");	if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	num_expected_ = 0;	expected_metadata_sequence_[num_expected_++] = &streaminfo_;	expected_metadata_sequence_[num_expected_++] = &padding_;	expected_metadata_sequence_[num_expected_++] = &seektable_;	expected_metadata_sequence_[num_expected_++] = &application2_;	expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;	expected_metadata_sequence_[num_expected_++] = &cuesheet_;	expected_metadata_sequence_[num_expected_++] = &unknown_;	if(!decoder->test_respond())		return false;	/*	 * respond all, ignore APPLICATION id of app#1 & app#2	 */	printf("testing set_metadata_respond_all()... ");	if(!decoder->set_metadata_respond_all()) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing set_metadata_ignore_application(of app block #1)... ");	if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing set_metadata_ignore_application(of app block #2)... ");	if(!decoder->set_metadata_ignore_application(application2_.data.application.id)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	num_expected_ = 0;	expected_metadata_sequence_[num_expected_++] = &streaminfo_;	expected_metadata_sequence_[num_expected_++] = &padding_;	expected_metadata_sequence_[num_expected_++] = &seektable_;	expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;	expected_metadata_sequence_[num_expected_++] = &cuesheet_;	expected_metadata_sequence_[num_expected_++] = &unknown_;	if(!decoder->test_respond())		return false;	/*	 * ignore all, respond VORBIS_COMMENT	 */	printf("testing set_metadata_ignore_all()... ");	if(!decoder->set_metadata_ignore_all()) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing set_metadata_respond(VORBIS_COMMENT)... ");	if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_VORBIS_COMMENT)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	num_expected_ = 0;	expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;	if(!decoder->test_respond())		return false;	/*	 * ignore all, respond APPLICATION	 */	printf("testing set_metadata_ignore_all()... ");	if(!decoder->set_metadata_ignore_all()) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing set_metadata_respond(APPLICATION)... ");	if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	num_expected_ = 0;	expected_metadata_sequence_[num_expected_++] = &application1_;	expected_metadata_sequence_[num_expected_++] = &application2_;	if(!decoder->test_respond())		return false;	/*	 * ignore all, respond APPLICATION id of app#1	 */	printf("testing set_metadata_ignore_all()... ");	if(!decoder->set_metadata_ignore_all()) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing set_metadata_respond_application(of app block #1)... ");	if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	num_expected_ = 0;	expected_metadata_sequence_[num_expected_++] = &application1_;	if(!decoder->test_respond())		return false;	/*	 * ignore all, respond APPLICATION id of app#1 & app#2	 */	printf("testing set_metadata_ignore_all()... ");	if(!decoder->set_metadata_ignore_all()) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing set_metadata_respond_application(of app block #1)... ");	if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing set_metadata_respond_application(of app block #2)... ");	if(!decoder->set_metadata_respond_application(application2_.data.application.id)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	num_expected_ = 0;	expected_metadata_sequence_[num_expected_++] = &application1_;	expected_metadata_sequence_[num_expected_++] = &application2_;	if(!decoder->test_respond())		return false;	/*	 * respond all, ignore APPLICATION, respond APPLICATION id of app#1	 */	printf("testing set_metadata_respond_all()... ");	if(!decoder->set_metadata_respond_all()) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing set_metadata_ignore(APPLICATION)... ");	if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_APPLICATION)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing set_metadata_respond_application(of app block #1)... ");	if(!decoder->set_metadata_respond_application(application1_.data.application.id)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	num_expected_ = 0;	expected_metadata_sequence_[num_expected_++] = &streaminfo_;	expected_metadata_sequence_[num_expected_++] = &padding_;	expected_metadata_sequence_[num_expected_++] = &seektable_;	expected_metadata_sequence_[num_expected_++] = &application1_;	expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;	expected_metadata_sequence_[num_expected_++] = &cuesheet_;	expected_metadata_sequence_[num_expected_++] = &unknown_;	if(!decoder->test_respond())		return false;	/*	 * ignore all, respond APPLICATION, ignore APPLICATION id of app#1	 */	printf("testing set_metadata_ignore_all()... ");	if(!decoder->set_metadata_ignore_all()) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing set_metadata_respond(APPLICATION)... ");	if(!decoder->set_metadata_respond(FLAC__METADATA_TYPE_APPLICATION)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing set_metadata_ignore_application(of app block #1)... ");	if(!decoder->set_metadata_ignore_application(application1_.data.application.id)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	num_expected_ = 0;	expected_metadata_sequence_[num_expected_++] = &application2_;	if(!decoder->test_respond())		return false;	/* done, now leave the sequence the way we found it... */	num_expected_ = 0;	expected_metadata_sequence_[num_expected_++] = &streaminfo_;	expected_metadata_sequence_[num_expected_++] = &padding_;	expected_metadata_sequence_[num_expected_++] = &seektable_;	expected_metadata_sequence_[num_expected_++] = &application1_;	expected_metadata_sequence_[num_expected_++] = &application2_;	expected_metadata_sequence_[num_expected_++] = &vorbiscomment_;	expected_metadata_sequence_[num_expected_++] = &cuesheet_;	expected_metadata_sequence_[num_expected_++] = &unknown_;	::fclose(decoder->file_);	printf("freeing decoder instance... ");	delete decoder;	printf("OK\n");	printf("\nPASSED!\n");	return true;}class SeekableStreamDecoder : public FLAC::Decoder::SeekableStream, public DecoderCommon {public:	SeekableStreamDecoder(): FLAC::Decoder::SeekableStream(), DecoderCommon() { }	~SeekableStreamDecoder() { }	// from FLAC::Decoder::SeekableStream	::FLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes);	::FLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);	::FLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);	::FLAC__SeekableStreamDecoderLengthStatus length_callback(FLAC__uint64 *stream_length);	bool eof_callback();	::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);	void metadata_callback(const ::FLAC__StreamMetadata *metadata);	void error_callback(::FLAC__StreamDecoderErrorStatus status);	bool die(const char *msg = 0) const;	bool test_respond();};::FLAC__SeekableStreamDecoderReadStatus SeekableStreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes){	switch(common_read_callback_(buffer, bytes)) {		case ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:			return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;		case ::FLAC__STREAM_DECODER_READ_STATUS_ABORT:		case ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:			return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;		default:			FLAC__ASSERT(0);			return ::FLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;	}}::FLAC__SeekableStreamDecoderSeekStatus SeekableStreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset){	if(error_occurred_)		return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;	if(::fseek(file_, (long)absolute_byte_offset, SEEK_SET) < 0) {		error_occurred_ = true;		return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;	}	return ::FLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;}::FLAC__SeekableStreamDecoderTellStatus SeekableStreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset){	if(error_occurred_)		return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;	long offset = ::ftell(file_);	*absolute_byte_offset = (FLAC__uint64)offset;	if(offset < 0) {		error_occurred_ = true;		return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR;	}	return ::FLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;}::FLAC__SeekableStreamDecoderLengthStatus SeekableStreamDecoder::length_callback(FLAC__uint64 *stream_length){	if(error_occurred_)		return ::FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;	*stream_length = (FLAC__uint64)flacfilesize_;	return ::FLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;}bool SeekableStreamDecoder::eof_callback(){	if(error_occurred_)		return true;	return (bool)feof(file_);}::FLAC__StreamDecoderWriteStatus SeekableStreamDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]){	(void)buffer;	return common_write_callback_(frame);}void SeekableStreamDecoder::metadata_callback(const ::FLAC__StreamMetadata *metadata){	common_metadata_callback_(metadata);}void SeekableStreamDecoder::error_callback(::FLAC__StreamDecoderErrorStatus status){	common_error_callback_(status);}bool SeekableStreamDecoder::die(const char *msg) const{	State state = get_state();	if(msg)		printf("FAILED, %s", msg);	else		printf("FAILED");	printf(", state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());	if(state == ::FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR) {		FLAC::Decoder::Stream::State state_ = get_stream_decoder_state();		printf("      stream decoder state = %u (%s)\n", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring());	}	return false;}bool SeekableStreamDecoder::test_respond(){	if(!set_md5_checking(true)) {		printf("FAILED at set_md5_checking(), returned false\n");		return false;	}	printf("testing init()... ");	if(init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)		return die();	printf("OK\n");	current_metadata_number_ = 0;	if(::fseek(file_, 0, SEEK_SET) < 0) {		printf("FAILED rewinding input, errno = %d\n", errno);		return false;	}	printf("testing process_until_end_of_stream()... ");	if(!process_until_end_of_stream()) {		State state = get_state();		printf("FAILED, returned false, state = %u (%s)\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());		return false;	}	printf("OK\n");	printf("testing finish()... ");	finish();	printf("OK\n");	return true;}static bool test_seekable_stream_decoder(){	SeekableStreamDecoder *decoder;	printf("\n+++ libFLAC++ unit test: FLAC::Decoder::SeekableStream\n\n");	//	// test new -> delete	//	printf("allocating decoder instance... ");	decoder = new SeekableStreamDecoder();	if(0 == decoder) {		printf("FAILED, new returned NULL\n");		return false;	}	printf("OK\n");	printf("testing is_valid()... ");	if(!decoder->is_valid()) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("freeing decoder instance... ");	delete decoder;	printf("OK\n");	//	// test new -> init -> delete	//	printf("allocating decoder instance... ");	decoder = new SeekableStreamDecoder();	if(0 == decoder) {		printf("FAILED, new returned NULL\n");		return false;	}	printf("OK\n");	printf("testing is_valid()... ");	if(!decoder->is_valid()) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing init()... ");	if(decoder->init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)		return decoder->die();	printf("OK\n");	printf("freeing decoder instance... ");	delete decoder;	printf("OK\n");	//	// test normal usage	//	num_expected_ = 0;	expected_metadata_sequence_[num_expected_++] = &streaminfo_;	printf("allocating decoder instance... ");	decoder = new SeekableStreamDecoder();	if(0 == decoder) {		printf("FAILED, new returned NULL\n");		return false;	}	printf("OK\n");	printf("testing is_valid()... ");	if(!decoder->is_valid()) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing set_md5_checking()... ");	if(!decoder->set_md5_checking(true)) {		printf("FAILED, returned false\n");		return false;	}	printf("OK\n");	printf("testing init()... ");	if(decoder->init() != ::FLAC__SEEKABLE_STREAM_DECODER_OK)		return decoder->die();	printf("OK\n");	printf("testing get_state()... ");	FLAC::Decoder::SeekableStream::State state = decoder->get_state();	printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__SeekableStreamDecoderState)state), state.as_cstring());	printf("testing get_stream_decoder_state()... ");	FLAC::Decoder::Stream::State state_ = decoder->get_stream_decoder_state();	printf("returned state = %u (%s)... OK\n", (unsigned)((::FLAC__StreamDecoderState)state_), state_.as_cstring());	decoder->current_metadata_number_ = 0;	decoder->ignore_errors_ = false;	decoder->error_occurred_ = false;	printf("opening FLAC file... ");	decoder->file_ = ::fopen(flacfilename_, "rb");	if(0 == decoder->file_) {		printf("ERROR\n");		return false;	}	printf("OK\n");	printf("testing get_md5_checking()... ");	if(!decoder->get_md5_checking()) {		printf("FAILED, returned false, expected true\n");		return false;	}	printf("OK\n");	printf("testing process_until_end_of_metadata()... ");	if(!decoder->process_until_end_of_metadata())		return decoder->die("returned false");	printf("OK\n");	printf("testing process_single()... ");	if(!decoder->process_single())		return decoder->die("returned false");	printf("OK\n");	printf("testing skip_single_frame()... ");	if(!decoder->skip_single_frame())		return decoder->die("returned false");	printf("OK\n");	printf("testing flush()... ");	if(!decoder->flush())		return decoder->die("returned false");	printf("OK\n");	decoder->ignore_errors_ = true;	printf("testing process_single()... ");	if(!decoder->process_single())		return decoder->die("returned false");	printf("OK\n");	decoder->ignore_errors_ = false;	printf("testing seek_absolute()... ");	if(!decoder->seek_absolute(0))		return decoder->die("returned false");

⌨️ 快捷键说明

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