Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master:
Add a tool that uses avio to read and write, doing a plain copy of data
ARM: fix build with FFT enabled and MDCT disabled
lavf: force single-threaded decoding in avformat_find_stream_info
avidec: migrate last of lavf from FF_ER_* to AV_EF_*
avserver: fix build after the next bump.

Conflicts:
libavformat/Makefile
libavformat/avidec.c
libavformat/utils.c

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

Michael Niedermayer authored on 2012/01/21 09:33:31
Showing 6 changed files
... ...
@@ -30,13 +30,16 @@
30 30
 #include <string.h>
31 31
 #include <stdlib.h>
32 32
 #include "libavformat/avformat.h"
33
+// FIXME those are internal headers, avserver _really_ shouldn't use them
33 34
 #include "libavformat/ffm.h"
34 35
 #include "libavformat/network.h"
35 36
 #include "libavformat/os_support.h"
36 37
 #include "libavformat/rtpdec.h"
37 38
 #include "libavformat/rtsp.h"
38
-// XXX for ffio_open_dyn_packet_buffer, to be removed
39 39
 #include "libavformat/avio_internal.h"
40
+#include "libavformat/internal.h"
41
+#include "libavformat/url.h"
42
+
40 43
 #include "libavutil/avstring.h"
41 44
 #include "libavutil/lfg.h"
42 45
 #include "libavutil/dict.h"
... ...
@@ -874,7 +877,7 @@ static void close_connection(HTTPContext *c)
874 874
         }
875 875
         h = c->rtp_handles[i];
876 876
         if (h)
877
-            url_close(h);
877
+            ffurl_close(h);
878 878
     }
879 879
 
880 880
     ctx = &c->fmt_ctx;
... ...
@@ -2255,7 +2258,6 @@ static int http_prepare_data(HTTPContext *c)
2255 2255
          * Default value from FFmpeg
2256 2256
          * Try to set it use configuration option
2257 2257
          */
2258
-        c->fmt_ctx.preload   = (int)(0.5*AV_TIME_BASE);
2259 2258
         c->fmt_ctx.max_delay = (int)(0.7*AV_TIME_BASE);
2260 2259
 
2261 2260
         if (avformat_write_header(&c->fmt_ctx, NULL) < 0) {
... ...
@@ -2374,7 +2376,7 @@ static int http_prepare_data(HTTPContext *c)
2374 2374
                         if (c->rtp_protocol == RTSP_LOWER_TRANSPORT_TCP)
2375 2375
                             max_packet_size = RTSP_TCP_MAX_PACKET_SIZE;
2376 2376
                         else
2377
-                            max_packet_size = url_get_max_packet_size(c->rtp_handles[c->packet_stream_index]);
2377
+                            max_packet_size = c->rtp_handles[c->packet_stream_index]->max_packet_size;
2378 2378
                         ret = ffio_open_dyn_packet_buf(&ctx->pb, max_packet_size);
2379 2379
                     } else {
2380 2380
                         ret = avio_open_dyn_buf(&ctx->pb);
... ...
@@ -2527,8 +2529,8 @@ static int http_send_data(HTTPContext *c)
2527 2527
                 } else {
2528 2528
                     /* send RTP packet directly in UDP */
2529 2529
                     c->buffer_ptr += 4;
2530
-                    url_write(c->rtp_handles[c->packet_stream_index],
2531
-                              c->buffer_ptr, len);
2530
+                    ffurl_write(c->rtp_handles[c->packet_stream_index],
2531
+                                c->buffer_ptr, len);
2532 2532
                     c->buffer_ptr += len;
2533 2533
                     /* here we continue as we can send several packets per 10 ms slot */
2534 2534
                 }
... ...
@@ -3411,10 +3413,10 @@ static int rtp_new_av_stream(HTTPContext *c,
3411 3411
                      "rtp://%s:%d", ipaddr, ntohs(dest_addr->sin_port));
3412 3412
         }
3413 3413
 
3414
-        if (url_open(&h, ctx->filename, AVIO_FLAG_WRITE) < 0)
3414
+        if (ffurl_open(&h, ctx->filename, AVIO_FLAG_WRITE, NULL, NULL) < 0)
3415 3415
             goto fail;
3416 3416
         c->rtp_handles[stream_index] = h;
3417
-        max_packet_size = url_get_max_packet_size(h);
3417
+        max_packet_size = h->max_packet_size;
3418 3418
         break;
3419 3419
     case RTSP_LOWER_TRANSPORT_TCP:
3420 3420
         /* RTP/TCP case */
