Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master:
vble: remove vble_error_close
VBLE Decoder
tta: use an integer instead of a pointer to iterate output samples
shorten: do not modify samples pointer when interleaving
mpc7: only support stereo input.
dpcm: do not try to decode empty packets
dpcm: remove unneeded buf_size==0 check.
twinvq: add SSE/AVX optimized sum/difference stereo interleaving
vqf/twinvq: pass vqf COMM chunk info in extradata
vqf: do not set bits_per_coded_sample for TwinVQ.
twinvq: check for allocation failure in init_mdct_win()
swscale: add padding to conversion buffer.
rtpdec: Simplify finalize_packet
http: Handle proxy authentication
http: Print an error message for Authorization Required, too
AVOptions: don't return an invalid option when option list is empty
AIFF: add 'twos' FourCC for the mux/demuxer (big endian PCM audio)

Conflicts:
libavcodec/avcodec.h
libavcodec/tta.c
libavcodec/vble.c
libavcodec/version.h
libavutil/opt.c
libswscale/utils.c

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

Michael Niedermayer authored on 2011/11/12 10:50:25
Showing 15 changed files
... ...
@@ -179,9 +179,6 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
179 179
     int stereo = s->channels - 1;
180 180
     int16_t *output_samples = data;
181 181
 
182
-    if (!buf_size)
183
-        return 0;
184
-
185 182
     /* calculate output size */
186 183
     switch(avctx->codec->id) {
187 184
     case CODEC_ID_ROQ_DPCM:
... ...
@@ -201,7 +198,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
201 201
         break;
202 202
     }
203 203
     out *= av_get_bytes_per_sample(avctx->sample_fmt);
204
-    if (out < 0) {
204
+    if (out <= 0) {
205 205
         av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
206 206
         return AVERROR(EINVAL);
207 207
     }
... ...
@@ -2543,6 +2543,18 @@ static void butterflies_float_c(float *restrict v1, float *restrict v2,
2543 2543
     }
2544 2544
 }
2545 2545
 
2546
+static void butterflies_float_interleave_c(float *dst, const float *src0,
2547
+                                           const float *src1, int len)
2548
+{
2549
+    int i;
2550
+    for (i = 0; i < len; i++) {
2551
+        float f1 = src0[i];
2552
+        float f2 = src1[i];
2553
+        dst[2*i    ] = f1 + f2;
2554
+        dst[2*i + 1] = f1 - f2;
2555
+    }
2556
+}
2557
+
2546 2558
 static float scalarproduct_float_c(const float *v1, const float *v2, int len)
