Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master: (32 commits)
doc: create separate section for audio encoders
swscale: Remove orphaned, commented-out function declaration.
swscale: Eliminate rgb24toyv12_c() duplication.
Remove h263_msmpeg4 from MpegEncContext.
APIchanges: Fill in git hash for fps_probe_size (30315a8)
avformat: Add fpsprobesize as an AVOption.
avoptions: Return explicitly NAN or {0,0} if the option isn't found
rtmp: Reindent
rtmp: Don't try to do av_malloc(0)
tty: replace AVFormatParameters.sample_rate abuse with a private option.
Fix end time of last chapter in compute_chapters_end
ffmpeg: get rid of useless AVInputStream.nb_streams.
ffmpeg: simplify managing input files and streams
ffmpeg: purge redundant AVInputStream.index.
lavf: deprecate AVFormatParameters.channel.
libdc1394: add a private option for channel.
dv1394: add a private option for channel.
v4l2: reindent.
v4l2: add a private option for channel.
lavf: deprecate AVFormatParameters.standard.
...

Conflicts:
doc/APIchanges
doc/encoders.texi
ffmpeg.c
libavdevice/alsa-audio.h
libavformat/version.h
libavutil/opt.c
libswscale/rgb2rgb.h
libswscale/rgb2rgb_template.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2011/05/26 10:00:37
Showing 31 changed files
... ...
@@ -26,6 +26,9 @@ API changes, most recent first:
26 26
 2011-05-XX - XXXXXX - lavfi 2.6.0 - avcodec.h
27 27
   Add avfilter_get_video_buffer_ref_from_frame() to libavfilter/avcodec.h.
28 28
 
29
+2011-05-25 - 30315a8 - lavf 53.1.0 - avformat.h
30
+  Add fps_probe_size to AVFormatContext.
31
+
29 32
 2011-05-18 - 64150ff - lavc 53.4.0 - AVCodecContext.request_sample_fmt
30 33
   Add request_sample_fmt field to AVCodecContext.
31 34
 
... ...
@@ -477,5 +477,4 @@ Selected by Encoder (default)
477 477
 
478 478
 @end table
479 479
 
480
-@c man end ENCODERS
481
-
480
+@c man end AUDIO ENCODERS
... ...
@@ -114,11 +114,9 @@ static const OptionDef options[];
114 114
 #define MAX_STREAMS 1024    /* arbitrary sanity check value */
115 115
 
116 116
 static const char *last_asked_format = NULL;
117
-static AVFormatContext *input_files[MAX_FILES];
118 117
 static int64_t input_files_ts_offset[MAX_FILES];
119 118
 static double *input_files_ts_scale[MAX_FILES] = {NULL};
120 119
 static AVCodec **input_codecs = NULL;
121
-static int nb_input_files = 0;
122 120
 static int nb_input_codecs = 0;
123 121
 static int nb_input_files_ts_scale[MAX_FILES] = {0};
124 122
 
... ...
@@ -319,7 +317,6 @@ static int nb_output_streams_for_file[MAX_FILES] = { 0 };
319 319
 
320 320
 typedef struct AVInputStream {
321 321
     int file_index;
322
-    int index;
323 322
     AVStream *st;
324 323
     int discard;             /* true if stream data should be discarded */
325 324
     int decoding_needed;     /* true if the packets must be decoded in 'raw_fifo' */
... ...
@@ -339,10 +336,10 @@ typedef struct AVInputStream {
339 339
 } AVInputStream;
340 340
 
341 341
 typedef struct AVInputFile {
342
+    AVFormatContext *ctx;
342 343
     int eof_reached;      /* true if eof reached */
343 344
     int ist_index;        /* index of first stream in ist_table */
344 345
     int buffer_size;      /* current total buffer size */
345
-    int nb_streams;       /* nb streams we are aware of */
346 346
 } AVInputFile;
347 347
 
348 348
 #if HAVE_TERMIOS_H
... ...
@@ -351,6 +348,11 @@ typedef struct AVInputFile {
351 351
 static struct termios oldtty;
352 352
 #endif
353 353
 
354
+static AVInputStream *input_streams = NULL;
355
+static int         nb_input_streams = 0;
356
+static AVInputFile   *input_files   = NULL;
357
+static int         nb_input_files   = 0;
358
+
354 359
 #if CONFIG_AVFILTER
355 360
 
356 361
 static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost)
... ...
@@ -537,7 +539,7 @@ static int ffmpeg_exit(int ret)
537 537
         av_free(output_streams_for_file[i]);
538 538
     }
539 539
     for(i=0;i<nb_input_files;i++) {
540
-        av_close_input_file(input_files[i]);
540
+        av_close_input_file(input_files[i].ctx);
541 541
         av_free(input_files_ts_scale[i]);
542 542
     }
543 543
 
... ...
@@ -554,6 +556,9 @@ static int ffmpeg_exit(int ret)
554 554
     av_free(stream_maps);
555 555
     av_free(meta_data_maps);
556 556
 
557
+    av_freep(&input_streams);
558
+    av_freep(&input_files);
559
+
557 560
     av_free(video_codec_name);
558 561
     av_free(audio_codec_name);
559 562
     av_free(subtitle_codec_name);
