From c6607ea5fe9cb482d5cbd07433a7124b613d8a04 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 9 Sep 2016 10:05:24 -0400 Subject: [PATCH] change sematics of pop to return the packet* instead of boolean. Free packets in clearQueue --- src/zm_packetqueue.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/zm_packetqueue.cpp b/src/zm_packetqueue.cpp index fbf48613d..42a74af98 100644 --- a/src/zm_packetqueue.cpp +++ b/src/zm_packetqueue.cpp @@ -18,6 +18,7 @@ #include "zm_packetqueue.h" +#include "zm_ffmpeg.h" #define VIDEO_QUEUESIZE 200 #define AUDIO_QUEUESIZE 50 @@ -34,28 +35,34 @@ zm_packetqueue::~zm_packetqueue() { bool zm_packetqueue::queuePacket( AVPacket* packet ) { - AVPacket input_ref = { 0 }; - if ( av_packet_ref(&input_ref, packet) < 0 ) { - return false; - } - pktQueue.push(*packet); + //AVPacket *input_ref = (AVPacket *)av_malloc(sizeof(AVPacket)); + //if ( av_packet_ref( input_ref, packet ) < 0 ) { + //free(input_ref); + //return false; + //} + pktQueue.push( packet ); return true; } -bool zm_packetqueue::popPacket( AVPacket* packet ) { +AVPacket* zm_packetqueue::popPacket( ) { if ( pktQueue.empty() ) { - return false; + return NULL; } - *packet = pktQueue.front(); + AVPacket *packet = pktQueue.front(); pktQueue.pop(); - return true; + return packet; } void zm_packetqueue::clearQueue() { + AVPacket *packet = NULL; while(!pktQueue.empty()) { - pktQueue.pop(); + + packet = pktQueue.front(); + pktQueue.pop(); + // If we clear it, then no freeing gets done, whereas when we pop off, we assume that the packet was freed somewhere else. + zm_av_unref_packet( packet ); } }