Skip to content

Commit

Permalink
Merge remote-tracking branch 'newdev/master'
Browse files Browse the repository at this point in the history
Merged-by: Michael Niedermayer <[email protected]>
  • Loading branch information
michaelni committed Mar 15, 2011
2 parents 27293b8 + c76374c commit 6947b0c
Show file tree
Hide file tree
Showing 31 changed files with 214 additions and 79 deletions.
16 changes: 16 additions & 0 deletions doc/protocols.texi
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion ffplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 37 additions & 0 deletions libavcodec/ac3dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions libavcodec/ac3dsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 12 additions & 13 deletions libavcodec/ac3enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1139,15 +1138,15 @@ 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;

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:
Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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);
Expand Down
52 changes: 21 additions & 31 deletions libavcodec/ac3enc_fixed.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ static av_cold int mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct,


/** 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; \
}


Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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]);
}
}
}


Expand Down
2 changes: 2 additions & 0 deletions libavcodec/ac3enc_fixed.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions libavcodec/ac3enc_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion libavcodec/h264_mp4toannexb_bsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/vp8.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ static int decode_block_coeffs_internal(VP56RangeCoder *c, DCTELEM block[16],

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];
Expand Down
45 changes: 45 additions & 0 deletions libavcodec/x86/ac3dsp.asm
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,48 @@ INIT_XMM
AC3_MAX_MSB_ABS_INT16 sse2, min_max
%define ABS2 ABS2_SSSE3
AC3_MAX_MSB_ABS_INT16 ssse3, or_abs

;-----------------------------------------------------------------------------
; macro used for ff_ac3_lshift_int16() and ff_ac3_rshift_int32()
;-----------------------------------------------------------------------------

%macro AC3_SHIFT 4 ; l/r, 16/32, shift instruction, instruction set
cglobal ac3_%1shift_int%2_%4, 3,3,5, src, len, shift
movd m0, shiftd
.loop:
mova m1, [srcq ]
mova m2, [srcq+mmsize ]
mova m3, [srcq+mmsize*2]
mova m4, [srcq+mmsize*3]
%3 m1, m0
%3 m2, m0
%3 m3, m0
%3 m4, m0
mova [srcq ], m1
mova [srcq+mmsize ], m2
mova [srcq+mmsize*2], m3
mova [srcq+mmsize*3], m4
add srcq, mmsize*4
sub lend, mmsize*32/%2
ja .loop
.end:
REP_RET
%endmacro

;-----------------------------------------------------------------------------
; void ff_ac3_lshift_int16(int16_t *src, unsigned int len, unsigned int shift)
;-----------------------------------------------------------------------------

INIT_MMX
AC3_SHIFT l, 16, psllw, mmx
INIT_XMM
AC3_SHIFT l, 16, psllw, sse2

;-----------------------------------------------------------------------------
; void ff_ac3_rshift_int32(int32_t *src, unsigned int len, unsigned int shift)
;-----------------------------------------------------------------------------

INIT_MMX
AC3_SHIFT r, 32, psrad, mmx
INIT_XMM
AC3_SHIFT r, 32, psrad, sse2
Loading

0 comments on commit 6947b0c

Please sign in to comment.