Mercurial > libavcodec.hg
comparison mlp_parser.c @ 7176:ae78650d4ac8 libavcodec
Make ff_mlp_read_major_sync() take a GetBitContext instead of buffers.
| author | ramiro |
|---|---|
| date | Tue, 01 Jul 2008 01:36:16 +0000 |
| parents | a9ed669e8cd1 |
| children | a82e7d9c8c34 |
comparison
equal
deleted
inserted
replaced
| 7175:4a635a1859f0 | 7176:ae78650d4ac8 |
|---|---|
| 86 } | 86 } |
| 87 | 87 |
| 88 /** Read a major sync info header - contains high level information about | 88 /** Read a major sync info header - contains high level information about |
| 89 * the stream - sample rate, channel arrangement etc. Most of this | 89 * the stream - sample rate, channel arrangement etc. Most of this |
| 90 * information is not actually necessary for decoding, only for playback. | 90 * information is not actually necessary for decoding, only for playback. |
| 91 * gb must be a freshly initialized GetBitContext with no bits read. | |
| 91 */ | 92 */ |
| 92 | 93 |
| 93 int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, const uint8_t *buf, | 94 int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb) |
| 94 unsigned int buf_size) | 95 { |
| 95 { | |
| 96 GetBitContext gb; | |
| 97 int ratebits; | 96 int ratebits; |
| 98 uint16_t checksum; | 97 uint16_t checksum; |
| 99 | 98 |
| 100 if (buf_size < 28) { | 99 assert(get_bits_count(gb) == 0); |
| 100 | |
| 101 if (gb->size_in_bits < 28 << 3) { | |
| 101 av_log(log, AV_LOG_ERROR, "Packet too short, unable to read major sync\n"); | 102 av_log(log, AV_LOG_ERROR, "Packet too short, unable to read major sync\n"); |
| 102 return -1; | 103 return -1; |
| 103 } | 104 } |
| 104 | 105 |
| 105 checksum = mlp_checksum16(buf, 26); | 106 checksum = mlp_checksum16(gb->buffer, 26); |
| 106 if (checksum != AV_RL16(buf+26)) { | 107 if (checksum != AV_RL16(gb->buffer+26)) { |
| 107 av_log(log, AV_LOG_ERROR, "Major sync info header checksum error\n"); | 108 av_log(log, AV_LOG_ERROR, "Major sync info header checksum error\n"); |
| 108 return -1; | 109 return -1; |
| 109 } | 110 } |
| 110 | 111 |
| 111 init_get_bits(&gb, buf, buf_size * 8); | 112 if (get_bits_long(gb, 24) != 0xf8726f) /* Sync words */ |
| 112 | |
| 113 if (get_bits_long(&gb, 24) != 0xf8726f) /* Sync words */ | |
| 114 return -1; | 113 return -1; |
| 115 | 114 |
| 116 mh->stream_type = get_bits(&gb, 8); | 115 mh->stream_type = get_bits(gb, 8); |
| 117 | 116 |
| 118 if (mh->stream_type == 0xbb) { | 117 if (mh->stream_type == 0xbb) { |
| 119 mh->group1_bits = mlp_quants[get_bits(&gb, 4)]; | 118 mh->group1_bits = mlp_quants[get_bits(gb, 4)]; |
| 120 mh->group2_bits = mlp_quants[get_bits(&gb, 4)]; | 119 mh->group2_bits = mlp_quants[get_bits(gb, 4)]; |
| 121 | 120 |
| 122 ratebits = get_bits(&gb, 4); | 121 ratebits = get_bits(gb, 4); |
| 123 mh->group1_samplerate = mlp_samplerate(ratebits); | 122 mh->group1_samplerate = mlp_samplerate(ratebits); |
| 124 mh->group2_samplerate = mlp_samplerate(get_bits(&gb, 4)); | 123 mh->group2_samplerate = mlp_samplerate(get_bits(gb, 4)); |
| 125 | 124 |
| 126 skip_bits(&gb, 11); | 125 skip_bits(gb, 11); |
| 127 | 126 |
| 128 mh->channels_mlp = get_bits(&gb, 5); | 127 mh->channels_mlp = get_bits(gb, 5); |
| 129 } else if (mh->stream_type == 0xba) { | 128 } else if (mh->stream_type == 0xba) { |
| 130 mh->group1_bits = 24; // TODO: Is this information actually conveyed anywhere? | 129 mh->group1_bits = 24; // TODO: Is this information actually conveyed anywhere? |
| 131 mh->group2_bits = 0; | 130 mh->group2_bits = 0; |
| 132 | 131 |
| 133 ratebits = get_bits(&gb, 4); | 132 ratebits = get_bits(gb, 4); |
| 134 mh->group1_samplerate = mlp_samplerate(ratebits); | 133 mh->group1_samplerate = mlp_samplerate(ratebits); |
| 135 mh->group2_samplerate = 0; | 134 mh->group2_samplerate = 0; |
| 136 | 135 |
| 137 skip_bits(&gb, 8); | 136 skip_bits(gb, 8); |
| 138 | 137 |
| 139 mh->channels_thd_stream1 = get_bits(&gb, 5); | 138 mh->channels_thd_stream1 = get_bits(gb, 5); |
| 140 | 139 |
| 141 skip_bits(&gb, 2); | 140 skip_bits(gb, 2); |
| 142 | 141 |
| 143 mh->channels_thd_stream2 = get_bits(&gb, 13); | 142 mh->channels_thd_stream2 = get_bits(gb, 13); |
| 144 } else | 143 } else |
| 145 return -1; | 144 return -1; |
| 146 | 145 |
| 147 mh->access_unit_size = 40 << (ratebits & 7); | 146 mh->access_unit_size = 40 << (ratebits & 7); |
| 148 mh->access_unit_size_pow2 = 64 << (ratebits & 7); | 147 mh->access_unit_size_pow2 = 64 << (ratebits & 7); |
| 149 | 148 |
| 150 skip_bits_long(&gb, 48); | 149 skip_bits_long(gb, 48); |
| 151 | 150 |
| 152 mh->is_vbr = get_bits1(&gb); | 151 mh->is_vbr = get_bits1(gb); |
| 153 | 152 |
| 154 mh->peak_bitrate = (get_bits(&gb, 15) * mh->group1_samplerate + 8) >> 4; | 153 mh->peak_bitrate = (get_bits(gb, 15) * mh->group1_samplerate + 8) >> 4; |
| 155 | 154 |
| 156 mh->num_substreams = get_bits(&gb, 4); | 155 mh->num_substreams = get_bits(gb, 4); |
| 157 | 156 |
| 158 skip_bits_long(&gb, 4 + 11 * 8); | 157 skip_bits_long(gb, 4 + 11 * 8); |
| 159 | 158 |
| 160 return 0; | 159 return 0; |
| 161 } | 160 } |
| 162 | 161 |
| 163 typedef struct MLPParseContext | 162 typedef struct MLPParseContext |
| 256 if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) { | 255 if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) { |
| 257 av_log(avctx, AV_LOG_INFO, "mlpparse: Parity check failed.\n"); | 256 av_log(avctx, AV_LOG_INFO, "mlpparse: Parity check failed.\n"); |
| 258 goto lost_sync; | 257 goto lost_sync; |
| 259 } | 258 } |
| 260 } else { | 259 } else { |
| 260 GetBitContext gb; | |
| 261 MLPHeaderInfo mh; | 261 MLPHeaderInfo mh; |
| 262 | 262 |
| 263 if (ff_mlp_read_major_sync(avctx, &mh, buf + 4, buf_size - 4) < 0) | 263 init_get_bits(&gb, buf + 4, (buf_size - 4) << 3); |
| 264 if (ff_mlp_read_major_sync(avctx, &mh, &gb) < 0) | |
| 264 goto lost_sync; | 265 goto lost_sync; |
| 265 | 266 |
| 266 #ifdef CONFIG_AUDIO_NONSHORT | 267 #ifdef CONFIG_AUDIO_NONSHORT |
| 267 avctx->bits_per_sample = mh.group1_bits; | 268 avctx->bits_per_sample = mh.group1_bits; |
| 268 if (avctx->bits_per_sample > 16) | 269 if (avctx->bits_per_sample > 16) |