... ...
@@ -3437,7 +3439,7 @@ static int rtp_new_av_stream(HTTPContext *c,
3437 3437
     if (avformat_write_header(ctx, NULL) < 0) {
3438 3438
     fail:
3439 3439
         if (h)
3440
-            url_close(h);
3440
+            ffurl_close(h);
3441 3441
         av_free(ctx);
3442 3442
         return -1;
3443 3443
     }
... ...
@@ -3474,7 +3476,7 @@ static AVStream *add_av_stream1(FFStream *stream, AVCodecContext *codec, int cop
3474 3474
     }
3475 3475
     fst->priv_data = av_mallocz(sizeof(FeedData));
3476 3476
     fst->index = stream->nb_streams;
3477
-    av_set_pts_info(fst, 33, 1, 90000);
3477
+    avpriv_set_pts_info(fst, 33, 1, 90000);
3478 3478
     fst->sample_aspect_ratio = codec->sample_aspect_ratio;
3479 3479
     stream->streams[stream->nb_streams++] = fst;
3480 3480
     return fst;
... ...
@@ -42,10 +42,12 @@ av_cold void ff_fft_init_arm(FFTContext *s)
42 42
     if (HAVE_NEON) {
43 43
         s->fft_permute  = ff_fft_permute_neon;
44 44
         s->fft_calc     = ff_fft_calc_neon;
45
+#if CONFIG_MDCT
45 46
         s->imdct_calc   = ff_imdct_calc_neon;
46 47
         s->imdct_half   = ff_imdct_half_neon;
47 48
         s->mdct_calc    = ff_mdct_calc_neon;
48 49
         s->mdct_permutation = FF_MDCT_PERM_INTERLEAVE;
50
+#endif
49 51
     }
50 52
 }
51 53
 
... ...
@@ -374,4 +374,4 @@ OBJS-$(CONFIG_UDP_PROTOCOL)              += udp.o
374 374
 
375 375
 SKIPHEADERS-$(CONFIG_NETWORK)            += network.h rtsp.h
376 376
 TESTPROGS = seek
377
-TOOLS     = pktdumper probetest
377
+TOOLS     = aviocat pktdumper probetest
... ...
@@ -724,8 +724,8 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
724 724
         case MKTAG('i', 'n', 'd', 'x'):
725 725
             i= avio_tell(pb);
726 726
             if(pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX) && avi->use_odml &&
727
-               read_braindead_odml_indx(s, 0) < 0 && s->error_recognition >= FF_ER_EXPLODE){
728
-                goto fail;            }
727
+               read_braindead_odml_indx(s, 0) < 0 && s->error_recognition >= FF_ER_EXPLODE)
728
+                goto fail;
729 729
             avio_seek(pb, i+size, SEEK_SET);
730 730
             break;
731 731
         case MKTAG('v', 'p', 'r', 'p'):
... ...
@@ -762,7 +762,8 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
762 762
             if(size > 1000000){
763 763
                 av_log(s, AV_LOG_ERROR, "Something went wrong during header parsing, "
764 764
                                         "I will ignore it and try to continue anyway.\n");
765
-                if (s->error_recognition >= FF_ER_EXPLODE) goto fail;
765
+                if (s->error_recognition & AV_EF_EXPLODE)
766
+                    goto fail;
766 767
                 avi->movi_list = avio_tell(pb) - 4;
767 768
                 avi->movi_end  = avi->fsize;
768 769
                 goto end_of_header;
... ...
@@ -2244,10 +2244,18 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **option
2244 2244
     AVPacket pkt = *avpkt;
2245 2245
 
2246 2246
     if(!st->codec->codec){
2247
+        AVDictionary *thread_opt = NULL;
2248
+
2247 2249
         codec = avcodec_find_decoder(st->codec->codec_id);
2248 2250
         if (!codec)
2249 2251
             return -1;
2250
-        ret = avcodec_open2(st->codec, codec, options);
2252
+
2253
+        /* force thread count to 1 since the h264 decoder will not extract SPS
2254
+         *  and PPS to extradata during multi-threaded decoding */
2255
+        av_dict_set(options ? options : &thread_opt, "threads", "1", 0);
2256
+        ret = avcodec_open2(st->codec, codec, options ? options : &thread_opt);
2257
+        if (!options)
2258
+            av_dict_free(&thread_opt);
2251 2259
         if (ret < 0)
2252 2260
             return ret;
2253 2261
     }
... ...
@@ -2384,15 +2392,13 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
2384 2384
     int i, count, ret, read_size, j;
2385 2385
     AVStream *st;
2386 2386
     AVPacket pkt1, *pkt;
2387
-    AVDictionary *one_thread_opt = NULL;
2388 2387
     int64_t old_offset = avio_tell(ic->pb);
2389 2388
     int orig_nb_streams = ic->nb_streams;        // new streams might appear, no options for those
2390 2389
     int flush_codecs = 1;
2391 2390
 
2392
-    av_dict_set(&one_thread_opt, "threads", "1", 0);
2393
-
2394 2391
     for(i=0;i<ic->nb_streams;i++) {
2395 2392
         AVCodec *codec;
2393
+        AVDictionary *thread_opt = NULL;
2396 2394
         st = ic->streams[i];
2397 2395
 
2398 2396
         if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO ||
... ...
@@ -2412,20 +2418,24 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
2412 2412
         assert(!st->codec->codec);
2413 2413
         codec = avcodec_find_decoder(st->codec->codec_id);
2414 2414
 
2415
-        if (options)
2416
-            av_dict_set(&options[i], "threads", "1", 0);
2415
+        /* force thread count to 1 since the h264 decoder will not extract SPS
2416
+         *  and PPS to extradata during multi-threaded decoding */
2417
+        av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0);
2417 2418
 
2418 2419
         /* Ensure that subtitle_header is properly set. */
2419 2420
         if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE
2420 2421
             && codec && !st->codec->codec)
