Revision 158b3912

View differences:

libavcodec/aac.c
86 86
#include "aactab.h"
87 87
#include "aacdectab.h"
88 88
#include "mpeg4audio.h"
89
#include "aac_parser.h"
89 90

  
90 91
#include <assert.h>
91 92
#include <errno.h>
......
384 385

  
385 386
    ac->avccontext = avccontext;
386 387

  
387
    if (avccontext->extradata_size <= 0 ||
388
        decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size))
388
    if (avccontext->extradata_size > 0) {
389
        if(decode_audio_specific_config(ac, avccontext->extradata, avccontext->extradata_size))
390
            return -1;
391
        avccontext->sample_rate = ac->m4ac.sample_rate;
392
    } else if (avccontext->channels > 0) {
393
        enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];
394
        memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
395
        if(set_default_channel_config(ac, new_che_pos, avccontext->channels - (avccontext->channels == 8)))
396
            return -1;
397
        if(output_configure(ac, ac->che_pos, new_che_pos))
398
            return -1;
399
        ac->m4ac.sample_rate = avccontext->sample_rate;
400
    } else {
401
        ff_log_missing_feature(ac->avccontext, "Implicit channel configuration is", 0);
389 402
        return -1;
403
    }
390 404

  
391 405
    avccontext->sample_fmt  = SAMPLE_FMT_S16;
392
    avccontext->sample_rate = ac->m4ac.sample_rate;
393 406
    avccontext->frame_size  = 1024;
394 407

  
395 408
    AAC_INIT_VLC_STATIC( 0, 144);
......
1506 1519
    }
