Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master: (29 commits)
doc: update libavfilter documentation
tls: Use the URLContext as logging context
aes: Avoid illegal read and don't generate more key than we use.
mpc7: Fix memset call in mpc7_decode_frame function
atrac1: use correct context for av_log()
apedec: consume the whole packet when copying to the decoder buffer.
apedec: do not needlessly copy s->samples to nblocks.
apedec: check output buffer size after calculating actual output size
apedec: remove unneeded entropy decoder normalization.
truespeech: use memmove() in truespeech_update_filters()
vorbisdec: remove AVCODEC_MAX_AUDIO_FRAME_SIZE check
vorbisdec: remove unneeded buf_size==0 check
vorbisdec: return proper error codes instead of made-up ones
http: Don't add a Range: bytes=0- header for POST
sunrast: Check for invalid/corrupted bitstream
http: Change the chunksize AVOption into chunked_post
http: Add encoding/decoding flags to the AVOptions
avconv: remove some codec-specific hacks
crypto: add decoding flag to options.
tls: use AVIO_FLAG_NONBLOCK instead of deprecated URL_FLAG_NONBLOCK
...

Conflicts:
doc/libavfilter.texi
libavcodec/atrac1.c
libavcodec/sunrast.c

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

Michael Niedermayer authored on 2011/11/11 10:32:38
Showing 18 changed files
... ...
@@ -2122,10 +2122,6 @@ static int transcode_init(OutputFile *output_files,
2122 2122
                 codec->frame_size = icodec->frame_size;
2123 2123
                 codec->audio_service_type = icodec->audio_service_type;
2124 2124
                 codec->block_align= icodec->block_align;
2125
-                if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3)
2126
-                    codec->block_align= 0;
2127
-                if(codec->codec_id == CODEC_ID_AC3)
2128
-                    codec->block_align= 0;
2129 2125
                 break;
2130 2126
             case AVMEDIA_TYPE_VIDEO:
2131 2127
                 codec->pix_fmt = icodec->pix_fmt;
... ...
@@ -36,11 +36,10 @@ and the vflip filter before merging it back with the other stream by
36 36
 overlaying it on top. You can use the following command to achieve this:
37 37
 
38 38
 @example
39
-./ffmpeg -i in.avi -s 240x320 -vf "[in] split [T1], fifo, [T2] overlay= 0:240 [out]; [T1] fifo, crop=0:0:-1:240, vflip [T2]
39
+./ffmpeg -i input -vf "[in] split [T1], fifo, [T2] overlay=0:H/2 [out]; [T1] fifo, crop=iw:ih/2:0:ih/2, vflip [T2]" output
40 40
 @end example
41 41
 
42
-where input_video.avi has a vertical resolution of 480 pixels. The
43
-result will be that in output the top half of the video is mirrored
42
+The result will be that in output the top half of the video is mirrored
44 43
 onto the bottom half.
45 44
 
46 45
 Video filters are loaded using the @var{-vf} option passed to
... ...
@@ -2165,10 +2165,6 @@ static int transcode_init(OutputFile *output_files, int nb_output_files,
2165 2165
                 codec->frame_size = icodec->frame_size;
2166 2166
                 codec->audio_service_type = icodec->audio_service_type;
2167 2167
                 codec->block_align= icodec->block_align;
2168
-                if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3)
2169
-                    codec->block_align= 0;
2170
-                if(codec->codec_id == CODEC_ID_AC3)
2171
-                    codec->block_align= 0;
2172 2168
                 break;
2173 2169
             case AVMEDIA_TYPE_VIDEO:
2174 2170
                 codec->pix_fmt = icodec->pix_fmt;
... ...
@@ -140,8 +140,6 @@ typedef struct APEContext {
140 140
 
141 141
     uint32_t CRC;                            ///< frame CRC
142 142
     int frameflags;                          ///< frame flags
143
-    int currentframeblocks;                  ///< samples (per channel) in current frame
144
-    int blocksdecoded;                       ///< count of decoded samples in current frame
145 143
     APEPredictor predictor;                  ///< predictor used for final reconstruction
146 144
 
147 145
     int32_t decoded0[BLOCKS_PER_LOOP];       ///< decoded data for the first channel
... ...
@@ -157,7 +155,6 @@ typedef struct APEContext {
157 157
     uint8_t *data;                           ///< current frame data
158 158
     uint8_t *data_end;                       ///< frame data end
159 159
     const uint8_t *ptr;                      ///< current position in frame data
160
-    const uint8_t *last_ptr;                 ///< position where last 4608-sample block ended
161 160
 
162 161
     int error;
163 162
 } APEContext;
... ...
@@ -457,8 +454,6 @@ static void entropy_decode(APEContext *ctx, int blockstodecode, int stereo)
457 457
     int32_t *decoded0 = ctx->decoded0;
458 458
     int32_t *decoded1 = ctx->decoded1;
459 459
 
460
-    ctx->blocksdecoded = blockstodecode;
461
-
462 460
     if (ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) {
463 461
         /* We are pure silence, just memset the output buffer. */
464 462
         memset(decoded0, 0, blockstodecode * sizeof(int32_t));
... ...
@@ -470,9 +465,6 @@ static void entropy_decode(APEContext *ctx, int blockstodecode, int stereo)
470 470
                 *decoded1++ = ape_decode_value(ctx, &ctx->riceX);
471 471
         }
472 472
     }
473
-
474
-    if (ctx->blocksdecoded == ctx->currentframeblocks)
475
-        range_dec_normalize(ctx);   /* normalize to use up all bytes */
476 473
 }
477 474
 
478 475
 static int init_entropy_decoder(APEContext *ctx)
... ...
@@ -492,9 +484,6 @@ static int init_entropy_decoder(APEContext *ctx)
492 492
         ctx->frameflags = bytestream_get_be32(&ctx->ptr);
493 493
     }
494 494
 
495
-    /* Keep a count of the blocks decoded in this frame */
496
-    ctx->blocksdecoded = 0;
497
-
498 495
     /* Initialize the rice structs */
499 496
     ctx->riceX.k = 10;
500 497
     ctx->riceX.ksum = (1 << ctx->riceX.k) * 16;
