From 059ed728d027c3adcba2ae92097eaa702dd5fe8d Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Mon, 9 Jun 2014 13:59:04 -0400 Subject: [PATCH] video: change VideoDecoder::decode() prototype This patch fixes frame buffer usage outside of this function by moving packet buffer creation into the caller. The caller is now responsible for creating and destroying it. This fix crashes found during shm_sink rendering. Note: only reproducible with libav _prior_ to commit 759001c534287a96dc96d1e274665feb7059145d: Author: Anton Khirnov <anton at khirnov.net> Committer: Anton Khirnov <anton at khirnov.net> Date: Wed Nov 21 21:34:46 2012 +0100 lavc decoders: work with refcounted frames. Refs #49174 Change-Id: I3900a64690568a1ecf107ccfc07a2952981eefa4 --- daemon/src/video/video_decoder.cpp | 4 +--- daemon/src/video/video_decoder.h | 2 +- daemon/src/video/video_input.cpp | 4 ++-- daemon/src/video/video_receive_thread.cpp | 3 ++- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/daemon/src/video/video_decoder.cpp b/daemon/src/video/video_decoder.cpp index 4604c77ab1..d7ea420345 100644 --- a/daemon/src/video/video_decoder.cpp +++ b/daemon/src/video/video_decoder.cpp @@ -194,10 +194,8 @@ int VideoDecoder::setupFromVideoData() } VideoDecoder::Status -VideoDecoder::decode(VideoFrame& result) +VideoDecoder::decode(VideoFrame& result, VideoPacket& video_packet) { - // Guarantee that we free the packet every iteration - VideoPacket video_packet; AVPacket *inpacket = video_packet.get(); int ret = av_read_frame(inputCtx_, inpacket); if (ret == AVERROR(EAGAIN)) { diff --git a/daemon/src/video/video_decoder.h b/daemon/src/video/video_decoder.h index d81f0052ab..69e092733a 100644 --- a/daemon/src/video/video_decoder.h +++ b/daemon/src/video/video_decoder.h @@ -65,7 +65,7 @@ namespace sfl_video { int openInput(const std::string &source_str, const std::string &format_str); int setupFromVideoData(); - Status decode(VideoFrame&); + Status decode(VideoFrame&, VideoPacket&); Status flush(VideoFrame&); int getWidth() const; diff --git a/daemon/src/video/video_input.cpp b/daemon/src/video/video_input.cpp index 472634810b..42a2c6cd88 100644 --- a/daemon/src/video/video_input.cpp +++ b/daemon/src/video/video_input.cpp @@ -110,8 +110,8 @@ int VideoInput::interruptCb(void *data) bool VideoInput::captureFrame() { - VideoFrame& frame = getNewFrame(); - const auto ret = decoder_->decode(frame); + VideoPacket pkt; + const auto ret = decoder_->decode(getNewFrame(), pkt); switch (ret) { case VideoDecoder::Status::FrameFinished: diff --git a/daemon/src/video/video_receive_thread.cpp b/daemon/src/video/video_receive_thread.cpp index de5eb9084d..fe7b9c1671 100644 --- a/daemon/src/video/video_receive_thread.cpp +++ b/daemon/src/video/video_receive_thread.cpp @@ -185,7 +185,8 @@ void VideoReceiveThread::addIOContext(SocketPair &socketPair) bool VideoReceiveThread::decodeFrame() { - const auto ret = videoDecoder_->decode(getNewFrame()); + VideoPacket pkt; + const auto ret = videoDecoder_->decode(getNewFrame(), pkt); switch (ret) { case VideoDecoder::Status::FrameFinished: -- GitLab