From 69aaf6ab0491d99011c4f031641295bb5fa98195 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Thu, 13 May 2021 14:45:13 +0200 Subject: [PATCH] don't touch frame->data --- extern/osg-ffmpeg-videoplayer/videostate.cpp | 30 +++++++++++++------- extern/osg-ffmpeg-videoplayer/videostate.hpp | 4 +-- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/extern/osg-ffmpeg-videoplayer/videostate.cpp b/extern/osg-ffmpeg-videoplayer/videostate.cpp index cda965edd..99c1dc7ec 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.cpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.cpp @@ -45,6 +45,14 @@ namespace av_packet_unref(packet); } }; + + struct AVFrameFree + { + void operator()(AVFrame* frame) const + { + av_frame_free(&frame); + } + }; } namespace Video @@ -316,7 +324,7 @@ void VideoState::video_refresh() } -int VideoState::queue_picture(AVFrame *pFrame, double pts) +int VideoState::queue_picture(const AVFrame &pFrame, double pts) { VideoPicture *vp; @@ -337,8 +345,8 @@ int VideoState::queue_picture(AVFrame *pFrame, double pts) // Convert the image into RGBA format // TODO: we could do this in a pixel shader instead, if the source format // matches a commonly used format (ie YUV420P) - const int w = pFrame->width; - const int h = pFrame->height; + const int w = pFrame.width; + const int h = pFrame.height; if(this->sws_context == nullptr || this->sws_context_w != w || this->sws_context_h != h) { if (this->sws_context != nullptr) @@ -356,7 +364,7 @@ int VideoState::queue_picture(AVFrame *pFrame, double pts) if (vp->set_dimensions(w, h) < 0) return -1; - sws_scale(this->sws_context, pFrame->data, pFrame->linesize, + sws_scale(this->sws_context, pFrame.data, pFrame.linesize, 0, this->video_ctx->height, vp->rgbaFrame->data, vp->rgbaFrame->linesize); // now we inform our display thread that we have a pic ready @@ -366,7 +374,7 @@ int VideoState::queue_picture(AVFrame *pFrame, double pts) return 0; } -double VideoState::synchronize_video(AVFrame *src_frame, double pts) +double VideoState::synchronize_video(const AVFrame &src_frame, double pts) { double frame_delay; @@ -380,7 +388,7 @@ double VideoState::synchronize_video(AVFrame *src_frame, double pts) frame_delay = av_q2d(this->video_ctx->pkt_timebase); /* if we are repeating a frame, adjust clock accordingly */ - frame_delay += src_frame->repeat_pict * (frame_delay * 0.5); + frame_delay += src_frame.repeat_pict * (frame_delay * 0.5); this->video_clock += frame_delay; return pts; @@ -415,8 +423,8 @@ public: VideoState* self = mVideoState; AVPacket packetData; av_init_packet(&packetData); - std::unique_ptr packet(&packetData, AVPacketUnref{}); - std::unique_ptr pFrame{av_frame_alloc()}; + std::unique_ptr packet(&packetData); + std::unique_ptr pFrame{av_frame_alloc()}; while(self->videoq.get(packet.get(), self) >= 0) { @@ -448,9 +456,9 @@ public: double pts = pFrame->best_effort_timestamp; pts *= av_q2d((*self->video_st)->time_base); - pts = self->synchronize_video(pFrame.get(), pts); + pts = self->synchronize_video(*pFrame, pts); - if(self->queue_picture(pFrame.get(), pts) < 0) + if(self->queue_picture(*pFrame, pts) < 0) break; } } @@ -483,7 +491,7 @@ public: AVFormatContext *pFormatCtx = self->format_ctx; AVPacket packetData; av_init_packet(&packetData); - std::unique_ptr packet(&packetData, AVPacketUnref{}); + std::unique_ptr packet(&packetData); try { diff --git a/extern/osg-ffmpeg-videoplayer/videostate.hpp b/extern/osg-ffmpeg-videoplayer/videostate.hpp index 015656084..8f7f1cadd 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.hpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.hpp @@ -132,8 +132,8 @@ struct VideoState { void video_display(VideoPicture* vp); void video_refresh(); - int queue_picture(AVFrame *pFrame, double pts); - double synchronize_video(AVFrame *src_frame, double pts); + int queue_picture(const AVFrame &pFrame, double pts); + double synchronize_video(const AVFrame &src_frame, double pts); double get_audio_clock(); double get_video_clock();