... ...
@@ -824,25 +813,22 @@ static int ape_decode_frame(AVCodecContext *avctx,
824 824
     int buf_size = avpkt->size;
825 825
     APEContext *s = avctx->priv_data;
826 826
     int16_t *samples = data;
827
-    uint32_t nblocks;
828 827
     int i;
829
-    int blockstodecode;
830
-    int bytes_used;
831
-
832
-    /* should not happen but who knows */
833
-    if (BLOCKS_PER_LOOP * 2 * avctx->channels > *data_size) {
834
-        av_log (avctx, AV_LOG_ERROR, "Output buffer is too small.\n");
835
-        return AVERROR(EINVAL);
836
-    }
828
+    int blockstodecode, out_size;
829
+    int bytes_used = 0;
837 830
 
838 831
     /* this should never be negative, but bad things will happen if it is, so
839 832
        check it just to make sure. */
840 833
     av_assert0(s->samples >= 0);
841 834
 
842 835
     if(!s->samples){
843
-        uint32_t offset;
836
+        uint32_t nblocks, offset;
844 837
         void *tmp_data;
845 838
 
839
+        if (!buf_size) {
840
+            *data_size = 0;
841
+            return 0;
842
+        }
846 843
         if (buf_size < 8) {
847 844
             av_log(avctx, AV_LOG_ERROR, "Packet is too small\n");
848 845
             return AVERROR_INVALIDDATA;
... ...
@@ -853,7 +839,7 @@ static int ape_decode_frame(AVCodecContext *avctx,
853 853
             return AVERROR(ENOMEM);
854 854
         s->data = tmp_data;
855 855
         s->dsp.bswap_buf((uint32_t*)s->data, (const uint32_t*)buf, buf_size >> 2);
856
-        s->ptr = s->last_ptr = s->data;
856
+        s->ptr = s->data;
857 857
         s->data_end = s->data + buf_size;
858 858
 
859 859
         nblocks = bytestream_get_be32(&s->ptr);
... ...
@@ -873,7 +859,7 @@ static int ape_decode_frame(AVCodecContext *avctx,
873 873
             av_log(avctx, AV_LOG_ERROR, "Invalid sample count: %u.\n", nblocks);
874 874
             return AVERROR_INVALIDDATA;
875 875
         }
876
-        s->currentframeblocks = s->samples = nblocks;
876
+        s->samples = nblocks;
877 877
 
878 878
         memset(s->decoded0,  0, sizeof(s->decoded0));
879 879
         memset(s->decoded1,  0, sizeof(s->decoded1));
... ...
@@ -883,6 +869,8 @@ static int ape_decode_frame(AVCodecContext *avctx,
883 883
             av_log(avctx, AV_LOG_ERROR, "Error reading frame header\n");
884 884
             return AVERROR_INVALIDDATA;
885 885
         }
886
+
887
+        bytes_used = buf_size;
886 888
     }
887 889
 
888 890
     if (!s->data) {
... ...
@@ -890,8 +878,14 @@ static int ape_decode_frame(AVCodecContext *avctx,
890 890
         return buf_size;
891 891
     }
892 892
 
893
-    nblocks = s->samples;
894
-    blockstodecode = FFMIN(BLOCKS_PER_LOOP, nblocks);
893
+    blockstodecode = FFMIN(BLOCKS_PER_LOOP, s->samples);
894
+
895
+    out_size = blockstodecode * avctx->channels *
896
+               av_get_bytes_per_sample(avctx->sample_fmt);
897
+    if (*data_size < out_size) {
898
+        av_log(avctx, AV_LOG_ERROR, "Output buffer is too small.\n");
899
+        return AVERROR(EINVAL);
900
+    }
895 901
 
896 902
     s->error=0;
897 903
 
... ...
@@ -915,9 +909,7 @@ static int ape_decode_frame(AVCodecContext *avctx,
915 915
 
916 916
     s->samples -= blockstodecode;
917 917
 
918
-    *data_size = blockstodecode * 2 * s->channels;
919
-    bytes_used = s->samples ? s->ptr - s->last_ptr : buf_size;
920
-    s->last_ptr = s->ptr;
918
+    *data_size = out_size;
921 919
     return bytes_used;
922 920
 }
923 921
 
... ...
@@ -935,7 +927,7 @@ AVCodec ff_ape_decoder = {
935 935
     .init           = ape_decode_init,
936 936
     .close          = ape_decode_close,
937 937
     .decode         = ape_decode_frame,
938
-    .capabilities = CODEC_CAP_SUBFRAMES,
938
+    .capabilities   = CODEC_CAP_SUBFRAMES | CODEC_CAP_DELAY,
939 939
     .flush = ape_flush,
940 940
     .long_name = NULL_IF_CONFIG_SMALL("Monkey's Audio"),
941 941
 };
... ...
@@ -284,7 +284,7 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
284 284
 
285 285
 
286 286
     if (buf_size < 212 * q->channels) {
287
-        av_log(avctx,AV_LOG_ERROR,"Not enough data to decode!\n");
287
+        av_log(avctx, AV_LOG_ERROR, "Not enough data to decode!\n");
288 288
         return AVERROR_INVALIDDATA;
289 289
     }
290 290
 
... ...
@@ -200,7 +200,7 @@ static int mpc7_decode_frame(AVCodecContext * avctx,
200 200
     int off, out_size;
201 201
     int bits_used, bits_avail;
202 202
 
203
-    memset(bands, 0, sizeof(bands));
203
+    memset(bands, 0, sizeof(*bands) * (c->maxbands + 1));
204 204
     if(buf_size <= 4){
205 205
         av_log(avctx, AV_LOG_ERROR, "Too small buffer passed (%i bytes)\n", buf_size);
206 206
         return AVERROR(EINVAL);
... ...
@@ -68,7 +68,7 @@ static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
68 68
     type      = AV_RB32(buf+20);
69 69
     maptype   = AV_RB32(buf+24);
70 70
     maplength = AV_RB32(buf+28);
71
-    buf += 32;
71
+    buf      += 32;
72 72
 
73 73
     if (type < RT_OLD || type > RT_FORMAT_IFF) {
74 74
         av_log(avctx, AV_LOG_ERROR, "invalid (compression) type\n");
... ...
@@ -233,8 +233,7 @@ static void truespeech_update_filters(TSContext *dec, int16_t *out, int quart)
233 233
 {
234 234
     int i;
235 235
 
236
-    for(i = 0; i < 86; i++)
237
-        dec->filtbuf[i] = dec->filtbuf[i + 60];
236
+    memmove(dec->filtbuf, &dec->filtbuf[60], 86 * sizeof(*dec->filtbuf));
238 237
     for(i = 0; i < 60; i++){
239 238
         dec->filtbuf[i + 86] = out[i] + dec->newvec[i] - (dec->newvec[i] >> 3);
240 239
         out[i] += dec->newvec[i];
... ...
@@ -168,7 +168,7 @@ static const char idx_err_str[] = "Index value %d out of range (0 - %d) for %s a
168 168
         av_log(vc->avccontext, AV_LOG_ERROR,\
169 169
                idx_err_str,\
170 170
                (int)(idx), (int)(limit - 1), #idx, __FILE__, __LINE__);\
171
-        return -1;\
171
+        return AVERROR_INVALIDDATA;\
172 172
     }
173 173
 #define GET_VALIDATED_INDEX(idx, bits, limit) \
174 174
     {\
... ...
@@ -241,6 +241,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
241 241
     uint32_t *tmp_vlc_codes;
242 242
     GetBitContext *gb = &vc->gb;
243 243
     uint16_t *codebook_multiplicands;
244
+    int ret = 0;
244 245
 
245 246
     vc->codebook_count = get_bits(gb, 8) + 1;
246 247
 
... ...
@@ -260,6 +261,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
260 260
         if (get_bits(gb, 24) != 0x564342) {
261 261
             av_log(vc->avccontext, AV_LOG_ERROR,
262 262
                    " %u. Codebook setup data corrupt.\n", cb);
263
+            ret = AVERROR_INVALIDDATA;
263 264
             goto error;
264 265
         }
265 266
 
... ...
@@ -268,6 +270,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
268 268
             av_log(vc->avccontext, AV_LOG_ERROR,
269 269
                    " %u. Codebook's dimension is invalid (%d).\n",
270 270
                    cb, codebook_setup->dimensions);
271
+            ret = AVERROR_INVALIDDATA;
271 272
             goto error;
272 273
         }
273 274
         entries = get_bits(gb, 24);
... ...
@@ -275,6 +278,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
275 275
             av_log(vc->avccontext, AV_LOG_ERROR,
276 276
                    " %u. Codebook has too many entries (%u).\n",
277 277
                    cb, entries);
278
+            ret = AVERROR_INVALIDDATA;
278 279
             goto error;
279 280
         }
280 281
 
... ...
@@ -332,6 +336,7 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
332 332
             }
333 333
             if (current_entry>used_entries) {
334 334
                 av_log(vc->avccontext, AV_LOG_ERROR, " More codelengths than codes in codebook. \n");
335
+                ret = AVERROR_INVALIDDATA;
335 336
                 goto error;
336 337
             }
337 338
         }
... ...
@@ -399,17 +404,20 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
399 399
             }
400 400
             if (j != used_entries) {
401 401
                 av_log(vc->avccontext, AV_LOG_ERROR, "Bug in codevector vector building code. \n");
402
+                ret = AVERROR_INVALIDDATA;
402 403
                 goto error;
403 404
             }
404 405
             entries = used_entries;
405 406
         } else if (codebook_setup->lookup_type >= 2) {
406 407
             av_log(vc->avccontext, AV_LOG_ERROR, "Codebook lookup type not supported. \n");
408
+            ret = AVERROR_INVALIDDATA;
407 409
             goto error;
408 410
         }
409 411
 
410 412
 // Initialize VLC table
411 413
         if (ff_vorbis_len2vlc(tmp_vlc_bits, tmp_vlc_codes, entries)) {
412 414
             av_log(vc->avccontext, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n");
415
+            ret = AVERROR_INVALIDDATA;
413 416
             goto error;
414 417
         }
415 418
         codebook_setup->maxdepth = 0;
... ...
@@ -424,7 +432,11 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
424 424
 
425 425
         codebook_setup->maxdepth = (codebook_setup->maxdepth+codebook_setup->nb_bits - 1) / codebook_setup->nb_bits;
426 426
 
427
-        if (init_vlc(&codebook_setup->vlc, codebook_setup->nb_bits, entries, tmp_vlc_bits, sizeof(*tmp_vlc_bits), sizeof(*tmp_vlc_bits), tmp_vlc_codes, sizeof(*tmp_vlc_codes), sizeof(*tmp_vlc_codes), INIT_VLC_LE)) {
427
+        if ((ret = init_vlc(&codebook_setup->vlc, codebook_setup->nb_bits,
428
+                            entries, tmp_vlc_bits, sizeof(*tmp_vlc_bits),
429
+                            sizeof(*tmp_vlc_bits), tmp_vlc_codes,
430
+                            sizeof(*tmp_vlc_codes), sizeof(*tmp_vlc_codes),
431
+                            INIT_VLC_LE))) {
428 432
             av_log(vc->avccontext, AV_LOG_ERROR, " Error generating vlc tables. \n");
429 433
             goto error;
430 434
         }
... ...
@@ -440,7 +452,7 @@ error:
440 440
     av_free(tmp_vlc_bits);
441 441
     av_free(tmp_vlc_codes);
442 442
     av_free(codebook_multiplicands);
443
-    return -1;
443
+    return ret;
444 444
 }
445 445
 
446 446
 // Process time domain transforms part (unused in Vorbis I)
... ...
@@ -458,7 +470,7 @@ static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc)
458 458
 
459 459
         if (vorbis_tdtransform) {
460 460
             av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis time domain transform data nonzero. \n");
461
-            return -1;
461
+            return AVERROR_INVALIDDATA;
462 462
         }
463 463
     }
464 464
     return 0;
... ...
@@ -550,7 +562,7 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
550 550
                 av_log(vc->avccontext, AV_LOG_ERROR,
551 551
                        "Floor value is too large for blocksize: %u (%"PRIu32")\n",
552 552
                        rangemax, vc->blocksize[1] / 2);
553
-                return -1;
553
+                return AVERROR_INVALIDDATA;
554 554
             }
555 555
             floor_setup->data.t1.list[0].x = 0;
556 556
             floor_setup->data.t1.list[1].x = rangemax;
... ...
@@ -580,7 +592,7 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
580 580
             if (floor_setup->data.t0.amplitude_bits == 0) {
581 581
                 av_log(vc->avccontext, AV_LOG_ERROR,
582 582
                        "Floor 0 amplitude bits is 0.\n");
583
-                return -1;
583
+                return AVERROR_INVALIDDATA;
584 584
             }
585 585
             floor_setup->data.t0.amplitude_offset = get_bits(gb, 8);
586 586
             floor_setup->data.t0.num_books        = get_bits(gb, 4) + 1;
... ...
@@ -589,7 +601,7 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
589 589
             floor_setup->data.t0.book_list =
590 590
                 av_malloc(floor_setup->data.t0.num_books);
591 591
             if (!floor_setup->data.t0.book_list)
592
-                return -1;
592
+                return AVERROR(ENOMEM);
593 593
             /* read book indexes */
594 594
             {
595 595
                 int idx;
... ...
@@ -610,7 +622,7 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
610 610
                 av_malloc((floor_setup->data.t0.order + 1 + max_codebook_dim)
611 611
                           * sizeof(*floor_setup->data.t0.lsp));
612 612
             if (!floor_setup->data.t0.lsp)
613
-                return -1;
613
+                return AVERROR(ENOMEM);
614 614
 
615 615
             /* debug output parsed headers */
616 616
             av_dlog(NULL, "floor0 order: %u\n", floor_setup->data.t0.order);
... ...
@@ -634,7 +646,7 @@ static int vorbis_parse_setup_hdr_floors(vorbis_context *vc)
634 634
             }
635 635
         } else {
636 636
             av_log(vc->avccontext, AV_LOG_ERROR, "Invalid floor type!\n");
637
-            return -1;
637
+            return AVERROR_INVALIDDATA;
638 638
         }
639 639
     }
