Browse Source

Merge remote-tracking branch 'newdev/master'

Merged-by: Michael Niedermayer <michaelni@gmx.at>
Michael Niedermayer 14 years ago
parent
commit
6947b0c42e

+ 16 - 0
doc/protocols.texi

@@ -19,6 +19,22 @@ supported protocols.
 
 A description of the currently available protocols follows.
 
+@section applehttp
+
+Read Apple HTTP Live Streaming compliant segmented stream as
+a uniform one. The M3U8 playlists describing the segments can be
+remote HTTP resources or local files, accessed using the standard
+file protocol.
+HTTP is default, specific protocol can be declared using the "+"
+specifier.
+
+@example
+applehttp://host/path/to/remote/resource.m3u8
+applehttp+http://host/path/to/remote/resource.m3u8
+applehttp+file://path/to/local/resource.m3u8
+@end example
+
+
 @section concat
 
 Physical concatenation protocol.

+ 1 - 1
ffplay.c

@@ -2575,7 +2575,7 @@ static int decode_thread(void *arg)
         if (ret < 0) {
             if (ret == AVERROR_EOF || url_feof(ic->pb))
                 eof=1;
-            if (url_ferror(ic->pb))
+            if (ic->pb->error)
                 break;
             SDL_Delay(100); /* wait for user event */
             continue;

+ 37 - 0
libavcodec/ac3dsp.c

@@ -50,10 +50,47 @@ static int ac3_max_msb_abs_int16_c(const int16_t *src, int len)
     return v;
 }
 
+static void ac3_lshift_int16_c(int16_t *src, unsigned int len,
+                               unsigned int shift)
+{
+    uint32_t *src32 = (uint32_t *)src;
+    const uint32_t mask = ~(((1 << shift) - 1) << 16);
+    int i;
+    len >>= 1;
+    for (i = 0; i < len; i += 8) {
+        src32[i  ] = (src32[i  ] << shift) & mask;
+        src32[i+1] = (src32[i+1] << shift) & mask;
+        src32[i+2] = (src32[i+2] << shift) & mask;
+        src32[i+3] = (src32[i+3] << shift) & mask;
+        src32[i+4] = (src32[i+4] << shift) & mask;
+        src32[i+5] = (src32[i+5] << shift) & mask;
+        src32[i+6] = (src32[i+6] << shift) & mask;
+        src32[i+7] = (src32[i+7] << shift) & mask;
+    }
+}
+
+static void ac3_rshift_int32_c(int32_t *src, unsigned int len,
+                               unsigned int shift)
+{
+    do {
+        *src++ >>= shift;
+        *src++ >>= shift;
+        *src++ >>= shift;
+        *src++ >>= shift;
+        *src++ >>= shift;
+        *src++ >>= shift;
+        *src++ >>= shift;
+        *src++ >>= shift;
+        len -= 8;
+    } while (len > 0);
+}
+
 av_cold void ff_ac3dsp_init(AC3DSPContext *c)
 {
     c->ac3_exponent_min = ac3_exponent_min_c;
     c->ac3_max_msb_abs_int16 = ac3_max_msb_abs_int16_c;
+    c->ac3_lshift_int16 = ac3_lshift_int16_c;
+    c->ac3_rshift_int32 = ac3_rshift_int32_c;
 
     if (HAVE_MMX)
         ff_ac3dsp_init_x86(c);

+ 22 - 0
libavcodec/ac3dsp.h

@@ -46,6 +46,28 @@ typedef struct AC3DSPContext {
      * @return    a value with the same MSB as max(abs(src[]))
      */
     int (*ac3_max_msb_abs_int16)(const int16_t *src, int len);
+
+    /**
+     * Left-shift each value in an array of int16_t by a specified amount.
+     * @param src    input array
+     *               constraints: align 16
+     * @param len    number of values in the array
+     *               constraints: multiple of 32 greater than 0
+     * @param shift  left shift amount
+     *               constraints: range [0,15]
+     */
+    void (*ac3_lshift_int16)(int16_t *src, unsigned int len, unsigned int shift);
+
+    /**
+     * Right-shift each value in an array of int32_t by a specified amount.
+     * @param src    input array
+     *               constraints: align 16
+     * @param len    number of values in the array
+     *               constraints: multiple of 16 greater than 0
+     * @param shift  right shift amount
+     *               constraints: range [0,31]
+     */
+    void (*ac3_rshift_int32)(int32_t *src, unsigned int len, unsigned int shift);
 } AC3DSPContext;
 
 void ff_ac3dsp_init    (AC3DSPContext *c);

+ 12 - 13
libavcodec/ac3enc.c

@@ -78,7 +78,7 @@ typedef struct AC3Block {
     int16_t  **band_psd;                        ///< psd per critical band
     int16_t  **mask;                            ///< masking curve
     uint16_t **qmant;                           ///< quantized mantissas
-    int8_t   exp_shift[AC3_MAX_CHANNELS];       ///< exponent shift values
+    uint8_t  coeff_shift[AC3_MAX_CHANNELS];     ///< fixed-point coefficient shift values
     uint8_t  new_rematrixing_strategy;          ///< send new rematrixing flags in this block
     uint8_t  rematrixing_flags[4];              ///< rematrixing flags
 } AC3Block;
@@ -269,7 +269,7 @@ static void apply_mdct(AC3EncodeContext *s)
 
             apply_window(&s->dsp, s->windowed_samples, input_samples, s->mdct.window, AC3_WINDOW_SIZE);
 
-            block->exp_shift[ch] = normalize_samples(s);
+            block->coeff_shift[ch] = normalize_samples(s);
 
             mdct512(&s->mdct, block->mdct_coef[ch], s->windowed_samples);
         }
