aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-03-27 11:52:08 +0200
committerMichael Niedermayer <michaelni@gmx.at>2012-03-27 11:59:39 +0200
commit6999f8bcf56bb167124bf85bdaa89090acdd5d9c (patch)
tree5bfb541bec48db787901f2441bd887d3629737ea /libavformat
parentab31db06103c6ac0c1bd1f9fdfa93220d8801e19 (diff)
parent904100e5fc13dacc954b1d093bf87bc44f4e7a7b (diff)
downloadffmpeg-6999f8bcf56bb167124bf85bdaa89090acdd5d9c.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: make av_interleaved_write_frame() flush packets when pkt is NULL mpegts: Fix dead error checks vc1: Do not read from array if index is invalid. targa: convert to bytestream2. rv34: set mb_num_left to 0 after finishing a frame Conflicts: libavcodec/targa.c libavcodec/vc1data.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/avformat.h2
-rw-r--r--libavformat/mpegts.c18
-rw-r--r--libavformat/utils.c30
3 files changed, 32 insertions, 18 deletions
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index fcdaebe2d4..7c307a7db2 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1607,6 +1607,8 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt);
* @param s media file handle
* @param pkt The packet containing the data to be written. Libavformat takes
* ownership of the data and will free it when it sees fit using the packet's
+ * This can be NULL (at any time, not just at the end), to flush the
+ * interleaving queues.
* @ref AVPacket.destruct "destruct" field. The caller must not access the data
* after this function returns, as it may already be freed.
* Packet's @ref AVPacket.stream_index "stream_index" field must be set to the
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index cff970ee4e..8ca39cfb8f 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -1428,17 +1428,19 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
return;
clear_program(ts, h->id);
- pcr_pid = get16(&p, p_end) & 0x1fff;
+ pcr_pid = get16(&p, p_end);
if (pcr_pid < 0)
return;
+ pcr_pid &= 0x1fff;
add_pid_to_pmt(ts, h->id, pcr_pid);
set_pcr_pid(ts->stream, h->id, pcr_pid);
av_dlog(ts->stream, "pcr_pid=0x%x\n", pcr_pid);
- program_info_length = get16(&p, p_end) & 0xfff;
+ program_info_length = get16(&p, p_end);
if (program_info_length < 0)
return;
+ program_info_length &= 0xfff;
while(program_info_length >= 2) {
uint8_t tag, len;
tag = get8(&p, p_end);
@@ -1476,9 +1478,10 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
stream_type = get8(&p, p_end);
if (stream_type < 0)
break;
- pid = get16(&p, p_end) & 0x1fff;
+ pid = get16(&p, p_end);
if (pid < 0)
break;
+ pid &= 0x1fff;
/* now create stream */
if (ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES) {
@@ -1516,9 +1519,10 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
ff_program_add_stream_index(ts->stream, h->id, st->index);
- desc_list_len = get16(&p, p_end) & 0xfff;
+ desc_list_len = get16(&p, p_end);
if (desc_list_len < 0)
break;
+ desc_list_len &= 0xfff;
desc_list_end = p + desc_list_len;
if (desc_list_end > p_end)
break;
@@ -1565,9 +1569,10 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
sid = get16(&p, p_end);
if (sid < 0)
break;
- pmt_pid = get16(&p, p_end) & 0x1fff;
+ pmt_pid = get16(&p, p_end);
if (pmt_pid < 0)
break;
+ pmt_pid &= 0x1fff;
av_dlog(ts->stream, "sid=0x%x pid=0x%x\n", sid, pmt_pid);
@@ -1617,9 +1622,10 @@ static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
val = get8(&p, p_end);
if (val < 0)
break;
- desc_list_len = get16(&p, p_end) & 0xfff;
+ desc_list_len = get16(&p, p_end);
if (desc_list_len < 0)
break;
+ desc_list_len &= 0xfff;
desc_list_end = p + desc_list_len;
if (desc_list_end > p_end)
break;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 2989a08fc0..0f8b940566 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3481,24 +3481,30 @@ static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, in
}
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){
- AVStream *st= s->streams[ pkt->stream_index];
- int ret;
+ int ret, flush = 0;
- //FIXME/XXX/HACK drop zero sized packets
- if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size==0)
- return 0;
+ if (pkt) {
+ AVStream *st= s->streams[ pkt->stream_index];
- av_dlog(s, "av_interleaved_write_frame size:%d dts:%"PRId64" pts:%"PRId64"\n",
- pkt->size, pkt->dts, pkt->pts);
- if((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
- return ret;
+ //FIXME/XXX/HACK drop zero sized packets
+ if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size==0)
+ return 0;
- if(pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
- return AVERROR(EINVAL);
+ av_dlog(s, "av_interleaved_write_frame size:%d dts:%"PRId64" pts:%"PRId64"\n",
+ pkt->size, pkt->dts, pkt->pts);
+ if((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
+ return ret;
+
+ if(pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS))
+ return AVERROR(EINVAL);
+ } else {
+ av_dlog(s, "av_interleaved_write_frame FLUSH\n");
+ flush = 1;
+ }
for(;;){
AVPacket opkt;
- int ret= interleave_packet(s, &opkt, pkt, 0);
+ int ret= interleave_packet(s, &opkt, pkt, flush);
if(ret<=0) //FIXME cleanup needed for ret<0 ?
return ret;