Commit 904100e5 authored by Jindrich Makovicka's avatar Jindrich Makovicka Committed by Martin Storsjö

make av_interleaved_write_frame() flush packets when pkt is NULL

This patch allows the user to force flushing of all queued packets
by calling av_interleaved_write_frame() with pkt set to NULL.
Signed-off-by: 's avatarJindrich Makovicka <jindrich.makovicka@nangu.tv>
Signed-off-by: 's avatarMartin Storsjö <martin@martin.st>
parent c9024a9f
...@@ -1436,6 +1436,8 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt); ...@@ -1436,6 +1436,8 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt);
* @param s media file handle * @param s media file handle
* @param pkt The packet containing the data to be written. Libavformat takes * @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 * 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 * @ref AVPacket.destruct "destruct" field. The caller must not access the data
* after this function returns, as it may already be freed. * after this function returns, as it may already be freed.
* Packet's @ref AVPacket.stream_index "stream_index" field must be set to the * Packet's @ref AVPacket.stream_index "stream_index" field must be set to the
......
...@@ -3128,8 +3128,10 @@ static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, in ...@@ -3128,8 +3128,10 @@ static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, in
} }
int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){
int ret, flush = 0;
if (pkt) {
AVStream *st= s->streams[ pkt->stream_index]; AVStream *st= s->streams[ pkt->stream_index];
int ret;
//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)
...@@ -3142,10 +3144,14 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){ ...@@ -3142,10 +3144,14 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){
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); return AVERROR(EINVAL);
} else {
av_dlog(s, "av_interleaved_write_frame FLUSH\n");
flush = 1;
}
for(;;){ for(;;){
AVPacket opkt; 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 ? if(ret<=0) //FIXME cleanup needed for ret<0 ?
return ret; return ret;
......
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