📄 decoders.cpp
字号:
decoder->finish(); printf("OK\n"); /* * respond all */ printf("testing set_metadata_respond_all()... "); if(!decoder->set_metadata_respond_all()) { printf("FAILED, returned false\n"); return false; } printf("OK\n"); num_expected_ = 0; expected_metadata_sequence_[num_expected_++] = &streaminfo_; expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; 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_++] = &cuesheet_; expected_metadata_sequence_[num_expected_++] = &unknown_; if(!decoder->test_respond()) return false; /* * ignore all */ printf("testing set_metadata_ignore_all()... "); if(!decoder->set_metadata_ignore_all()) { printf("FAILED, returned false\n"); return false; } printf("OK\n"); num_expected_ = 0; if(!decoder->test_respond()) return false; /* * respond all, ignore VORBIS_COMMENT */ 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(VORBIS_COMMENT)... "); if(!decoder->set_metadata_ignore(FLAC__METADATA_TYPE_VORBIS_COMMENT)) { 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_++] = &application2_; expected_metadata_sequence_[num_expected_++] = &cuesheet_; expected_metadata_sequence_[num_expected_++] = &unknown_; if(!decoder->test_respond()) return false; /* * respond all, ignore APPLICATION */ 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"); num_expected_ = 0; expected_metadata_sequence_[num_expected_++] = &streaminfo_; expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; expected_metadata_sequence_[num_expected_++] = &padding_; expected_metadata_sequence_[num_expected_++] = &seektable_; 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 */ 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"); num_expected_ = 0; expected_metadata_sequence_[num_expected_++] = &streaminfo_; expected_metadata_sequence_[num_expected_++] = &vorbiscomment_; expected_metadata_sequence_[num_expected_++] = &padding_; expected_metadata_sequence_[num_expected_++] = &seektable_; expected_metadata_sequence_[num_expected_++] = &application2_; 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_++] = &vorbiscomment_; expected_metadata_sequence_[num_expected_++] = &padding_; expected_metadata_sequence_[num_expected_++] = &seektable_; 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_++] = &vorbiscomment_; expected_metadata_sequence_[num_expected_++] = &padding_; expected_metadata_sequence_[num_expected_++] = &seektable_; expected_metadata_sequence_[num_expected_++] = &application1_; 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_++] = &vorbiscomment_; 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_++] = &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 OggFLAC::Decoder::SeekableStream, public DecoderCommon {public: SeekableStreamDecoder(): OggFLAC::Decoder::SeekableStream(), DecoderCommon() { } ~SeekableStreamDecoder() { } // from OggFLAC::Decoder::SeekableStream ::OggFLAC__SeekableStreamDecoderReadStatus read_callback(FLAC__byte buffer[], unsigned *bytes); ::OggFLAC__SeekableStreamDecoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset); ::OggFLAC__SeekableStreamDecoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset); ::OggFLAC__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();};::OggFLAC__SeekableStreamDecoderReadStatus SeekableStreamDecoder::read_callback(FLAC__byte buffer[], unsigned *bytes){ switch(common_read_callback_(buffer, bytes)) { case ::FLAC__STREAM_DECODER_READ_STATUS_CONTINUE: case ::FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM: return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK; case ::FLAC__STREAM_DECODER_READ_STATUS_ABORT: return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; default: FLAC__ASSERT(0); return ::OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR; }}::OggFLAC__SeekableStreamDecoderSeekStatus SeekableStreamDecoder::seek_callback(FLAC__uint64 absolute_byte_offset){ if(error_occurred_) return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR; if(::fseek(file_, (long)absolute_byte_offset, SEEK_SET) < 0) { error_occurred_ = true; return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR; } return ::OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;}::OggFLAC__SeekableStreamDecoderTellStatus SeekableStreamDecoder::tell_callback(FLAC__uint64 *absolute_byte_offset){ if(error_occurred_) return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR; long offset = ::ftell(file_); *absolute_byte_offset = (FLAC__uint64)offset; if(offset < 0) { error_occurred_ = true; return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR; } return ::OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;}::OggFLAC__SeekableStreamDecoderLengthStatus SeekableStreamDecoder::length_callback(FLAC__uint64 *stream_length){ if(error_occurred_) return ::OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR; *stream_length = (FLAC__uint64)oggflacfilesize_; return ::OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;}bool SeekableStreamDecoder::eof_callback(){ if(error_occurred_) return true; return (bool)feof(file_);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -