comparison ac3_parser.c @ 6005:7d9dddd54817 libavcodec

cosmetics: rename common ac3 variables
author jbr
date Sun, 09 Dec 2007 03:27:14 +0000
parents 608c8e9ac412
children 4f8fcb40bf2c
comparison
equal deleted inserted replaced
6004:713d66164428 6005:7d9dddd54817
45 hdr->sync_word = get_bits(&gbc, 16); 45 hdr->sync_word = get_bits(&gbc, 16);
46 if(hdr->sync_word != 0x0B77) 46 if(hdr->sync_word != 0x0B77)
47 return AC3_PARSE_ERROR_SYNC; 47 return AC3_PARSE_ERROR_SYNC;
48 48
49 /* read ahead to bsid to make sure this is AC-3, not E-AC-3 */ 49 /* read ahead to bsid to make sure this is AC-3, not E-AC-3 */
50 hdr->bsid = show_bits_long(&gbc, 29) & 0x1F; 50 hdr->bitstream_id = show_bits_long(&gbc, 29) & 0x1F;
51 if(hdr->bsid > 10) 51 if(hdr->bitstream_id > 10)
52 return AC3_PARSE_ERROR_BSID; 52 return AC3_PARSE_ERROR_BSID;
53 53
54 hdr->crc1 = get_bits(&gbc, 16); 54 hdr->crc1 = get_bits(&gbc, 16);
55 hdr->sr_code = get_bits(&gbc, 2); 55 hdr->sr_code = get_bits(&gbc, 2);
56 if(hdr->sr_code == 3) 56 if(hdr->sr_code == 3)
57 return AC3_PARSE_ERROR_SAMPLE_RATE; 57 return AC3_PARSE_ERROR_SAMPLE_RATE;
58 58
59 hdr->frmsizecod = get_bits(&gbc, 6); 59 hdr->frame_size_code = get_bits(&gbc, 6);
60 if(hdr->frmsizecod > 37) 60 if(hdr->frame_size_code > 37)
61 return AC3_PARSE_ERROR_FRAME_SIZE; 61 return AC3_PARSE_ERROR_FRAME_SIZE;
62 62
63 skip_bits(&gbc, 5); // skip bsid, already got it 63 skip_bits(&gbc, 5); // skip bsid, already got it
64 64
65 hdr->bsmod = get_bits(&gbc, 3); 65 hdr->bitstream_mode = get_bits(&gbc, 3);
66 hdr->acmod = get_bits(&gbc, 3); 66 hdr->channel_mode = get_bits(&gbc, 3);
67 if((hdr->acmod & 1) && hdr->acmod != AC3_ACMOD_MONO) { 67 if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO) {
68 hdr->cmixlev = get_bits(&gbc, 2); 68 hdr->center_mix_level = get_bits(&gbc, 2);
69 } 69 }
70 if(hdr->acmod & 4) { 70 if(hdr->channel_mode & 4) {
71 hdr->surmixlev = get_bits(&gbc, 2); 71 hdr->surround_mix_level = get_bits(&gbc, 2);
72 } 72 }
73 if(hdr->acmod == AC3_ACMOD_STEREO) { 73 if(hdr->channel_mode == AC3_CHMODE_STEREO) {
74 hdr->dsurmod = get_bits(&gbc, 2); 74 hdr->dolby_surround_mode = get_bits(&gbc, 2);
75 } 75 }
76 hdr->lfeon = get_bits1(&gbc); 76 hdr->lfe_on = get_bits1(&gbc);
77 77
78 hdr->sr_shift = FFMAX(hdr->bsid, 8) - 8; 78 hdr->sr_shift = FFMAX(hdr->bitstream_id, 8) - 8;
79 hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code] >> hdr->sr_shift; 79 hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code] >> hdr->sr_shift;
80 hdr->bit_rate = (ff_ac3_bitrate_tab[hdr->frmsizecod>>1] * 1000) >> hdr->sr_shift; 80 hdr->bit_rate = (ff_ac3_bitrate_tab[hdr->frame_size_code>>1] * 1000) >> hdr->sr_shift;
81 hdr->channels = ff_ac3_channels_tab[hdr->acmod] + hdr->lfeon; 81 hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on;
82 hdr->frame_size = ff_ac3_frame_size_tab[hdr->frmsizecod][hdr->sr_code] * 2; 82 hdr->frame_size = ff_ac3_frame_size_tab[hdr->frame_size_code][hdr->sr_code] * 2;
83 83
84 return 0; 84 return 0;
85 } 85 }
86 86
87 static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate, 87 static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate,
88 int *bit_rate, int *samples) 88 int *bit_rate, int *samples)
89 { 89 {
90 int err; 90 int err;
91 unsigned int sr_code, acmod, bsid, lfeon; 91 unsigned int sr_code, channel_mode, bitstream_id, lfe_on;
92 unsigned int strmtyp, substreamid, frmsiz, sr_code2, numblkscod; 92 unsigned int stream_type, substream_id, frame_size, sr_code2, num_blocks_code;
93 GetBitContext bits; 93 GetBitContext bits;
94 AC3HeaderInfo hdr; 94 AC3HeaderInfo hdr;
95 95
96 err = ff_ac3_parse_header(buf, &hdr); 96 err = ff_ac3_parse_header(buf, &hdr);
97 97
98 if(err < 0 && err != -2) 98 if(err < 0 && err != -2)
99 return 0; 99 return 0;
100 100
101 bsid = hdr.bsid; 101 bitstream_id = hdr.bitstream_id;
102 if(bsid <= 10) { /* Normal AC-3 */ 102 if(bitstream_id <= 10) { /* Normal AC-3 */
103 *sample_rate = hdr.sample_rate; 103 *sample_rate = hdr.sample_rate;
104 *bit_rate = hdr.bit_rate; 104 *bit_rate = hdr.bit_rate;
105 *channels = hdr.channels; 105 *channels = hdr.channels;
106 *samples = AC3_FRAME_SIZE; 106 *samples = AC3_FRAME_SIZE;
107 return hdr.frame_size; 107 return hdr.frame_size;
108 } else if (bsid > 10 && bsid <= 16) { /* Enhanced AC-3 */ 108 } else if (bitstream_id > 10 && bitstream_id <= 16) { /* Enhanced AC-3 */
109 init_get_bits(&bits, &buf[2], (AC3_HEADER_SIZE-2) * 8); 109 init_get_bits(&bits, &buf[2], (AC3_HEADER_SIZE-2) * 8);
110 strmtyp = get_bits(&bits, 2); 110 stream_type = get_bits(&bits, 2);
111 substreamid = get_bits(&bits, 3); 111 substream_id = get_bits(&bits, 3);
112 112
113 if (strmtyp != 0 || substreamid != 0) 113 if (stream_type != 0 || substream_id != 0)
114 return 0; /* Currently don't support additional streams */ 114 return 0; /* Currently don't support additional streams */
115 115
116 frmsiz = get_bits(&bits, 11) + 1; 116 frame_size = get_bits(&bits, 11) + 1;
117 if(frmsiz*2 < AC3_HEADER_SIZE) 117 if(frame_size*2 < AC3_HEADER_SIZE)
118 return 0; 118 return 0;
119 119
120 sr_code = get_bits(&bits, 2); 120 sr_code = get_bits(&bits, 2);
121 if (sr_code == 3) { 121 if (sr_code == 3) {
122 sr_code2 = get_bits(&bits, 2); 122 sr_code2 = get_bits(&bits, 2);
123 numblkscod = 3; 123 num_blocks_code = 3;
124 124
125 if(sr_code2 == 3) 125 if(sr_code2 == 3)
126 return 0; 126 return 0;
127 127
128 *sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2; 128 *sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2;
129 } else { 129 } else {
130 numblkscod = get_bits(&bits, 2); 130 num_blocks_code = get_bits(&bits, 2);
131 131
132 *sample_rate = ff_ac3_sample_rate_tab[sr_code]; 132 *sample_rate = ff_ac3_sample_rate_tab[sr_code];
133 } 133 }
134 134
135 acmod = get_bits(&bits, 3); 135 channel_mode = get_bits(&bits, 3);
136 lfeon = get_bits1(&bits); 136 lfe_on = get_bits1(&bits);
137 137
138 *samples = eac3_blocks[numblkscod] * 256; 138 *samples = eac3_blocks[num_blocks_code] * 256;
139 *bit_rate = frmsiz * (*sample_rate) * 16 / (*samples); 139 *bit_rate = frame_size * (*sample_rate) * 16 / (*samples);
140 *channels = ff_ac3_channels_tab[acmod] + lfeon; 140 *channels = ff_ac3_channels_tab[channel_mode] + lfe_on;
141 141
142 return frmsiz * 2; 142 return frame_size * 2;
143 } 143 }
144 144
145 /* Unsupported bitstream version */ 145 /* Unsupported bitstream version */
146 return 0; 146 return 0;
147 } 147 }