[FFmpeg-devel] [PATCH] What is missing for working AVFMT_FLAG_NONBLOCK?
Michael Niedermayer
michaelni
Tue Mar 3 03:50:15 CET 2009
On Tue, Mar 03, 2009 at 03:06:21AM +0100, Michael Niedermayer wrote:
> Hi
>
> AVFMT_FLAG_NONBLOCK is not enabled in ffmpeg/ffplay.c
> what is missing for it?
> capturing from several devices is likely going to work better if they
> dont block. And yes i know it all should be using select() but that is
> harder. And simple polling with non blocking demuxers should already
> work pretty well.
>
> is the only thing missing the code in ffmpeg.c that picks files
> based on the next expected timestamp?
>
> id like to set AVFMT_FLAG_NONBLOCK by default in ffmpeg.c
The patch that i had in mind is below, passes reg tests
comments welcome (if i receive none or no objections than ill apply
tomorrow)
Index: ffmpeg.c
===================================================================
--- ffmpeg.c (revision 17740)
+++ ffmpeg.c (working copy)
@@ -1559,6 +1559,8 @@
AVInputFile *file_table;
int key;
int want_sdp = 1;
+ uint8_t no_packet[MAX_FILES]={0};
+ int no_packet_count=0;
file_table= av_mallocz(nb_input_files * sizeof(AVInputFile));
if (!file_table)
@@ -2067,6 +2069,8 @@
ost = ost_table[i];
os = output_files[ost->file_index];
ist = ist_table[ost->source_index];
+ if(no_packet[ist->file_index])
+ continue;
if(ost->st->codec->codec_type == CODEC_TYPE_VIDEO)
opts = ost->sync_opts * av_q2d(ost->st->codec->time_base);
else
@@ -2089,6 +2093,11 @@
}
/* if none, if is finished */
if (file_index < 0) {
+ if(no_packet_count){
+ no_packet_count=0;
+ memset(no_packet, 0, sizeof(no_packet));
+ continue;
+ }
break;
}
@@ -2103,8 +2112,11 @@
/* read a frame from it and output it in the fifo */
is = input_files[file_index];
ret= av_read_frame(is, &pkt);
- if(ret == AVERROR(EAGAIN) && strcmp(is->iformat->name, "ffm"))
+ if(ret == AVERROR(EAGAIN) && strcmp(is->iformat->name, "ffm")){
+ no_packet[file_index]=1;
+ no_packet_count++;
continue;
+ }
if (ret < 0) {
file_table[file_index].eof_reached = 1;
if (opt_shortest)
@@ -2113,6 +2125,9 @@
continue;
}
+ no_packet_count=0;
+ memset(no_packet, 0, sizeof(no_packet));
+
if (do_pkt_dump) {
av_pkt_dump_log(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump);
}
@@ -3412,6 +3427,7 @@
oc->preload= (int)(mux_preload*AV_TIME_BASE);
oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
oc->loop_output = loop_output;
+ oc->flags |= AVFMT_FLAG_NONBLOCK;
set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM);
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Thouse who are best at talking, realize last or never when they are wrong.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090303/60787b13/attachment.pgp>
More information about the ffmpeg-devel
mailing list