2547 2559
 {
2548 2560
     float p = 0.0;
... ...
@@ -3066,6 +3078,7 @@ av_cold void dsputil_init(DSPContext* c, AVCodecContext *avctx)
3066 3066
     c->vector_clip_int32 = vector_clip_int32_c;
3067 3067
     c->scalarproduct_float = scalarproduct_float_c;
3068 3068
     c->butterflies_float = butterflies_float_c;
3069
+    c->butterflies_float_interleave = butterflies_float_interleave_c;
3069 3070
     c->vector_fmul_scalar = vector_fmul_scalar_c;
3070 3071
     c->vector_fmac_scalar = vector_fmac_scalar_c;
3071 3072
 
... ...
@@ -451,6 +451,23 @@ typedef struct DSPContext {
451 451
      */
452 452
     void (*butterflies_float)(float *restrict v1, float *restrict v2, int len);
453 453
 
454
+    /**
455
+     * Calculate the sum and difference of two vectors of floats and interleave
456
+     * results into a separate output vector of floats, with each sum
457
+     * positioned before the corresponding difference.
458
+     *
459
+     * @param dst  output vector
460
+     *             constraints: 16-byte aligned
461
+     * @param src0 first input vector
462
+     *             constraints: 32-byte aligned
463
+     * @param src1 second input vector
464
+     *             constraints: 32-byte aligned
465
+     * @param len  number of elements in the input
466
+     *             constraints: multiple of 8
467
+     */
468
+    void (*butterflies_float_interleave)(float *dst, const float *src0,
469
+                                         const float *src1, int len);
470
+
454 471
     /* (I)DCT */
455 472
     void (*fdct)(DCTELEM *block/* align 16*/);
456 473
     void (*fdct248)(DCTELEM *block/* align 16*/);
... ...
@@ -61,6 +61,13 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
61 61
     static VLC_TYPE hdr_table[1 << MPC7_HDR_BITS][2];
62 62
     static VLC_TYPE quant_tables[7224][2];
63 63
 
64
+    /* Musepack SV7 is always stereo */
65
+    if (avctx->channels != 2) {
66
+        av_log_ask_for_sample(avctx, "Unsupported number of channels: %d\n",
67
+                              avctx->channels);
68
+        return AVERROR_PATCHWELCOME;
69
+    }
70
+
64 71
     if(avctx->extradata_size < 16){
65 72
         av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size);
66 73
         return -1;
... ...
@@ -88,7 +95,7 @@ static av_cold int mpc7_decode_init(AVCodecContext * avctx)
88 88
     c->frames_to_skip = 0;
89 89
 
90 90
     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
91
-    avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
91
+    avctx->channel_layout = AV_CH_LAYOUT_STEREO;
92 92
 
93 93
     if(vlc_initialized) return 0;
94 94
     av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n");
... ...
@@ -252,12 +252,13 @@ static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header,
252 252
     return 0;
253 253
 }
254 254
 
255
-static int16_t * interleave_buffer(int16_t *samples, int nchan, int blocksize, int32_t **buffer) {
255
+static void interleave_buffer(int16_t *samples, int nchan, int blocksize,
256
+                              int32_t **buffer)
257
+{
256 258
     int i, chan;
257 259
     for (i=0; i<blocksize; i++)
258 260
         for (chan=0; chan < nchan; chan++)
259 261
             *samples++ = av_clip_int16(buffer[chan][i]);
260
-    return samples;
261 262
 }
262 263
 
263 264
 static const int fixed_coeffs[3][3] = {
... ...
@@ -576,7 +577,7 @@ static int shorten_decode_frame(AVCodecContext *avctx,
576 576
                     av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
577 577
                     return AVERROR(EINVAL);
578 578
                 }
579
-                samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded);
579
+                interleave_buffer(samples, s->channels, s->blocksize, s->decoded);
580 580
                 *data_size = out_size;
581 581
             }
582 582
         }
... ...
@@ -665,8 +665,9 @@ static void imdct_output(TwinContext *tctx, enum FrameType ftype, int wtype,
665 665
                          float *out)
