From d77546b7dcbd832ba1b977a63aac0d294eae3663 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 21 Sep 2014 12:58:11 +0200 Subject: [PATCH 1/3] Fix for compiler warnings and deprecated functions usage in videoplayer. Deprecated functions were: - AVCodecContext::get_buffer - AVCodecContext::release_buffer Changed to: AVCodecContext::get_buffer2 and setting AVCodecContext::refcounted_frames to 1 before call to avcodec_open2(). release_buffer usage was removed. Also changed places when some fileds were compared to AV_NOPTS_VALUE - it's signed, so removed unsigned int casting, or changed casting to signed int. Signed-off-by: Lukasz Gromanowski --- apps/openmw/mwrender/videoplayer.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwrender/videoplayer.cpp b/apps/openmw/mwrender/videoplayer.cpp index aa2f24101..a0576b222 100644 --- a/apps/openmw/mwrender/videoplayer.cpp +++ b/apps/openmw/mwrender/videoplayer.cpp @@ -220,7 +220,7 @@ void PacketQueue::put(AVPacket *pkt) pkt1->pkt = *pkt; pkt1->next = NULL; - if(pkt1->pkt.destruct == NULL) + if(pkt1->pkt.buf == NULL) { if(av_dup_packet(&pkt1->pkt) < 0) { @@ -425,7 +425,7 @@ class MovieAudioDecoder : public MWSound::Sound_Decoder return -1; /* if update, update the audio clock w/pts */ - if((uint64_t)pkt->pts != AV_NOPTS_VALUE) + if(pkt->pts != AV_NOPTS_VALUE) mAudioClock = av_q2d(mAVStream->time_base)*pkt->pts; } } @@ -820,20 +820,14 @@ double VideoState::synchronize_video(AVFrame *src_frame, double pts) * a frame at the time it is allocated. */ static uint64_t global_video_pkt_pts = static_cast(AV_NOPTS_VALUE); -static int our_get_buffer(struct AVCodecContext *c, AVFrame *pic) +static int our_get_buffer2(struct AVCodecContext *c, AVFrame *pic, int flags = AV_GET_BUFFER_FLAG_REF) { - int ret = avcodec_default_get_buffer(c, pic); + int ret = avcodec_default_get_buffer2(c, pic, flags); uint64_t *pts = (uint64_t*)av_malloc(sizeof(uint64_t)); *pts = global_video_pkt_pts; pic->opaque = pts; return ret; } -static void our_release_buffer(struct AVCodecContext *c, AVFrame *pic) -{ - if(pic) av_freep(&pic->opaque); - avcodec_default_release_buffer(c, pic); -} - void VideoState::video_thread_loop(VideoState *self) { @@ -856,9 +850,9 @@ void VideoState::video_thread_loop(VideoState *self) throw std::runtime_error("Error decoding video frame"); pts = 0; - if((uint64_t)packet->dts != AV_NOPTS_VALUE) + if(packet->dts != AV_NOPTS_VALUE) pts = packet->dts; - else if(pFrame->opaque && *(uint64_t*)pFrame->opaque != AV_NOPTS_VALUE) + else if(pFrame->opaque && *(int64_t*)pFrame->opaque != AV_NOPTS_VALUE) pts = *(uint64_t*)pFrame->opaque; pts *= av_q2d((*self->video_st)->time_base); @@ -959,6 +953,7 @@ int VideoState::stream_open(int stream_index, AVFormatContext *pFormatCtx) // Get a pointer to the codec context for the video stream codecCtx = pFormatCtx->streams[stream_index]->codec; codec = avcodec_find_decoder(codecCtx->codec_id); + codecCtx->refcounted_frames = 1; if(!codec || (avcodec_open2(codecCtx, codec, NULL) < 0)) { fprintf(stderr, "Unsupported codec!\n"); @@ -985,8 +980,7 @@ int VideoState::stream_open(int stream_index, AVFormatContext *pFormatCtx) this->frame_last_delay = 40e-3; - codecCtx->get_buffer = our_get_buffer; - codecCtx->release_buffer = our_release_buffer; + codecCtx->get_buffer2 = our_get_buffer2; this->video_thread = boost::thread(video_thread_loop, this); this->refresh_thread = boost::thread(video_refresh, this); break; From f5589b42ea499c3f2ed6b9713d1c05f9377c876b Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 21 Sep 2014 16:09:16 +0200 Subject: [PATCH 2/3] Fix for compiler warnings and deprecated functions usage in videoplayer. Added ifdefs because changes in API were introduced in libavc 56.1 and this code doesn't compile with older versions (ie. on Ubuntu, or Debian). Signed-off-by: Lukasz Gromanowski --- apps/openmw/mwrender/videoplayer.cpp | 46 +++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwrender/videoplayer.cpp b/apps/openmw/mwrender/videoplayer.cpp index a0576b222..036fa9316 100644 --- a/apps/openmw/mwrender/videoplayer.cpp +++ b/apps/openmw/mwrender/videoplayer.cpp @@ -32,6 +32,16 @@ extern "C" #include #include + +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,1,0) +#define IS_NOTEQ_NOPTS_VAL(x) ((uint64_t)x != AV_NOPTS_VALUE) +#define IS_NOTEQ_NOPTS_VAL_PTR(x) (*(uint64_t*)x != AV_NOPTS_VALUE) +#else +#define IS_NOTEQ_NOPTS_VAL(x) ((int64_t)x != AV_NOPTS_VALUE) +#define IS_NOTEQ_NOPTS_VAL_PTR(x) (*(int64_t*)x != AV_NOPTS_VALUE) +#endif /* LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,1,0) */ + + #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1) #define av_frame_alloc avcodec_alloc_frame #endif @@ -219,8 +229,11 @@ void PacketQueue::put(AVPacket *pkt) if(!pkt1) throw std::bad_alloc(); pkt1->pkt = *pkt; pkt1->next = NULL; - +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,1,0) + if(pkt1->pkt.destruct == NULL) +#else if(pkt1->pkt.buf == NULL) +#endif /* LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,1,0) */ { if(av_dup_packet(&pkt1->pkt) < 0) { @@ -425,7 +438,7 @@ class MovieAudioDecoder : public MWSound::Sound_Decoder return -1; /* if update, update the audio clock w/pts */ - if(pkt->pts != AV_NOPTS_VALUE) + if(IS_NOTEQ_NOPTS_VAL(pkt->pts)) mAudioClock = av_q2d(mAVStream->time_base)*pkt->pts; } } @@ -820,6 +833,22 @@ double VideoState::synchronize_video(AVFrame *src_frame, double pts) * a frame at the time it is allocated. */ static uint64_t global_video_pkt_pts = static_cast(AV_NOPTS_VALUE); + +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,1,0) +static int our_get_buffer(struct AVCodecContext *c, AVFrame *pic) +{ + int ret = avcodec_default_get_buffer(c, pic); + uint64_t *pts = (uint64_t*)av_malloc(sizeof(uint64_t)); + *pts = global_video_pkt_pts; + pic->opaque = pts; + return ret; +} +static void our_release_buffer(struct AVCodecContext *c, AVFrame *pic) +{ + if(pic) av_freep(&pic->opaque); + avcodec_default_release_buffer(c, pic); +} +#else static int our_get_buffer2(struct AVCodecContext *c, AVFrame *pic, int flags = AV_GET_BUFFER_FLAG_REF) { int ret = avcodec_default_get_buffer2(c, pic, flags); @@ -828,6 +857,7 @@ static int our_get_buffer2(struct AVCodecContext *c, AVFrame *pic, int flags = A pic->opaque = pts; return ret; } +#endif /* LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,1,0) */ void VideoState::video_thread_loop(VideoState *self) { @@ -850,9 +880,9 @@ void VideoState::video_thread_loop(VideoState *self) throw std::runtime_error("Error decoding video frame"); pts = 0; - if(packet->dts != AV_NOPTS_VALUE) + if(IS_NOTEQ_NOPTS_VAL(packet->dts)) pts = packet->dts; - else if(pFrame->opaque && *(int64_t*)pFrame->opaque != AV_NOPTS_VALUE) + else if(pFrame->opaque && IS_NOTEQ_NOPTS_VAL_PTR(pFrame->opaque)) pts = *(uint64_t*)pFrame->opaque; pts *= av_q2d((*self->video_st)->time_base); @@ -953,7 +983,9 @@ int VideoState::stream_open(int stream_index, AVFormatContext *pFormatCtx) // Get a pointer to the codec context for the video stream codecCtx = pFormatCtx->streams[stream_index]->codec; codec = avcodec_find_decoder(codecCtx->codec_id); +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,1,0) codecCtx->refcounted_frames = 1; +#endif /* LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,1,0) */ if(!codec || (avcodec_open2(codecCtx, codec, NULL) < 0)) { fprintf(stderr, "Unsupported codec!\n"); @@ -979,8 +1011,12 @@ int VideoState::stream_open(int stream_index, AVFormatContext *pFormatCtx) this->video_st = pFormatCtx->streams + stream_index; this->frame_last_delay = 40e-3; - +#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,1,0) + codecCtx->get_buffer = our_get_buffer; + codecCtx->release_buffer = our_release_buffer; +#else codecCtx->get_buffer2 = our_get_buffer2; +#endif /* LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,1,0) */ this->video_thread = boost::thread(video_thread_loop, this); this->refresh_thread = boost::thread(video_refresh, this); break; From b40c1ff26c7b47a4a8cd27ca50d68b7089ca09d6 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 21 Sep 2014 16:23:05 +0200 Subject: [PATCH 3/3] Removed a warning about comparision between signed and unsigned variable in ffmpeg_decoder. Corrected ifdef from previous commit around codecCtx->refcounted_frames = 1; Signed-off-by: Lukasz Gromanowski --- apps/openmw/mwrender/videoplayer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwrender/videoplayer.cpp b/apps/openmw/mwrender/videoplayer.cpp index 036fa9316..ed9ed3f2a 100644 --- a/apps/openmw/mwrender/videoplayer.cpp +++ b/apps/openmw/mwrender/videoplayer.cpp @@ -983,9 +983,9 @@ int VideoState::stream_open(int stream_index, AVFormatContext *pFormatCtx) // Get a pointer to the codec context for the video stream codecCtx = pFormatCtx->streams[stream_index]->codec; codec = avcodec_find_decoder(codecCtx->codec_id); -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,1,0) +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(56,1,0) codecCtx->refcounted_frames = 1; -#endif /* LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56,1,0) */ +#endif /* LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(56,1,0) */ if(!codec || (avcodec_open2(codecCtx, codec, NULL) < 0)) { fprintf(stderr, "Unsupported codec!\n");