avc_utils.cpp revision 91fe76a157847825601b8f7a627efd1c9cbadcae
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18#define LOG_TAG "avc_utils"
19#include <utils/Log.h>
20
21#include "include/avc_utils.h"
22
23#include <media/stagefright/foundation/ABitReader.h>
24#include <media/stagefright/foundation/ADebug.h>
25#include <media/stagefright/foundation/hexdump.h>
26#include <media/stagefright/MediaDefs.h>
27#include <media/stagefright/MediaErrors.h>
28#include <media/stagefright/MetaData.h>
29
30namespace android {
31
32unsigned parseUE(ABitReader *br) {
33    unsigned numZeroes = 0;
34    while (br->getBits(1) == 0) {
35        ++numZeroes;
36    }
37
38    unsigned x = br->getBits(numZeroes);
39
40    return x + (1u << numZeroes) - 1;
41}
42
43signed parseSE(ABitReader *br) {
44    unsigned codeNum = parseUE(br);
45
46    return (codeNum & 1) ? (codeNum + 1) / 2 : -(codeNum / 2);
47}
48
49static void skipScalingList(ABitReader *br, size_t sizeOfScalingList) {
50    size_t lastScale = 8;
51    size_t nextScale = 8;
52    for (size_t j = 0; j < sizeOfScalingList; ++j) {
53        if (nextScale != 0) {
54            signed delta_scale = parseSE(br);
55            nextScale = (lastScale + delta_scale + 256) % 256;
56        }
57
58        lastScale = (nextScale == 0) ? lastScale : nextScale;
59    }
60}
61
62// Determine video dimensions from the sequence parameterset.
63void FindAVCDimensions(
64        const sp<ABuffer> &seqParamSet,
65        int32_t *width, int32_t *height,
66        int32_t *sarWidth, int32_t *sarHeight) {
67    ABitReader br(seqParamSet->data() + 1, seqParamSet->size() - 1);
68
69    unsigned profile_idc = br.getBits(8);
70    br.skipBits(16);
71    parseUE(&br);  // seq_parameter_set_id
72
73    unsigned chroma_format_idc = 1;  // 4:2:0 chroma format
74
75    if (profile_idc == 100 || profile_idc == 110
76            || profile_idc == 122 || profile_idc == 244
77            || profile_idc == 44 || profile_idc == 83 || profile_idc == 86) {
78        chroma_format_idc = parseUE(&br);
79        if (chroma_format_idc == 3) {
80            br.skipBits(1);  // residual_colour_transform_flag
81        }
82        parseUE(&br);  // bit_depth_luma_minus8
83        parseUE(&br);  // bit_depth_chroma_minus8
84        br.skipBits(1);  // qpprime_y_zero_transform_bypass_flag
85
86        if (br.getBits(1)) {  // seq_scaling_matrix_present_flag
87            for (size_t i = 0; i < 8; ++i) {
88                if (br.getBits(1)) {  // seq_scaling_list_present_flag[i]
89
90                    // WARNING: the code below has not ever been exercised...
91                    // need a real-world example.
92
93                    if (i < 6) {
94                        // ScalingList4x4[i],16,...
95                        skipScalingList(&br, 16);
96                    } else {
97                        // ScalingList8x8[i-6],64,...
98                        skipScalingList(&br, 64);
99                    }
100                }
101            }
102        }
103    }
104
105    parseUE(&br);  // log2_max_frame_num_minus4
106    unsigned pic_order_cnt_type = parseUE(&br);
107
108    if (pic_order_cnt_type == 0) {
109        parseUE(&br);  // log2_max_pic_order_cnt_lsb_minus4
110    } else if (pic_order_cnt_type == 1) {
111        // offset_for_non_ref_pic, offset_for_top_to_bottom_field and
112        // offset_for_ref_frame are technically se(v), but since we are
113        // just skipping over them the midpoint does not matter.
114
115        br.getBits(1);  // delta_pic_order_always_zero_flag
116        parseUE(&br);  // offset_for_non_ref_pic
117        parseUE(&br);  // offset_for_top_to_bottom_field
118
119        unsigned num_ref_frames_in_pic_order_cnt_cycle = parseUE(&br);
120        for (unsigned i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; ++i) {
121            parseUE(&br);  // offset_for_ref_frame
122        }
123    }
124
125    parseUE(&br);  // num_ref_frames
126    br.getBits(1);  // gaps_in_frame_num_value_allowed_flag
127
128    unsigned pic_width_in_mbs_minus1 = parseUE(&br);
129    unsigned pic_height_in_map_units_minus1 = parseUE(&br);
130    unsigned frame_mbs_only_flag = br.getBits(1);
131
132    *width = pic_width_in_mbs_minus1 * 16 + 16;
133
134    *height = (2 - frame_mbs_only_flag)
135        * (pic_height_in_map_units_minus1 * 16 + 16);
136
137    if (!frame_mbs_only_flag) {
138        br.getBits(1);  // mb_adaptive_frame_field_flag
139    }
140
141    br.getBits(1);  // direct_8x8_inference_flag
142
143    if (br.getBits(1)) {  // frame_cropping_flag
144        unsigned frame_crop_left_offset = parseUE(&br);
145        unsigned frame_crop_right_offset = parseUE(&br);
146        unsigned frame_crop_top_offset = parseUE(&br);
147        unsigned frame_crop_bottom_offset = parseUE(&br);
148
149        unsigned cropUnitX, cropUnitY;
150        if (chroma_format_idc == 0  /* monochrome */) {
151            cropUnitX = 1;
152            cropUnitY = 2 - frame_mbs_only_flag;
153        } else {
154            unsigned subWidthC = (chroma_format_idc == 3) ? 1 : 2;
155            unsigned subHeightC = (chroma_format_idc == 1) ? 2 : 1;
156
157            cropUnitX = subWidthC;
158            cropUnitY = subHeightC * (2 - frame_mbs_only_flag);
159        }
160
161        ALOGV("frame_crop = (%u, %u, %u, %u), cropUnitX = %u, cropUnitY = %u",
162             frame_crop_left_offset, frame_crop_right_offset,
163             frame_crop_top_offset, frame_crop_bottom_offset,
164             cropUnitX, cropUnitY);
165
166        *width -=
167            (frame_crop_left_offset + frame_crop_right_offset) * cropUnitX;
168        *height -=
169            (frame_crop_top_offset + frame_crop_bottom_offset) * cropUnitY;
170    }
171
172    if (sarWidth != NULL) {
173        *sarWidth = 0;
174    }
175
176    if (sarHeight != NULL) {
177        *sarHeight = 0;
178    }
179
180    if (br.getBits(1)) {  // vui_parameters_present_flag
181        unsigned sar_width = 0, sar_height = 0;
182
183        if (br.getBits(1)) {  // aspect_ratio_info_present_flag
184            unsigned aspect_ratio_idc = br.getBits(8);
185
186            if (aspect_ratio_idc == 255 /* extendedSAR */) {
187                sar_width = br.getBits(16);
188                sar_height = br.getBits(16);
189            } else if (aspect_ratio_idc > 0 && aspect_ratio_idc < 14) {
190                static const int32_t kFixedSARWidth[] = {
191                    1, 12, 10, 16, 40, 24, 20, 32, 80, 18, 15, 64, 160
192                };
193
194                static const int32_t kFixedSARHeight[] = {
195                    1, 11, 11, 11, 33, 11, 11, 11, 33, 11, 11, 33, 99
196                };
197
198                sar_width = kFixedSARWidth[aspect_ratio_idc - 1];
199                sar_height = kFixedSARHeight[aspect_ratio_idc - 1];
200            }
201        }
202
203        ALOGV("sample aspect ratio = %u : %u", sar_width, sar_height);
204
205        if (sarWidth != NULL) {
206            *sarWidth = sar_width;
207        }
208
209        if (sarHeight != NULL) {
210            *sarHeight = sar_height;
211        }
212    }
213}
214
215status_t getNextNALUnit(
216        const uint8_t **_data, size_t *_size,
217        const uint8_t **nalStart, size_t *nalSize,
218        bool startCodeFollows) {
219    const uint8_t *data = *_data;
220    size_t size = *_size;
221
222    *nalStart = NULL;
223    *nalSize = 0;
224
225    if (size == 0) {
226        return -EAGAIN;
227    }
228
229    // Skip any number of leading 0x00.
230
231    size_t offset = 0;
232    while (offset < size && data[offset] == 0x00) {
233        ++offset;
234    }
235
236    if (offset == size) {
237        return -EAGAIN;
238    }
239
240    // A valid startcode consists of at least two 0x00 bytes followed by 0x01.
241
242    if (offset < 2 || data[offset] != 0x01) {
243        return ERROR_MALFORMED;
244    }
245
246    ++offset;
247
248    size_t startOffset = offset;
249
250    for (;;) {
251        while (offset < size && data[offset] != 0x01) {
252            ++offset;
253        }
254
255        if (offset == size) {
256            if (startCodeFollows) {
257                offset = size + 2;
258                break;
259            }
260
261            return -EAGAIN;
262        }
263
264        if (data[offset - 1] == 0x00 && data[offset - 2] == 0x00) {
265            break;
266        }
267
268        ++offset;
269    }
270
271    size_t endOffset = offset - 2;
272    while (endOffset > startOffset + 1 && data[endOffset - 1] == 0x00) {
273        --endOffset;
274    }
275
276    *nalStart = &data[startOffset];
277    *nalSize = endOffset - startOffset;
278
279    if (offset + 2 < size) {
280        *_data = &data[offset - 2];
281        *_size = size - offset + 2;
282    } else {
283        *_data = NULL;
284        *_size = 0;
285    }
286
287    return OK;
288}
289
290static sp<ABuffer> FindNAL(const uint8_t *data, size_t size, unsigned nalType) {
291    const uint8_t *nalStart;
292    size_t nalSize;
293    while (getNextNALUnit(&data, &size, &nalStart, &nalSize, true) == OK) {
294        if ((nalStart[0] & 0x1f) == nalType) {
295            sp<ABuffer> buffer = new ABuffer(nalSize);
296            memcpy(buffer->data(), nalStart, nalSize);
297            return buffer;
298        }
299    }
300
301    return NULL;
302}
303
304const char *AVCProfileToString(uint8_t profile) {
305    switch (profile) {
306        case kAVCProfileBaseline:
307            return "Baseline";
308        case kAVCProfileMain:
309            return "Main";
310        case kAVCProfileExtended:
311            return "Extended";
312        case kAVCProfileHigh:
313            return "High";
314        case kAVCProfileHigh10:
315            return "High 10";
316        case kAVCProfileHigh422:
317            return "High 422";
318        case kAVCProfileHigh444:
319            return "High 444";
320        case kAVCProfileCAVLC444Intra:
321            return "CAVLC 444 Intra";
322        default:   return "Unknown";
323    }
324}
325
326sp<MetaData> MakeAVCCodecSpecificData(const sp<ABuffer> &accessUnit) {
327    const uint8_t *data = accessUnit->data();
328    size_t size = accessUnit->size();
329
330    sp<ABuffer> seqParamSet = FindNAL(data, size, 7);
331    if (seqParamSet == NULL) {
332        return NULL;
333    }
334
335    int32_t width, height;
336    int32_t sarWidth, sarHeight;
337    FindAVCDimensions(
338            seqParamSet, &width, &height, &sarWidth, &sarHeight);
339
340    sp<ABuffer> picParamSet = FindNAL(data, size, 8);
341    CHECK(picParamSet != NULL);
342
343    size_t csdSize =
344        1 + 3 + 1 + 1
345        + 2 * 1 + seqParamSet->size()
346        + 1 + 2 * 1 + picParamSet->size();
347
348    sp<ABuffer> csd = new ABuffer(csdSize);
349    uint8_t *out = csd->data();
350
351    *out++ = 0x01;  // configurationVersion
352    memcpy(out, seqParamSet->data() + 1, 3);  // profile/level...
353
354    uint8_t profile = out[0];
355    uint8_t level = out[2];
356
357    out += 3;
358    *out++ = (0x3f << 2) | 1;  // lengthSize == 2 bytes
359    *out++ = 0xe0 | 1;
360
361    *out++ = seqParamSet->size() >> 8;
362    *out++ = seqParamSet->size() & 0xff;
363    memcpy(out, seqParamSet->data(), seqParamSet->size());
364    out += seqParamSet->size();
365
366    *out++ = 1;
367
368    *out++ = picParamSet->size() >> 8;
369    *out++ = picParamSet->size() & 0xff;
370    memcpy(out, picParamSet->data(), picParamSet->size());
371
372#if 0
373    ALOGI("AVC seq param set");
374    hexdump(seqParamSet->data(), seqParamSet->size());
375#endif
376
377    sp<MetaData> meta = new MetaData;
378    meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC);
379
380    meta->setData(kKeyAVCC, kTypeAVCC, csd->data(), csd->size());
381    meta->setInt32(kKeyWidth, width);
382    meta->setInt32(kKeyHeight, height);
383
384    if (sarWidth > 1 || sarHeight > 1) {
385        // We treat 0:0 (unspecified) as 1:1.
386
387        meta->setInt32(kKeySARWidth, sarWidth);
388        meta->setInt32(kKeySARHeight, sarHeight);
389
390        ALOGI("found AVC codec config (%d x %d, %s-profile level %d.%d) "
391              "SAR %d : %d",
392             width,
393             height,
394             AVCProfileToString(profile),
395             level / 10,
396             level % 10,
397             sarWidth,
398             sarHeight);
399    } else {
400        ALOGI("found AVC codec config (%d x %d, %s-profile level %d.%d)",
401             width,
402             height,
403             AVCProfileToString(profile),
404             level / 10,
405             level % 10);
406    }
407
408    return meta;
409}
410
411bool IsIDR(const sp<ABuffer> &buffer) {
412    const uint8_t *data = buffer->data();
413    size_t size = buffer->size();
414
415    bool foundIDR = false;
416
417    const uint8_t *nalStart;
418    size_t nalSize;
419    while (getNextNALUnit(&data, &size, &nalStart, &nalSize, true) == OK) {
420        if (nalSize == 0u) {
421            ALOGW("skipping empty nal unit from potentially malformed bitstream");
422            continue;
423        }
424
425        unsigned nalType = nalStart[0] & 0x1f;
426
427        if (nalType == 5) {
428            foundIDR = true;
429            break;
430        }
431    }
432
433    return foundIDR;
434}
435
436bool IsAVCReferenceFrame(const sp<ABuffer> &accessUnit) {
437    const uint8_t *data = accessUnit->data();
438    size_t size = accessUnit->size();
439
440    const uint8_t *nalStart;
441    size_t nalSize;
442    while (getNextNALUnit(&data, &size, &nalStart, &nalSize, true) == OK) {
443        CHECK_GT(nalSize, 0u);
444
445        unsigned nalType = nalStart[0] & 0x1f;
446
447        if (nalType == 5) {
448            return true;
449        } else if (nalType == 1) {
450            unsigned nal_ref_idc = (nalStart[0] >> 5) & 3;
451            return nal_ref_idc != 0;
452        }
453    }
454
455    return true;
456}
457
458sp<MetaData> MakeAACCodecSpecificData(
459        unsigned profile, unsigned sampling_freq_index,
460        unsigned channel_configuration) {
461    sp<MetaData> meta = new MetaData;
462    meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_AAC);
463
464    CHECK_LE(sampling_freq_index, 11u);
465    static const int32_t kSamplingFreq[] = {
466        96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
467        16000, 12000, 11025, 8000
468    };
469    meta->setInt32(kKeySampleRate, kSamplingFreq[sampling_freq_index]);
470    meta->setInt32(kKeyChannelCount, channel_configuration);
471
472    static const uint8_t kStaticESDS[] = {
473        0x03, 22,
474        0x00, 0x00,     // ES_ID
475        0x00,           // streamDependenceFlag, URL_Flag, OCRstreamFlag
476
477        0x04, 17,
478        0x40,                       // Audio ISO/IEC 14496-3
479        0x00, 0x00, 0x00, 0x00,
480        0x00, 0x00, 0x00, 0x00,
481        0x00, 0x00, 0x00, 0x00,
482
483        0x05, 2,
484        // AudioSpecificInfo follows
485
486        // oooo offf fccc c000
487        // o - audioObjectType
488        // f - samplingFreqIndex
489        // c - channelConfig
490    };
491    sp<ABuffer> csd = new ABuffer(sizeof(kStaticESDS) + 2);
492    memcpy(csd->data(), kStaticESDS, sizeof(kStaticESDS));
493
494    csd->data()[sizeof(kStaticESDS)] =
495        ((profile + 1) << 3) | (sampling_freq_index >> 1);
496
497    csd->data()[sizeof(kStaticESDS) + 1] =
498        ((sampling_freq_index << 7) & 0x80) | (channel_configuration << 3);
499
500    meta->setData(kKeyESDS, 0, csd->data(), csd->size());
501
502    return meta;
503}
504
505bool ExtractDimensionsFromVOLHeader(
506        const uint8_t *data, size_t size, int32_t *width, int32_t *height) {
507    ABitReader br(&data[4], size - 4);
508    br.skipBits(1);  // random_accessible_vol
509    unsigned video_object_type_indication = br.getBits(8);
510
511    CHECK_NE(video_object_type_indication,
512             0x21u /* Fine Granularity Scalable */);
513
514    unsigned video_object_layer_verid;
515    unsigned video_object_layer_priority;
516    if (br.getBits(1)) {
517        video_object_layer_verid = br.getBits(4);
518        video_object_layer_priority = br.getBits(3);
519    }
520    unsigned aspect_ratio_info = br.getBits(4);
521    if (aspect_ratio_info == 0x0f /* extended PAR */) {
522        br.skipBits(8);  // par_width
523        br.skipBits(8);  // par_height
524    }
525    if (br.getBits(1)) {  // vol_control_parameters
526        br.skipBits(2);  // chroma_format
527        br.skipBits(1);  // low_delay
528        if (br.getBits(1)) {  // vbv_parameters
529            br.skipBits(15);  // first_half_bit_rate
530            CHECK(br.getBits(1));  // marker_bit
531            br.skipBits(15);  // latter_half_bit_rate
532            CHECK(br.getBits(1));  // marker_bit
533            br.skipBits(15);  // first_half_vbv_buffer_size
534            CHECK(br.getBits(1));  // marker_bit
535            br.skipBits(3);  // latter_half_vbv_buffer_size
536            br.skipBits(11);  // first_half_vbv_occupancy
537            CHECK(br.getBits(1));  // marker_bit
538            br.skipBits(15);  // latter_half_vbv_occupancy
539            CHECK(br.getBits(1));  // marker_bit
540        }
541    }
542    unsigned video_object_layer_shape = br.getBits(2);
543    CHECK_EQ(video_object_layer_shape, 0x00u /* rectangular */);
544
545    CHECK(br.getBits(1));  // marker_bit
546    unsigned vop_time_increment_resolution = br.getBits(16);
547    CHECK(br.getBits(1));  // marker_bit
548
549    if (br.getBits(1)) {  // fixed_vop_rate
550        // range [0..vop_time_increment_resolution)
551
552        // vop_time_increment_resolution
553        // 2 => 0..1, 1 bit
554        // 3 => 0..2, 2 bits
555        // 4 => 0..3, 2 bits
556        // 5 => 0..4, 3 bits
557        // ...
558
559        CHECK_GT(vop_time_increment_resolution, 0u);
560        --vop_time_increment_resolution;
561
562        unsigned numBits = 0;
563        while (vop_time_increment_resolution > 0) {
564            ++numBits;
565            vop_time_increment_resolution >>= 1;
566        }
567
568        br.skipBits(numBits);  // fixed_vop_time_increment
569    }
570
571    CHECK(br.getBits(1));  // marker_bit
572    unsigned video_object_layer_width = br.getBits(13);
573    CHECK(br.getBits(1));  // marker_bit
574    unsigned video_object_layer_height = br.getBits(13);
575    CHECK(br.getBits(1));  // marker_bit
576
577    unsigned interlaced = br.getBits(1);
578
579    *width = video_object_layer_width;
580    *height = video_object_layer_height;
581
582    return true;
583}
584
585bool GetMPEGAudioFrameSize(
586        uint32_t header, size_t *frame_size,
587        int *out_sampling_rate, int *out_channels,
588        int *out_bitrate, int *out_num_samples) {
589    *frame_size = 0;
590
591    if (out_sampling_rate) {
592        *out_sampling_rate = 0;
593    }
594
595    if (out_channels) {
596        *out_channels = 0;
597    }
598
599    if (out_bitrate) {
600        *out_bitrate = 0;
601    }
602
603    if (out_num_samples) {
604        *out_num_samples = 1152;
605    }
606
607    if ((header & 0xffe00000) != 0xffe00000) {
608        return false;
609    }
610
611    unsigned version = (header >> 19) & 3;
612
613    if (version == 0x01) {
614        return false;
615    }
616
617    unsigned layer = (header >> 17) & 3;
618
619    if (layer == 0x00) {
620        return false;
621    }
622
623    unsigned protection = (header >> 16) & 1;
624
625    unsigned bitrate_index = (header >> 12) & 0x0f;
626
627    if (bitrate_index == 0 || bitrate_index == 0x0f) {
628        // Disallow "free" bitrate.
629        return false;
630    }
631
632    unsigned sampling_rate_index = (header >> 10) & 3;
633
634    if (sampling_rate_index == 3) {
635        return false;
636    }
637
638    static const int kSamplingRateV1[] = { 44100, 48000, 32000 };
639    int sampling_rate = kSamplingRateV1[sampling_rate_index];
640    if (version == 2 /* V2 */) {
641        sampling_rate /= 2;
642    } else if (version == 0 /* V2.5 */) {
643        sampling_rate /= 4;
644    }
645
646    unsigned padding = (header >> 9) & 1;
647
648    if (layer == 3) {
649        // layer I
650
651        static const int kBitrateV1[] = {
652            32, 64, 96, 128, 160, 192, 224, 256,
653            288, 320, 352, 384, 416, 448
654        };
655
656        static const int kBitrateV2[] = {
657            32, 48, 56, 64, 80, 96, 112, 128,
658            144, 160, 176, 192, 224, 256
659        };
660
661        int bitrate =
662            (version == 3 /* V1 */)
663                ? kBitrateV1[bitrate_index - 1]
664                : kBitrateV2[bitrate_index - 1];
665
666        if (out_bitrate) {
667            *out_bitrate = bitrate;
668        }
669
670        *frame_size = (12000 * bitrate / sampling_rate + padding) * 4;
671
672        if (out_num_samples) {
673            *out_num_samples = 384;
674        }
675    } else {
676        // layer II or III
677
678        static const int kBitrateV1L2[] = {
679            32, 48, 56, 64, 80, 96, 112, 128,
680            160, 192, 224, 256, 320, 384
681        };
682
683        static const int kBitrateV1L3[] = {
684            32, 40, 48, 56, 64, 80, 96, 112,
685            128, 160, 192, 224, 256, 320
686        };
687
688        static const int kBitrateV2[] = {
689            8, 16, 24, 32, 40, 48, 56, 64,
690            80, 96, 112, 128, 144, 160
691        };
692
693        int bitrate;
694        if (version == 3 /* V1 */) {
695            bitrate = (layer == 2 /* L2 */)
696                ? kBitrateV1L2[bitrate_index - 1]
697                : kBitrateV1L3[bitrate_index - 1];
698
699            if (out_num_samples) {
700                *out_num_samples = 1152;
701            }
702        } else {
703            // V2 (or 2.5)
704
705            bitrate = kBitrateV2[bitrate_index - 1];
706            if (out_num_samples) {
707                *out_num_samples = (layer == 1 /* L3 */) ? 576 : 1152;
708            }
709        }
710
711        if (out_bitrate) {
712            *out_bitrate = bitrate;
713        }
714
715        if (version == 3 /* V1 */) {
716            *frame_size = 144000 * bitrate / sampling_rate + padding;
717        } else {
718            // V2 or V2.5
719            size_t tmp = (layer == 1 /* L3 */) ? 72000 : 144000;
720            *frame_size = tmp * bitrate / sampling_rate + padding;
721        }
722    }
723
724    if (out_sampling_rate) {
725        *out_sampling_rate = sampling_rate;
726    }
727
728    if (out_channels) {
729        int channel_mode = (header >> 6) & 3;
730
731        *out_channels = (channel_mode == 3) ? 1 : 2;
732    }
733
734    return true;
735}
736
737}  // namespace android
738
739