1507 1520
}
1508 1521

  
1522
static int parse_adts_frame_header(AACContext * ac, GetBitContext * gb) {
1523

  
1524
    int size;
1525
    AACADTSHeaderInfo hdr_info;
1526

  
1527
    size = ff_aac_parse_header(gb, &hdr_info);
1528
    if (size > 0) {
1529
        if (hdr_info.chan_config)
1530
            ac->m4ac.chan_config = hdr_info.chan_config;
1531
        ac->m4ac.sample_rate     = hdr_info.sample_rate;
1532
        ac->m4ac.sampling_index  = hdr_info.sampling_index;
1533
        ac->m4ac.object_type     = hdr_info.object_type;
1534
    }
1535
    if (hdr_info.num_aac_frames == 1) {
1536
        if (!hdr_info.crc_absent)
1537
            skip_bits(gb, 16);
1538
    } else {
1539
        ff_log_missing_feature(ac->avccontext, "More than one AAC RDB per ADTS frame is", 0);
1540
        return -1;
1541
    }
1542
    return size;
1543
}
1544

  
1509 1545
static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data_size, const uint8_t * buf, int buf_size) {
1510 1546
    AACContext * ac = avccontext->priv_data;
1511 1547
    GetBitContext gb;
......
1514 1550

  
1515 1551
    init_get_bits(&gb, buf, buf_size*8);
1516 1552

  
1553
    if (show_bits(&gb, 12) == 0xfff) {
1554
        if ((err = parse_adts_frame_header(ac, &gb)) < 0) {
1555
            av_log(avccontext, AV_LOG_ERROR, "Error decoding AAC frame header.\n");
1556
            return -1;
1557
        }
1558
    }
1559

  
1517 1560
    // parse
1518 1561
    while ((elem_type = get_bits(&gb, 3)) != TYPE_END) {
1519 1562
        elem_id = get_bits(&gb, 4);
libavcodec/aac_parser.c
22 22

  
23 23
#include "parser.h"
24 24
#include "aac_ac3_parser.h"
25
#include "aac_parser.h"
25 26
#include "bitstream.h"
26 27
#include "mpeg4audio.h"
27 28

  
28 29
#define AAC_HEADER_SIZE 7
29 30

  
31
int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
32
{
33
    int size, rdb, ch, sr;
34
    int aot, crc_abs;
35

  
36
    if(get_bits(gbc, 12) != 0xfff)
37
        return AAC_AC3_PARSE_ERROR_SYNC;
38

  
39
    skip_bits1(gbc);             /* id */
40
    skip_bits(gbc, 2);           /* layer */
41
    crc_abs = get_bits1(gbc);    /* protection_absent */
42
    aot     = get_bits(gbc, 2);  /* profile_objecttype */
43
    sr      = get_bits(gbc, 4);  /* sample_frequency_index */
44
    if(!ff_mpeg4audio_sample_rates[sr])
45
        return AAC_AC3_PARSE_ERROR_SAMPLE_RATE;
46
    skip_bits1(gbc);             /* private_bit */
47
    ch      = get_bits(gbc, 3);  /* channel_configuration */
48

  
49
    if(!ff_mpeg4audio_channels[ch])
50
        return AAC_AC3_PARSE_ERROR_CHANNEL_CFG;
51

  
52
    skip_bits1(gbc);             /* original/copy */
53
    skip_bits1(gbc);             /* home */
54

  
55
    /* adts_variable_header */
56
    skip_bits1(gbc);             /* copyright_identification_bit */
57
    skip_bits1(gbc);             /* copyright_identification_start */
58
    size    = get_bits(gbc, 13); /* aac_frame_length */
59
    if(size < AAC_HEADER_SIZE)
60
        return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
61

  
62
    skip_bits(gbc, 11);          /* adts_buffer_fullness */
63
    rdb = get_bits(gbc, 2);      /* number_of_raw_data_blocks_in_frame */
64

  
65
    hdr->object_type    = aot;
66
    hdr->chan_config    = ch;
67
    hdr->crc_absent     = crc_abs;
68
    hdr->num_aac_frames = rdb + 1;
69
    hdr->sampling_index = sr;
70
    hdr->sample_rate    = ff_mpeg4audio_sample_rates[sr];
71
    hdr->samples        = (rdb + 1) * 1024;
72
    hdr->bit_rate       = size * 8 * hdr->sample_rate / hdr->samples;
73

  
74
    return size;
75
}
76

  
30 77
static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info,
31 78
        int *need_next_header, int *new_frame_start)
32 79
{
33 80
    GetBitContext bits;
34
    int size, rdb, ch, sr;
81
    AACADTSHeaderInfo hdr;
82
    int size;
35 83
    union {
36 84
        uint64_t u64;
37 85
        uint8_t  u8[8];
......
40 88
    tmp.u64 = be2me_64(state);
41 89
    init_get_bits(&bits, tmp.u8+8-AAC_HEADER_SIZE, AAC_HEADER_SIZE * 8);
42 90

  
43
    if(get_bits(&bits, 12) != 0xfff)
44
        return 0;
45

  
46
    skip_bits1(&bits);          /* id */
47
    skip_bits(&bits, 2);        /* layer */
48
    skip_bits1(&bits);          /* protection_absent */
49
    skip_bits(&bits, 2);        /* profile_objecttype */
50
    sr = get_bits(&bits, 4);    /* sample_frequency_index */
51
    if(!ff_mpeg4audio_sample_rates[sr])
52
        return 0;
53
    skip_bits1(&bits);          /* private_bit */
54
    ch = get_bits(&bits, 3);    /* channel_configuration */
55
    if(!ff_mpeg4audio_channels[ch])
91
    if ((size = ff_aac_parse_header(&bits, &hdr)) < 0)
56 92
        return 0;
57
    skip_bits1(&bits);          /* original/copy */
58
    skip_bits1(&bits);          /* home */
59

  
60
    /* adts_variable_header */
61
    skip_bits1(&bits);          /* copyright_identification_bit */
62
    skip_bits1(&bits);          /* copyright_identification_start */
63
    size = get_bits(&bits, 13); /* aac_frame_length */
64
    if(size < AAC_HEADER_SIZE)
65
        return 0;
66

  
67
    skip_bits(&bits, 11);       /* adts_buffer_fullness */
68
    rdb = get_bits(&bits, 2);   /* number_of_raw_data_blocks_in_frame */
69

  
70
    hdr_info->channels = ff_mpeg4audio_channels[ch];
71
    hdr_info->sample_rate = ff_mpeg4audio_sample_rates[sr];
72
    hdr_info->samples = (rdb + 1) * 1024;
73
    hdr_info->bit_rate = size * 8 * hdr_info->sample_rate / hdr_info->samples;
74

  
75 93
    *need_next_header = 0;
76 94
    *new_frame_start  = 1;
95
    hdr_info->sample_rate = hdr.sample_rate;
96
    hdr_info->channels    = ff_mpeg4audio_channels[hdr.chan_config];
97
    hdr_info->samples     = hdr.samples;
98
    hdr_info->bit_rate    = hdr.bit_rate;
77 99
    return size;
78 100
}
79 101

  
libavcodec/aac_parser.h
1
/*
2
 * AAC parser prototypes
3
 * Copyright (c) 2003 Fabrice Bellard
4
 * Copyright (c) 2003 Michael Niedermayer
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

  
23
#ifndef AVCODEC_AAC_PARSER_H
24
#define AVCODEC_AAC_PARSER_H
25

  
26
#include <stdint.h>
27
#include "aac_ac3_parser.h"
28
#include "bitstream.h"
29

  
30
typedef struct {
31
    uint32_t sample_rate;
32
    uint32_t samples;
33
    uint32_t bit_rate;
34
    uint8_t  crc_absent;
35
    uint8_t  object_type;
36
    uint8_t  sampling_index;
37
    uint8_t  chan_config;
38
    uint8_t  num_aac_frames;
39
} AACADTSHeaderInfo;
40

  
41
/**
42
 * Parses AAC frame header.
43
 * Parses the ADTS frame header to the end of the variable header, which is
44
 * the first 54 bits.
45
 * @param gbc[in] BitContext containing the first 54 bits of the frame.
46
 * @param hdr[out] Pointer to struct where header info is written.
47
 * @return Returns 0 on success, -1 if there is a sync word mismatch,
48
 * -2 if the version element is invalid, -3 if the sample rate
49
 * element is invalid, or -4 if the bit rate element is invalid.
50
 */
51
int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr);
52

  
53
#endif /* AVCODEC_AAC_PARSER_H */

Also available in: Unified diff