2421
-            avcodec_open2(st->codec, codec, options ? &options[i] : &one_thread_opt);
2422
+            avcodec_open2(st->codec, codec, options ? &options[i]
2423
+                              : &thread_opt);
2422 2424
 
2423 2425
         //try to just open decoders, in case this is enough to get parameters
2424 2426
         if(!has_codec_parameters(st->codec)){
2425 2427
             if (codec && !st->codec->codec)
2426 2428
                 avcodec_open2(st->codec, codec, options ? &options[i]
2427
-                              : &one_thread_opt);
2429
+                              : &thread_opt);
2428 2430
         }
2431
+        if (!options)
2432
+            av_dict_free(&thread_opt);
2429 2433
     }
2430 2434
 
2431 2435
     for (i=0; i<ic->nb_streams; i++) {
... ...
@@ -2715,8 +2725,6 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
2715 2715
             ic->streams[i]->codec->thread_count = 0;
2716 2716
         av_freep(&ic->streams[i]->info);
2717 2717
     }
2718
-
2719
-    av_dict_free(&one_thread_opt);
2720 2718
     return ret;
2721 2719
 }
2722 2720
 
2723 2721
new file mode 100644
... ...
@@ -0,0 +1,97 @@
0
+/*
1
+ * Copyright (c) 2012 Martin Storsjo
2
+ *
3
+ * This file is part of Libav.
4
+ *
5
+ * Libav is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * Libav is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with Libav; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+#include <stdio.h>
21
+#include <string.h>
22
+#include <unistd.h>
23
+#include <sys/stat.h>
24
+#include "libavformat/avformat.h"
25
+#include "libavformat/riff.h"
26
+#include "libavutil/intreadwrite.h"
27
+#include "libavutil/mathematics.h"
28
+
29
+static int usage(const char *argv0, int ret)
30
+{
31
+    fprintf(stderr, "%s [-b bytespersec] input_url output_url\n", argv0);
32
+    return ret;
33
+}
34
+
35
+int main(int argc, char **argv)
36
+{
37
+    int bps = 0, ret, i;
38
+    const char *input_url = NULL, *output_url = NULL;
39
+    int64_t stream_pos = 0;
40
+    int64_t start_time;
41
+    char errbuf[50];
42
+    AVIOContext *input, *output;
43
+
44
+    av_register_all();
45
+    avformat_network_init();
46
+
47
+    for (i = 1; i < argc; i++) {
48
+        if (!strcmp(argv[i], "-b")) {
49
+            bps = atoi(argv[i + 1]);
50
+            i++;
51
+        } else if (!input_url) {
52
+            input_url = argv[i];
53
+        } else if (!output_url) {
54
+            output_url = argv[i];
55
+        } else {
56
+            return usage(argv[0], 1);
57
+        }
58
+    }
59
+    if (!output_url)
60
+        return usage(argv[0], 1);
61
+
62
+    ret = avio_open2(&input, input_url, AVIO_FLAG_READ, NULL, NULL);
63
+    if (ret) {
64
+        av_strerror(ret, errbuf, sizeof(errbuf));
65
+        fprintf(stderr, "Unable to open %s: %s\n", input_url, errbuf);
66
+        return 1;
67
+    }
68
+    ret = avio_open2(&output, output_url, AVIO_FLAG_WRITE, NULL, NULL);
69
+    if (ret) {
70
+        av_strerror(ret, errbuf, sizeof(errbuf));
71
+        fprintf(stderr, "Unable to open %s: %s\n", output_url, errbuf);
72
+        goto fail;
73
+    }
74
+
75
+    start_time = av_gettime();
76
+    while (1) {
77
+        uint8_t buf[1024];
78
+        int n;
79
+        n = avio_read(input, buf, sizeof(buf));
80
+        if (n <= 0)
81
+            break;
82
+        avio_write(output, buf, n);
83
+        stream_pos += n;
84
+        if (bps) {
85
+            avio_flush(output);
86
+            while ((av_gettime() - start_time)*bps/AV_TIME_BASE < stream_pos)
87
+                usleep(50*1000);
88
+        }
89
+    }
90
+
91
+    avio_close(output);
92
+fail:
93
+    avio_close(input);
94
+    avformat_network_deinit();
95
+    return ret ? 1 : 0;
96
+}