@@ -328,10 +328,10 @@ static void compute_rematrixing_strategy(AC3EncodeContext *s)
                 CoefType rt = block->mdct_coef[1][i];
                 CoefType md = lt + rt;
                 CoefType sd = lt - rt;
-                sum[0] += lt * lt;
-                sum[1] += rt * rt;
-                sum[2] += md * md;
-                sum[3] += sd * sd;
+                MAC_COEF(sum[0], lt, lt);
+                MAC_COEF(sum[1], rt, rt);
+                MAC_COEF(sum[2], md, md);
+                MAC_COEF(sum[3], sd, sd);
             }
 
             /* compare sums to determine if rematrixing will be used for this band */
@@ -416,14 +416,13 @@ static void extract_exponents(AC3EncodeContext *s)
             AC3Block *block = &s->blocks[blk];
             uint8_t *exp   = block->exp[ch];
             int32_t *coef = block->fixed_coef[ch];
-            int exp_shift  = block->exp_shift[ch];
             for (i = 0; i < AC3_MAX_COEFS; i++) {
                 int e;
                 int v = abs(coef[i]);
                 if (v == 0)
                     e = 24;
                 else {
-                    e = 23 - av_log2(v) + exp_shift;
+                    e = 23 - av_log2(v);
                     if (e >= 24) {
                         e = 24;
                         coef[i] = 0;
@@ -1139,7 +1138,7 @@ static inline int asym_quant(int c, int e, int qbits)
  * Quantize a set of mantissas for a single channel in a single block.
  */
 static void quantize_mantissas_blk_ch(AC3EncodeContext *s, int32_t *fixed_coef,
-                                      int8_t exp_shift, uint8_t *exp,
+                                      uint8_t *exp,
                                       uint8_t *bap, uint16_t *qmant, int n)
 {
     int i;
@@ -1147,7 +1146,7 @@ static void quantize_mantissas_blk_ch(AC3EncodeContext *s, int32_t *fixed_coef,
     for (i = 0; i < n; i++) {
         int v;
         int c = fixed_coef[i];
-        int e = exp[i] - exp_shift;
+        int e = exp[i];
         int b = bap[i];
         switch (b) {
         case 0:
@@ -1243,7 +1242,7 @@ static void quantize_mantissas(AC3EncodeContext *s)
         s->qmant1_ptr = s->qmant2_ptr = s->qmant4_ptr = NULL;
 
         for (ch = 0; ch < s->channels; ch++) {
-            quantize_mantissas_blk_ch(s, block->fixed_coef[ch], block->exp_shift[ch],
+            quantize_mantissas_blk_ch(s, block->fixed_coef[ch],
                                       block->exp[ch], block->bap[ch],
                                       block->qmant[ch], s->nb_coefs[ch]);
         }
@@ -1507,10 +1506,10 @@ static int ac3_encode_frame(AVCodecContext *avctx, unsigned char *frame,
 
     apply_mdct(s);
 
-    compute_rematrixing_strategy(s);
-
     scale_coefficients(s);
 
+    compute_rematrixing_strategy(s);
+
     apply_rematrixing(s);
 
     process_exponents(s);

+ 21 - 31
libavcodec/ac3enc_fixed.c

@@ -131,10 +131,10 @@ mdct_alloc_fail:
 
 
 /** Complex multiply */
-#define CMUL(pre, pim, are, aim, bre, bim)              \
+#define CMUL(pre, pim, are, aim, bre, bim, rshift)      \
 {                                                       \
-   pre = (MUL16(are, bre) - MUL16(aim, bim)) >> 15;     \
-   pim = (MUL16(are, bim) + MUL16(bre, aim)) >> 15;     \
+   pre = (MUL16(are, bre) - MUL16(aim, bim)) >> rshift; \
+   pim = (MUL16(are, bim) + MUL16(bre, aim)) >> rshift; \
 }
 
 
@@ -195,7 +195,7 @@ static void fft(AC3MDCTContext *mdct, IComplex *z, int ln)
             p++;
             q++;
             for(l = nblocks; l < np2; l += nblocks) {
-                CMUL(tmp_re, tmp_im, mdct->costab[l], -mdct->sintab[l], q->re, q->im);
+                CMUL(tmp_re, tmp_im, mdct->costab[l], -mdct->sintab[l], q->re, q->im, 15);
                 BF(p->re, p->im, q->re,  q->im,
                    p->re, p->im, tmp_re, tmp_im);
                 p++;
@@ -234,7 +234,7 @@ static void mdct512(AC3MDCTContext *mdct, int32_t *out, int16_t *in)
     for (i = 0; i < n4; i++) {
         re =  ((int)rot[   2*i] - (int)rot[ n-1-2*i]) >> 1;
         im = -((int)rot[n2+2*i] - (int)rot[n2-1-2*i]) >> 1;
-        CMUL(x[i].re, x[i].im, re, im, -mdct->xcos1[i], mdct->xsin1[i]);
+        CMUL(x[i].re, x[i].im, re, im, -mdct->xcos1[i], mdct->xsin1[i], 15);
     }
 
     fft(mdct, x, mdct->nbits - 2);
@@ -243,7 +243,7 @@ static void mdct512(AC3MDCTContext *mdct, int32_t *out, int16_t *in)
     for (i = 0; i < n4; i++) {
         re = x[i].re;
         im = x[i].im;
-        CMUL(out[n2-1-2*i], out[2*i], re, im, mdct->xsin1[i], mdct->xcos1[i]);
+        CMUL(out[n2-1-2*i], out[2*i], re, im, mdct->xsin1[i], mdct->xcos1[i], 0);
     }
 }
 
@@ -277,46 +277,36 @@ static int log2_tab(AC3EncodeContext *s, int16_t *src, int len)
 }
 
 
-/**
- * Left-shift each value in an array by a specified amount.
- * @param tab    input array
- * @param n      number of values in the array
- * @param lshift left shift amount
- */
-static void lshift_tab(int16_t *tab, int n, unsigned int lshift)
-{
-    int i;
-
-    if (lshift > 0) {
-        for (i = 0; i < n; i++)
-            tab[i] <<= lshift;
-    }
-}
-
-
 /**
  * Normalize the input samples to use the maximum available precision.
- * This assumes signed 16-bit input samples. Exponents are reduced by 9 to
- * match the 24-bit internal precision for MDCT coefficients.
+ * This assumes signed 16-bit input samples.
  *
  * @return exponent shift
  */
 static int normalize_samples(AC3EncodeContext *s)
 {
     int v = 14 - log2_tab(s, s->windowed_samples, AC3_WINDOW_SIZE);
-    lshift_tab(s->windowed_samples, AC3_WINDOW_SIZE, v);
-    return v - 9;
+    if (v > 0)
+        s->ac3dsp.ac3_lshift_int16(s->windowed_samples, AC3_WINDOW_SIZE, v);
+    /* +6 to right-shift from 31-bit to 25-bit */
+    return v + 6;
 }
 
 
 /**
- * Scale MDCT coefficients from float to fixed-point.
+ * Scale MDCT coefficients to 25-bit signed fixed-point.
  */
 static void scale_coefficients(AC3EncodeContext *s)
 {
-    /* scaling/conversion is obviously not needed for the fixed-point encoder
-       since the coefficients are already fixed-point. */
-    return;
+    int blk, ch;
+
+    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+        AC3Block *block = &s->blocks[blk];
+        for (ch = 0; ch < s->channels; ch++) {
+            s->ac3dsp.ac3_rshift_int32(block->mdct_coef[ch], AC3_MAX_COEFS,
+                                       block->coeff_shift[ch]);
+        }
+    }
 }
 
 

+ 2 - 0
libavcodec/ac3enc_fixed.h

@@ -36,6 +36,8 @@ typedef int16_t SampleType;
 typedef int32_t CoefType;
 typedef int64_t CoefSumType;
 
+#define MAC_COEF(d,a,b) MAC64(d,a,b)
+
 
 /**
  * Compex number.

+ 2 - 0
libavcodec/ac3enc_float.h

@@ -36,6 +36,8 @@ typedef float SampleType;
 typedef float CoefType;
 typedef float CoefSumType;
 
+#define MAC_COEF(d,a,b) ((d)+=(a)*(b))
+
 
 typedef struct AC3MDCTContext {
     const float *window;    ///< MDCT window function

+ 4 - 1
libavcodec/h264_mp4toannexb_bsf.c

@@ -116,8 +116,11 @@ static int h264_mp4toannexb_filter(AVBitStreamFilterContext *bsfc,
             memcpy(out+total_size-unit_size,   extradata+2, unit_size);
             extradata += 2+unit_size;
 
-            if (!unit_nb && !sps_done++)
+            if (!unit_nb && !sps_done++) {
                 unit_nb = *extradata++; /* number of pps unit(s) */
+                if (unit_nb)
+                    pps_seen = 1;
+            }
         }
 
         if(out)

+ 1 - 1
libavcodec/vp8.c

@@ -695,7 +695,7 @@ skip_eob:
 
 static av_always_inline
 int decode_block_coeffs(VP56RangeCoder *c, DCTELEM block[16],
-                        uint8_t probs[8][3][NUM_DCT_TOKENS-1],
+                        uint8_t probs[16][3][NUM_DCT_TOKENS-1],
                         int i, int zero_nhood, int16_t qmul[2])
 {
     uint8_t *token_prob = probs[i][zero_nhood];

Some files were not shown because too many files changed in this diff