640 640
     return 0;
... ...
@@ -672,7 +684,7 @@ static int vorbis_parse_setup_hdr_residues(vorbis_context *vc)
672 672
                    "partition out of bounds: type, begin, end, size, blocksize: %"PRIu16", %"PRIu32", %"PRIu32", %u, %"PRIu32"\n",
673 673
                    res_setup->type, res_setup->begin, res_setup->end,
674 674
                    res_setup->partition_size, vc->blocksize[1] / 2);
675
-            return -1;
675
+            return AVERROR_INVALIDDATA;
676 676
         }
677 677
 
678 678
         res_setup->classifications = get_bits(gb, 6) + 1;
... ...
@@ -737,7 +749,7 @@ static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc)
737 737
 
738 738
         if (get_bits(gb, 16)) {
739 739
             av_log(vc->avccontext, AV_LOG_ERROR, "Other mappings than type 0 are not compliant with the Vorbis I specification. \n");
740
-            return -1;
740
+            return AVERROR_INVALIDDATA;
741 741
         }
742 742
         if (get_bits1(gb)) {
743 743
             mapping_setup->submaps = get_bits(gb, 4) + 1;
... ...
@@ -764,7 +776,7 @@ static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc)
764 764
 
765 765
         if (get_bits(gb, 2)) {
766 766
             av_log(vc->avccontext, AV_LOG_ERROR, "%u. mapping setup data invalid.\n", i);
767
-            return -1; // following spec.
767
+            return AVERROR_INVALIDDATA; // following spec.
768 768
         }