... ...
@@ -839,7 +844,7 @@ need_realloc:
839 839
     if ((ost->audio_resample && !ost->resample) || resample_changed) {
840 840
         if (resample_changed) {
841 841
             av_log(NULL, AV_LOG_INFO, "Input stream #%d.%d frame changed from rate:%d fmt:%s ch:%d to rate:%d fmt:%s ch:%d\n",
842
-                   ist->file_index, ist->index,
842
+                   ist->file_index, ist->st->index,
843 843
                    ost->resample_sample_rate, av_get_sample_fmt_name(ost->resample_sample_fmt), ost->resample_channels,
844 844
                    dec->sample_rate, av_get_sample_fmt_name(dec->sample_fmt), dec->channels);
845 845
             ost->resample_sample_fmt  = dec->sample_fmt;
... ...
@@ -1202,7 +1207,7 @@ static void do_video_out(AVFormatContext *s,
1202 1202
     if (resample_changed) {
1203 1203
         av_log(NULL, AV_LOG_INFO,
1204 1204
                "Input stream #%d.%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
1205
-               ist->file_index, ist->index,
1205
+               ist->file_index, ist->st->index,
1206 1206
                ost->resample_width, ost->resample_height, avcodec_get_pix_fmt_name(ost->resample_pix_fmt),
1207 1207
                dec->width         , dec->height         , avcodec_get_pix_fmt_name(dec->pix_fmt));
1208 1208
         ost->resample_width   = dec->width;
... ...
@@ -1903,7 +1908,7 @@ static void print_sdp(AVFormatContext **avc, int n)
1903 1903
 
1904 1904
 static int copy_chapters(int infile, int outfile)
1905 1905
 {
1906
-    AVFormatContext *is = input_files[infile];
1906
+    AVFormatContext *is = input_files[infile].ctx;
1907 1907
     AVFormatContext *os = output_files[outfile];
1908 1908
     int i;
1909 1909
 
... ...
@@ -1969,16 +1974,16 @@ static void parse_forced_key_frames(char *kf, AVOutputStream *ost,
1969 1969
  */
1970 1970
 static int transcode(AVFormatContext **output_files,
1971 1971
                      int nb_output_files,
1972
-                     AVFormatContext **input_files,
1972
+                     AVInputFile *input_files,
1973 1973
                      int nb_input_files,
1974 1974
                      AVStreamMap *stream_maps, int nb_stream_maps)
1975 1975
 {
1976
-    int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0, step;
1976
+    int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0,step;
1977
+
1977 1978
     AVFormatContext *is, *os;
1978 1979
     AVCodecContext *codec, *icodec;
1979 1980
     AVOutputStream *ost, **ost_table = NULL;
1980
-    AVInputStream *ist, **ist_table = NULL;
1981
-    AVInputFile *file_table;
1981
+    AVInputStream *ist;
1982 1982
     char error[1024];
1983 1983
     int key;
1984 1984
     int want_sdp = 1;
... ...
@@ -1987,46 +1992,9 @@ static int transcode(AVFormatContext **output_files,
1987 1987
     int nb_frame_threshold[AVMEDIA_TYPE_NB]={0};
1988 1988
     int nb_streams[AVMEDIA_TYPE_NB]={0};
1989 1989
 
1990
-    file_table= av_mallocz(nb_input_files * sizeof(AVInputFile));
1991
-    if (!file_table)
1992
-        goto fail;
1993
-
1994
-    /* input stream init */
1995
-    j = 0;
1996
-    for(i=0;i<nb_input_files;i++) {
1997
-        is = input_files[i];
1998
-        file_table[i].ist_index = j;
1999
-        file_table[i].nb_streams = is->nb_streams;
2000
-        j += is->nb_streams;
2001
-    }
2002
-    nb_istreams = j;
2003
-
2004
-    ist_table = av_mallocz(nb_istreams * sizeof(AVInputStream *));
2005
-    if (!ist_table)
2006
-        goto fail;
2007
-
2008
-    for(i=0;i<nb_istreams;i++) {
2009
-        ist = av_mallocz(sizeof(AVInputStream));
2010
-        if (!ist)
2011
-            goto fail;
2012
-        ist_table[i] = ist;
2013
-    }
2014
-    j = 0;
2015
-    for(i=0;i<nb_input_files;i++) {
2016
-        is = input_files[i];
2017
-        for(k=0;k<is->nb_streams;k++) {
2018
-            ist = ist_table[j++];
2019
-            ist->st = is->streams[k];
2020
-            ist->file_index = i;
2021
-            ist->index = k;
2022
-            ist->discard = 1; /* the stream is discarded by default
2023
-                                 (changed later) */
2024
-
2025
-            if (rate_emu) {
2026
-                ist->start = av_gettime();
2027
-            }
2028
-        }
2029
-    }
1990
+    if (rate_emu)
1991
+        for (i = 0; i < nb_input_streams; i++)
1992
+            input_streams[i].start = av_gettime();
2030 1993
 
2031 1994
     /* output stream init */
2032 1995
     nb_ostreams = 0;
... ...
@@ -2052,7 +2020,7 @@ static int transcode(AVFormatContext **output_files,
2052 2052
         int si = stream_maps[i].stream_index;
2053 2053
 
2054 2054
         if (fi < 0 || fi > nb_input_files - 1 ||
2055
-            si < 0 || si > file_table[fi].nb_streams - 1) {
2055
+            si < 0 || si > input_files[fi].ctx->nb_streams - 1) {
2056 2056
             fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si);
2057 2057
             ret = AVERROR(EINVAL);
2058 2058
             goto fail;
... ...
@@ -2060,7 +2028,7 @@ static int transcode(AVFormatContext **output_files,
2060 2060
         fi = stream_maps[i].sync_file_index;
2061 2061
         si = stream_maps[i].sync_stream_index;
2062 2062
         if (fi < 0 || fi > nb_input_files - 1 ||
2063
-            si < 0 || si > file_table[fi].nb_streams - 1) {
2063
+            si < 0 || si > input_files[fi].ctx->nb_streams - 1) {
2064 2064
             fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si);
2065 2065
             ret = AVERROR(EINVAL);
2066 2066
             goto fail;
... ...
@@ -2082,12 +2050,12 @@ static int transcode(AVFormatContext **output_files,
2082 2082
         for(j=0; j<AVMEDIA_TYPE_NB; j++)
2083 2083
             nb_frame_threshold[j] += step;
2084 2084
 
2085
-        for(j=0; j<nb_istreams; j++) {
2085
+        for(j=0; j<nb_input_streams; j++) {
2086 2086
             int skip=0;
2087
-            ist = ist_table[j];
2087
+            ist = &input_streams[j];
2088 2088
             if(opt_programid){
2089 2089
                 int pi,si;
2090
-                AVFormatContext *f= input_files[ ist->file_index ];
2090
+                AVFormatContext *f= input_files[ ist->file_index ].ctx;
2091 2091
                 skip=1;
2092 2092
                 for(pi=0; pi<f->nb_programs; pi++){
2093 2093
                     AVProgram *p= f->programs[pi];
... ...
@@ -2115,11 +2083,11 @@ static int transcode(AVFormatContext **output_files,
2115 2115
             ost = ost_table[n] = output_streams_for_file[k][i];
2116 2116
             ost->st = os->streams[i];
2117 2117
             if (nb_stream_maps > 0) {
2118
-                ost->source_index = file_table[stream_maps[n].file_index].ist_index +
2118
+                ost->source_index = input_files[stream_maps[n].file_index].ist_index +
2119 2119
                     stream_maps[n].stream_index;
2120 2120
 
2121 2121
                 /* Sanity check that the stream types match */
2122
-                if (ist_table[ost->source_index]->st->codec->codec_type != ost->st->codec->codec_type) {
2122
+                if (input_streams[ost->source_index].st->codec->codec_type != ost->st->codec->codec_type) {
2123 2123
                     int i= ost->file_index;
2124 2124
                     av_dump_format(output_files[i], i, output_files[i]->filename, 1);
2125 2125
                     fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n",
... ...
@@ -2131,12 +2099,12 @@ static int transcode(AVFormatContext **output_files,
2131 2131
             } else {
2132 2132
                 /* get corresponding input stream index : we select the first one with the right type */
2133 2133
                 found = 0;
2134
-                for(j=0;j<nb_istreams;j++) {
2134
+                for (j = 0; j < nb_input_streams; j++) {
2135 2135
                     int skip=0;
2136
-                    ist = ist_table[j];
2136
+                    ist = &input_streams[j];
2137 2137
                     if(opt_programid){
2138 2138
                         int pi,si;
2139
-                        AVFormatContext *f= input_files[ ist->file_index ];
2139
+                        AVFormatContext *f = input_files[ist->file_index].ctx;
2140 2140
                         skip=1;
2141 2141
                         for(pi=0; pi<f->nb_programs; pi++){
2142 2142
                             AVProgram *p= f->programs[pi];
... ...
@@ -2159,8 +2127,8 @@ static int transcode(AVFormatContext **output_files,
2159 2159
                 if (!found) {
2160 2160
                     if(! opt_programid) {
2161 2161
                         /* try again and reuse existing stream */
2162
-                        for(j=0;j<nb_istreams;j++) {
2163
-                            ist = ist_table[j];
2162
+                        for (j = 0; j < nb_input_streams; j++) {
2163
+                            ist = &input_streams[j];
2164 2164
                             if (   ist->st->codec->codec_type == ost->st->codec->codec_type
2165 2165
                                 && ist->st->discard != AVDISCARD_ALL) {
2166 2166
                                 ost->source_index = j;
... ...
@@ -2177,10 +2145,10 @@ static int transcode(AVFormatContext **output_files,
2177 2177
                     }
2178 2178
                 }
2179 2179
             }
2180
-            ist = ist_table[ost->source_index];
2180
+            ist = &input_streams[ost->source_index];
2181 2181
             ist->discard = 0;
2182 2182
             ost->sync_ist = (nb_stream_maps > 0) ?
2183
-                ist_table[file_table[stream_maps[n].sync_file_index].ist_index +
2183
+                &input_streams[input_files[stream_maps[n].sync_file_index].ist_index +
2184 2184
                          stream_maps[n].sync_stream_index] : ist;
2185 2185
         }
2186 2186
     }
... ...
@@ -2189,7 +2157,7 @@ static int transcode(AVFormatContext **output_files,
2189 2189
     for(i=0;i<nb_ostreams;i++) {
2190 2190
         ost = ost_table[i];
2191 2191
         os = output_files[ost->file_index];
2192
-        ist = ist_table[ost->source_index];
2192
+        ist = &input_streams[ost->source_index];
2193 2193
 
2194 2194
         codec = ost->st->codec;
2195 2195
         icodec = ist->st->codec;
... ...
@@ -2368,7 +2336,7 @@ static int transcode(AVFormatContext **output_files,
2368 2368
         ost = ost_table[i];
2369 2369
         if (ost->encoding_needed) {
2370 2370
             AVCodec *codec = i < nb_output_codecs ? output_codecs[i] : NULL;
2371
-            AVCodecContext *dec = ist_table[ost->source_index]->st->codec;
2371
+            AVCodecContext *dec = input_streams[ost->source_index].st->codec;
2372 2372
             if (!codec)
2373 2373
                 codec = avcodec_find_encoder(ost->st->codec->codec_id);
2374 2374
             if (!codec) {
... ...
@@ -2397,21 +2365,21 @@ static int transcode(AVFormatContext **output_files,
2397 2397
     }
2398 2398
 
2399 2399
     /* open each decoder */
2400
-    for(i=0;i<nb_istreams;i++) {
2401
-        ist = ist_table[i];
2400
+    for (i = 0; i < nb_input_streams; i++) {
2401
+        ist = &input_streams[i];
2402 2402
         if (ist->decoding_needed) {
2403 2403
             AVCodec *codec = i < nb_input_codecs ? input_codecs[i] : NULL;
2404 2404
             if (!codec)
2405 2405
                 codec = avcodec_find_decoder(ist->st->codec->codec_id);
2406 2406
             if (!codec) {
2407 2407
                 snprintf(error, sizeof(error), "Decoder (codec id %d) not found for input stream #%d.%d",
2408
-                        ist->st->codec->codec_id, ist->file_index, ist->index);
2408
+                        ist->st->codec->codec_id, ist->file_index, ist->st->index);
2409 2409
                 ret = AVERROR(EINVAL);
2410 2410
                 goto dump_format;
2411 2411
             }
2412 2412
             if (avcodec_open(ist->st->codec, codec) < 0) {
2413 2413
                 snprintf(error, sizeof(error), "Error while opening decoder for input stream #%d.%d",
2414
-                        ist->file_index, ist->index);
2414
+                        ist->file_index, ist->st->index);
2415 2415
                 ret = AVERROR(EINVAL);
2416 2416
                 goto dump_format;
2417 2417
             }
... ...
@@ -2421,9 +2389,9 @@ static int transcode(AVFormatContext **output_files,
2421 2421
     }
2422 2422
 
2423 2423
     /* init pts */
2424
-    for(i=0;i<nb_istreams;i++) {
2424
+    for (i = 0; i < nb_input_streams; i++) {
2425 2425
         AVStream *st;
2426
-        ist = ist_table[i];
2426
+        ist = &input_streams[i];
2427 2427
         st= ist->st;
2428 2428
         ist->pts = st->avg_frame_rate.num ? - st->codec->has_b_frames*AV_TIME_BASE / av_q2d(st->avg_frame_rate) : 0;
2429 2429
         ist->next_pts = AV_NOPTS_VALUE;
... ...
@@ -2452,7 +2420,7 @@ static int transcode(AVFormatContext **output_files,
2452 2452
         METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file")
2453 2453
 
2454 2454
         files[0] = output_files[out_file_index];
2455
-        files[1] = input_files[in_file_index];
2455
+        files[1] = input_files[in_file_index].ctx;
2456 2456
 
2457 2457
         for (j = 0; j < 2; j++) {
2458 2458
             AVMetaDataMap *map = &meta_data_maps[i][j];
... ...
@@ -2483,7 +2451,7 @@ static int transcode(AVFormatContext **output_files,
2483 2483
     if (metadata_global_autocopy) {
2484 2484
 
2485 2485
         for (i = 0; i < nb_output_files; i++)
2486
-            av_metadata_copy(&output_files[i]->metadata, input_files[0]->metadata,
2486
+            av_metadata_copy(&output_files[i]->metadata, input_files[0].ctx->metadata,
2487 2487
                              AV_METADATA_DONT_OVERWRITE);
2488 2488
     }
2489 2489
 
... ...
@@ -2510,7 +2478,7 @@ static int transcode(AVFormatContext **output_files,
2510 2510
     /* copy chapters from the first input file that has them*/
2511 2511
     if (!nb_chapter_maps)
2512 2512
         for (i = 0; i < nb_input_files; i++) {
2513
-            if (!input_files[i]->nb_chapters)
2513
+            if (!input_files[i].ctx->nb_chapters)
2514 2514
                 continue;
2515 2515
 
2516 2516
             for (j = 0; j < nb_output_files; j++)
... ...
@@ -2545,14 +2513,14 @@ static int transcode(AVFormatContext **output_files,
2545 2545
         for(i=0;i<nb_ostreams;i++) {
2546 2546
             ost = ost_table[i];
2547 2547
             fprintf(stderr, "  Stream #%d.%d -> #%d.%d",
2548
-                    ist_table[ost->source_index]->file_index,
2549
-                    ist_table[ost->source_index]->index,
2548
+                    input_streams[ost->source_index].file_index,
2549
+                    input_streams[ost->source_index].st->index,
2550 2550
                     ost->file_index,
2551 2551
                     ost->index);
2552
-            if (ost->sync_ist != ist_table[ost->source_index])
2552
+            if (ost->sync_ist != &input_streams[ost->source_index])
2553 2553
                 fprintf(stderr, " [sync #%d.%d]",
2554 2554
                         ost->sync_ist->file_index,
2555
-                        ost->sync_ist->index);
2555
+                        ost->sync_ist->st->index);
2556 2556
             fprintf(stderr, "\n");
2557 2557
         }
2558 2558
     }
... ...
@@ -2607,16 +2575,14 @@ static int transcode(AVFormatContext **output_files,
2607 2607
             if (key == 'd' || key == 'D'){
2608 2608
                 int debug=0;
2609 2609
                 if(key == 'D') {
2610
-                    ist = ist_table[0];
2611
-                    debug = ist->st->codec->debug<<1;
2610
+                    debug = input_streams[0].st->codec->debug<<1;
2612 2611
                     if(!debug) debug = 1;
2613 2612
                     while(debug & (FF_DEBUG_DCT_COEFF|FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) //unsupported, would just crash
2614 2613
                         debug += debug;
2615 2614
                 }else
2616 2615
                     scanf("%d", &debug);
2617
-                for(i=0;i<nb_istreams;i++) {
2618
-                    ist = ist_table[i];
2619
-                    ist->st->codec->debug = debug;
2616
+                for(i=0;i<nb_input_streams;i++) {
2617
+                    input_streams[i].st->codec->debug = debug;
2620 2618
                 }
2621 2619
                 for(i=0;i<nb_ostreams;i++) {
2622 2620
                     ost = ost_table[i];
... ...
@@ -2645,12 +2611,12 @@ static int transcode(AVFormatContext **output_files,
2645 2645
             double ipts, opts;
2646 2646
             ost = ost_table[i];
2647 2647
             os = output_files[ost->file_index];
2648
-            ist = ist_table[ost->source_index];
2648
+            ist = &input_streams[ost->source_index];
2649 2649
             if(ist->is_past_recording_time || no_packet[ist->file_index])
2650 2650
                 continue;
2651 2651
                 opts = ost->st->pts.val * av_q2d(ost->st->time_base);
2652 2652
             ipts = (double)ist->pts;
2653
-            if (!file_table[ist->file_index].eof_reached){
2653
+            if (!input_files[ist->file_index].eof_reached){
2654 2654
                 if(ipts < ipts_min) {
2655 2655
                     ipts_min = ipts;
2656 2656
                     if(input_sync ) file_index = ist->file_index;
... ...
@@ -2681,7 +2647,7 @@ static int transcode(AVFormatContext **output_files,
2681 2681
             break;
2682 2682
 
2683 2683
         /* read a frame from it and output it in the fifo */
2684
-        is = input_files[file_index];
2684
+        is = input_files[file_index].ctx;
2685 2685
         ret= av_read_frame(is, &pkt);
2686 2686
         if(ret == AVERROR(EAGAIN)){
2687 2687
             no_packet[file_index]=1;
... ...
@@ -2689,7 +2655,7 @@ static int transcode(AVFormatContext **output_files,
2689 2689
             continue;
2690 2690
         }
2691 2691
         if (ret < 0) {
2692
-            file_table[file_index].eof_reached = 1;
2692
+            input_files[file_index].eof_reached = 1;
2693 2693
             if (opt_shortest)
2694 2694
                 break;
2695 2695
             else
... ...
@@ -2705,10 +2671,10 @@ static int transcode(AVFormatContext **output_files,
2705 2705
         }
2706 2706
         /* the following test is needed in case new streams appear
2707 2707
            dynamically in stream : we ignore them */
2708
-        if (pkt.stream_index >= file_table[file_index].nb_streams)
2708
+        if (pkt.stream_index >= input_files[file_index].ctx->nb_streams)
2709 2709
             goto discard_packet;
2710
-        ist_index = file_table[file_index].ist_index + pkt.stream_index;
2711
-        ist = ist_table[ist_index];
2710
+        ist_index = input_files[file_index].ist_index + pkt.stream_index;
2711
+        ist = &input_streams[ist_index];
2712 2712
         if (ist->discard)
2713 2713
             goto discard_packet;
2714 2714
 
... ...
@@ -2751,12 +2717,12 @@ static int transcode(AVFormatContext **output_files,
2751 2751
             goto discard_packet;
2752 2752
         }
2753 2753
 
2754
-        //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size);
2754
+        //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->st->index, pkt.size);
2755 2755
         if (output_packet(ist, ist_index, ost_table, nb_ostreams, &pkt) < 0) {
2756 2756
 
2757 2757
             if (verbose >= 0)
2758 2758
                 fprintf(stderr, "Error while decoding stream #%d.%d\n",
2759
-                        ist->file_index, ist->index);
2759
+                        ist->file_index, ist->st->index);
2760 2760
             if (exit_on_error)
2761 2761
                 ffmpeg_exit(1);
2762 2762
             av_free_packet(&pkt);
... ...
@@ -2771,8 +2737,8 @@ static int transcode(AVFormatContext **output_files,
2771 2771
     }
2772 2772
 
2773 2773
     /* at the end of stream, we must flush the decoder buffers */
2774
-    for(i=0;i<nb_istreams;i++) {
2775
-        ist = ist_table[i];
2774
+    for (i = 0; i < nb_input_streams; i++) {
2775
+        ist = &input_streams[i];
2776 2776
         if (ist->decoding_needed) {
2777 2777
             output_packet(ist, i, ost_table, nb_ostreams, NULL);
2778 2778
         }
... ...
@@ -2802,8 +2768,8 @@ static int transcode(AVFormatContext **output_files,
2802 2802
     }
2803 2803
 
2804 2804
     /* close each decoder */
2805
-    for(i=0;i<nb_istreams;i++) {
2806
-        ist = ist_table[i];
2805
+    for (i = 0; i < nb_input_streams; i++) {
2806
+        ist = &input_streams[i];
2807 2807
         if (ist->decoding_needed) {
2808 2808
             avcodec_close(ist->st->codec);
2809 2809
         }
... ...
@@ -2814,15 +2780,7 @@ static int transcode(AVFormatContext **output_files,
2814 2814
 
2815 2815
  fail:
2816 2816
     av_freep(&bit_buffer);
2817
-    av_free(file_table);
2818 2817
 
2819
-    if (ist_table) {
2820
-        for(i=0;i<nb_istreams;i++) {
2821
-            ist = ist_table[i];
2822
-            av_free(ist);
2823
-        }
2824
-        av_free(ist_table);
2825
-    }
2826 2818
     if (ost_table) {
2827 2819
         for(i=0;i<nb_ostreams;i++) {
2828 2820
             ost = ost_table[i];
... ...
@@ -3375,8 +3333,17 @@ static void opt_input_file(const char *filename)
3375 3375
     for(i=0;i<ic->nb_streams;i++) {
3376 3376
         AVStream *st = ic->streams[i];
3377 3377
         AVCodecContext *dec = st->codec;
3378
+        AVInputStream *ist;
3379
+
3378 3380
         dec->thread_count = thread_count;
3379 3381
         input_codecs = grow_array(input_codecs, sizeof(*input_codecs), &nb_input_codecs, nb_input_codecs + 1);
3382
+
3383
+        input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1);
3384
+        ist = &input_streams[nb_input_streams - 1];
3385
+        ist->st = st;
3386
+        ist->file_index = nb_input_files;
3387
+        ist->discard = 1;
3388
+
3380 3389
         switch (dec->codec_type) {
3381 3390
         case AVMEDIA_TYPE_AUDIO:
3382 3391
             input_codecs[nb_input_codecs-1] = avcodec_find_decoder_by_name(audio_codec_name);
... ...
@@ -3449,13 +3416,14 @@ static void opt_input_file(const char *filename)
3449 3449
         }
3450 3450
     }
3451 3451
 
3452
-    input_files[nb_input_files] = ic;
3453 3452
     input_files_ts_offset[nb_input_files] = input_ts_offset - (copy_ts ? 0 : timestamp);
3454 3453
     /* dump the file content */
3455 3454
     if (verbose >= 0)
3456 3455
         av_dump_format(ic, nb_input_files, filename, 0);
3457 3456
 
3458
-    nb_input_files++;
3457
+    input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1);
3458
+    input_files[nb_input_files - 1].ctx        = ic;
3459
+    input_files[nb_input_files - 1].ist_index  = nb_input_streams - ic->nb_streams;
3459 3460
 
3460 3461
     video_channel = 0;
3461 3462
     top_field_first = -1;
... ...
@@ -3481,7 +3449,7 @@ static void check_inputs(int *has_video_ptr,
3481 3481
     has_data = 0;
3482 3482
 
3483 3483
     for(j=0;j<nb_input_files;j++) {
3484
-        ic = input_files[j];
3484
+        ic = input_files[j].ctx;
3485 3485
         for(i=0;i<ic->nb_streams;i++) {
3486 3486
             AVCodecContext *enc = ic->streams[i]->codec;
3487 3487
             switch(enc->codec_type) {
... ...
@@ -4159,9 +4127,9 @@ static void opt_target(const char *arg)
4159 4159
             /* Try to determine PAL/NTSC by peeking in the input files */
4160 4160
             if(nb_input_files) {
4161 4161
                 int i, j;
4162
-                for(j = 0; j < nb_input_files; j++) {
4163
-                    for(i = 0; i < input_files[j]->nb_streams; i++) {
4164
-                        AVCodecContext *c = input_files[j]->streams[i]->codec;
4162
+                for (j = 0; j < nb_input_files; j++) {
4163
+                    for (i = 0; i < input_files[j].ctx->nb_streams; i++) {
4164
+                        AVCodecContext *c = input_files[j].ctx->streams[i]->codec;
4165 4165
                         if(c->codec_type != AVMEDIA_TYPE_VIDEO)
4166 4166
                             continue;
4167 4167
                         fr = c->time_base.den * 1000 / c->time_base.num;
... ...
@@ -70,33 +70,27 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
70 70
     case CODEC_ID_MPEG4:
71 71
         break;
72 72
     case CODEC_ID_MSMPEG4V1:
73
-        s->h263_msmpeg4 = 1;
74 73
         s->h263_pred = 1;
75 74
         s->msmpeg4_version=1;
76 75
         break;
77 76
     case CODEC_ID_MSMPEG4V2:
78
-        s->h263_msmpeg4 = 1;
79 77
         s->h263_pred = 1;
80 78
         s->msmpeg4_version=2;
81 79
         break;
82 80
     case CODEC_ID_MSMPEG4V3:
83
-        s->h263_msmpeg4 = 1;
84 81
         s->h263_pred = 1;
85 82
         s->msmpeg4_version=3;
86 83
         break;
87 84
     case CODEC_ID_WMV1:
88
-        s->h263_msmpeg4 = 1;
89 85
         s->h263_pred = 1;
90 86
         s->msmpeg4_version=4;
91 87
         break;
92 88
     case CODEC_ID_WMV2:
93
-        s->h263_msmpeg4 = 1;
94 89
         s->h263_pred = 1;
95 90
         s->msmpeg4_version=5;
96 91
         break;
97 92
     case CODEC_ID_VC1:
98 93
     case CODEC_ID_WMV3:
99
-        s->h263_msmpeg4 = 1;
100 94
         s->h263_pred = 1;
101 95
         s->msmpeg4_version=6;
102 96
         avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
... ...
@@ -672,7 +666,7 @@ retry:
672 672
         decode_slice(s);
673 673
     }
674 674
 
675
-    if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I)
675
+    if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I)
676 676
         if(!CONFIG_MSMPEG4_DECODER || msmpeg4_decode_ext_header(s, buf_size) < 0){
677 677
             s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR;
678 678
         }
... ...
@@ -2155,7 +2155,7 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64],
2155 2155
             }
2156 2156
 
2157 2157
             /* add dct residue */
2158
-            if(s->encoding || !(   s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO
2158
+            if(s->encoding || !(   s->msmpeg4_version || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO
2159 2159
                                 || (s->codec_id==CODEC_ID_MPEG4 && !s->mpeg_quant))){
2160 2160
                 add_dequant_dct(s, block[0], 0, dest_y                          , dct_linesize, s->qscale);
2161 2161
                 add_dequant_dct(s, block[1], 1, dest_y              + block_size, dct_linesize, s->qscale);
... ...
@@ -209,7 +209,6 @@ typedef struct MpegEncContext {
209 209
 
210 210
 /* the following codec id fields are deprecated in favor of codec_id */
211 211
     int h263_plus;    ///< h263 plus headers
212
-    int h263_msmpeg4; ///< generate MSMPEG4 compatible stream (deprecated, use msmpeg4_version instead)
213 212
     int h263_flv;     ///< use flv h263 header
214 213
 
215 214
     enum CodecID codec_id;     /* see CODEC_ID_xxx */
... ...
@@ -843,4 +842,3 @@ void ff_wmv2_encode_mb(MpegEncContext * s,
843 843
                        int motion_x, int motion_y);
844 844
 
845 845
 #endif /* AVCODEC_MPEGVIDEO_H */
846
-
... ...
@@ -640,7 +640,6 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
640 640
         break;
641 641
     case CODEC_ID_MSMPEG4V2:
642 642
         s->out_format = FMT_H263;
643
-        s->h263_msmpeg4 = 1;
644 643
         s->h263_pred = 1;
645 644
         s->unrestricted_mv = 1;
646 645
         s->msmpeg4_version= 2;
... ...
@@ -649,7 +648,6 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
649 649
         break;
650 650
     case CODEC_ID_MSMPEG4V3:
651 651
         s->out_format = FMT_H263;
652
-        s->h263_msmpeg4 = 1;
653 652
         s->h263_pred = 1;
654 653
         s->unrestricted_mv = 1;
655 654
         s->msmpeg4_version= 3;
... ...
@@ -659,7 +657,6 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
659 659
         break;
660 660
     case CODEC_ID_WMV1:
661 661
         s->out_format = FMT_H263;
662
-        s->h263_msmpeg4 = 1;
663 662
         s->h263_pred = 1;
664 663
         s->unrestricted_mv = 1;
665 664
         s->msmpeg4_version= 4;
... ...
@@ -669,7 +666,6 @@ av_cold int MPV_encode_init(AVCodecContext *avctx)
669 669
         break;
670 670
     case CODEC_ID_WMV2:
671 671
         s->out_format = FMT_H263;
672
-        s->h263_msmpeg4 = 1;
673 672
         s->h263_pred = 1;
674 673
         s->unrestricted_mv = 1;
675 674
         s->msmpeg4_version= 5;
... ...
@@ -2773,7 +2769,7 @@ static int encode_picture(MpegEncContext *s, int picture_number)
2773 2773
 
2774 2774
     /* we need to initialize some time vars before we can encode b-frames */
2775 2775
     // RAL: Condition added for MPEG1VIDEO
2776
-    if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4))
2776
+    if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->msmpeg4_version))
2777 2777
         set_frame_distances(s);
2778 2778
     if(CONFIG_MPEG4_ENCODER && s->codec_id == CODEC_ID_MPEG4)
2779 2779
         ff_set_mpeg4_time(s);
... ...
@@ -2942,7 +2938,7 @@ static int encode_picture(MpegEncContext *s, int picture_number)
2942 2942
     case FMT_H263:
2943 2943
         if (CONFIG_WMV2_ENCODER && s->codec_id == CODEC_ID_WMV2)
2944 2944
             ff_wmv2_encode_picture_header(s, picture_number);
2945
-        else if (CONFIG_MSMPEG4_ENCODER && s->h263_msmpeg4)
2945
+        else if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version)
2946 2946
             msmpeg4_encode_picture_header(s, picture_number);
2947 2947
         else if (CONFIG_MPEG4_ENCODER && s->h263_pred)
2948 2948
             mpeg4_encode_picture_header(s, picture_number);
... ...
@@ -47,6 +47,7 @@
47 47
 
48 48
 #include <alsa/asoundlib.h>
49 49
 #include "libavformat/avformat.h"
50
+#include "libavutil/opt.h"
50 51
 
51 52
 #include "alsa-audio.h"
52 53
 
... ...
@@ -56,21 +57,16 @@ static av_cold int audio_read_header(AVFormatContext *s1,
56 56
     AlsaData *s = s1->priv_data;
57 57
     AVStream *st;
58 58
     int ret;
59
-    unsigned int sample_rate;
60 59
     enum CodecID codec_id;
61 60
     snd_pcm_sw_params_t *sw_params;
62 61
 
63
-    if (ap->sample_rate <= 0) {
64
-        av_log(s1, AV_LOG_ERROR, "Bad sample rate %d\n", ap->sample_rate);
62
+#if FF_API_FORMAT_PARAMETERS
63
+    if (ap->sample_rate > 0)
64
+        s->sample_rate = ap->sample_rate;
65 65
 
66
-        return AVERROR(EIO);
67
-    }
68
-
69
-    if (ap->channels <= 0) {
70
-        av_log(s1, AV_LOG_ERROR, "Bad channels number %d\n", ap->channels);
71
-
72
-        return AVERROR(EIO);
73
-    }
66
+    if (ap->channels > 0)
67
+        s->channels = ap->channels;
68
+#endif
74 69
 
75 70
     st = av_new_stream(s1, 0);
76 71
     if (!st) {
... ...
@@ -78,10 +74,9 @@ static av_cold int audio_read_header(AVFormatContext *s1,
78 78
 
79 79
         return AVERROR(ENOMEM);
80 80
     }
81
-    sample_rate = ap->sample_rate;
82 81
     codec_id    = s1->audio_codec_id;
83 82
 
84
-    ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &sample_rate, ap->channels,
83
+    ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &s->sample_rate, s->channels,
85 84
         &codec_id);
86 85
     if (ret < 0) {
87 86
         return AVERROR(EIO);
... ...
@@ -113,8 +108,8 @@ static av_cold int audio_read_header(AVFormatContext *s1,
113 113
     /* take real parameters */
114 114
     st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
115 115
     st->codec->codec_id    = codec_id;
116
-    st->codec->sample_rate = sample_rate;
117
-    st->codec->channels    = ap->channels;
116
+    st->codec->sample_rate = s->sample_rate;
117
+    st->codec->channels    = s->channels;
118 118
     av_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
119 119
 
120 120
     return 0;
... ...
@@ -163,6 +158,19 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
163 163
     return 0;
164 164
 }
165 165
 
166
+static const AVOption options[] = {
167
+    { "sample_rate", "", offsetof(AlsaData, sample_rate), FF_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
168
+    { "channels",    "", offsetof(AlsaData, channels),    FF_OPT_TYPE_INT, {.dbl = 2},     1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
169
+    { NULL },
170
+};
171
+
172
+static const AVClass alsa_demuxer_class = {
173
+    .class_name     = "ALSA demuxer",
174
+    .item_name      = av_default_item_name,
175
+    .option         = options,
176
+    .version        = LIBAVUTIL_VERSION_INT,
177
+};
178
+
166 179
 AVInputFormat ff_alsa_demuxer = {
167 180
     "alsa",
168 181
     NULL_IF_CONFIG_SMALL("ALSA audio input"),
... ...
@@ -172,4 +180,5 @@ AVInputFormat ff_alsa_demuxer = {
172 172
     audio_read_packet,
173 173
     ff_alsa_close,
174 174
     .flags = AVFMT_NOFILE,
175
+    .priv_class = &alsa_demuxer_class,
175 176
 };
... ...
@@ -33,6 +33,7 @@
33 33
 #include <alsa/asoundlib.h>
34 34
 #include "config.h"
35 35
 #include "libavformat/avformat.h"
36
+#include "libavutil/log.h"
36 37
 
37 38
 /* XXX: we make the assumption that the soundcard accepts this format */
38 39
 /* XXX: find better solution with "preinit" method, needed also in
... ...
@@ -42,12 +43,15 @@
42 42
 typedef void (*ff_reorder_func)(const void *, void *, int);
43 43
 
44 44
 typedef struct {
45
+    AVClass *class;
45 46
     snd_pcm_t *h;
46 47
     int frame_size;  ///< preferred size for reads and writes
47 48
     int period_size; ///< bytes per sample * channels
48 49
     ff_reorder_func reorder_func;
49 50
     void *reorder_buf;
50 51
     int reorder_buf_size; ///< in frames
52
+    int sample_rate; ///< sample rate set by user
53
+    int channels;    ///< number of channels set by user
51 54
 } AlsaData;
52 55
 
53 56
 /**
... ...
@@ -25,6 +25,8 @@
25 25
  */
26 26
 
27 27
 #include "libavformat/avformat.h"
28
+#include "libavutil/log.h"
29
+#include "libavutil/opt.h"
28 30
 #if HAVE_DEV_BKTR_IOCTL_METEOR_H && HAVE_DEV_BKTR_IOCTL_BT848_H
29 31
 # include <dev/bktr/ioctl_meteor.h>
30 32
 # include <dev/bktr/ioctl_bt848.h>
... ...
@@ -47,12 +49,14 @@
47 47
 #include <strings.h>
48 48
 
49 49
 typedef struct {
50
+    AVClass *class;
50 51
     int video_fd;
51 52
     int tuner_fd;
52 53
     int width, height;
53 54
     int frame_rate;
54 55
     int frame_rate_base;
55 56
     uint64_t per_frame;
57
+    int standard;
56 58
 } VideoData;
57 59
 
58 60
 
... ...
@@ -245,7 +249,6 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
245 245
     int width, height;
246 246
     int frame_rate;
247 247
     int frame_rate_base;
248
-    int format = -1;
249 248
 
250 249
     if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0)
251 250
         return -1;
... ...
@@ -274,16 +277,18 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
274 274
     st->codec->time_base.den = frame_rate;
275 275
     st->codec->time_base.num = frame_rate_base;
276 276
 
277
+#if FF_API_FORMAT_PARAMETERS
277 278
     if (ap->standard) {
278 279
         if (!strcasecmp(ap->standard, "pal"))
279
-            format = PAL;
280
+            s->standard = PAL;
280 281
         else if (!strcasecmp(ap->standard, "secam"))
281
-            format = SECAM;
282
+            s->standard = SECAM;
282 283
         else if (!strcasecmp(ap->standard, "ntsc"))
283
-            format = NTSC;
284
+            s->standard = NTSC;
284 285
     }
286
+#endif
285 287
 
286
-    if (bktr_init(s1->filename, width, height, format,
288
+    if (bktr_init(s1->filename, width, height, s->standard,
287 289
             &(s->video_fd), &(s->tuner_fd), -1, 0.0) < 0)
288 290
         return AVERROR(EIO);
289 291
 
... ...
@@ -311,6 +316,24 @@ static int grab_read_close(AVFormatContext *s1)
311 311
     return 0;
312 312
 }
313 313
 
314
+static const AVOption options[] = {
315
+    { "standard", "", offsetof(VideoData, standard), FF_OPT_TYPE_INT, {.dbl = VIDEO_FORMAT}, PAL, NTSCJ, AV_OPT_FLAG_DECODING_PARAM, "standard" },
316
+    { "PAL",      "", 0, FF_OPT_TYPE_CONST, {.dbl = PAL},   0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
317
+    { "NTSC",     "", 0, FF_OPT_TYPE_CONST, {.dbl = NTSC},  0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
318
+    { "SECAM",    "", 0, FF_OPT_TYPE_CONST, {.dbl = SECAM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
319
+    { "PALN",     "", 0, FF_OPT_TYPE_CONST, {.dbl = PALN},  0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
320
+    { "PALM",     "", 0, FF_OPT_TYPE_CONST, {.dbl = PALM},  0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
321
+    { "NTSCJ",    "", 0, FF_OPT_TYPE_CONST, {.dbl = NTSCJ}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
322
+    { NULL },
323
+};
324
+
325
+static const AVClass bktr_class = {
326
+    .class_name = "BKTR grab interface",
327
+    .item_name  = av_default_item_name,
328
+    .option     = options,
329
+    .version    = LIBAVUTIL_VERSION_INT,
330
+};
331
+
314 332
 AVInputFormat ff_bktr_demuxer = {
315 333
     "bktr",
316 334
     NULL_IF_CONFIG_SMALL("video grab"),
... ...
@@ -320,4 +343,5 @@ AVInputFormat ff_bktr_demuxer = {
320 320
     grab_read_packet,
321 321
     grab_read_close,
322 322
     .flags = AVFMT_NOFILE,
323
+    .priv_class = &bktr_class,
323 324
 };
... ...
@@ -30,6 +30,8 @@
30 30
 #include <time.h>
31 31
 #include <strings.h>
32 32
 
33
+#include "libavutil/log.h"
34
+#include "libavutil/opt.h"
33 35
 #include "libavformat/avformat.h"
34 36
 
35 37
 #undef DV1394_DEBUG
... ...
@@ -38,6 +40,7 @@
38 38
 #include "dv1394.h"
39 39
 
40 40
 struct dv1394_data {
41
+    AVClass *class;
41 42
     int fd;
42 43
     int channel;
43 44
     int format;
... ...
@@ -90,15 +93,17 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap
90 90
     if (!dv->dv_demux)
91 91
         goto failed;
92 92
 
93
-    if (ap->standard && !strcasecmp(ap->standard, "pal"))
94
-        dv->format = DV1394_PAL;
95
-    else
96
-        dv->format = DV1394_NTSC;
93
+#if FF_API_FORMAT_PARAMETERS
94
+    if (ap->standard) {
95
+       if (!strcasecmp(ap->standard, "pal"))
96
+           dv->format = DV1394_PAL;
97
+       else
98
+           dv->format = DV1394_NTSC;
99
+    }
97 100
 
98 101
     if (ap->channel)
99 102
         dv->channel = ap->channel;
100
-    else
101
-        dv->channel = DV1394_DEFAULT_CHANNEL;
103
+#endif
102 104
 
103 105
     /* Open and initialize DV1394 device */
104 106
     dv->fd = open(context->filename, O_RDONLY);
... ...
@@ -227,6 +232,21 @@ static int dv1394_close(AVFormatContext * context)
227 227
     return 0;
228 228
 }
229 229
 
230
+static const AVOption options[] = {
231
+    { "standard", "", offsetof(struct dv1394_data, format), FF_OPT_TYPE_INT, {.dbl = DV1394_NTSC}, DV1394_PAL, DV1394_NTSC, AV_OPT_FLAG_DECODING_PARAM, "standard" },
232
+    { "PAL",      "", 0, FF_OPT_TYPE_CONST, {.dbl = DV1394_PAL},   0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
233
+    { "NTSC",     "", 0, FF_OPT_TYPE_CONST, {.dbl = DV1394_NTSC},  0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
234
+    { "channel",  "", offsetof(struct dv1394_data, channel), FF_OPT_TYPE_INT, {.dbl = DV1394_DEFAULT_CHANNEL}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
235
+    { NULL },
236
+};
237
+
238
+static const AVClass dv1394_class = {
239
+    .class_name = "DV1394 indev",
240
+    .item_name  = av_default_item_name,
241
+    .option     = options,
242
+    .version    = LIBAVUTIL_VERSION_INT,
243
+};
244
+
230 245
 AVInputFormat ff_dv1394_demuxer = {
231 246
     .name           = "dv1394",
232 247
     .long_name      = NULL_IF_CONFIG_SMALL("DV1394 A/V grab"),
... ...
@@ -234,5 +254,6 @@ AVInputFormat ff_dv1394_demuxer = {
234 234
     .read_header    = dv1394_read_header,
235 235
     .read_packet    = dv1394_read_packet,
236 236
     .read_close     = dv1394_close,
237
-    .flags          = AVFMT_NOFILE
237
+    .flags          = AVFMT_NOFILE,
238
+    .priv_class     = &dv1394_class,
238 239
 };
... ...
@@ -22,6 +22,8 @@
22 22
 
23 23
 #include "config.h"
24 24
 #include "libavformat/avformat.h"
25
+#include "libavutil/log.h"
26
+#include "libavutil/opt.h"
25 27
 
26 28
 #if HAVE_LIBDC1394_2
27 29
 #include <dc1394/dc1394.h>
... ...
@@ -45,9 +47,11 @@
45 45
 #undef free
46 46
 
47 47
 typedef struct dc1394_data {
48
+    AVClass *class;
48 49
 #if HAVE_LIBDC1394_1
49 50
     raw1394handle_t handle;
50 51
     dc1394_cameracapture camera;
52
+    int channel;
51 53
 #elif HAVE_LIBDC1394_2
52 54
     dc1394_t *d;
53 55
     dc1394camera_t *camera;
... ...
@@ -155,6 +159,11 @@ static int dc1394_v1_read_header(AVFormatContext *c, AVFormatParameters * ap)
155 155
     if (dc1394_read_common(c,ap,&fmt,&fps) != 0)
156 156
         return -1;
157 157
 
158
+#if FF_API_FORMAT_PARAMETERS
159
+    if (ap->channel)
160
+        dc1394->channel = ap->channel;
161
+#endif
162
+
158 163
     /* Now let us prep the hardware. */
159 164
     dc1394->handle = dc1394_create_handle(0); /* FIXME: gotta have ap->port */
160 165
     if (!dc1394->handle) {
... ...
@@ -162,11 +171,11 @@ static int dc1394_v1_read_header(AVFormatContext *c, AVFormatParameters * ap)
162 162
         goto out;
163 163
     }
164 164
     camera_nodes = dc1394_get_camera_nodes(dc1394->handle, &res, 1);
165
-    if (!camera_nodes || camera_nodes[ap->channel] == DC1394_NO_CAMERA) {
166
-        av_log(c, AV_LOG_ERROR, "There's no IIDC camera on the channel %d\n", ap->channel);
165
+    if (!camera_nodes || camera_nodes[dc1394->channel] == DC1394_NO_CAMERA) {
166
+        av_log(c, AV_LOG_ERROR, "There's no IIDC camera on the channel %d\n", dc1394->channel);
167 167
         goto out_handle;
168 168
     }
169
-    res = dc1394_dma_setup_capture(dc1394->handle, camera_nodes[ap->channel],
169
+    res = dc1394_dma_setup_capture(dc1394->handle, camera_nodes[dc1394->channel],
170 170
                                    0,
171 171
                                    FORMAT_VGA_NONCOMPRESSED,
172 172
                                    fmt->frame_size_id,
... ...
@@ -236,6 +245,20 @@ static int dc1394_v1_close(AVFormatContext * context)
236 236
     return 0;
237 237
 }
238 238
 
239
+static const AVOption options[] = {
240
+#if HAVE_LIBDC1394_1
241
+    { "channel", "", offsetof(dc1394_data, channel), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
242
+#endif
243
+    { NULL },
244
+};
245
+
246
+static const AVClass libdc1394_class = {
247
+    .class_name = "libdc1394 indev",
248
+    .item_name  = av_default_item_name,
249
+    .option     = options,
250
+    .version    = LIBAVUTIL_VERSION_INT,
251
+};
252
+
239 253
 #elif HAVE_LIBDC1394_2
240 254
 static int dc1394_v2_read_header(AVFormatContext *c, AVFormatParameters * ap)
241 255
 {
... ...
@@ -356,6 +379,7 @@ AVInputFormat ff_libdc1394_demuxer = {
356 356
     .read_packet    = dc1394_v2_read_packet,
357 357
     .read_close     = dc1394_v2_close,
358 358
     .flags          = AVFMT_NOFILE
359
+    .priv_class     = &libdc1394_class,
359 360
 };
360 361
 
361 362
 #endif
... ...
@@ -367,6 +391,7 @@ AVInputFormat ff_libdc1394_demuxer = {
367 367
     .read_header    = dc1394_v1_read_header,
368 368
     .read_packet    = dc1394_v1_read_packet,
369 369
     .read_close     = dc1394_v1_close,
370
-    .flags          = AVFMT_NOFILE
370
+    .flags          = AVFMT_NOFILE,
371
+    .priv_class     = &libdc1394_class,
371 372
 };
372 373
 #endif
... ...
@@ -37,12 +37,14 @@
37 37
 #include <sys/select.h>
38 38
 
39 39
 #include "libavutil/log.h"
40
+#include "libavutil/opt.h"
40 41
 #include "libavcodec/avcodec.h"
41 42
 #include "libavformat/avformat.h"
42 43
 
43 44
 #define AUDIO_BLOCK_SIZE 4096
44 45
 
45 46
 typedef struct {
47
+    AVClass *class;
46 48
     int fd;
47 49
     int sample_rate;
48 50
     int channels;
... ...
@@ -214,15 +216,17 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap)
214 214
     AVStream *st;
215 215
     int ret;
216 216
 
217
-    if (ap->sample_rate <= 0 || ap->channels <= 0)
218
-        return -1;
217
+#if FF_API_FORMAT_PARAMETERS
218
+    if (ap->sample_rate > 0)
219
+        s->sample_rate = ap->sample_rate;
220
+    if (ap->channels > 0)
221
+        s->channels = ap->channels;
222
+#endif
219 223
 
220 224
     st = av_new_stream(s1, 0);
221 225
     if (!st) {
222 226
         return AVERROR(ENOMEM);
223 227
     }
224
-    s->sample_rate = ap->sample_rate;
225
-    s->channels = ap->channels;
226 228
 
227 229
     ret = audio_open(s1, 0, s1->filename);
228 230
     if (ret < 0) {
... ...
@@ -291,6 +295,19 @@ static int audio_read_close(AVFormatContext *s1)
291 291
 }
292 292
 
293 293
 #if CONFIG_OSS_INDEV
294
+static const AVOption options[] = {
295
+    { "sample_rate", "", offsetof(AudioData, sample_rate), FF_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
296
+    { "channels",    "", offsetof(AudioData, channels),    FF_OPT_TYPE_INT, {.dbl = 2},     1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
297
+    { NULL },
298
+};
299
+
300
+static const AVClass oss_demuxer_class = {
301
+    .class_name     = "OSS demuxer",
302
+    .item_name      = av_default_item_name,
303
+    .option         = options,
304
+    .version        = LIBAVUTIL_VERSION_INT,
305
+};
306
+
294 307
 AVInputFormat ff_oss_demuxer = {
295 308
     "oss",
296 309
     NULL_IF_CONFIG_SMALL("Open Sound System capture"),
... ...
@@ -300,6 +317,7 @@ AVInputFormat ff_oss_demuxer = {
300 300
     audio_read_packet,
301 301
     audio_read_close,
302 302
     .flags = AVFMT_NOFILE,
303
+    .priv_class = &oss_demuxer_class,
303 304
 };
304 305
 #endif
305 306
 
... ...
@@ -26,8 +26,10 @@
26 26
 #include <sndio.h>
27 27
 
28 28
 #include "libavformat/avformat.h"
29
+#include "libavutil/log.h"
29 30
 
30 31
 typedef struct {
32
+    AVClass *class;
31 33
     struct sio_hdl *hdl;
32 34
     enum CodecID codec_id;
33 35
     int64_t hwpos;
... ...
@@ -23,6 +23,7 @@
23 23
 #include <sndio.h>
24 24
 
25 25
 #include "libavformat/avformat.h"
26
+#include "libavutil/opt.h"
26 27
 
27 28
 #include "sndio_common.h"
28 29
 
... ...
@@ -33,16 +34,17 @@ static av_cold int audio_read_header(AVFormatContext *s1,
33 33
     AVStream *st;
34 34
     int ret;
35 35
 
36
-    if (ap->sample_rate <= 0 || ap->channels <= 0)
37
-        return AVERROR(EINVAL);
36
+#if FF_API_FORMAT_PARAMETERS
37
+    if (ap->sample_rate > 0)
38
+        s->sample_rate = ap->sample_rate;
39
+    if (ap->channels > 0)
40
+        s->channels = ap->channels;
41
+#endif
38 42
 
39 43
     st = av_new_stream(s1, 0);
40 44
     if (!st)
41 45
         return AVERROR(ENOMEM);
42 46
 
43
-    s->sample_rate = ap->sample_rate;
44
-    s->channels    = ap->channels;
45
-
46 47
     ret = ff_sndio_open(s1, 0, s1->filename);
47 48
     if (ret < 0)
48 49
         return ret;
... ...
@@ -97,6 +99,19 @@ static av_cold int audio_read_close(AVFormatContext *s1)
97 97
     return 0;
98 98
 }
99 99
 
100
+static const AVOption options[] = {
101
+    { "sample_rate", "", offsetof(SndioData, sample_rate), FF_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
102
+    { "channels",    "", offsetof(SndioData, channels),    FF_OPT_TYPE_INT, {.dbl = 2},     1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
103
+    { NULL },
104
+};
105
+
106
+static const AVClass sndio_demuxer_class = {
107
+    .class_name     = "sndio indev",
108
+    .item_name      = av_default_item_name,
109
+    .option         = options,
110
+    .version        = LIBAVUTIL_VERSION_INT,
111
+};
112
+
100 113
 AVInputFormat ff_sndio_demuxer = {
101 114
     .name           = "sndio",
102 115
     .long_name      = NULL_IF_CONFIG_SMALL("sndio audio capture"),
... ...
@@ -105,4 +120,5 @@ AVInputFormat ff_sndio_demuxer = {
105 105
     .read_packet    = audio_read_packet,
106 106
     .read_close     = audio_read_close,
107 107
     .flags          = AVFMT_NOFILE,
108
+    .priv_class     = &sndio_demuxer_class,
108 109
 };
... ...
@@ -23,6 +23,8 @@
23 23
 #include "config.h"
24 24
 #include "libavutil/rational.h"
25 25
 #include "libavutil/imgutils.h"
26
+#include "libavutil/log.h"
27
+#include "libavutil/opt.h"
26 28
 #include "libavformat/avformat.h"
27 29
 #include "libavcodec/dsputil.h"
28 30
 #include <unistd.h>
... ...
@@ -36,6 +38,7 @@
36 36
 #include <strings.h>
37 37
 
38 38
 typedef struct {
39
+    AVClass *class;
39 40
     int fd;
40 41
     int frame_format; /* see VIDEO_PALETTE_xxx */
41 42
     int use_mmap;
... ...
@@ -49,6 +52,7 @@ typedef struct {
49 49
     struct video_mbuf gb_buffers;
50 50
     struct video_mmap gb_buf;
51 51
     int gb_frame;
52
+    int standard;
52 53
 } VideoData;
53 54
 
54 55
 static const struct {
... ...
@@ -131,13 +135,18 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
131 131
     }
132 132
 
133 133
     /* set tv standard */
134
-    if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
135
-        if (!strcasecmp(ap->standard, "pal"))
136
-            tuner.mode = VIDEO_MODE_PAL;
137
-        else if (!strcasecmp(ap->standard, "secam"))
138
-            tuner.mode = VIDEO_MODE_SECAM;
139
-        else
140
-            tuner.mode = VIDEO_MODE_NTSC;
134
+    if (!ioctl(video_fd, VIDIOCGTUNER, &tuner)) {
135
+#if FF_API_FORMAT_PARAMETERS
136
+        if (ap->standard) {
137
+            if (!strcasecmp(ap->standard, "pal"))
138
+                s->standard = VIDEO_MODE_PAL;
139
+            else if (!strcasecmp(ap->standard, "secam"))
140
+                s->standard = VIDEO_MODE_SECAM;
141
+            else
142
+                s->standard = VIDEO_MODE_NTSC;
143
+        }
144
+#endif
145
+        tuner.mode = s->standard;
141 146
         ioctl(video_fd, VIDIOCSTUNER, &tuner);
142 147
     }
143 148
 
... ...
@@ -339,6 +348,21 @@ static int grab_read_close(AVFormatContext *s1)
339 339
     return 0;
340 340
 }
341 341
 
342
+static const AVOption options[] = {
343
+    { "standard", "", offsetof(VideoData, standard), FF_OPT_TYPE_INT, {.dbl = VIDEO_MODE_NTSC}, VIDEO_MODE_PAL, VIDEO_MODE_NTSC, AV_OPT_FLAG_DECODING_PARAM, "standard" },
344
+    { "PAL",   "", 0, FF_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_PAL},   0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
345
+    { "SECAM", "", 0, FF_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_SECAM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
346
+    { "NTSC",  "", 0, FF_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_NTSC},  0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" },
347
+    { NULL },
348
+};
349
+
350
+static const AVClass v4l_class = {
351
+    .class_name = "V4L indev",
352
+    .item_name  = av_default_item_name,
353
+    .option     = options,
354
+    .version    = LIBAVUTIL_VERSION_INT,
355
+};
356
+
342 357
 AVInputFormat ff_v4l_demuxer = {
343 358
     "video4linux",
344 359
     NULL_IF_CONFIG_SMALL("Video4Linux device grab"),
... ...
@@ -348,4 +372,5 @@ AVInputFormat ff_v4l_demuxer = {
348 348
     grab_read_packet,
349 349
     grab_read_close,
350 350
     .flags = AVFMT_NOFILE,
351
+    .priv_class = &v4l_class,
351 352
 };
... ...
@@ -44,6 +44,8 @@
44 44
 #include <time.h>
45 45
 #include <strings.h>
46 46
 #include "libavutil/imgutils.h"
47
+#include "libavutil/log.h"
48
+#include "libavutil/opt.h"
47 49
 
48 50
 static const int desired_video_buffers = 256;
49 51
 
... ...
@@ -54,6 +56,7 @@ enum io_method {
54 54
 };
55 55
 
56 56
 struct video_data {
57
+    AVClass *class;
57 58
     int fd;
58 59
     int frame_format; /* V4L2_PIX_FMT_* */
59 60
     enum io_method io_method;
... ...
@@ -64,6 +67,8 @@ struct video_data {
64 64
     int buffers;
65 65
     void **buf_start;
66 66
     unsigned int *buf_len;
67
+    char *standard;
68
+    int channel;
67 69
 };
68 70
 
69 71
 struct buff_data {
... ...
@@ -448,50 +453,61 @@ static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap)
448 448
 
449 449
     streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
450 450
 
451
-    if (ap->channel>=0) {
452
-        /* set tv video input */
453
-        memset (&input, 0, sizeof (input));
454
-        input.index = ap->channel;
455
-        if (ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
456
-            av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n");
457
-            return AVERROR(EIO);
458
-        }
451
+#if FF_API_FORMAT_PARAMETERS
452
+    if (ap->channel > 0)
453
+        s->channel = ap->channel;
454
+#endif
459 455
 
460
-        av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n",
461
-               ap->channel, input.name);
462
-        if (ioctl(s->fd, VIDIOC_S_INPUT, &input.index) < 0) {
463
-            av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set input(%d) failed\n",
464
-                   ap->channel);
465
-            return AVERROR(EIO);
466
-        }
456
+    /* set tv video input */
457
+    memset (&input, 0, sizeof (input));
458
+    input.index = s->channel;
459
+    if (ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) {
460
+        av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n");
461
+        return AVERROR(EIO);
462
+    }
463
+
464
+    av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n",
465
+            s->channel, input.name);
466
+    if (ioctl(s->fd, VIDIOC_S_INPUT, &input.index) < 0) {
467
+        av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set input(%d) failed\n",
468
+                s->channel);
469
+        return AVERROR(EIO);
467 470
     }
468 471
 
472
+#if FF_API_FORMAT_PARAMETERS
469 473
     if (ap->standard) {
474
+        av_freep(&s->standard);
475
+        s->standard = av_strdup(ap->standard);
476
+    }
477
+#endif
478
+
479
+    if (s->standard) {
470 480
         av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n",
471
-               ap->standard);
481
+               s->standard);
472 482
         /* set tv standard */
473 483
         memset (&standard, 0, sizeof (standard));
474 484
         for(i=0;;i++) {
475 485
             standard.index = i;
476 486
             if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) {
477 487
                 av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n",
478
-                       ap->standard);
488
+                       s->standard);
479 489
                 return AVERROR(EIO);
480 490
             }
481 491
 
482
-            if (!strcasecmp(standard.name, ap->standard)) {
492
+            if (!strcasecmp(standard.name, s->standard)) {
483 493
                 break;
484 494
             }
485 495
         }
486 496
 
487 497
         av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s, id: %"PRIu64"\n",
488
-               ap->standard, (uint64_t)standard.id);
498
+               s->standard, (uint64_t)standard.id);
489 499
         if (ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) {
490 500
             av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n",
491
-                   ap->standard);
501
+                   s->standard);
492 502
             return AVERROR(EIO);
493 503
         }
494 504
     }
505
+    av_freep(&s->standard);
495 506
 
496 507
     if (ap->time_base.num && ap->time_base.den) {
497 508
         av_log(s1, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n",
... ...
@@ -680,6 +696,19 @@ static int v4l2_read_close(AVFormatContext *s1)
680 680
     return 0;
681 681
 }
682 682
 
683
+static const AVOption options[] = {
684
+    { "standard", "", offsetof(struct video_data, standard), FF_OPT_TYPE_STRING, {.str = "NTSC" }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
685
+    { "channel",  "", offsetof(struct video_data, channel),  FF_OPT_TYPE_INT,    {.dbl = 0 }, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
686
+    { NULL },
687
+};
688
+
689
+static const AVClass v4l2_class = {
690
+    .class_name = "V4L2 indev",
691
+    .item_name  = av_default_item_name,
692
+    .option     = options,
693
+    .version    = LIBAVUTIL_VERSION_INT,
694
+};
695
+
683 696
 AVInputFormat ff_v4l2_demuxer = {
684 697
     "video4linux2",
685 698
     NULL_IF_CONFIG_SMALL("Video4Linux2 device grab"),
... ...
@@ -689,4 +718,5 @@ AVInputFormat ff_v4l2_demuxer = {
689 689
     v4l2_read_packet,
690 690
     v4l2_read_close,
691 691
     .flags = AVFMT_NOFILE,
692
+    .priv_class = &v4l2_class,
692 693
 };
... ...
@@ -228,17 +228,20 @@ typedef struct AVProbeData {
228 228
 
229 229
 typedef struct AVFormatParameters {
230 230
     AVRational time_base;
231
-    int sample_rate;
232
-    int channels;
231
+#if FF_API_FORMAT_PARAMETERS
232
+    attribute_deprecated int sample_rate;
233
+    attribute_deprecated int channels;
234
+#endif
233 235
     int width;
234 236
     int height;
235 237
     enum PixelFormat pix_fmt;
236
-    int channel; /**< Used to select DV channel. */
237
-    const char *standard; /**< TV standard, NTSC, PAL, SECAM */
238
-    unsigned int mpeg2ts_raw:1;  /**< Force raw MPEG-2 transport stream output, if possible. */
239
-    unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport
240
-                                            stream packet (only meaningful if
241
-                                            mpeg2ts_raw is TRUE). */
238
+#if FF_API_FORMAT_PARAMETERS
239
+    attribute_deprecated int channel; /**< Used to select DV channel. */
240
+    attribute_deprecated const char *standard; /**< deprecated, use demuxer-specific options instead. */
241
+    attribute_deprecated unsigned int mpeg2ts_raw:1;  /**< deprecated, use mpegtsraw demuxer */
242
+    /**< deprecated, use mpegtsraw demuxer-specific options instead */
243
+    attribute_deprecated unsigned int mpeg2ts_compute_pcr:1;
244
+#endif
242 245
     unsigned int initial_pause:1;       /**< Do not begin to play the stream
243 246
                                             immediately (RTSP only). */
244 247
     unsigned int prealloced_context:1;
... ...
@@ -824,6 +827,11 @@ typedef struct AVFormatContext {
824 824
      * - decoding: Unused.
825 825
      */
826 826
     int64_t start_time_realtime;
827
+
828
+    /**
829
+     * decoding: number of frames used to probe fps
830
+     */
831
+    int fps_probe_size;
827 832
 } AVFormatContext;
828 833
 
829 834
 typedef struct AVPacketList {
... ...
@@ -25,6 +25,8 @@
25 25
 
26 26
 #include "libavutil/crc.h"
27 27
 #include "libavutil/intreadwrite.h"
28
+#include "libavutil/log.h"
29
+#include "libavutil/opt.h"
28 30
 #include "libavcodec/bytestream.h"
29 31
 #include "avformat.h"
30 32
 #include "mpegts.h"
... ...
@@ -86,6 +88,7 @@ struct Program {
86 86
 };
87 87
 
88 88
 struct MpegTSContext {
89
+    const AVClass *class;
89 90
     /* user data */
90 91
     AVFormatContext *stream;
91 92
     /** raw packet size, including FEC if present            */
... ...
@@ -122,6 +125,19 @@ struct MpegTSContext {
122 122
     MpegTSFilter *pids[NB_PID_MAX];
123 123
 };
124 124
 
125
+static const AVOption options[] = {
126
+    {"compute_pcr", "Compute exact PCR for each transport stream packet.", offsetof(MpegTSContext, mpeg2ts_compute_pcr), FF_OPT_TYPE_INT,
127
+     {.dbl = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
128
+    { NULL },
129
+};
130
+
131
+static const AVClass mpegtsraw_class = {
132
+    .class_name = "mpegtsraw demuxer",
133
+    .item_name  = av_default_item_name,
134
+    .option     = options,
135
+    .version    = LIBAVUTIL_VERSION_INT,
136
+};
137
+
125 138
 /* TS stream handling */
126 139
 
127 140
 enum MpegTSState {
... ...
@@ -1455,13 +1471,16 @@ static int mpegts_read_header(AVFormatContext *s,
1455 1455
     int len;
1456 1456
     int64_t pos;
1457 1457
 
1458
+#if FF_API_FORMAT_PARAMETERS
1458 1459
     if (ap) {
1459
-        ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr;
1460
+        if (ap->mpeg2ts_compute_pcr)
1461
+            ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr;
1460 1462
         if(ap->mpeg2ts_raw){
1461 1463
             av_log(s, AV_LOG_ERROR, "use mpegtsraw_demuxer!\n");
1462 1464
             return -1;
1463 1465
         }
1464 1466
     }
1467
+#endif
1465 1468
 
1466 1469
     /* read the first 1024 bytes to get packet size */
1467 1470
     pos = avio_tell(pb);
... ...
@@ -1883,4 +1902,5 @@ AVInputFormat ff_mpegtsraw_demuxer = {
1883 1883
 #ifdef USE_SYNCPOINT_SEARCH
1884 1884
     .read_seek2 = read_seek2,
1885 1885
 #endif
1886
+    .priv_class = &mpegtsraw_class,
1886 1887
 };
... ...
@@ -60,6 +60,7 @@ static const AVOption options[]={
60 60
 {"fdebug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, E|D, "fdebug"},
61 61
 {"ts", NULL, 0, FF_OPT_TYPE_CONST, {.dbl = FF_FDEBUG_TS }, INT_MIN, INT_MAX, E|D, "fdebug"},
62 62
 {"max_delay", "maximum muxing or demuxing delay in microseconds", OFFSET(max_delay), FF_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E|D},
63
+{"fpsprobesize", "number of frames used to probe fps", OFFSET(fps_probe_size), FF_OPT_TYPE_INT, -1, -1, INT_MAX-1, D},
63 64
 {NULL},
64 65
 };
65 66
 
... ...
@@ -50,7 +50,7 @@ static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
50 50
 AVInputFormat ff_pcm_ ## name ## _demuxer = {\
51 51
     #name,\
52 52
     NULL_IF_CONFIG_SMALL(long_name),\
53
-    0,\
53
+    sizeof(RawAudioDemuxerContext),\
54 54
     NULL,\
55 55
     ff_raw_read_header,\
56 56
     raw_read_packet,\
... ...
@@ -59,6 +59,7 @@ AVInputFormat ff_pcm_ ## name ## _demuxer = {\
59 59
     .flags= AVFMT_GENERIC_INDEX,\
60 60
     .extensions = ext,\
61 61
     .value = codec,\
62
+    .priv_class = &ff_rawaudio_demuxer_class,\
62 63
 };
63 64
 
64 65
 PCMDEF(f64be, "PCM 64 bit floating-point big-endian format",
... ...
@@ -23,6 +23,7 @@
23 23
 #include "avformat.h"
24 24
 #include "avio_internal.h"
25 25
 #include "rawdec.h"
26
+#include "libavutil/opt.h"
26 27
 
27 28
 /* raw input */
28 29
 int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
... ...
@@ -43,15 +44,28 @@ int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
43 43
         st->codec->codec_id = id;
44 44
 
45 45
         switch(st->codec->codec_type) {
46
-        case AVMEDIA_TYPE_AUDIO:
47
-            st->codec->sample_rate = ap->sample_rate;
48
-            if(ap->channels) st->codec->channels = ap->channels;
49
-            else             st->codec->channels = 1;
46
+        case AVMEDIA_TYPE_AUDIO: {
47
+            RawAudioDemuxerContext *s1 = s->priv_data;
48
+
49
+#if FF_API_FORMAT_PARAMETERS
50
+            if (ap->sample_rate)
51
+                st->codec->sample_rate = ap->sample_rate;
52
+            if (ap->channels)
53
+                st->codec->channels    = ap->channels;
54
+            else st->codec->channels   = 1;
55
+#endif
56
+
57
+            if (s1->sample_rate)
58
+                st->codec->sample_rate = s1->sample_rate;
59
+            if (s1->channels)
60
+                st->codec->channels    = s1->channels;
61
+
50 62
             st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
51 63
             assert(st->codec->bits_per_coded_sample > 0);
52 64
             st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;
53 65
             av_set_pts_info(st, 64, 1, st->codec->sample_rate);
54 66
             break;
67
+            }
55 68
         case AVMEDIA_TYPE_VIDEO:
56 69
             if(ap->time_base.num)
57 70
                 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
... ...
@@ -139,17 +153,31 @@ int ff_raw_video_read_header(AVFormatContext *s,
139 139
 
140 140
 /* Note: Do not forget to add new entries to the Makefile as well. */
141 141
 
142
+static const AVOption audio_options[] = {
143
+    { "sample_rate", "", offsetof(RawAudioDemuxerContext, sample_rate), FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
144
+    { "channels",    "", offsetof(RawAudioDemuxerContext, channels),    FF_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
145
+    { NULL },
146
+};
147
+
148
+const AVClass ff_rawaudio_demuxer_class = {
149
+    .class_name     = "rawaudio demuxer",
150
+    .item_name      = av_default_item_name,
151
+    .option         = audio_options,
152
+    .version        = LIBAVUTIL_VERSION_INT,
153
+};
154
+
142 155
 #if CONFIG_G722_DEMUXER
143 156
 AVInputFormat ff_g722_demuxer = {
144 157
     "g722",
145 158
     NULL_IF_CONFIG_SMALL("raw G.722"),
146
-    0,
159
+    sizeof(RawAudioDemuxerContext),
147 160
     NULL,
148 161
     ff_raw_read_header,
149 162
     ff_raw_read_partial_packet,
150 163
     .flags= AVFMT_GENERIC_INDEX,
151 164
     .extensions = "g722,722",
152 165
     .value = CODEC_ID_ADPCM_G722,
166
+    .priv_class = &ff_rawaudio_demuxer_class,
153 167
 };
154 168
 #endif
155 169
 
... ...
@@ -23,6 +23,15 @@
23 23
 #define AVFORMAT_RAWDEC_H
24 24
 
25 25
 #include "avformat.h"
26
+#include "libavutil/log.h"
27
+
28
+typedef struct RawAudioDemuxerContext {
29
+    AVClass *class;
30
+    int sample_rate;
31
+    int channels;
32
+} RawAudioDemuxerContext;
33
+
34
+extern const AVClass ff_rawaudio_demuxer_class;
26 35
 
27 36
 int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap);
28 37
 
... ...
@@ -233,9 +233,11 @@ int ff_rtmp_packet_write(URLContext *h, RTMPPacket *pkt,
233 233
 int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type,
234 234
                           int timestamp, int size)
235 235
 {
236
-    pkt->data = av_malloc(size);
237
-    if (!pkt->data)
238
-        return AVERROR(ENOMEM);
236
+    if (size) {
237
+        pkt->data = av_malloc(size);
238
+        if (!pkt->data)
239
+            return AVERROR(ENOMEM);
240
+    }
239 241
     pkt->data_size  = size;
240 242
     pkt->channel_id = channel_id;
241 243
     pkt->type       = type;
... ...
@@ -683,7 +683,7 @@ static int get_packet(URLContext *s, int for_header)
683 683
         return AVERROR_EOF;
684 684
 
685 685
     for (;;) {
686
-        RTMPPacket rpkt;
686
+        RTMPPacket rpkt = { 0 };
687 687
         if ((ret = ff_rtmp_packet_read(rt->stream, &rpkt,
688 688
                                        rt->chunk_size, rt->prev_pkt[0])) <= 0) {
689 689
             if (ret == 0) {
... ...
@@ -26,12 +26,13 @@
26 26
 
27 27
 #include "libavutil/intreadwrite.h"
28 28
 #include "libavutil/avstring.h"
29
+#include "libavutil/log.h"
30
+#include "libavutil/opt.h"
29 31
 #include "avformat.h"
30 32
 #include "sauce.h"
31 33
 
32
-#define LINE_RATE 6000 /* characters per second */
33
-
34 34
 typedef struct {
35
+    AVClass *class;
35 36
     int chars_per_frame;
36 37
     uint64_t fsize;  /**< file size less metadata buffer */
37 38
 } TtyDemuxContext;
... ...
@@ -86,7 +87,11 @@ static int read_header(AVFormatContext *avctx,
86 86
     }
87 87
 
88 88
     /* simulate tty display speed */
89
-    s->chars_per_frame = FFMAX(av_q2d(st->time_base) * (ap->sample_rate ? ap->sample_rate : LINE_RATE), 1);
89
+#if FF_API_FORMAT_PARAMETERS
90
+    if (ap->sample_rate)
91
+        s->chars_per_frame = ap->sample_rate;
92
+#endif
93
+    s->chars_per_frame = FFMAX(av_q2d(st->time_base)*s->chars_per_frame, 1);
90 94
 
91 95
     if (avctx->pb->seekable) {
92 96
         s->fsize = avio_size(avctx->pb);
... ...
@@ -124,6 +129,18 @@ static int read_packet(AVFormatContext *avctx, AVPacket *pkt)
124 124
     return 0;
125 125
 }
126 126
 
127
+static const AVOption options[] = {
128
+    { "chars_per_frame", "", offsetof(TtyDemuxContext, chars_per_frame), FF_OPT_TYPE_INT, {.dbl = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM},
129
+    { NULL },
130
+};
131
+
132
+static const AVClass tty_demuxer_class = {
133
+    .class_name     = "TTY demuxer",
134
+    .item_name      = av_default_item_name,
135
+    .option         = options,
136
+    .version        = LIBAVUTIL_VERSION_INT,
137
+};
138
+
127 139
 AVInputFormat ff_tty_demuxer = {
128 140
     .name           = "tty",
129 141
     .long_name      = NULL_IF_CONFIG_SMALL("Tele-typewriter"),
... ...
@@ -131,4 +148,5 @@ AVInputFormat ff_tty_demuxer = {
131 131
     .read_header    = read_header,
132 132
     .read_packet    = read_packet,
133 133
     .extensions     = "ans,art,asc,diz,ice,nfo,txt,vt",
134
+    .priv_class     = &tty_demuxer_class,
134 135
 };
... ...
@@ -2272,6 +2272,8 @@ int av_find_stream_info(AVFormatContext *ic)
2272 2272
                the correct fps */
2273 2273
             if (av_q2d(st->time_base) > 0.0005)
2274 2274
                 fps_analyze_framecount *= 2;
2275
+            if (ic->fps_probe_size >= 0)
2276
+                fps_analyze_framecount = ic->fps_probe_size;
2275 2277
             /* variable fps and no guess at the real fps */
2276 2278
             if(   tb_unreliable(st->codec) && !(st->r_frame_rate.num && st->avg_frame_rate.num)
2277 2279
                && st->info->duration_count < fps_analyze_framecount
... ...
@@ -71,5 +71,8 @@
71 71
 #ifndef FF_API_ALLOC_OUTPUT_CONTEXT
72 72
 #define FF_API_ALLOC_OUTPUT_CONTEXT    (LIBAVFORMAT_VERSION_MAJOR < 54)
73 73
 #endif
74
+#ifndef FF_API_FORMAT_PARAMETERS
75
+#define FF_API_FORMAT_PARAMETERS       (LIBAVFORMAT_VERSION_MAJOR < 54)
76
+#endif
74 77
 
75 78
 #endif /* AVFORMAT_VERSION_H */
... ...
@@ -290,7 +290,8 @@ double av_get_double(void *obj, const char *name, const AVOption **o_out)
290 290
     double num=1;
291 291
     int den=1;
292 292
 
293
-    av_get_number(obj, name, o_out, &num, &den, &intnum);
293
+    if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0)
294
+        return NAN;
294 295
     return num*intnum/den;
295 296
 }
296 297
 
... ...
@@ -300,7 +301,8 @@ AVRational av_get_q(void *obj, const char *name, const AVOption **o_out)
300 300
     double num=1;
301 301
     int den=1;
302 302
 
303
-    av_get_number(obj, name, o_out, &num, &den, &intnum);
303
+    if (av_get_number(obj, name, o_out, &num, &den, &intnum) < 0)
304
+        return (AVRational){0, 0};
304 305
     if (num == 1.0 && (int)intnum == intnum)
305 306
         return (AVRational){intnum, den};
306 307
     else
... ...
@@ -68,13 +68,6 @@ void shuffle_bytes_1230(const uint8_t *src, uint8_t *dst, long src_size);
68 68
 void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, long src_size);
69 69
 void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, long src_size);
70 70
 
71
-void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst,
72
-                   uint8_t *udst, uint8_t *vdst,
73
-                   long width, long height,
74
-                   long lumStride, long chromStride,
75
-                   long srcStride);
76
-
77
-
78 71
 #if LIBSWSCALE_VERSION_MAJOR < 1
79 72
 /* deprecated, use the public versions in swscale.h */
80 73
 attribute_deprecated void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
... ...
@@ -85,13 +78,10 @@ attribute_deprecated void palette8torgb16(const uint8_t *src, uint8_t *dst, long
85 85
 attribute_deprecated void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
86 86
 #endif
87 87
 
88
-/**
89
- * Height should be a multiple of 2 and width should be a multiple of 16.
90
- * (If this is a problem for anyone then tell me, and I will fix it.)
91
- * Chrominance data is only taken from every second line, others are ignored.
92
- * FIXME: Write high quality version.
93
- */
94
-//void uyvytoyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
88
+
89
+void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
90
+                   uint8_t *vdst, long width, long height, long lumStride,
91
+                   long chromStride, long srcStride);
95 92
 
96 93
 /**
97 94
  * Height should be a multiple of 2 and width should be a multiple of 16.
... ...
@@ -633,11 +633,9 @@ static inline void uyvytoyv12_c(const uint8_t *src, uint8_t *ydst,
633 633
  * others are ignored in the C version.
634 634
  * FIXME: Write HQ version.
635 635
  */
636
-void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst,
637
-                                 uint8_t *udst, uint8_t *vdst,
638
-                                 long width, long height,
639
-                                 long lumStride, long chromStride,
640
-                                 long srcStride)
636
+void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
637
+                   uint8_t *vdst, long width, long height, long lumStride,
638
+                   long chromStride, long srcStride)
641 639
 {
642 640
     long y;
643 641
     const int chromWidth = width >> 1;