Hi all,I'm still working on this bug. Don't worry. We can let avifile removed for a while and I'll bring it back soon.
The current patch is as attachment. It ports lots of functions to ffmpeg 5.0 and also works in old version.
But there are still 2 function needs to be migrated. I'll finish that later.I also wrote an autopkgtest so that we can know if the forward porting is still good or not.
Attached in this mail too. Yours, Paul
Index: avifile-0.7.48~20090503.ds/configure.in =================================================================== --- avifile-0.7.48~20090503.ds.orig/configure.in +++ avifile-0.7.48~20090503.ds/configure.in @@ -825,7 +825,7 @@ dnl ======================= AM_PATH_FFMPEG tmp_LIBS="$LIBS" -AC_CHECK_LIB([avcodec], [avcodec_register_all], [], +AC_CHECK_LIB([avcodec], [avcodec_version], [], [AC_MSG_ERROR([libavcodec is required to build this package.])]) AC_CHECK_FUNCS([avcodec_decode_audio3 avcodec_decode_video2]) LIBS="$tmp_LIBS" Index: avifile-0.7.48~20090503.ds/lib/codeckeeper.cpp =================================================================== --- avifile-0.7.48~20090503.ds.orig/lib/codeckeeper.cpp +++ avifile-0.7.48~20090503.ds/lib/codeckeeper.cpp @@ -294,7 +294,6 @@ static void plugin_fill() audio_codecs.clear(); // FFMPEG initialization - avcodec_register_all(); uncompressed_FillPlugins(video_codecs); Index: avifile-0.7.48~20090503.ds/plugins/libffmpeg/fillplugins.h =================================================================== --- avifile-0.7.48~20090503.ds.orig/plugins/libffmpeg/fillplugins.h +++ avifile-0.7.48~20090503.ds/plugins/libffmpeg/fillplugins.h @@ -28,7 +28,7 @@ struct FCodec { }; -static void libffmpeg_get_attr(avm::vector<AttributeInfo>& a, AVCodec* codec) +static void libffmpeg_get_attr(avm::vector<AttributeInfo>& a, const AVCodec* codec) { if (!codec) return; Index: avifile-0.7.48~20090503.ds/lib/aviread/FFReadHandler.cpp =================================================================== --- avifile-0.7.48~20090503.ds.orig/lib/aviread/FFReadHandler.cpp +++ avifile-0.7.48~20090503.ds/lib/aviread/FFReadHandler.cpp @@ -3,6 +3,7 @@ #include "avm_output.h" #include "avm_avformat.h" +#include "avm_avcodec.h" #include <stdlib.h> #include <string.h> @@ -24,7 +25,7 @@ public: virtual ~AVStreamPacket() { if (memory) { - av_free_packet(&packet); + av_packet_unref(&packet); memory = 0; } } @@ -46,7 +47,6 @@ FFReadHandler::FFReadHandler() if (!g_iInitilized) { - av_register_all(); g_iInitilized++; } } @@ -88,8 +88,10 @@ int FFReadHandler::Init(const char* url) m_Streams.resize(m_pContext->nb_streams); for (unsigned i = 0; i < m_pContext->nb_streams; ++i) { - AVCodecContext* avc = m_pContext->streams[i]->codec; - AVCodec* codec = avcodec_find_decoder(avc->codec_id); + AVCodecParameters* avp = m_pContext->streams[i]->codecpar; + const AVCodec* codec = avcodec_find_decoder(avp->codec_id); + AVCodecContext* avc = avcodec_alloc_context3(codec); + avcodec_parameters_to_context(avc, avp); AVM_WRITE("FF reader", "S: %d %s CodecID:%x bitrate:%d (%d) samplerate:%d chn:%d framerate:%d/%d wxh %dx%d %d/%d\n", i, codec ? codec->name : "", avc->codec_id, avc->bit_rate, avc->bit_rate_tolerance, avc->sample_rate, avc->channels, avc->time_base.num, avc->time_base.den, @@ -127,7 +129,7 @@ IMediaReadStream* FFReadHandler::GetStre for (unsigned i = 0; i < m_pContext->nb_streams; ++i) { - if (m_pContext->streams[i]->codec->codec_type == t) + if (m_pContext->streams[i]->codecpar->codec_type == t) { if (cnt == stream_id) return m_Streams[i]; @@ -151,7 +153,7 @@ size_t FFReadHandler::GetStreamCount(ISt } for (unsigned i = 0; i < m_pContext->nb_streams; ++i) - if (m_pContext->streams[i]->codec->codec_type == t) + if (m_pContext->streams[i]->codecpar->codec_type == t) cnt++; return cnt; } @@ -239,7 +241,7 @@ int FFReadHandler::readPacket() //else printf("Bitrate %d\n", ast->codec.bit_rate); //printf("TIMESTAMP %" PRId64 " pts: %" PRId64 " dts: %" PRId64 "\n", p->timestamp, pkt.pts, pkt.dts); - switch (ast.codec->codec_type) + switch (ast.codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: s.m_uiPosition += pkt.size; Index: avifile-0.7.48~20090503.ds/lib/aviread/FFReadStream.cpp =================================================================== --- avifile-0.7.48~20090503.ds.orig/lib/aviread/FFReadStream.cpp +++ avifile-0.7.48~20090503.ds/lib/aviread/FFReadStream.cpp @@ -5,6 +5,7 @@ #include "utils.h" #include "avm_avformat.h" +#include "avm_avcodec.h" #include <stdio.h> #include <stdlib.h> @@ -60,13 +61,13 @@ FFReadStream::FFReadStream(FFReadHandler AVM_WRITE("FF stream", "Starttime:%" PRId64 " Duration:%fs\n", m_StartTime, m_dLength); //printf("codec %d %.4s\n", avs->codec->codec_id, &avs->codec->codec_tag); //printf("CODECRA %d %d %d\n", avs->codec->frame_rate, avs->codec->frame_rate_base, avs->r_frame_rate_base); - if (0 && avs->codec->codec_id == AV_CODEC_ID_MPEG1VIDEO) + if (0 && avs->codecpar->codec_id == AV_CODEC_ID_MPEG1VIDEO) { m_pAvContext = avcodec_alloc_context3(NULL); //AVCodec* codec = avcodec_find_encoder(avs->codec->codec_id); if (m_pAvContext) { - AVCodec* codec = avcodec_find_decoder(avs->codec->codec_id); + const AVCodec* codec = avcodec_find_decoder(avs->codecpar->codec_id); if (codec && avcodec_open2(m_pAvContext, codec, NULL) == 0) { m_pAvContext->flags |= AV_CODEC_FLAG_TRUNCATED; @@ -155,30 +156,30 @@ StreamInfo* FFReadStream::GetStreamInfo( m_StreamInfo.m_p->m_iQuality = 0; m_StreamInfo.m_p->m_iSampleSize = 1;//m_Header.dwSampleSize; - switch (avs->codec->codec_type) + switch (avs->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: - m_StreamInfo.m_p->setAudio(avs->codec->channels, - avs->codec->sample_rate, - avs->codec->frame_bits); + m_StreamInfo.m_p->setAudio(avs->codecpar->channels, + avs->codecpar->sample_rate, + avs->codecpar->frame_size); m_StreamInfo.m_p->m_Type = StreamInfo::Audio; - m_StreamInfo.m_p->m_uiFormat = avs->codec->codec_tag; + m_StreamInfo.m_p->m_uiFormat = avs->codecpar->codec_tag; AVM_WRITE("FF stream", "Audio Format: %.4s (0x%x)\n", - (const char*)&avs->codec->codec_tag, avs->codec->codec_tag); + (const char*)&avs->codecpar->codec_tag, avs->codecpar->codec_tag); break; case AVMEDIA_TYPE_VIDEO: - m_StreamInfo.m_p->setVideo(avs->codec->width, avs->codec->height, - 0, (float)avs->codec->sample_aspect_ratio.num / - (float)avs->codec->sample_aspect_ratio.den); + m_StreamInfo.m_p->setVideo(avs->codecpar->width, avs->codecpar->height, + 0, (float)avs->codecpar->sample_aspect_ratio.num / + (float)avs->codecpar->sample_aspect_ratio.den); m_StreamInfo.m_p->m_Type = StreamInfo::Video; - m_StreamInfo.m_p->m_uiFormat = avs->codec->codec_tag; + m_StreamInfo.m_p->m_uiFormat = avs->codecpar->codec_tag; AVM_WRITE("FF stream", "Codec tag format %.4s\n", (char*) &m_StreamInfo.m_p->m_uiFormat); break; default: return 0; } if (m_StreamInfo.m_p->m_uiFormat == 0) { - m_StreamInfo.m_p->m_uiFormat = get_fcc(avs->codec->codec_id); + m_StreamInfo.m_p->m_uiFormat = get_fcc(avs->codecpar->codec_id); if (m_StreamInfo.m_p->m_uiFormat == 0) AVM_WRITE("FF stream", "StreamInfo extension neeeded\n"); @@ -203,7 +204,7 @@ size_t FFReadStream::GetSampleSize() con IStream::StreamType FFReadStream::GetType() const { - switch (m_pHandler->m_pContext->streams[m_uiSId]->codec->codec_type) + switch (m_pHandler->m_pContext->streams[m_uiSId]->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: return IStream::Audio; case AVMEDIA_TYPE_VIDEO: return IStream::Video; @@ -215,8 +216,8 @@ size_t FFReadStream::GetFormat(void *for { AVStream* avs = m_pHandler->m_pContext->streams[m_uiSId]; - int tag = get_fcc(avs->codec->codec_id); - switch (avs->codec->codec_type) + int tag = get_fcc(avs->codecpar->codec_id); + switch (avs->codecpar->codec_type) { case AVMEDIA_TYPE_AUDIO: if (format && size >= sizeof(WAVEFORMATEX)) @@ -230,7 +231,7 @@ size_t FFReadStream::GetFormat(void *for // using extension - there is no free place in original WAVEFORMATEX wfx.wFormatTag = WAVE_FORMAT_EXTENSIBLE; avm_set_le32(&ffwfx.wfex.SubFormat.f1, CodecInfo::FFMPEG); - avm_set_le32(&ffwfx.dwCodecID, avs->codec->codec_id); + avm_set_le32(&ffwfx.dwCodecID, avs->codecpar->codec_id); } else { memset(&wfx, 0, sizeof(wfx)); wfx.wFormatTag = (uint16_t)tag; @@ -238,21 +239,21 @@ size_t FFReadStream::GetFormat(void *for //if (avs->codec->codec_tag == 0) wf->wFormatTag = av_codec_get_fourcc(avs->codec->codec_id); //printf("CODEC %x %x %x\n", wf.wFormatTag, avs->codec->codec_id, avs->codec->codec_tag); - wfx.nChannels = (uint16_t)avs->codec->channels; - wfx.nSamplesPerSec = avs->codec->sample_rate; - wfx.nAvgBytesPerSec = avs->codec->bit_rate / 8; - //printf("SAMP:%d AVGBYTES:%d ALIGN:%d BITS:%d\n", avs->codec->sample_rate, avs->codec->bit_rate, avs->codec->block_align, avs->codec->bits_per_coded_sample); - wfx.nBlockAlign = (uint16_t)avs->codec->block_align; - wfx.wBitsPerSample = (uint16_t)avs->codec->bits_per_coded_sample; + wfx.nChannels = (uint16_t)avs->codecpar->channels; + wfx.nSamplesPerSec = avs->codecpar->sample_rate; + wfx.nAvgBytesPerSec = avs->codecpar->bit_rate / 8; + //printf("SAMP:%d AVGBYTES:%d ALIGN:%d BITS:%d\n", avs->codec->sample_rate, avs->codec->bit_rate, avs->codecpar->block_align, avs->codec->bits_per_coded_sample); + wfx.nBlockAlign = (uint16_t)avs->codecpar->block_align; + wfx.wBitsPerSample = (uint16_t)avs->codecpar->bits_per_coded_sample; wfx.cbSize = tag ? 0 : sizeof(FFMPEGWAVEFORMATEX) - sizeof(WAVEFORMATEX); - if (avs->codec->extradata - && size >= (sizeof(WAVEFORMATEX) + wfx.cbSize + avs->codec->extradata_size)) + if (avs->codecpar->extradata + && size >= (sizeof(WAVEFORMATEX) + wfx.cbSize + avs->codecpar->extradata_size)) { - memcpy((uint8_t*)(&wfx + 1) + wfx.cbSize, avs->codec->extradata, avs->codec->extradata_size); - wfx.cbSize = (uint16_t)(wfx.cbSize + avs->codec->extradata_size); + memcpy((uint8_t*)(&wfx + 1) + wfx.cbSize, avs->codecpar->extradata, avs->codecpar->extradata_size); + wfx.cbSize = (uint16_t)(wfx.cbSize + avs->codecpar->extradata_size); } - if (avs->codec->codec_id == AV_CODEC_ID_AAC) { + if (avs->codecpar->codec_id == AV_CODEC_ID_AAC) { // hmm currenly hack - ffmpeg seems to fail properly detect this stream wfx.nChannels = 2; wfx.nSamplesPerSec = 44100; @@ -263,7 +264,7 @@ size_t FFReadStream::GetFormat(void *for ///printf("AUDIO %d %x %x %d\n", avs->codec->extradata_size, wf->wFormatTag, avs->codec->codec_tag, avs->codec->codec_id); } return (tag ? sizeof(WAVEFORMATEX) : sizeof(FFMPEGWAVEFORMATEX)) - + ((avs->codec->extradata) ? avs->codec->extradata_size : 0); + + ((avs->codecpar->extradata) ? avs->codecpar->extradata_size : 0); case AVMEDIA_TYPE_VIDEO: if (format && size >= sizeof(BITMAPINFOHEADER)) { @@ -271,28 +272,28 @@ size_t FFReadStream::GetFormat(void *for BITMAPINFOHEADER& bih = *(BITMAPINFOHEADER*)format; //printf("FORMAT %p %d %d\n", format, m_uiSId, avc->width); bih.biSize = sizeof(BITMAPINFOHEADER); - bih.biWidth = avs->codec->width; - bih.biHeight = avs->codec->height; + bih.biWidth = avs->codecpar->width; + bih.biHeight = avs->codecpar->height; bih.biPlanes = 1; - bih.biCompression = get_fcc(avs->codec->codec_id); - bih.biBitCount = (uint16_t)avs->codec->bits_per_coded_sample; + bih.biCompression = get_fcc(avs->codecpar->codec_id); + bih.biBitCount = (uint16_t)avs->codecpar->bits_per_coded_sample; // hack which might be eventually usefull //memcpy(&bih->biXPelsPerMeter, &m_pHandler->m_pContext, sizeof(void*)); if (!bih.biCompression) { bih.biCompression = CodecInfo::FFMPEG; - bih.biSizeImage = avs->codec->codec_id; + bih.biSizeImage = avs->codecpar->codec_id; } - if (avs->codec->extradata && size >= (sizeof(BITMAPINFOHEADER) + avs->codec->extradata_size)) + if (avs->codecpar->extradata && size >= (sizeof(BITMAPINFOHEADER) + avs->codecpar->extradata_size)) { - bih.biSize += avs->codec->extradata_size; - memcpy(&bih + 1, avs->codec->extradata, avs->codec->extradata_size); + bih.biSize += avs->codecpar->extradata_size; + memcpy(&bih + 1, avs->codecpar->extradata, avs->codecpar->extradata_size); //printf("COPY EXTRA %d\n", avs->extradata_size); //for (unsigned i = 0; i < size; i++) printf("%d 0x%x\n", i, ((uint8_t*)format)[i]); } //BitmapInfo(*bih).Print(); } return sizeof(BITMAPINFOHEADER) - + ((avs->codec->extradata) ? avs->codec->extradata_size : 0); + + ((avs->codecpar->extradata) ? avs->codecpar->extradata_size : 0); default: return 0; } @@ -354,7 +355,7 @@ int FFReadStream::SeekTime(double time) return m_pHandler->seek(time); if (time < 1.) { - if (m_pAvStream->codec->codec_type == AVMEDIA_TYPE_AUDIO) + if (m_pAvStream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) // check if more streams are available // and seek only with the video return 0;
all: test1 AVIFILE_LIBS=$(shell pkg-config --libs avifile) AVIFILE_CFLAGS=$(shell pkg-config --cflags avifile) AUBIO_LIBS=$(shell pkg-config --libs aubio) AUBIO_CFLAGS=$(shell pkg-config --cflags aubio) test1: test1.cc g++ -Wall -g -o test1 test1.cc \ $(AVIFILE_LIBS) $(AVIFILE_CFLAGS) \ $(AUBIO_LIBS) $(AUBIO_CFLAGS) \ -lm clean: rm -f test1
/* C++ header */ #include <iostream> /* C header */ #include <cstdio> #include <cstring> #include <cstdlib> #include <cstdint> #include <cmath> /* UNIX header */ #include <unistd.h> /* AVIFILE header */ #include <avifile.h> #include <aviplay.h> #include <avm_fourcc.h> #include <avm_cpuinfo.h> #include <avm_except.h> #include <avm_creators.h> #include <utils.h> #include <version.h> #include <videodecoder.h> #include <audiodecoder.h> #include <renderer.h> /* AUBIO */ #include <aubio/aubio.h> #include <aubio/fvec.h> float getFreq(const char *audioBuf, int audioBufSize, int bitsPerSample, int channels, int sampleRate) { int i; int n=0; float freq=0.0; fvec_t *input; fvec_t *out; aubio_pitch_t *pitch1; freq = nanf(""); if (audioBuf == NULL || audioBufSize <= 0) { return freq; } if (bitsPerSample == 32) { n = audioBufSize / 4; n = n / channels; pitch1 = new_aubio_pitch ("default", n, n, sampleRate); input = new_fvec(n); out = new_fvec(1); for (i = 0; i<n; i++) { int32_t *p2; int32_t data1 = 0; int i1; i1 = i*4*channels; if (i1 < audioBufSize) { p2 = (int32_t *)&(audioBuf[i1]); data1 = *p2; } fvec_set_sample(input, ((float)(data1)) / (((float)(INT32_MAX))+1.0), i); } aubio_pitch_do(pitch1, input, out); freq = fvec_get_sample(out, 0); del_fvec (out); del_fvec (input); del_aubio_pitch (pitch1); return freq; } else if (bitsPerSample == 16) { n = audioBufSize / 2; n = n / channels; pitch1 = new_aubio_pitch ("default", n, n, sampleRate); input = new_fvec(n); out = new_fvec(1); for (i = 0; i<n; i++) { int16_t *p2; int16_t data1 = 0; int i1; i1 = i*2*channels; if (i1 < audioBufSize) { p2 = (int16_t *)&(audioBuf[i1]); data1 = *p2; } fvec_set_sample(input, ((float)(data1)) / (((float)(INT16_MAX))+1.0), i); } aubio_pitch_do(pitch1, input, out); freq = fvec_get_sample(out, 0); del_fvec (out); del_fvec (input); del_aubio_pitch (pitch1); aubio_cleanup (); return freq; } else if (bitsPerSample == 8) { n = audioBufSize; n = n / channels; pitch1 = new_aubio_pitch ("default", n, n, sampleRate); input = new_fvec(n); out = new_fvec(1); for (i = 0; i<n; i++) { int8_t *p2; int8_t data1 = 0; int i1; i1 = i*channels; if (i1 < audioBufSize) { p2 = (int8_t *)&(audioBuf[i1]); data1 = *p2; } fvec_set_sample(input, ((float)(data1)) / (((float)(INT8_MAX))+1.0), i); } aubio_pitch_do(pitch1, input, out); freq = fvec_get_sample(out, 0); del_fvec (out); del_fvec (input); del_aubio_pitch (pitch1); aubio_cleanup (); return freq; } return freq; } int main(int argc, char *argv[]) { int version; char *filename; avm::IReadFile *file = NULL; avm::IReadStream *videoStream; avm::IReadStream *audioStream; BITMAPINFOHEADER bh; BITMAPINFOHEADER bhy; WAVEFORMATEX wave_fmt; fourcc_t fcc; avm::IVideoDecoder::CAPS caps; int width = 0; int height = 0; char audioBuf[102400]; size_t totalAudioSamplesRead = 0; size_t totalAudioBytesRead = 0; bool audioCheckedFlag = false; /* check version */ version = GetAvifileVersion(); std::cout << "This binary was compiled for Avifile ver. " << AVIFILE_VERSION << ", " << "the library is ver. " << GetAvifileVersion() << std::endl; if (version != AVIFILE_VERSION) { std::cerr << "Version mismatched. " << " - Aborting." << std::endl; return 1; } /* get filename */ if (argc != 2) { std::cerr << "No filename provided" << std::endl; return 2; } filename = argv[1]; /* open file */ file = avm::CreateReadFile(filename); if (!file) { std::cerr << "Open file " << filename << " error" << std::endl; return 3; } /* open video stream */ videoStream = file->GetStream(0, avm::IStream::Video); if (!videoStream) { std::cerr << "Cannot get video stream" << std::endl; return 4; } if (videoStream->StartStreaming() != 0) { std::cerr << "Cannot decode video stream" << std::endl; return 5; } /* open audio stream */ audioStream = file->GetStream(0, avm::IStream::Audio); if (!audioStream) { std::cerr << "Cannot get audio stream" << std::endl; return 4; } if (audioStream->StartStreaming() != 0) { std::cerr << "Cannot decode audio stream" << std::endl; return 5; } /* get information of video stream */ videoStream->GetOutputFormat(&bh, sizeof(bh)); std::cout << "bh.biHeight = " << bh.biHeight << ", " << "bh.biWidth = " << bh.biWidth << std::endl; if (bh.biHeight < 0) { bh.biHeight = -bh.biHeight; std::cout << "bh.biHeight < 0, correct the value to " << bh.biHeight << std::endl; } std::cout << "Movie size: " << bh.biWidth << " x " << bh.biHeight << " [" << ((char *)(&bh.biCompression)) << "]" << std::endl; width = bh.biWidth; height = bh.biHeight; if (width <= 0 || height <= 0) { return 6; } /* get information of audio stream */ audioStream->GetAudioDecoder()->GetOutputFormat(&wave_fmt); std::cout << "audio format: " << wave_fmt.wFormatTag << ", " << "Channels: " << wave_fmt.nChannels << ", " << "Samples/sec: " << wave_fmt.nSamplesPerSec << ", " << "Bits/Sample: " << wave_fmt.wBitsPerSample << ", " << "Bytes/sec: " << wave_fmt.nAvgBytesPerSec << std::endl; if (wave_fmt.nChannels <= 0 || wave_fmt.nSamplesPerSec <= 0) { return 6; } /* video length */ std::cout << "Video Length: " << videoStream->GetLength() << std::endl; std::cout << "Video Pos: " << videoStream->GetPos() << std::endl; if (videoStream->GetLength() <= 0) { return 7; } /* audio length */ std::cout << "Audio Length: " << audioStream->GetLength() << std::endl; std::cout << "Audio Pos: " << audioStream->GetPos() << std::endl; if (audioStream->GetLength() <= 0) { return 7; } /* video format */ videoStream->GetVideoFormat(&bhy, sizeof(bhy)); caps = videoStream->GetVideoDecoder()->GetCapabilities(); std::cout << "Decoder YUV capabilities: 0x" << std::hex << caps << std::dec << std::endl; if (caps & avm::IVideoDecoder::CAP_YUY2) { fcc = fccYUY2; std::cout << "CAPS is CAP_YUY2" << std::endl; } else if (caps & avm::IVideoDecoder::CAP_YV12) { fcc = fccYV12; std::cout << "CAPS is CAP_YV12" << std::endl; } else if (caps & avm::IVideoDecoder::CAP_UYVY) { fcc = fccUYVY; std::cout << "CAPS is CAP_UYVY" << std::endl; } else { std::cerr << "YUV format unsupported by decoder" << std::endl; return 8; } if (fcc) { if (videoStream->GetVideoDecoder()->SetDestFmt(0, fcc)) { std::cerr << "Error setting YUV decoder output" << std::endl; return 9; } } /* decoding video/audio */ videoStream->SetBuffering(4, 0); while (!videoStream->Eof() || !audioStream->Eof()) { avm::CImage* im; uint8_t *pixelData; std::cout << "TIME " << videoStream->GetTime() << " " << videoStream->GetPos() << std::endl; if (!videoStream->Eof()) { videoStream->ReadFrame(true); im = videoStream->GetFrame(); } else { im = NULL; } if (im) { if (im->Width() != width || im->Height() != height) { std::cerr << "IMAGE " << im->Width() << " x " << im->Height() << std::endl; return 10; } avm::BitmapInfo bi1(im->Width(), im->Height(), 24); bi1.SetRGB(); avm::CImage imRGB(im, &bi1); if (imRGB.Width() != im->Width() || imRGB.Height() != im->Height()) { std::cerr << "imRGB size (" << imRGB.Width() << " x " << imRGB.Height() << ")" << " != " << "im size (" << im->Width() << " x " << im->Height() << ")" << std::endl; return 11; } if (imRGB.Bpp() != 3) { std::cerr << "imRGB.Bpp() = " << imRGB.Bpp() << " != 3" << std::endl; return 12; } if (imRGB.Depth() != 24) { std::cerr << "imRGB.Depth() = " << imRGB.Depth() << " != 24" << std::endl; return 13; } /* Test for frame no. 100 ~ 120 */ if (100 <= videoStream->GetPos() && videoStream->GetPos() <= 120) { /* check for Red */ pixelData = imRGB.At(im->Width()*11/14,im->Height()*1/3); if (!(pixelData[0] > 128 && pixelData[1] < 128 && pixelData[2] < 128)) { std::cerr << "Red check failed at frame " << videoStream->GetPos() << std::endl; return 14; } /* check for Green */ pixelData = imRGB.At(im->Width()*7/14,im->Height()*1/3); if (!(pixelData[0] < 128 && pixelData[1] > 128 && pixelData[2] < 128)) { std::cerr << "Green check failed at frame " << videoStream->GetPos() << std::endl; return 15; } /* check for Blue */ pixelData = imRGB.At(im->Width()*13/14,im->Height()*1/3); if (!(pixelData[0] < 128 && pixelData[1] < 128 && pixelData[2] > 128)) { std::cerr << "Blue check failed at frame " << videoStream->GetPos() << std::endl; return 16; } std::cout << "RGB check passed" << std::endl; } im->Release(); } else { std::cout << "Zero image!" << std::endl; } while (!audioStream->Eof() && (audioStream->GetTime() <= videoStream->GetTime() || videoStream->Eof()) ) { size_t samples_read; size_t bytes_read; audioStream->ReadFrames(audioBuf, sizeof(audioBuf), 1024, samples_read, bytes_read); std::cout << "Audio read " << samples_read << " samples, " << bytes_read << " bytes." << std::endl; float freq; freq = getFreq(audioBuf, bytes_read, wave_fmt.wBitsPerSample, wave_fmt.nChannels, wave_fmt.nSamplesPerSec); std::cout << "Audio frequency " << freq << " hz" << std::endl; if (350.0 <= freq && freq <= 500.0) { audioCheckedFlag = true; } totalAudioSamplesRead += samples_read; totalAudioBytesRead += bytes_read; } } std::cout << "audio: totalAudioSamplesRead = " << totalAudioSamplesRead << std::endl; std::cout << "audio: totalAudioBytesRead = " << totalAudioBytesRead << std::endl; if (totalAudioSamplesRead != audioStream->GetLength()) { std::cerr << "totalAudioSampleRead " << totalAudioSamplesRead << " != " << audioStream->GetLength() << std::endl; return 17; } if (!audioCheckedFlag) { std::cerr << "Didn't detect audio track with 440 hz" << std::endl; return 18; } std::cout << "Test Pass" << std::endl; aubio_cleanup (); return 0; }
OpenPGP_signature
Description: OpenPGP digital signature