769 769
 
770 770
         if (mapping_setup->submaps>1) {
... ...
@@ -851,41 +863,42 @@ static int vorbis_parse_setup_hdr_modes(vorbis_context *vc)
851 851
 static int vorbis_parse_setup_hdr(vorbis_context *vc)
852 852
 {
853 853
     GetBitContext *gb = &vc->gb;
854
+    int ret;
854 855
 
855 856
     if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') ||
856 857
         (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') ||
857 858
         (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) {
858 859
         av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n");
859
-        return -1;
860
+        return AVERROR_INVALIDDATA;
860 861
     }
861 862
 
862
-    if (vorbis_parse_setup_hdr_codebooks(vc)) {
863
+    if ((ret = vorbis_parse_setup_hdr_codebooks(vc))) {
863 864
         av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (codebooks). \n");
864
-        return -2;
865
+        return ret;
865 866
     }
866
-    if (vorbis_parse_setup_hdr_tdtransforms(vc)) {
867
+    if ((ret = vorbis_parse_setup_hdr_tdtransforms(vc))) {
867 868
         av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (time domain transforms). \n");
868
-        return -3;
869
+        return ret;
869 870
     }
870
-    if (vorbis_parse_setup_hdr_floors(vc)) {
871
+    if ((ret = vorbis_parse_setup_hdr_floors(vc))) {
871 872
         av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (floors). \n");
872
-        return -4;
873
+        return ret;
873 874
     }
874
-    if (vorbis_parse_setup_hdr_residues(vc)) {
875
+    if ((ret = vorbis_parse_setup_hdr_residues(vc))) {
875 876
         av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (residues). \n");
876
-        return -5;
877
+        return ret;
877 878
     }
878
-    if (vorbis_parse_setup_hdr_mappings(vc)) {
879
+    if ((ret = vorbis_parse_setup_hdr_mappings(vc))) {
879 880
         av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (mappings). \n");
880
-        return -6;
881
+        return ret;
881 882
     }
882
-    if (vorbis_parse_setup_hdr_modes(vc)) {
883
+    if ((ret = vorbis_parse_setup_hdr_modes(vc))) {
883 884
         av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (modes). \n");
884
-        return -7;
885
+        return ret;
885 886
     }
886 887
     if (!get_bits1(gb)) {
887 888
         av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (framing flag). \n");
888
-        return -8; // framing flag bit unset error
889
+        return AVERROR_INVALIDDATA; // framing flag bit unset error
889 890
     }
890 891
 
891 892
     return 0;
... ...
@@ -902,19 +915,19 @@ static int vorbis_parse_id_hdr(vorbis_context *vc)
902 902
         (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') ||
903 903
         (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) {
904 904
         av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n");
905
-        return -1;
905
+        return AVERROR_INVALIDDATA;
906 906
     }
907 907
 
908 908
     vc->version        = get_bits_long(gb, 32);    //FIXME check 0
909 909
     vc->audio_channels = get_bits(gb, 8);
910 910
     if (vc->audio_channels <= 0) {
911 911
         av_log(vc->avccontext, AV_LOG_ERROR, "Invalid number of channels\n");
912
-        return -1;
912
+        return AVERROR_INVALIDDATA;
913 913
     }
914 914
     vc->audio_samplerate = get_bits_long(gb, 32);
915 915
     if (vc->audio_samplerate <= 0) {
916 916
         av_log(vc->avccontext, AV_LOG_ERROR, "Invalid samplerate\n");
917
-        return -1;
917
+        return AVERROR_INVALIDDATA;
918 918
     }
919 919
     vc->bitrate_maximum = get_bits_long(gb, 32);
920 920
     vc->bitrate_nominal = get_bits_long(gb, 32);
... ...
@@ -925,20 +938,14 @@ static int vorbis_parse_id_hdr(vorbis_context *vc)
925 925
     vc->blocksize[1] = (1 << bl1);
926 926
     if (bl0 > 13 || bl0 < 6 || bl1 > 13 || bl1 < 6 || bl1 < bl0) {
927 927
         av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n");
928
-        return -3;
929
-    }
930
-    // output format int16
931
-    if (vc->blocksize[1] / 2 * vc->audio_channels * 2 > AVCODEC_MAX_AUDIO_FRAME_SIZE) {
932
-        av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis channel count makes "
933
-               "output packets too large.\n");
934
-        return -4;
928
+        return AVERROR_INVALIDDATA;
935 929
     }
936 930
     vc->win[0] = ff_vorbis_vwin[bl0 - 6];
937 931
     vc->win[1] = ff_vorbis_vwin[bl1 - 6];
938 932
 
939 933
     if ((get_bits1(gb)) == 0) {
940 934
         av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n");
941
-        return -2;
935
+        return AVERROR_INVALIDDATA;
942 936
     }
943 937
 
944 938
     vc->channel_residues =  av_malloc((vc->blocksize[1]  / 2) * vc->audio_channels * sizeof(*vc->channel_residues));
... ...
@@ -972,7 +979,7 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext)
972 972
     uint8_t *header_start[3];
973 973
     int header_len[3];
974 974
     GetBitContext *gb = &(vc->gb);
975
-    int hdr_type;
975
+    int hdr_type, ret;
976 976
 
977 977
     vc->avccontext = avccontext;
978 978
     dsputil_init(&vc->dsp, avccontext);
... ...
@@ -988,24 +995,24 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext)
988 988
 
989 989
     if (!headers_len) {
990 990
         av_log(avccontext, AV_LOG_ERROR, "Extradata missing.\n");
991
-        return -1;
991
+        return AVERROR_INVALIDDATA;
992 992
     }
993 993
 
994
-    if (avpriv_split_xiph_headers(headers, headers_len, 30, header_start, header_len) < 0) {
994
+    if ((ret = avpriv_split_xiph_headers(headers, headers_len, 30, header_start, header_len)) < 0) {
995 995
         av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n");
996
-        return -1;
996
+        return ret;
997 997
     }
998 998
 
999 999
     init_get_bits(gb, header_start[0], header_len[0]*8);
1000 1000
     hdr_type = get_bits(gb, 8);
1001 1001
     if (hdr_type != 1) {
1002 1002
         av_log(avccontext, AV_LOG_ERROR, "First header is not the id header.\n");
1003
-        return -1;
1003
+        return AVERROR_INVALIDDATA;
1004 1004
     }
1005
-    if (vorbis_parse_id_hdr(vc)) {
1005
+    if ((ret = vorbis_parse_id_hdr(vc))) {
1006 1006
         av_log(avccontext, AV_LOG_ERROR, "Id header corrupt.\n");
1007 1007
         vorbis_free(vc);
1008
-        return -1;
1008
+        return ret;
1009 1009
     }
1010 1010
 
1011 1011
     init_get_bits(gb, header_start[2], header_len[2]*8);
... ...
@@ -1013,12 +1020,12 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext)
1013 1013
     if (hdr_type != 5) {
1014 1014
         av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n");
1015 1015
         vorbis_free(vc);
1016
-        return -1;
1016
+        return AVERROR_INVALIDDATA;
1017 1017
     }
1018
-    if (vorbis_parse_setup_hdr(vc)) {
1018
+    if ((ret = vorbis_parse_setup_hdr(vc))) {
1019 1019
         av_log(avccontext, AV_LOG_ERROR, "Setup header corrupt.\n");
1020 1020
         vorbis_free(vc);
1021
-        return -1;
1021
+        return ret;
1022 1022
     }
1023 1023
 
1024 1024
     if (vc->audio_channels > 8)
... ...
@@ -1061,7 +1068,7 @@ static int vorbis_floor0_decode(vorbis_context *vc,
1061 1061
         codebook = vc->codebooks[vf->book_list[book_idx]];
1062 1062
         /* Invalid codebook! */
1063 1063
         if (!codebook.codevectors)
1064
-            return -1;
1064
+            return AVERROR_INVALIDDATA;
1065 1065
 
1066 1066
         while (lsp_len<vf->order) {
1067 1067
             int vec_off;
... ...
@@ -1427,7 +1434,7 @@ static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr,
1427 1427
         return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, 0);
1428 1428
     else {
1429 1429
         av_log(vc->avccontext, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n");
1430
-        return -1;
1430
+        return AVERROR_INVALIDDATA;
1431 1431
     }
1432 1432
 }
1433 1433
 
... ...
@@ -1475,7 +1482,7 @@ static int vorbis_parse_audio_packet(vorbis_context *vc)
1475 1475
 
1476 1476
     if (get_bits1(gb)) {
1477 1477
         av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n");
1478
-        return -1; // packet type not audio
1478
+        return AVERROR_INVALIDDATA; // packet type not audio
1479 1479
     }
1480 1480
 
1481 1481
     if (vc->mode_count == 1) {
... ...
@@ -1512,7 +1519,7 @@ static int vorbis_parse_audio_packet(vorbis_context *vc)
1512 1512
 
1513 1513
         if (ret < 0) {
1514 1514
             av_log(vc->avccontext, AV_LOG_ERROR, "Invalid codebook in vorbis_floor_decode.\n");
1515
-            return -1;
1515
+            return AVERROR_INVALIDDATA;
1516 1516
         }
1517 1517
         no_residue[i] = ret;
1518 1518
         ch_floor_ptr += blocksize / 2;
... ...
@@ -1613,19 +1620,12 @@ static int vorbis_decode_frame(AVCodecContext *avccontext,
1613 1613
     const float *channel_ptrs[255];
1614 1614
     int i, len, out_size;
1615 1615
 
1616
-    if (!buf_size)
1617
-        return 0;
1618
-
1619 1616
     av_dlog(NULL, "packet length %d \n", buf_size);
1620 1617
 
1621 1618
     init_get_bits(gb, buf, buf_size*8);
1622 1619
 
1623
-    len = vorbis_parse_audio_packet(vc);
1624
-
1625
-    if (len <= 0) {
1626
-        *data_size = 0;
1627
-        return buf_size;
1628
-    }
1620
+    if ((len = vorbis_parse_audio_packet(vc)) <= 0)
1621
+        return len;
1629 1622
 
1630 1623
     if (!vc->first_frame) {
1631 1624
         vc->first_frame = 1;
... ...
@@ -75,8 +75,11 @@ int ff_avc_parse_nal_units(AVIOContext *pb, const uint8_t *buf_in, int size)
75 75
 
76 76
     size = 0;
77 77
     nal_start = ff_avc_find_startcode(p, end);
78
-    while (nal_start < end) {
79
-        while(!*(nal_start++));
78
+    for (;;) {
79
+        while (nal_start < end && !*(nal_start++));
80
+        if (nal_start == end)
81
+            break;
82
+
80 83
         nal_end = ff_avc_find_startcode(nal_start, end);
81 84
         avio_wb32(pb, nal_end - nal_start);
82 85
         avio_write(pb, nal_start, nal_end - nal_start);
... ...
@@ -117,22 +120,26 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
117 117
             end = buf + len;
118 118
 
119 119
             /* look for sps and pps */
120
-            while (buf < end) {
121
-                unsigned int size;
120
+            while (end - buf > 4) {
121
+                uint32_t size;
122 122
                 uint8_t nal_type;
123
-                size = AV_RB32(buf);
124
-                nal_type = buf[4] & 0x1f;
123
+                size = FFMIN(AV_RB32(buf), end - buf - 4);
124
+                buf += 4;
125
+                nal_type = buf[0] & 0x1f;
126
+
125 127
                 if (nal_type == 7) { /* SPS */
126
-                    sps = buf + 4;
128
+                    sps = buf;
127 129
                     sps_size = size;
128 130
                 } else if (nal_type == 8) { /* PPS */
129
-                    pps = buf + 4;
131
+                    pps = buf;
130 132
                     pps_size = size;
131 133
                 }
132
-                buf += size + 4;
134
+
135
+                buf += size;
133 136
             }
134
-            assert(sps);
135
-            assert(pps);
137
+
138
+            if (!sps || !pps || sps_size < 4 || sps_size > UINT16_MAX || pps_size > UINT16_MAX)
139
+                return AVERROR_INVALIDDATA;
136 140
 
137 141
             avio_w8(pb, 1); /* version */
138 142
             avio_w8(pb, sps[1]); /* profile */
... ...
@@ -338,8 +338,11 @@ int ffurl_close(URLContext *h)
338 338
 #if CONFIG_NETWORK
339 339
     ff_network_close();
340 340
 #endif
341
-    if (h->prot->priv_data_size)
341
+    if (h->prot->priv_data_size) {
342
+        if (h->prot->priv_data_class)
343
+            av_opt_free(h->priv_data);
342 344
         av_free(h->priv_data);
345
+    }
343 346
     av_free(h);
344 347
     return ret;
345 348
 }
... ...
@@ -45,9 +45,10 @@ typedef struct {
45 45
 } CryptoContext;
46 46
 
47 47
 #define OFFSET(x) offsetof(CryptoContext, x)
48
+#define D AV_OPT_FLAG_DECODING_PARAM
48 49
 static const AVOption options[] = {
49
-    {"key", "AES decryption key", OFFSET(key), AV_OPT_TYPE_BINARY },
50
-    {"iv",  "AES decryption initialization vector", OFFSET(iv),  AV_OPT_TYPE_BINARY },
50
+    {"key", "AES decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, .flags = D },
51
+    {"iv",  "AES decryption initialization vector", OFFSET(iv),  AV_OPT_TYPE_BINARY, .flags = D },
51 52
     { NULL }
52 53
 };
53 54
 
... ...
@@ -61,7 +62,7 @@ static const AVClass crypto_class = {
61 61
 static int crypto_open(URLContext *h, const char *uri, int flags)
62 62
 {
63 63
     const char *nested_url;
64
-    int ret;
64
+    int ret = 0;
65 65
     CryptoContext *c = h->priv_data;
66 66
 
67 67
     if (!av_strstart(uri, "crypto+", &nested_url) &&
... ...
@@ -95,10 +96,7 @@ static int crypto_open(URLContext *h, const char *uri, int flags)
95 95
 
96 96
     h->is_streamed = 1;
97 97
 
98
-    return 0;
99 98
 err:
100
-    av_freep(&c->key);
101
-    av_freep(&c->iv);
102 99
     return ret;
103 100
 }
104 101
 
... ...
@@ -157,8 +155,6 @@ static int crypto_close(URLContext *h)
157 157
     if (c->hd)
158 158
         ffurl_close(c->hd);
159 159
     av_freep(&c->aes);
160
-    av_freep(&c->key);
161
-    av_freep(&c->iv);
162 160
     return 0;
163 161
 }
164 162
 
... ...
@@ -47,36 +47,33 @@ typedef struct {
47 47
     int64_t off, filesize;
48 48
     char location[MAX_URL_SIZE];
49 49
     HTTPAuthState auth_state;
50
-    unsigned char headers[BUFFER_SIZE];
50
+    char *headers;
51 51
     int willclose;          /**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */
52
+    int chunked_post;
52 53
 } HTTPContext;
53 54
 
54 55
 #define OFFSET(x) offsetof(HTTPContext, x)
56
+#define D AV_OPT_FLAG_DECODING_PARAM
57
+#define E AV_OPT_FLAG_ENCODING_PARAM
55 58
 static const AVOption options[] = {
56
-{"chunksize", "use chunked transfer-encoding for posts, -1 disables it, 0 enables it", OFFSET(chunksize), AV_OPT_TYPE_INT64, {.dbl = 0}, -1, 0 }, /* Default to 0, for chunked POSTs */
59
+{"chunked_post", "use chunked transfer-encoding for posts", OFFSET(chunked_post), AV_OPT_TYPE_INT, {.dbl = 1}, 0, 1, E },
60
+{"headers", "custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E },
57 61
 {NULL}
58 62
 };
59
-static const AVClass httpcontext_class = {
60
-    .class_name     = "HTTP",
61
-    .item_name      = av_default_item_name,
62
-    .option         = options,
63
-    .version        = LIBAVUTIL_VERSION_INT,
63
+#define HTTP_CLASS(flavor)\
64
+static const AVClass flavor ## _context_class = {\
65
+    .class_name     = #flavor,\
66
+    .item_name      = av_default_item_name,\
67
+    .option         = options,\
68
+    .version        = LIBAVUTIL_VERSION_INT,\
64 69
 };
65 70
 
71
+HTTP_CLASS(http);
72
+HTTP_CLASS(https);
73
+
66 74
 static int http_connect(URLContext *h, const char *path, const char *hoststr,
67 75
                         const char *auth, int *new_location);
68 76
 
69
-void ff_http_set_headers(URLContext *h, const char *headers)
70
-{
71
-    HTTPContext *s = h->priv_data;
72
-    int len = strlen(headers);
73
-
74
-    if (len && strcmp("\r\n", headers + len - 2))
75
-        av_log(h, AV_LOG_ERROR, "No trailing CRLF found in HTTP header.\n");
76
-
77
-    av_strlcpy(s->headers, headers, sizeof(s->headers));
78
-}
79
-
80 77
 void ff_http_init_auth_state(URLContext *dest, const URLContext *src)
81 78
 {
82 79
     memcpy(&((HTTPContext*)dest->priv_data)->auth_state,
... ...
@@ -168,6 +165,12 @@ static int http_open(URLContext *h, const char *uri, int flags)
168 168
     s->filesize = -1;
169 169
     av_strlcpy(s->location, uri, sizeof(s->location));
170 170
 
171
+    if (s->headers) {
172
+        int len = strlen(s->headers);
173
+        if (len < 2 || strcmp("\r\n", s->headers + len - 2))
174
+            av_log(h, AV_LOG_WARNING, "No trailing CRLF found in HTTP header.\n");
175
+    }
176
+
171 177
     return http_open_cnx(h);
172 178
 }
173 179
 static int http_getc(HTTPContext *s)
... ...
@@ -285,6 +288,8 @@ static int process_line(URLContext *h, char *line, int line_count,
285 285
 static inline int has_header(const char *str, const char *header)
286 286
 {
287 287
     /* header + 2 to skip over CRLF prefix. (make sure you have one!) */
288
+    if (!str)
289
+        return 0;
288 290
     return av_stristart(str, header + 2, NULL) || av_stristr(str, header);
289 291
 }
290 292
 
... ...
@@ -312,7 +317,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
312 312
     if (!has_header(s->headers, "\r\nAccept: "))
313 313
         len += av_strlcpy(headers + len, "Accept: */*\r\n",
314 314
                           sizeof(headers) - len);
315
-    if (!has_header(s->headers, "\r\nRange: "))
315
+    if (!has_header(s->headers, "\r\nRange: ") && !post)
316 316
         len += av_strlcatf(headers + len, sizeof(headers) - len,
317 317
                            "Range: bytes=%"PRId64"-\r\n", s->off);
318 318
     if (!has_header(s->headers, "\r\nConnection: "))
... ...
@@ -323,7 +328,8 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
323 323
                            "Host: %s\r\n", hoststr);
324 324
 
325 325
     /* now add in custom headers */
326
-    av_strlcpy(headers+len, s->headers, sizeof(headers)-len);
326
+    if (s->headers)
327
+        av_strlcpy(headers + len, s->headers, sizeof(headers) - len);
327 328
 
328 329
     snprintf(s->buffer, sizeof(s->buffer),
329 330
              "%s %s HTTP/1.1\r\n"
... ...
@@ -333,7 +339,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
333 333
              "\r\n",
334 334
              post ? "POST" : "GET",
335 335
              path,
336
-             post && s->chunksize >= 0 ? "Transfer-Encoding: chunked\r\n" : "",
336
+             post && s->chunked_post ? "Transfer-Encoding: chunked\r\n" : "",
337 337
              headers,
338 338
              authstr ? authstr : "");
339 339
 
... ...
@@ -430,7 +436,7 @@ static int http_write(URLContext *h, const uint8_t *buf, int size)
430 430
     char crlf[] = "\r\n";
431 431
     HTTPContext *s = h->priv_data;
432 432
 
433
-    if (s->chunksize == -1) {
433
+    if (!s->chunked_post) {
434 434
         /* non-chunked data is sent without any special encoding */
435 435
         return ffurl_write(s->hd, buf, size);
436 436
     }
... ...
@@ -456,7 +462,7 @@ static int http_close(URLContext *h)
456 456
     HTTPContext *s = h->priv_data;
457 457
 
458 458
     /* signal end of chunked encoding if used */
459
-    if ((h->flags & AVIO_FLAG_WRITE) && s->chunksize != -1) {
459
+    if ((h->flags & AVIO_FLAG_WRITE) && s->chunked_post) {
460 460
         ret = ffurl_write(s->hd, footer, sizeof(footer) - 1);
461 461
         ret = ret > 0 ? 0 : ret;
462 462
     }
... ...
@@ -519,7 +525,7 @@ URLProtocol ff_http_protocol = {
519 519
     .url_close           = http_close,
520 520
     .url_get_file_handle = http_get_file_handle,
521 521
     .priv_data_size      = sizeof(HTTPContext),
522
-    .priv_data_class     = &httpcontext_class,
522
+    .priv_data_class     = &http_context_class,
523 523
 };
524 524
 #endif
525 525
 #if CONFIG_HTTPS_PROTOCOL
... ...
@@ -532,6 +538,6 @@ URLProtocol ff_https_protocol = {
532 532
     .url_close           = http_close,
533 533
     .url_get_file_handle = http_get_file_handle,
534 534
     .priv_data_size      = sizeof(HTTPContext),
535
-    .priv_data_class     = &httpcontext_class,
535
+    .priv_data_class     = &https_context_class,
536 536
 };
537 537
 #endif
... ...
@@ -25,24 +25,6 @@
25 25
 #include "url.h"
26 26
 
27 27
 /**
28
- * Set custom HTTP headers.
29
- * A trailing CRLF ("\r\n") is required for custom headers.
30
- * Passing in an empty header string ("\0") will reset to defaults.
31
- *
32
- * The following headers can be overriden by custom values,
33
- * otherwise they will be set to their defaults.
34
- *  -User-Agent
35
- *  -Accept
36
- *  -Range
37
- *  -Host
38
- *  -Connection
39
- *
40
- * @param h URL context for this HTTP connection
41
- * @param headers the custom headers to set
42
- */
43
-void ff_http_set_headers(URLContext *h, const char *headers);
44
-
45
-/**
46 28
  * Initialize the authentication state based on another HTTP URLContext.
47 29
  * This can be used to pre-initialize the authentication parameters if
48 30
  * they are known beforehand, to avoid having to do an initial failing
... ...
@@ -28,6 +28,7 @@
28 28
 #include <string.h>
29 29
 #include "libavutil/intreadwrite.h"
30 30
 #include "libavutil/avstring.h"
31
+#include "libavutil/opt.h"
31 32
 #include "internal.h"
32 33
 #include "mms.h"
33 34
 #include "asf.h"
... ...
@@ -246,7 +247,7 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim
246 246
              CLIENTGUID
247 247
              "Connection: Close\r\n",
248 248
              host, port, mmsh->request_seq++);
249
-    ff_http_set_headers(mms->mms_hd, headers);
249
+    av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0);
250 250
 
251 251
     err = ffurl_connect(mms->mms_hd);
252 252
     if (err) {
... ...
@@ -293,7 +294,7 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim
293 293
         goto fail;
294 294
     }
295 295
     av_dlog(NULL, "out_buffer is %s", headers);
296
-    ff_http_set_headers(mms->mms_hd, headers);
296
+    av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0);
297 297
 
298 298
     err = ffurl_connect(mms->mms_hd);
299 299
     if (err) {
... ...
@@ -1462,7 +1462,7 @@ redirect:
1462 1462
                  "Pragma: no-cache\r\n"
1463 1463
                  "Cache-Control: no-cache\r\n",
1464 1464
                  sessioncookie);
1465
-        ff_http_set_headers(rt->rtsp_hd, headers);
1465
+        av_opt_set(rt->rtsp_hd->priv_data, "headers", headers, 0);
1466 1466
 
1467 1467
         /* complete the connection */
1468 1468
         if (ffurl_connect(rt->rtsp_hd)) {
... ...
@@ -1485,8 +1485,8 @@ redirect:
1485 1485
                  "Content-Length: 32767\r\n"
1486 1486
                  "Expires: Sun, 9 Jan 1972 00:00:00 GMT\r\n",
1487 1487
                  sessioncookie);
1488
-        ff_http_set_headers(rt->rtsp_hd_out, headers);
1489
-        av_opt_set(rt->rtsp_hd_out->priv_data, "chunksize", "-1", 0);
1488
+        av_opt_set(rt->rtsp_hd_out->priv_data, "headers", headers, 0);
1489
+        av_opt_set(rt->rtsp_hd_out->priv_data, "chunked_post", "0", 0);
1490 1490
 
1491 1491
         /* Initialize the authentication state for the POST session. The HTTP
1492 1492
          * protocol implementation doesn't properly handle multi-pass
... ...
@@ -73,7 +73,7 @@ static int do_tls_poll(URLContext *h, int ret)
73 73
     struct pollfd p = { c->fd, 0, 0 };
74 74
 #if CONFIG_GNUTLS
75 75
     if (ret != GNUTLS_E_AGAIN && ret != GNUTLS_E_INTERRUPTED) {
76
-        av_log(NULL, AV_LOG_ERROR, "%s\n", gnutls_strerror(ret));
76
+        av_log(h, AV_LOG_ERROR, "%s\n", gnutls_strerror(ret));
77 77
         return AVERROR(EIO);
78 78
     }
79 79
     if (gnutls_record_get_direction(c->session))
... ...
@@ -87,11 +87,11 @@ static int do_tls_poll(URLContext *h, int ret)
87 87
     } else if (ret == SSL_ERROR_WANT_WRITE) {
88 88
         p.events = POLLOUT;
89 89
     } else {
90
-        av_log(NULL, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
90
+        av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
91 91
         return AVERROR(EIO);
92 92
     }
93 93
 #endif
94
-    if (h->flags & URL_FLAG_NONBLOCK)
94
+    if (h->flags & AVIO_FLAG_NONBLOCK)
95 95
         return AVERROR(EAGAIN);
96 96
     while (1) {
97 97
         int n = poll(&p, 1, 100);
... ...
@@ -148,13 +148,13 @@ static int tls_open(URLContext *h, const char *uri, int flags)
148 148
 #elif CONFIG_OPENSSL
149 149
     c->ctx = SSL_CTX_new(SSLv3_client_method());
150 150
     if (!c->ctx) {
151
-        av_log(NULL, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
151
+        av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
152 152
         ret = AVERROR(EIO);
153 153
         goto fail;
154 154
     }
155 155
     c->ssl = SSL_new(c->ctx);
156 156
     if (!c->ssl) {
157
-        av_log(NULL, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
157
+        av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL));
158 158
         ret = AVERROR(EIO);
159 159
         goto fail;
160 160
     }
... ...
@@ -166,7 +166,7 @@ static int tls_open(URLContext *h, const char *uri, int flags)
166 166
         if (ret > 0)
167 167
             break;
168 168
         if (ret == 0) {
169
-            av_log(NULL, AV_LOG_ERROR, "Unable to negotiate TLS/SSL session\n");
169
+            av_log(h, AV_LOG_ERROR, "Unable to negotiate TLS/SSL session\n");
170 170
             ret = AVERROR(EIO);
171 171
             goto fail;
172 172
         }
... ...
@@ -222,11 +222,9 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
222 222
     a->rounds = rounds;
223 223
 
224 224
     memcpy(tk, key, KC * 4);
225
+    memcpy(a->round_key[0].u8, key, KC * 4);
225 226
 
226
-    for (t = 0; t < (rounds + 1) * 16;) {
227
-        memcpy(a->round_key[0].u8 + t, tk, KC * 4);
228
-        t += KC * 4;
229
-
227
+    for (t = KC * 4; t < (rounds + 1) * 16; t += KC * 4) {
230 228
         for (i = 0; i < 4; i++)
231 229
             tk[0][i] ^= sbox[tk[KC - 1][(i + 1) & 3]];
232 230
         tk[0][0] ^= rcon[rconpointer++];
... ...
@@ -239,6 +237,8 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
239 239
                 for (i = 0; i < 4; i++)
240 240
                     tk[j][i] ^= sbox[tk[j - 1][i]];
241 241
         }
242
+
243
+        memcpy(a->round_key[0].u8 + t, tk, KC * 4);
242 244
     }
243 245
 
244 246
     if (decrypt) {