Skip to content
Snippets Groups Projects
Commit 059ed728 authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Tristan Matthews
Browse files

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
parent 2c7e0b33
Branches
Tags
No related merge requests found
...@@ -194,10 +194,8 @@ int VideoDecoder::setupFromVideoData() ...@@ -194,10 +194,8 @@ int VideoDecoder::setupFromVideoData()
} }
VideoDecoder::Status 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(); AVPacket *inpacket = video_packet.get();
int ret = av_read_frame(inputCtx_, inpacket); int ret = av_read_frame(inputCtx_, inpacket);
if (ret == AVERROR(EAGAIN)) { if (ret == AVERROR(EAGAIN)) {
......
...@@ -65,7 +65,7 @@ namespace sfl_video { ...@@ -65,7 +65,7 @@ namespace sfl_video {
int openInput(const std::string &source_str, int openInput(const std::string &source_str,
const std::string &format_str); const std::string &format_str);
int setupFromVideoData(); int setupFromVideoData();
Status decode(VideoFrame&); Status decode(VideoFrame&, VideoPacket&);
Status flush(VideoFrame&); Status flush(VideoFrame&);
int getWidth() const; int getWidth() const;
......
...@@ -110,8 +110,8 @@ int VideoInput::interruptCb(void *data) ...@@ -110,8 +110,8 @@ int VideoInput::interruptCb(void *data)
bool VideoInput::captureFrame() bool VideoInput::captureFrame()
{ {
VideoFrame& frame = getNewFrame(); VideoPacket pkt;
const auto ret = decoder_->decode(frame); const auto ret = decoder_->decode(getNewFrame(), pkt);
switch (ret) { switch (ret) {
case VideoDecoder::Status::FrameFinished: case VideoDecoder::Status::FrameFinished:
......
...@@ -185,7 +185,8 @@ void VideoReceiveThread::addIOContext(SocketPair &socketPair) ...@@ -185,7 +185,8 @@ void VideoReceiveThread::addIOContext(SocketPair &socketPair)
bool VideoReceiveThread::decodeFrame() bool VideoReceiveThread::decodeFrame()
{ {
const auto ret = videoDecoder_->decode(getNewFrame()); VideoPacket pkt;
const auto ret = videoDecoder_->decode(getNewFrame(), pkt);
switch (ret) { switch (ret) {
case VideoDecoder::Status::FrameFinished: case VideoDecoder::Status::FrameFinished:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment