Revision 9ef60390 libavcodec/ac3dec.c

View differences:

libavcodec/ac3dec.c
320 320
}
321 321
/*********** END INIT FUNCTIONS ***********/
322 322

  
323
/* Synchronize to ac3 bitstream.
324
 * This function searches for the syncword '0xb77'.
325
 *
326
 * @param buf Pointer to "probable" ac3 bitstream buffer
327
 * @param buf_size Size of buffer
328
 * @return Returns the position where syncword is found, -1 if no syncword is found
329
 */
330
static int ac3_synchronize(uint8_t *buf, int buf_size)
331
{
332
    int i;
333

  
334
    for (i = 0; i < buf_size - 1; i++)
335
        if (buf[i] == 0x0b && buf[i + 1] == 0x77)
336
            return i;
337

  
338
    return -1;
339
}
340

  
341 323
/* Parse the 'sync_info' from the ac3 bitstream.
342 324
 * This function extracts the sync_info from ac3 bitstream.
343 325
 * GetBitContext within AC3DecodeContext must point to
......
1645 1627
static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
1646 1628
{
1647 1629
    AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data;
1648
    int frame_start;
1649 1630
    int16_t *out_samples = (int16_t *)data;
1650 1631
    int i, j, k, start;
1651 1632
    int32_t *int_ptr[6];
......
1653 1634
    for (i = 0; i < 6; i++)
1654 1635
        int_ptr[i] = (int32_t *)(&ctx->output[i]);
1655 1636

  
1656
    //Synchronize the frame.
1657
    frame_start = ac3_synchronize(buf, buf_size);
1658
    if (frame_start == -1) {
1659
        av_log(avctx, AV_LOG_ERROR, "frame is not synchronized\n");
1660
        *data_size = 0;
1661
        return buf_size;
1662
    }
1663

  
1664 1637
    //Initialize the GetBitContext with the start of valid AC3 Frame.
1665
    init_get_bits(&(ctx->gb), buf + frame_start, (buf_size - frame_start) * 8);
1638
    init_get_bits(&ctx->gb, buf, buf_size * 8);
1666 1639

  
1667 1640
    //Parse the syncinfo.
1668 1641
    //If 'fscod' or 'bsid' is not valid the decoder shall mute as per the standard.

Also available in: Unified diff