From 67ba34c6f0b18d49d87b9c560576a59b4cd8a6a1 Mon Sep 17 00:00:00 2001 From: Jakub Bogusz Date: Sun, 30 Aug 2020 18:52:14 +0200 Subject: [PATCH] - enhanced ffmpeg patch to cover 4.x - added format,narrowing patches --- avifile-ffmpeg.patch | 335 ++++++++++++++++++++++++++++++++++++++++ avifile-format.patch | 11 ++ avifile-narrowing.patch | 25 +++ avifile.spec | 4 + 4 files changed, 375 insertions(+) create mode 100644 avifile-format.patch create mode 100644 avifile-narrowing.patch diff --git a/avifile-ffmpeg.patch b/avifile-ffmpeg.patch index b02883a..7aaa21a 100644 --- a/avifile-ffmpeg.patch +++ b/avifile-ffmpeg.patch @@ -374,3 +374,338 @@ { free(m_pAvContext); m_pAvContext = 0; +--- avifile-0.7-0.7.45/lib/aviread/FFReadHandler.cpp.orig 2020-08-29 20:43:18.688873368 +0200 ++++ avifile-0.7-0.7.45/lib/aviread/FFReadHandler.cpp 2020-08-29 20:43:43.955403155 +0200 +@@ -40,7 +40,7 @@ + delete m_Streams.back(); + m_Streams.pop_back(); + } +- av_close_input_file(m_pContext); ++ avformat_close_input(&m_pContext); + } + } + +@@ -58,7 +58,7 @@ + return -1; + } + +- if (av_find_stream_info(m_pContext) < 0) ++ if (avformat_find_stream_info(m_pContext, NULL) < 0) + return -1; + + AVM_WRITE("FF reader", "Format %s streams:%d\n", m_pContext->iformat->long_name, m_pContext->nb_streams); +@@ -161,9 +161,9 @@ + Locker locker(m_Mutex); + AVPacket pkt; + AVM_WRITE("FF reader", "readPacket()\n"); +- if (av_read_packet(m_pContext, &pkt) < 0) ++ if (av_read_frame(m_pContext, &pkt) < 0) + { +- if (!url_feof(m_pContext->pb)) ++ if (!avio_feof(m_pContext->pb)) + AVM_WRITE("FF reader", "ffmpeg packet error and not eof??\n"); + return -1; + } +--- avifile-0.7-0.7.45/lib/aviread/FFReadStream.cpp.orig 2020-08-29 20:22:05.882435419 +0200 ++++ avifile-0.7-0.7.45/lib/aviread/FFReadStream.cpp 2020-08-29 20:46:33.481151421 +0200 +@@ -21,15 +21,15 @@ + enum AVCodecID id; + uint32_t fcc; + } id2fcct[] = { +- { CODEC_ID_MPEG1VIDEO, RIFFINFO_MPG1 }, +- { CODEC_ID_H263, mmioFOURCC('H', '2', '6', '3') }, +- { CODEC_ID_H263P, mmioFOURCC('H', '2', '6', '3') }, +- { CODEC_ID_MP2, 0x50 }, +- { CODEC_ID_MP3, 0x55 }, +- { CODEC_ID_AC3, 0x2000 }, +- { CODEC_ID_DVVIDEO, mmioFOURCC('D', 'V', 'S', 'D') }, +- { CODEC_ID_DVAUDIO, ('D' << 8) | 'A' }, +- { CODEC_ID_NONE } ++ { AV_CODEC_ID_MPEG1VIDEO, RIFFINFO_MPG1 }, ++ { AV_CODEC_ID_H263, mmioFOURCC('H', '2', '6', '3') }, ++ { AV_CODEC_ID_H263P, mmioFOURCC('H', '2', '6', '3') }, ++ { AV_CODEC_ID_MP2, 0x50 }, ++ { AV_CODEC_ID_MP3, 0x55 }, ++ { AV_CODEC_ID_AC3, 0x2000 }, ++ { AV_CODEC_ID_DVVIDEO, mmioFOURCC('D', 'V', 'S', 'D') }, ++ { AV_CODEC_ID_DVAUDIO, ('D' << 8) | 'A' }, ++ { AV_CODEC_ID_NONE } + }; + + static int get_fcc(enum AVCodecID id) +@@ -51,7 +51,7 @@ + m_pHandler->m_pContext->start_time, m_pHandler->m_pContext->duration); + m_dLength = m_pHandler->m_pContext->duration / (double) AV_TIME_BASE; + //printf("CODECRA %d %d %d\n", avs->codec.frame_rate, avs->codec->frame_rate_base, m_pAvStream->r_frame_rate_base); +- if (0 && avs->codec->codec_id == CODEC_ID_MPEG1VIDEO) ++ if (0 && avs->codec->codec_id == AV_CODEC_ID_MPEG1VIDEO) + { + m_pAvContext = avcodec_alloc_context3(NULL); + //AVCodec* codec = avcodec_find_encoder(avs->codec->codec_id); +@@ -60,7 +60,7 @@ + AVCodec* codec = avcodec_find_decoder(avs->codec->codec_id); + if (codec && avcodec_open2(m_pAvContext, codec, NULL) == 0) + { +- m_pAvContext->flags |= CODEC_FLAG_TRUNCATED; ++ m_pAvContext->flags |= AV_CODEC_FLAG_TRUNCATED; + m_pAvContext->skip_idct = m_pAvContext->skip_frame = AVDISCARD_ALL; + //printf("Opened hurryup decoder %p %p\n", codec, m_pAvContext->codec->decode); + } +--- avifile-0.7-0.7.45/plugins/libffmpeg/FFAudioDecoder.cpp.orig 2020-08-29 21:50:27.323715047 +0200 ++++ avifile-0.7-0.7.45/plugins/libffmpeg/FFAudioDecoder.cpp 2020-08-29 21:50:31.260360387 +0200 +@@ -49,18 +49,23 @@ + return -1; + } + } +- int framesz = 0; ++ int got_frame = 0; + AVPacket avpkt; + av_init_packet(&avpkt); + avpkt.data = (uint8_t*)in_data; + avpkt.size = in_size; +- int hr = avcodec_decode_audio3(m_pAvContext, (int16_t*)out_data, &framesz, ++ AVFrame *decoded_frame = av_frame_alloc(); ++ int hr = avcodec_decode_audio4(m_pAvContext, decoded_frame, &got_frame, + &avpkt); +- //printf("CONVERT i:%d o:%d f:%d h:%d\n", in_size, out_size, framesz, hr); ++ int data_size = av_samples_get_buffer_size(NULL, m_pAvContext->channels, decoded_frame->nb_samples, m_pAvContext->sample_fmt, 1); + if (size_read) + *size_read = (hr < 0) ? in_size : hr; + if (size_written) +- *size_written = framesz; ++ *size_written = data_size; ++ ++ if (hr > 0) ++ memcpy(out_data, decoded_frame->data[0], data_size); ++ av_free(decoded_frame); + + if (hr < 0) + { +--- avifile-0.7-0.7.45/plugins/libffmpeg/FFVideoDecoder.cpp.orig 2020-08-29 20:47:30.190844199 +0200 ++++ avifile-0.7-0.7.45/plugins/libffmpeg/FFVideoDecoder.cpp 2020-08-30 17:57:09.138147425 +0200 +@@ -17,6 +17,12 @@ + #endif + + #define Debug if (0) ++ ++struct BufferData { ++ void *decoder; ++ AVFrame *pic; ++}; ++ + AVM_BEGIN_NAMESPACE; + + FFVideoDecoder::FFVideoDecoder(AVCodec* av, const CodecInfo& info, const BITMAPINFOHEADER& bh, int flip) +@@ -31,7 +37,7 @@ + if (1 && m_pFormat->biCompression == fccHFYU) + { + // for now disabled +- m_pAvCodec->capabilities &= ~(CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1); ++ m_pAvCodec->capabilities &= ~(AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1); + AVM_WRITE(m_Info.GetPrivateName(), "if you have troubles - use Win32 codec instead\n"); + m_Caps = (CAPS) (m_Caps | CAP_YUY2); + } +@@ -75,31 +81,39 @@ + d->m_pImg->Slice(&ci); + } + ++static void free_buffer(void *opaque, uint8_t *data); ++ + // callback to supply rendering buffer to ffmpeg +-static int get_buffer(AVCodecContext* avctx, AVFrame* pic) ++static int get_buffer2(AVCodecContext* avctx, AVFrame* pic, int flags) + { ++ BufferData* buf_dat; + FFVideoDecoder* d = (FFVideoDecoder*) avctx->opaque; + CImage* pImage = d->m_pImg; + d->m_bUsed = true; +- if (avctx->pix_fmt != PIX_FMT_YUV420P || !pImage || !d->m_bDirect) ++ if (avctx->pix_fmt != AV_PIX_FMT_YUV420P || !pImage || !d->m_bDirect) + { + Debug printf("FF: Unsupported pixel format for Dr1 %d\n", avctx->pix_fmt); //abort(); +- return avcodec_default_get_buffer(avctx, pic); ++ return avcodec_default_get_buffer2(avctx, pic, flags); + } + + Debug printf("FF: GetBuffer %p %dx%d %d %p:%p:%p %f\n", pImage, avctx->width, avctx->height, pic->pict_type, + pImage->Data(0), pImage->Data(2), pImage->Data(1), pImage->m_lTimestamp / 1000000.0); + + pic->opaque = pImage; +- pic->data[0] = pImage->Data(0); +- pic->data[1] = pImage->Data(2); +- pic->data[2] = pImage->Data(1); ++ buf_dat = (BufferData*)av_malloc(sizeof(*buf_dat)); ++ buf_dat->decoder = d; ++ buf_dat->pic = pic; ++ pic->buf[0] = av_buffer_create (pImage->Data(0), 0, free_buffer, buf_dat, 0); ++ pic->buf[1] = av_buffer_create (pImage->Data(2), 0, free_buffer, NULL, 0); ++ pic->buf[2] = av_buffer_create (pImage->Data(1), 0, free_buffer, NULL, 0); ++ pic->data[0] = pic->buf[0]->data; ++ pic->data[1] = pic->buf[1]->data; ++ pic->data[2] = pic->buf[2]->data; + pic->linesize[0] = pImage->Stride(0); + // Note: most ffmpeg codecs linsize[1] == linesize[2] ! + pic->linesize[1] = pImage->Stride(2); + pic->linesize[2] = pImage->Stride(1); + pic->pts = pImage->m_lTimestamp; +- pic->type = FF_BUFFER_TYPE_USER; + pImage->m_iType = pic->pict_type; + //pImage->m_iAge = (pic->pict_type == AV_PICTURE_TYPE_B) ? + //pImage->m_iAge = (pic->reference) ? +@@ -129,21 +143,16 @@ + return 0; + } + +-static void release_buffer(struct AVCodecContext* avctx, AVFrame* pic) ++static void free_buffer(void *opaque, uint8_t *data) + { +- if (pic->type == FF_BUFFER_TYPE_USER) +- { +- FFVideoDecoder* d = (FFVideoDecoder*) avctx->opaque; +- d->m_pReleased = (CImage*) pic->opaque; +- Debug printf("FF: Released buffer %p %p\n", pic->opaque, pic); +- for (int i = 4; i >= 0; i--) +- pic->data[i]= NULL; +- pic->opaque = NULL; +- } +- else ++ if (opaque) + { +- Debug printf("******************************\n"); +- avcodec_default_release_buffer(avctx, pic); ++ BufferData *buf_dat = (BufferData *) opaque; ++ FFVideoDecoder* d = (FFVideoDecoder*) buf_dat->decoder; ++ d->m_pReleased = (CImage*) buf_dat->pic->opaque; ++ Debug printf("FF: Released buffer %p %p\n", buf_dat->pic->opaque, buf_dat->pic); ++ buf_dat->pic->opaque = NULL; ++ av_free(buf_dat); + } + } + +@@ -171,8 +180,7 @@ + m_pAvContext->bits_per_coded_sample = m_pFormat->biBitCount; + m_pAvContext->width = m_Dest.biWidth; + m_pAvContext->height = (m_Dest.biHeight < 0) ? -m_Dest.biHeight : m_Dest.biHeight; +- m_pAvContext->get_buffer = avcodec_default_get_buffer; +- m_pAvContext->release_buffer = avcodec_default_release_buffer; ++ m_pAvContext->get_buffer2 = avcodec_default_get_buffer2; + + if (m_pFormat->biSize > sizeof(BITMAPINFOHEADER) + #if 0 +@@ -200,7 +208,7 @@ + const char* drtxt = "doesn't support DR1\n"; + + m_bDirect = false; +- if (m_pAvCodec->capabilities & CODEC_CAP_DR1) ++ if (m_pAvCodec->capabilities & AV_CODEC_CAP_DR1) + { + drtxt = "not using DR1\n"; + if (pImage) +@@ -220,12 +228,10 @@ + { + // for DR we needs some special width aligment + // also there are some more limitation +- m_pAvContext->flags |= CODEC_FLAG_EMU_EDGE; + drtxt = "using DR1\n"; + m_bDirect = true; + +- m_pAvContext->get_buffer = get_buffer; +- m_pAvContext->release_buffer = release_buffer; ++ m_pAvContext->get_buffer2 = get_buffer2; + } + } + } +@@ -234,8 +240,8 @@ + m_bRestart = false; + + if (m_Info.fourcc == RIFFINFO_MPG1 +- && m_pAvCodec->capabilities & CODEC_CAP_TRUNCATED) +- m_pAvContext->flags |= CODEC_FLAG_TRUNCATED; ++ && m_pAvCodec->capabilities & AV_CODEC_CAP_TRUNCATED) ++ m_pAvContext->flags |= AV_CODEC_FLAG_TRUNCATED; + + //m_pAvContext->error_resilience = 2; + //m_pAvContext->error_concealment = 3; +@@ -299,7 +305,7 @@ + // try using draw_horiz_band if DR1 is unsupported + m_pAvContext->draw_horiz_band = + (!m_bDirect && pImage && pImage->Format() == IMG_FMT_YV12 +- && (m_pAvCodec->capabilities & CODEC_CAP_DRAW_HORIZ_BAND) ++ && (m_pAvCodec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND) + && !pImage->Direction() && render) ? draw_slice : 0; + m_pAvContext->opaque = this; + +@@ -324,7 +330,7 @@ + AVM_WRITE(m_Info.GetPrivateName(), "WARNING: FFVideoDecoder::DecodeFrame() hr=%d\n", hr); + return hr; + } +- if (!(m_pAvContext->flags & CODEC_FLAG_TRUNCATED)) ++ if (!(m_pAvContext->flags & AV_CODEC_FLAG_TRUNCATED)) + { + hr = size; + //m_bUsed = true; +@@ -368,7 +374,6 @@ + return hr | NO_PICTURE; + // let's fake got_picture; + if (!pic.opaque) { +- pic.type = FF_BUFFER_TYPE_USER; + pic.opaque = m_pReleased; + } + got_picture = true; +@@ -382,14 +387,14 @@ + int imfmt = 0; + switch (m_pAvContext->pix_fmt) + { +- case PIX_FMT_BGR24: imfmt = IMG_FMT_BGR24; break; +- case PIX_FMT_RGB32: imfmt = IMG_FMT_BGR32; break; +- case PIX_FMT_YUYV422: imfmt = IMG_FMT_YUY2; break; +- case PIX_FMT_YUV410P: imfmt = IMG_FMT_I410; break; +- case PIX_FMT_YUV411P: imfmt = IMG_FMT_I411; break; +- case PIX_FMT_YUV420P: imfmt = IMG_FMT_I420; break; +- case PIX_FMT_YUV422P: imfmt = IMG_FMT_I422; break; +- case PIX_FMT_YUV444P: imfmt = IMG_FMT_I444; break; ++ case AV_PIX_FMT_BGR24: imfmt = IMG_FMT_BGR24; break; ++ case AV_PIX_FMT_RGB32: imfmt = IMG_FMT_BGR32; break; ++ case AV_PIX_FMT_YUYV422: imfmt = IMG_FMT_YUY2; break; ++ case AV_PIX_FMT_YUV410P: imfmt = IMG_FMT_I410; break; ++ case AV_PIX_FMT_YUV411P: imfmt = IMG_FMT_I411; break; ++ case AV_PIX_FMT_YUV420P: imfmt = IMG_FMT_I420; break; ++ case AV_PIX_FMT_YUV422P: imfmt = IMG_FMT_I422; break; ++ case AV_PIX_FMT_YUV444P: imfmt = IMG_FMT_I444; break; + default: break; + } + if (imfmt) { +@@ -415,11 +420,8 @@ + //printf("SWAP %d %d\n", m_Order.front().position, pImage->m_uiPosition); + //printf("P %d %lld\n", p, m_Order[0].timestamp, m_Order.size()); + +- //printf("PICTYPE %d %p %p %d\n", pic.type, m_pReleased, pOut, FF_BUFFER_TYPE_USER); + #if 1 +- if (pOut && pic.opaque && +- ((pic.type == FF_BUFFER_TYPE_USER) +- || (pic.type == FF_BUFFER_TYPE_COPY))) ++ if (pOut && pic.opaque) + { + *pOut = (CImage*) pic.opaque; + (*pOut)->m_lTimestamp = m_Order[0].timestamp; +--- avifile-0.7-0.7.45/plugins/libffmpeg/FFVideoEncoder.cpp.orig 2020-08-29 20:47:30.190844199 +0200 ++++ avifile-0.7-0.7.45/plugins/libffmpeg/FFVideoEncoder.cpp 2020-08-30 18:06:20.805158789 +0200 +@@ -220,11 +220,15 @@ + //printf("ECDING FF %p %p %p sz:%d\n", f.data[0], f.data[1], f.data[2], GetOutputSize()); + //printf("ECDING FF %d %d %d\n", f.linesize[0], f.linesize[1], f.linesize[2]); + +- int rsize = avcodec_encode_video(m_pAvContext, (unsigned char*) dest, +- GetOutputSize(), &f); ++ AVPacket pkt; ++ pkt.data = (uint8_t*)dest; ++ pkt.size = GetOutputSize(); ++ int got_output; ++ ++ int ret = avcodec_encode_video2(m_pAvContext, &pkt, &f, &got_output); + //printf("ECDING FF size %d\n", rsize); + if (size) +- *size = rsize; ++ *size = pkt.size; + if (is_keyframe) { + *is_keyframe = m_pAvContext->coded_frame->key_frame ? 16 : 0; + //printf("KEYFRAME %d\n", *is_keyframe); diff --git a/avifile-format.patch b/avifile-format.patch new file mode 100644 index 0000000..819d9e2 --- /dev/null +++ b/avifile-format.patch @@ -0,0 +1,11 @@ +--- avifile-0.7-0.7.45/drivers/libdha/mtrr.c.orig 2020-08-29 20:21:27.482643449 +0200 ++++ avifile-0.7-0.7.45/drivers/libdha/mtrr.c 2020-08-29 20:21:31.662620804 +0200 +@@ -80,7 +80,7 @@ + char sout[256]; + unsigned wr_len; + sprintf(sout,"base=0x%08X size=0x%08X type=%s\n",base,size,stype); +- wr_len = fprintf(mtrr_fd,sout); ++ wr_len = fprintf(mtrr_fd,"%s",sout); + /*printf("MTRR: %s\n",sout);*/ + fclose(mtrr_fd); + return wr_len == strlen(sout) ? 0 : EPERM; diff --git a/avifile-narrowing.patch b/avifile-narrowing.patch new file mode 100644 index 0000000..20451fd --- /dev/null +++ b/avifile-narrowing.patch @@ -0,0 +1,25 @@ +--- avifile-0.7-0.7.45/plugins/libmpeg_audiodec/huffmantable.cpp.orig 2002-05-26 11:03:09.000000000 +0200 ++++ avifile-0.7-0.7.45/plugins/libmpeg_audiodec/huffmantable.cpp 2020-08-30 18:43:09.596526072 +0200 +@@ -548,11 +548,11 @@ + + const HUFFMANCODETABLE Mpegtoraw::ht[HTN]= + { +- { 0, 0-1, 0-1, 0, 0, htd33}, ++ { 0, (unsigned)(0-1), (unsigned)(0-1), 0, 0, htd33}, + { 1, 2-1, 2-1, 0, 7,htd01}, + { 2, 3-1, 3-1, 0, 17,htd02}, + { 3, 3-1, 3-1, 0, 17,htd03}, +- { 4, 0-1, 0-1, 0, 0, htd33}, ++ { 4, (unsigned)(0-1), (unsigned)(0-1), 0, 0, htd33}, + { 5, 4-1, 4-1, 0, 31,htd05}, + { 6, 4-1, 4-1, 0, 31,htd06}, + { 7, 6-1, 6-1, 0, 71,htd07}, +@@ -562,7 +562,7 @@ + {11, 8-1, 8-1, 0,127,htd11}, + {12, 8-1, 8-1, 0,127,htd12}, + {13,16-1,16-1, 0,511,htd13}, +- {14, 0-1, 0-1, 0, 0, htd33}, ++ {14, (unsigned)(0-1), (unsigned)(0-1), 0, 0, htd33}, + {15,16-1,16-1, 0,511,htd15}, + {16,16-1,16-1, 1,511,htd16}, + {17,16-1,16-1, 2,511,htd16}, diff --git a/avifile.spec b/avifile.spec index d58aa61..e41d645 100644 --- a/avifile.spec +++ b/avifile.spec @@ -42,6 +42,8 @@ Patch20: %{name}-gcc44.patch Patch21: %{name}-types.patch Patch22: %{name}-ffmpeg.patch Patch23: %{name}-v4l.patch +Patch24: %{name}-format.patch +Patch25: %{name}-narrowing.patch URL: http://avifile.sourceforge.net/ BuildRequires: SDL-devel >= 1.2.0 BuildRequires: a52dec-libs-devel @@ -370,6 +372,8 @@ Sterownik VIDIX dla kart graficznych ATI Rage128. %patch21 -p1 %patch22 -p1 %patch23 -p1 +%patch24 -p1 +%patch25 -p1 # unwanted hack %{__rm} m4/as.m4 -- 2.44.0