666 666
 {
667 667
     const ModeTab *mtab = tctx->mtab;
668
+    int size1, size2;
668 669
     float *prev_buf = tctx->prev_frame + tctx->last_block_pos[0];
669
-    int i, j;
670
+    int i;
670 671
 
671 672
     for (i = 0; i < tctx->avctx->channels; i++) {
672 673
         imdct_and_window(tctx, ftype, wtype,
... ...
@@ -675,27 +676,24 @@ static void imdct_output(TwinContext *tctx, enum FrameType ftype, int wtype,
675 675
                          i);
676 676
     }
677 677
 
678
+    size2 = tctx->last_block_pos[0];
679
+    size1 = mtab->size - size2;
678 680
     if (tctx->avctx->channels == 2) {
679
-        for (i = 0; i < mtab->size - tctx->last_block_pos[0]; i++) {
680
-            float f1 = prev_buf[               i];
681
-            float f2 = prev_buf[2*mtab->size + i];
682
-            out[2*i    ] = f1 + f2;
683
-            out[2*i + 1] = f1 - f2;
684
-        }
685
-        for (j = 0; i < mtab->size; j++,i++) {
686
-            float f1 = tctx->curr_frame[               j];
687
-            float f2 = tctx->curr_frame[2*mtab->size + j];
688
-            out[2*i    ] = f1 + f2;
689
-            out[2*i + 1] = f1 - f2;
690
-        }
681
+        tctx->dsp.butterflies_float_interleave(out, prev_buf,
682
+                                               &prev_buf[2*mtab->size],
683
+                                               size1);
684
+
685
+        out += 2 * size1;
686
+
687
+        tctx->dsp.butterflies_float_interleave(out, tctx->curr_frame,
688
+                                               &tctx->curr_frame[2*mtab->size],
689
+                                               size2);
691 690
     } else {
692
-        memcpy(out, prev_buf,
693
-               (mtab->size - tctx->last_block_pos[0]) * sizeof(*out));
691
+        memcpy(out, prev_buf, size1 * sizeof(*out));
694 692
 
695
-        out +=  mtab->size - tctx->last_block_pos[0];
693
+        out += size1;
696 694
 
697
-        memcpy(out, tctx->curr_frame,
698
-               (tctx->last_block_pos[0]) * sizeof(*out));
695
+        memcpy(out, tctx->curr_frame, size2 * sizeof(*out));
699 696
     }
700 697
 
701 698
 }
... ...
@@ -871,9 +869,9 @@ static int twin_decode_frame(AVCodecContext * avctx, void *data,
871 871
 /**
872 872
  * Init IMDCT and windowing tables
873 873
  */
874
-static av_cold void init_mdct_win(TwinContext *tctx)
874
+static av_cold int init_mdct_win(TwinContext *tctx)
875 875
 {
876
-    int i,j;
876
+    int i, j, ret;
877 877
     const ModeTab *mtab = tctx->mtab;
878 878
     int size_s = mtab->size / mtab->fmode[FT_SHORT].sub;
879 879
     int size_m = mtab->size / mtab->fmode[FT_MEDIUM].sub;
... ...
@@ -882,20 +880,29 @@ static av_cold void init_mdct_win(TwinContext *tctx)
882 882
 
883 883
     for (i = 0; i < 3; i++) {
884 884
         int bsize = tctx->mtab->size/tctx->mtab->fmode[i].sub;
885
-        ff_mdct_init(&tctx->mdct_ctx[i], av_log2(bsize) + 1, 1,
886
-                     -sqrt(norm/bsize) / (1<<15));
885
+        if ((ret = ff_mdct_init(&tctx->mdct_ctx[i], av_log2(bsize) + 1, 1,
886
+                                -sqrt(norm/bsize) / (1<<15))))
887
+            return ret;
887 888
     }
888 889
 
889
-    tctx->tmp_buf  = av_malloc(mtab->size            * sizeof(*tctx->tmp_buf));
890
+    FF_ALLOC_OR_GOTO(tctx->avctx, tctx->tmp_buf,
891
+                     mtab->size * sizeof(*tctx->tmp_buf), alloc_fail);
890 892
 
891
-    tctx->spectrum  = av_malloc(2*mtab->size*channels*sizeof(float));
892
-    tctx->curr_frame = av_malloc(2*mtab->size*channels*sizeof(float));
893
-    tctx->prev_frame  = av_malloc(2*mtab->size*channels*sizeof(float));
893
+    FF_ALLOC_OR_GOTO(tctx->avctx, tctx->spectrum,
894
+                     2 * mtab->size * channels * sizeof(*tctx->spectrum),
895
+                     alloc_fail);
896
+    FF_ALLOC_OR_GOTO(tctx->avctx, tctx->curr_frame,
897
+                     2 * mtab->size * channels * sizeof(*tctx->curr_frame),
898
+                     alloc_fail);
899
+    FF_ALLOC_OR_GOTO(tctx->avctx, tctx->prev_frame,
900
+                     2 * mtab->size * channels * sizeof(*tctx->prev_frame),
901
+                     alloc_fail);
894 902
 
895 903
     for (i = 0; i < 3; i++) {
896 904
         int m = 4*mtab->size/mtab->fmode[i].sub;
897 905
         double freq = 2*M_PI/m;
898
-        tctx->cos_tabs[i] = av_malloc((m/4)*sizeof(*tctx->cos_tabs));
906
+        FF_ALLOC_OR_GOTO(tctx->avctx, tctx->cos_tabs[i],
907
+                         (m / 4) * sizeof(*tctx->cos_tabs[i]), alloc_fail);
899 908
 
900 909
         for (j = 0; j <= m/8; j++)
901 910
             tctx->cos_tabs[i][j] = cos((2*j + 1)*freq);
... ...
@@ -907,6 +914,10 @@ static av_cold void init_mdct_win(TwinContext *tctx)
907 907
     ff_init_ff_sine_windows(av_log2(size_m));
908 908
     ff_init_ff_sine_windows(av_log2(size_s/2));
909 909
     ff_init_ff_sine_windows(av_log2(mtab->size));
910
+
911
+    return 0;
912
+alloc_fail:
913
+    return AVERROR(ENOMEM);
910 914
 }
911 915
 
912 916
 /**
... ...
@@ -1068,20 +1079,54 @@ static av_cold void init_bitstream_params(TwinContext *tctx)
1068 1068
         construct_perm_table(tctx, frametype);
1069 1069
 }
1070 1070
 
1071
+static av_cold int twin_decode_close(AVCodecContext *avctx)
1072
+{
1073
+    TwinContext *tctx = avctx->priv_data;
1074
+    int i;
1075
+
1076
+    for (i = 0; i < 3; i++) {
1077
+        ff_mdct_end(&tctx->mdct_ctx[i]);
1078
+        av_free(tctx->cos_tabs[i]);
1079
+    }
1080
+
1081
+
1082
+    av_free(tctx->curr_frame);
1083
+    av_free(tctx->spectrum);
1084
+    av_free(tctx->prev_frame);
1085
+    av_free(tctx->tmp_buf);
1086
+
1087
+    return 0;
1088
+}
1089
+
1071 1090
 static av_cold int twin_decode_init(AVCodecContext *avctx)
1072 1091
 {
1092
+    int ret;
1073 1093
     TwinContext *tctx = avctx->priv_data;
1074
-    int isampf = avctx->sample_rate/1000;
1075
-    int ibps = avctx->bit_rate/(1000 * avctx->channels);
1094
+    int isampf, ibps;
1076 1095
 
1077 1096
     tctx->avctx       = avctx;
1078 1097
     avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
1079 1098
 
1099
+    if (!avctx->extradata || avctx->extradata_size < 12) {
1100
+        av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\n");
1101
+        return AVERROR_INVALIDDATA;
1102
+    }
1103
+    avctx->channels = AV_RB32(avctx->extradata    ) + 1;
1104
+    avctx->bit_rate = AV_RB32(avctx->extradata + 4) * 1000;
1105
+    isampf          = AV_RB32(avctx->extradata + 8);
1106
+    switch (isampf) {
1107
+    case 44: avctx->sample_rate = 44100;         break;
1108
+    case 22: avctx->sample_rate = 22050;         break;
1109
+    case 11: avctx->sample_rate = 11025;         break;
1110
+    default: avctx->sample_rate = isampf * 1000; break;
1111
+    }
1112
+
1080 1113
     if (avctx->channels > CHANNELS_MAX) {
1081 1114
         av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n",
1082 1115
                avctx->channels);
1083 1116
         return -1;
1084 1117
     }
1118
+    ibps = avctx->bit_rate / (1000 * avctx->channels);
1085 1119
 
1086 1120
     switch ((isampf << 8) +  ibps) {
1087 1121
     case (8 <<8) +  8: tctx->mtab = &mode_08_08; break;
... ...
@@ -1099,7 +1144,11 @@ static av_cold int twin_decode_init(AVCodecContext *avctx)
1099 1099
     }
1100 1100
 
1101 1101
     dsputil_init(&tctx->dsp, avctx);
1102
-    init_mdct_win(tctx);
1102
+    if ((ret = init_mdct_win(tctx))) {
1103
+        av_log(avctx, AV_LOG_ERROR, "Error initializing MDCT\n");
1104
+        twin_decode_close(avctx);
1105
+        return ret;
1106
+    }
1103 1107
     init_bitstream_params(tctx);
1104 1108
 
1105 1109
     memset_float(tctx->bark_hist[0][0], 0.1, FF_ARRAY_ELEMS(tctx->bark_hist));
... ...
@@ -1107,25 +1156,6 @@ static av_cold int twin_decode_init(AVCodecContext *avctx)
1107 1107
     return 0;
1108 1108
 }
1109 1109
 
1110
-static av_cold int twin_decode_close(AVCodecContext *avctx)
1111
-{
1112
-    TwinContext *tctx = avctx->priv_data;
1113
-    int i;
1114
-
1115
-    for (i = 0; i < 3; i++) {
1116
-        ff_mdct_end(&tctx->mdct_ctx[i]);
1117
-        av_free(tctx->cos_tabs[i]);
1118
-    }
1119
-
1120
-
1121
-    av_free(tctx->curr_frame);
1122
-    av_free(tctx->spectrum);
1123
-    av_free(tctx->prev_frame);
1124
-    av_free(tctx->tmp_buf);
1125
-
1126
-    return 0;
1127
-}
1128
-
1129 1110
 AVCodec ff_twinvq_decoder = {
1130 1111
     .name           = "twinvq",
1131 1112
     .type           = AVMEDIA_TYPE_AUDIO,
... ...
@@ -21,7 +21,7 @@
21 21
 #define AVCODEC_VERSION_H
22 22
 
23 23
 #define LIBAVCODEC_VERSION_MAJOR 53
24
-#define LIBAVCODEC_VERSION_MINOR 32
24
+#define LIBAVCODEC_VERSION_MINOR 33
25 25
 #define LIBAVCODEC_VERSION_MICRO  0
26 26
 
27 27
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
... ...
@@ -2407,6 +2407,11 @@ void ff_vector_clip_int32_int_sse2(int32_t *dst, const int32_t *src, int32_t min
2407 2407
 void ff_vector_clip_int32_sse4    (int32_t *dst, const int32_t *src, int32_t min,
2408 2408
                                    int32_t max, unsigned int len);
2409 2409
 
2410
+extern void ff_butterflies_float_interleave_sse(float *dst, const float *src0,
2411
+                                                const float *src1, int len);
2412
+extern void ff_butterflies_float_interleave_avx(float *dst, const float *src0,
2413
+                                                const float *src1, int len);
2414
+
2410 2415
 void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
2411 2416
 {
2412 2417
     int mm_flags = av_get_cpu_flags();
... ...
@@ -2849,6 +2854,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
2849 2849
             c->vector_clipf = vector_clipf_sse;
2850 2850
 #if HAVE_YASM
2851 2851
             c->scalarproduct_float = ff_scalarproduct_float_sse;
2852
+            c->butterflies_float_interleave = ff_butterflies_float_interleave_sse;
2852 2853
 #endif
2853 2854
         }
2854 2855
         if (HAVE_AMD3DNOW && (mm_flags & AV_CPU_FLAG_3DNOW))
... ...
@@ -2906,6 +2912,7 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx)
2906 2906
                 c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_10_avx;
2907 2907
                 c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_10_avx;
2908 2908
             }
2909
+            c->butterflies_float_interleave = ff_butterflies_float_interleave_avx;
2909 2910
         }
2910 2911
 #endif
2911 2912
     }
... ...
@@ -1129,3 +1129,51 @@ VECTOR_CLIP_INT32 11, 1, 1, 0
1129 1129
 %else
1130 1130
 VECTOR_CLIP_INT32 6, 1, 0, 0
1131 1131
 %endif
1132
+
1133
+;-----------------------------------------------------------------------------
1134
+; void ff_butterflies_float_interleave(float *dst, const float *src0,
1135
+;                                      const float *src1, int len);
1136
+;-----------------------------------------------------------------------------
1137
+
1138
+%macro BUTTERFLIES_FLOAT_INTERLEAVE 0
1139
+cglobal butterflies_float_interleave, 4,4,3, dst, src0, src1, len
1140
+%ifdef ARCH_X86_64
1141
+    movsxd    lenq, lend
1142
+%endif
1143
+    test      lenq, lenq
1144
+    jz .end
1145
+    shl       lenq, 2
1146
+    lea      src0q, [src0q +   lenq]
1147
+    lea      src1q, [src1q +   lenq]
1148
+    lea       dstq, [ dstq + 2*lenq]
1149
+    neg       lenq
1150
+.loop:
1151
+    mova        m0, [src0q + lenq]
1152
+    mova        m1, [src1q + lenq]
1153
+    subps       m2, m0, m1
1154
+    addps       m0, m0, m1
1155
+    unpcklps    m1, m0, m2
1156
+    unpckhps    m0, m0, m2
1157
+%if cpuflag(avx)
1158
+    vextractf128 [dstq + 2*lenq     ], m1, 0
1159
+    vextractf128 [dstq + 2*lenq + 16], m0, 0
1160
+    vextractf128 [dstq + 2*lenq + 32], m1, 1
1161
+    vextractf128 [dstq + 2*lenq + 48], m0, 1
1162
+%else
1163
+    mova [dstq + 2*lenq         ], m1
1164
+    mova [dstq + 2*lenq + mmsize], m0
1165
+%endif
1166
+    add       lenq, mmsize
1167
+    jl .loop
1168
+%if mmsize == 32
1169
+    vzeroupper
1170
+    RET
1171
+%endif
1172
+.end:
1173
+    REP_RET
1174
+%endmacro
1175
+
1176
+INIT_XMM sse
1177
+BUTTERFLIES_FLOAT_INTERLEAVE
1178
+INIT_YMM avx
1179
+BUTTERFLIES_FLOAT_INTERLEAVE
... ...
@@ -43,6 +43,7 @@ static const AVCodecTag ff_codec_aiff_tags[] = {
43 43
     { CODEC_ID_MACE6,        MKTAG('M','A','C','6') },
44 44
     { CODEC_ID_GSM,          MKTAG('G','S','M',' ') },
45 45
     { CODEC_ID_ADPCM_G726,   MKTAG('G','7','2','6') },
46
+    { CODEC_ID_PCM_S16BE,    MKTAG('t','w','o','s') },
46 47
     { CODEC_ID_PCM_S16LE,    MKTAG('s','o','w','t') },
47 48
     { CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') },
48 49
     { CODEC_ID_QDM2,         MKTAG('Q','D','M','2') },
... ...
@@ -47,6 +47,7 @@ typedef struct {
47 47
     int64_t off, filesize;
48 48
     char location[MAX_URL_SIZE];
49 49
     HTTPAuthState auth_state;
50
+    HTTPAuthState proxy_auth_state;
50 51
     char *headers;
51 52
     int willclose;          /**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */
52 53
     int chunked_post;
... ...
@@ -71,25 +72,29 @@ static const AVClass flavor ## _context_class = {\
71 71
 HTTP_CLASS(http);
72 72
 HTTP_CLASS(https);
73 73
 
74
-static int http_connect(URLContext *h, const char *path, const char *hoststr,
75
-                        const char *auth, int *new_location);
74
+static int http_connect(URLContext *h, const char *path, const char *local_path,
75
+                        const char *hoststr, const char *auth,
76
+                        const char *proxyauth, int *new_location);
76 77
 
77 78
 void ff_http_init_auth_state(URLContext *dest, const URLContext *src)
78 79
 {
79 80
     memcpy(&((HTTPContext*)dest->priv_data)->auth_state,
80 81
            &((HTTPContext*)src->priv_data)->auth_state, sizeof(HTTPAuthState));
82
+    memcpy(&((HTTPContext*)dest->priv_data)->proxy_auth_state,
83
+           &((HTTPContext*)src->priv_data)->proxy_auth_state,
84
+           sizeof(HTTPAuthState));
81 85
 }
82 86
 
83 87
 /* return non zero if error */
84 88
 static int http_open_cnx(URLContext *h)
85 89
 {
86
-    const char *path, *proxy_path, *lower_proto = "tcp";
90
+    const char *path, *proxy_path, *lower_proto = "tcp", *local_path;
87 91
     char hostname[1024], hoststr[1024], proto[10];
88
-    char auth[1024];
92
+    char auth[1024], proxyauth[1024];
89 93
     char path1[1024];
90
-    char buf[1024];
94
+    char buf[1024], urlbuf[1024];
91 95
     int port, use_proxy, err, location_changed = 0, redirects = 0;
92
-    HTTPAuthType cur_auth_type;
96
+    HTTPAuthType cur_auth_type, cur_proxy_auth_type;
93 97
     HTTPContext *s = h->priv_data;
94 98
     URLContext *hd = NULL;
95 99
 
... ...
@@ -105,15 +110,19 @@ static int http_open_cnx(URLContext *h)
105 105
                  path1, sizeof(path1), s->location);
106 106
     ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);
107 107
 
108
+    if (path1[0] == '\0')
109
+        path = "/";
110
+    else
111
+        path = path1;
112
+    local_path = path;
108 113
     if (use_proxy) {
109
-        av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
110
-                     NULL, 0, proxy_path);
111
-        path = s->location;
112
-    } else {
113
-        if (path1[0] == '\0')
114
-            path = "/";
115
-        else
116
-            path = path1;
114
+        /* Reassemble the request URL without auth string - we don't
115
+         * want to leak the auth to the proxy. */
116
+        ff_url_join(urlbuf, sizeof(urlbuf), proto, NULL, hostname, port, "%s",
117
+                    path1);
118
+        path = urlbuf;
119
+        av_url_split(NULL, 0, proxyauth, sizeof(proxyauth),
120
+                     hostname, sizeof(hostname), &port, NULL, 0, proxy_path);
117 121
     }
118 122
     if (!strcmp(proto, "https")) {
119 123
         lower_proto = "tls";
... ...
@@ -130,7 +139,8 @@ static int http_open_cnx(URLContext *h)
130 130
 
131 131
     s->hd = hd;
132 132
     cur_auth_type = s->auth_state.auth_type;
133
-    if (http_connect(h, path, hoststr, auth, &location_changed) < 0)
133
+    cur_proxy_auth_type = s->auth_state.auth_type;
134
+    if (http_connect(h, path, local_path, hoststr, auth, proxyauth, &location_changed) < 0)
134 135
         goto fail;
135 136
     if (s->http_code == 401) {
136 137
         if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) {
... ...
@@ -139,6 +149,14 @@ static int http_open_cnx(URLContext *h)
139 139
         } else
140 140
             goto fail;
141 141
     }
142
+    if (s->http_code == 407) {
143
+        if (cur_proxy_auth_type == HTTP_AUTH_NONE &&
144
+            s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) {
145
+            ffurl_close(hd);
146
+            goto redo;
147
+        } else
148
+            goto fail;
149
+    }
142 150
     if ((s->http_code == 301 || s->http_code == 302 || s->http_code == 303 || s->http_code == 307)
143 151
         && location_changed == 1) {
144 152
         /* url moved, get next */
... ...
@@ -236,7 +254,9 @@ static int process_line(URLContext *h, char *line, int line_count,
236 236
 
237 237
         /* error codes are 4xx and 5xx, but regard 401 as a success, so we
238 238
          * don't abort until all headers have been parsed. */
239
-        if (s->http_code >= 400 && s->http_code < 600 && s->http_code != 401) {
239
+        if (s->http_code >= 400 && s->http_code < 600 && (s->http_code != 401
240
+            || s->auth_state.auth_type != HTTP_AUTH_NONE) &&
241
+            (s->http_code != 407 || s->proxy_auth_state.auth_type != HTTP_AUTH_NONE)) {
240 242
             end += strspn(end, SPACE_CHARS);
241 243
             av_log(h, AV_LOG_WARNING, "HTTP error %d %s\n",
242 244
                    s->http_code, end);
... ...
@@ -277,6 +297,8 @@ static int process_line(URLContext *h, char *line, int line_count,
277 277
             ff_http_auth_handle_header(&s->auth_state, tag, p);
278 278
         } else if (!av_strcasecmp (tag, "Authentication-Info")) {
279 279
             ff_http_auth_handle_header(&s->auth_state, tag, p);
280
+        } else if (!av_strcasecmp (tag, "Proxy-Authenticate")) {
281
+            ff_http_auth_handle_header(&s->proxy_auth_state, tag, p);
280 282
         } else if (!av_strcasecmp (tag, "Connection")) {
281 283
             if (!strcmp(p, "close"))
282 284
                 s->willclose = 1;
... ...
@@ -293,22 +315,27 @@ static inline int has_header(const char *str, const char *header)
293 293
     return av_stristart(str, header + 2, NULL) || av_stristr(str, header);
294 294
 }
295 295
 
296
-static int http_connect(URLContext *h, const char *path, const char *hoststr,
297
-                        const char *auth, int *new_location)
296
+static int http_connect(URLContext *h, const char *path, const char *local_path,
297
+                        const char *hoststr, const char *auth,
298
+                        const char *proxyauth, int *new_location)
298 299
 {
299 300
     HTTPContext *s = h->priv_data;
300 301
     int post, err;
301 302
     char line[1024];
302 303
     char headers[1024] = "";
303
-    char *authstr = NULL;
304
+    char *authstr = NULL, *proxyauthstr = NULL;
304 305
     int64_t off = s->off;
305 306
     int len = 0;
307
+    const char *method;
306 308
 
307 309
 
308 310
     /* send http header */
309 311
     post = h->flags & AVIO_FLAG_WRITE;
310
-    authstr = ff_http_auth_create_response(&s->auth_state, auth, path,
311
-                                        post ? "POST" : "GET");
312
+    method = post ? "POST" : "GET";
313
+    authstr = ff_http_auth_create_response(&s->auth_state, auth, local_path,
314
+                                           method);
315
+    proxyauthstr = ff_http_auth_create_response(&s->proxy_auth_state, proxyauth,
316
+                                                local_path, method);
312 317
 
313 318
     /* set default headers if needed */
314 319
     if (!has_header(s->headers, "\r\nUser-Agent: "))
... ...
@@ -336,14 +363,17 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
336 336
              "%s"
337 337
              "%s"
338 338
              "%s"
339
+             "%s%s"
339 340
              "\r\n",
340
-             post ? "POST" : "GET",
341
+             method,
341 342
              path,
342 343
              post && s->chunked_post ? "Transfer-Encoding: chunked\r\n" : "",
343 344
              headers,
344
-             authstr ? authstr : "");
345
+             authstr ? authstr : "",
346
+             proxyauthstr ? "Proxy-" : "", proxyauthstr ? proxyauthstr : "");
345 347
 
346 348
     av_freep(&authstr);
349
+    av_freep(&proxyauthstr);
347 350
     if (ffurl_write(s->hd, s->buffer, strlen(s->buffer)) < 0)
348 351
         return AVERROR(EIO);
349 352
 
... ...
@@ -87,7 +87,7 @@ static void choose_qop(char *qop, int size)
87 87
 void ff_http_auth_handle_header(HTTPAuthState *state, const char *key,
88 88
                                 const char *value)
89 89
 {
90
-    if (!strcmp(key, "WWW-Authenticate")) {
90
+    if (!strcmp(key, "WWW-Authenticate") || !strcmp(key, "Proxy-Authenticate")) {
91 91
         const char *p;
92 92
         if (av_stristart(value, "Basic ", &p) &&
93 93
             state->auth_type <= HTTP_AUTH_BASIC) {
... ...
@@ -426,7 +426,10 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam
426 426
 {
427 427
     if (pkt->pts != AV_NOPTS_VALUE || pkt->dts != AV_NOPTS_VALUE)
428 428
         return; /* Timestamp already set by depacketizer */
429
-    if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE && timestamp != RTP_NOTS_VALUE) {
429
+    if (timestamp == RTP_NOTS_VALUE)
430
+        return;
431
+
432
+    if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE) {
430 433
         int64_t addend;
431 434
         int delta_timestamp;
432 435
 
... ...
@@ -438,8 +441,7 @@ static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestam
438 438
                    delta_timestamp;
439 439
         return;
440 440
     }
441
-    if (timestamp == RTP_NOTS_VALUE)
442
-        return;
441
+
443 442
     if (!s->base_timestamp)
444 443
         s->base_timestamp = timestamp;
445 444
     pkt->pts = s->range_start_offset + timestamp - s->base_timestamp;
... ...
@@ -70,6 +70,7 @@ static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap)
70 70
     int header_size;
71 71
     int read_bitrate = 0;
72 72
     int size;
73
+    uint8_t comm_chunk[12];
73 74
 
74 75
     if (!st)
75 76
         return AVERROR(ENOMEM);
... ...
@@ -100,13 +101,13 @@ static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap)
100 100
 
101 101
         switch(chunk_tag){
102 102
         case MKTAG('C','O','M','M'):
103
-            st->codec->channels = avio_rb32(s->pb) + 1;
104
-            read_bitrate        = avio_rb32(s->pb);
105
-            rate_flag           = avio_rb32(s->pb);
103
+            avio_read(s->pb, comm_chunk, 12);
104
+            st->codec->channels = AV_RB32(comm_chunk    ) + 1;
105
+            read_bitrate        = AV_RB32(comm_chunk + 4);
106
+            rate_flag           = AV_RB32(comm_chunk + 8);
106 107
             avio_skip(s->pb, len-12);
107 108
 
108 109
             st->codec->bit_rate              = read_bitrate*1000;
109
-            st->codec->bits_per_coded_sample = 16;
110 110
             break;
111 111
         case MKTAG('N','A','M','E'):
112 112
             add_metadata(s, "title"    , len, header_size);
... ...
@@ -193,6 +194,12 @@ static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap)
193 193
     c->frame_bit_len = st->codec->bit_rate*size/st->codec->sample_rate;
194 194
     av_set_pts_info(st, 64, 1, st->codec->sample_rate);
195 195
 
196
+    /* put first 12 bytes of COMM chunk in extradata */
197
+    if (!(st->codec->extradata = av_malloc(12 + FF_INPUT_BUFFER_PADDING_SIZE)))
198
+        return AVERROR(ENOMEM);
199
+    st->codec->extradata_size = 12;
200
+    memcpy(st->codec->extradata, comm_chunk, 12);
201
+
196 202
     return 0;
197 203
 }
198 204
 
... ...
@@ -55,9 +55,10 @@ const AVOption *av_next_option(void *obj, const AVOption *last)
55 55
 
56 56
 const AVOption *av_opt_next(void *obj, const AVOption *last)
57 57
 {
58
-    if (last && last[1].name) return ++last;
59
-    else if (last || !(*(AVClass**)obj)->option->name) return NULL;
60
-    else                      return (*(AVClass**)obj)->option;
58
+    AVClass *class = *(AVClass**)obj;
59
+    if (!last && class->option[0].name) return class->option;
60
+    if (last && last[1].name)           return ++last;
61
+    return NULL;
61 62
 }
62 63
 
63 64
 static int read_number(const AVOption *o, void *dst, double *num, int *den, int64_t *intnum)