[FFmpeg-cvslog] avpacket: Check for and return errors in ff_interleave_add_packet()
Nidhi Makhijani
git at videolan.org
Mon Jun 1 12:55:49 CEST 2015
ffmpeg | branch: release/2.2 | Nidhi Makhijani <nidhimj22 at gmail.com> | Mon Jul 14 12:10:44 2014 +0530| [e3c4eb87e4d9650d76f6d8d790a9b749b325e973] | committer: Reinhard Tartler
avpacket: Check for and return errors in ff_interleave_add_packet()
Signed-off-by: Diego Biurrun <diego at biurrun.de>
(cherry picked from commit 324ff59444ff5470bb325ff1e2be7c4b054fc944)
Signed-off-by: Reinhard Tartler <siretart at tauware.de>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e3c4eb87e4d9650d76f6d8d790a9b749b325e973
---
libavformat/audiointerleave.c | 8 +++++---
libavformat/internal.h | 4 ++--
libavformat/mux.c | 20 +++++++++++++++-----
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
index e4cde9d..e49c77f 100644
--- a/libavformat/audiointerleave.c
+++ b/libavformat/audiointerleave.c
@@ -99,7 +99,7 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt
int (*get_packet)(AVFormatContext *, AVPacket *, AVPacket *, int),
int (*compare_ts)(AVFormatContext *, AVPacket *, AVPacket *))
{
- int i;
+ int i, ret;
if (pkt) {
AVStream *st = s->streams[pkt->stream_index];
@@ -116,7 +116,8 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt
// rewrite pts and dts to be decoded time line position
pkt->pts = pkt->dts = aic->dts;
aic->dts += pkt->duration;
- ff_interleave_add_packet(s, pkt, compare_ts);
+ if ((ret = ff_interleave_add_packet(s, pkt, compare_ts)) < 0)
+ return ret;
}
pkt = NULL;
}
@@ -126,7 +127,8 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
AVPacket new_pkt;
while (interleave_new_audio_packet(s, &new_pkt, i, flush))
- ff_interleave_add_packet(s, &new_pkt, compare_ts);
+ if ((ret = ff_interleave_add_packet(s, &new_pkt, compare_ts)) < 0)
+ return ret;
}
}
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 0e7eb36..2824436 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -87,8 +87,8 @@ void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int i
* Add packet to AVFormatContext->packet_buffer list, determining its
* interleaved position using compare() function argument.
*/
-void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
- int (*compare)(AVFormatContext *, AVPacket *, AVPacket *));
+int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
+ int (*compare)(AVFormatContext *, AVPacket *, AVPacket *));
void ff_read_frame_flush(AVFormatContext *s);
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 59f9c42..8466605 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -477,12 +477,15 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt)
return ret;
}
-void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
- int (*compare)(AVFormatContext *, AVPacket *, AVPacket *))
+int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
+ int (*compare)(AVFormatContext *, AVPacket *, AVPacket *))
{
+ int ret;
AVPacketList **next_point, *this_pktl;
this_pktl = av_mallocz(sizeof(AVPacketList));
+ if (!this_pktl)
+ return AVERROR(ENOMEM);
this_pktl->pkt = *pkt;
#if FF_API_DESTRUCT_PACKET
FF_DISABLE_DEPRECATION_WARNINGS
@@ -490,7 +493,11 @@ FF_DISABLE_DEPRECATION_WARNINGS
FF_ENABLE_DEPRECATION_WARNINGS
#endif
pkt->buf = NULL;
- av_dup_packet(&this_pktl->pkt); // duplicate the packet if it uses non-alloced memory
+ // Duplicate the packet if it uses non-allocated memory
+ if ((ret = av_dup_packet(&this_pktl->pkt)) < 0) {
+ av_free(this_pktl);
+ return ret;
+ }
if (s->streams[pkt->stream_index]->last_in_packet_buffer) {
next_point = &(s->streams[pkt->stream_index]->last_in_packet_buffer->next);
@@ -515,6 +522,8 @@ next_non_null:
s->streams[pkt->stream_index]->last_in_packet_buffer =
*next_point = this_pktl;
+
+ return 0;
}
static int interleave_compare_dts(AVFormatContext *s, AVPacket *next,
@@ -535,10 +544,11 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out,
{
AVPacketList *pktl;
int stream_count = 0;
- int i;
+ int i, ret;
if (pkt) {
- ff_interleave_add_packet(s, pkt, interleave_compare_dts);
+ if ((ret = ff_interleave_add_packet(s, pkt, interleave_compare_dts)) < 0)
+ return ret;
}
if (s->max_interleave_delta > 0 && s->packet_buffer && !flush) {
More information about the ffmpeg-cvslog
mailing list