Commit 8560fdc4 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '394fb56c'

* commit '394fb56c':
  lavf: always unref the packet passed to av_interleaved_write_frame() on error
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents e93674c4 394fb56c
...@@ -2085,7 +2085,8 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt); ...@@ -2085,7 +2085,8 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt);
* correct values. * correct values.
* @endparblock * @endparblock
* *
* @return 0 on success, a negative AVERROR on error. * @return 0 on success, a negative AVERROR on error. Libavformat will always
* take care of freeing the packet, even if this function fails.
* *
* @see av_write_frame(), AVFormatContext.max_interleave_delta * @see av_write_frame(), AVFormatContext.max_interleave_delta
*/ */
......
...@@ -808,22 +808,26 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) ...@@ -808,22 +808,26 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
ret = check_packet(s, pkt); ret = check_packet(s, pkt);
if (ret < 0) if (ret < 0)
return ret; goto fail;
if (pkt) { if (pkt) {
AVStream *st = s->streams[pkt->stream_index]; AVStream *st = s->streams[pkt->stream_index];
//FIXME/XXX/HACK drop zero sized packets //FIXME/XXX/HACK drop zero sized packets
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size == 0) if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size == 0) {
return 0; ret = 0;
goto fail;
}
av_dlog(s, "av_interleaved_write_frame size:%d dts:%s pts:%s\n", av_dlog(s, "av_interleaved_write_frame size:%d dts:%s pts:%s\n",
pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts)); pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts));
if ((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) if ((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
return ret; goto fail;
if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) if (pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) {
return AVERROR(EINVAL); ret = AVERROR(EINVAL);
goto fail;
}
} else { } else {
av_dlog(s, "av_interleaved_write_frame FLUSH\n"); av_dlog(s, "av_interleaved_write_frame FLUSH\n");
flush = 1; flush = 1;
...@@ -832,6 +836,11 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) ...@@ -832,6 +836,11 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
for (;; ) { for (;; ) {
AVPacket opkt; AVPacket opkt;
int ret = interleave_packet(s, &opkt, pkt, flush); int ret = interleave_packet(s, &opkt, pkt, flush);
if (pkt) {
memset(pkt, 0, sizeof(*pkt));
av_init_packet(pkt);
pkt = NULL;
}
if (ret <= 0) //FIXME cleanup needed for ret<0 ? if (ret <= 0) //FIXME cleanup needed for ret<0 ?
return ret; return ret;
...@@ -840,13 +849,15 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) ...@@ -840,13 +849,15 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
s->streams[opkt.stream_index]->nb_frames++; s->streams[opkt.stream_index]->nb_frames++;
av_free_packet(&opkt); av_free_packet(&opkt);
pkt = NULL;
if (ret < 0) if (ret < 0)
return ret; return ret;
if(s->pb && s->pb->error) if(s->pb && s->pb->error)
return s->pb->error; return s->pb->error;
} }
fail:
av_packet_unref(pkt);
return ret;
} }
int av_write_trailer(AVFormatContext *s) int av_write_trailer(AVFormatContext *s)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment