| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * MPEG Audio header decoder | ||
| 3 | * Copyright (c) 2001, 2002 Fabrice Bellard | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | /** | ||
| 23 | * @file | ||
| 24 | * MPEG Audio header decoder. | ||
| 25 | */ | ||
| 26 | |||
| 27 | #include "libavutil/macros.h" | ||
| 28 | |||
| 29 | #include "mpegaudio.h" | ||
| 30 | #include "mpegaudiodata.h" | ||
| 31 | #include "mpegaudiodecheader.h" | ||
| 32 | |||
| 33 | |||
| 34 | 371537149 | int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) | |
| 35 | { | ||
| 36 | int sample_rate, frame_size, mpeg25, padding; | ||
| 37 | int sample_rate_index, bitrate_index; | ||
| 38 | int ret; | ||
| 39 | |||
| 40 | 371537149 | ret = ff_mpa_check_header(header); | |
| 41 |
2/2✓ Branch 0 taken 371335083 times.
✓ Branch 1 taken 202066 times.
|
371537149 | if (ret < 0) |
| 42 | 371335083 | return ret; | |
| 43 | |||
| 44 |
2/2✓ Branch 0 taken 177832 times.
✓ Branch 1 taken 24234 times.
|
202066 | if (header & (1<<20)) { |
| 45 | 177832 | s->lsf = (header & (1<<19)) ? 0 : 1; | |
| 46 | 177832 | mpeg25 = 0; | |
| 47 | } else { | ||
| 48 | 24234 | s->lsf = 1; | |
| 49 | 24234 | mpeg25 = 1; | |
| 50 | } | ||
| 51 | |||
| 52 | 202066 | s->layer = 4 - ((header >> 17) & 3); | |
| 53 | /* extract frequency */ | ||
| 54 | 202066 | sample_rate_index = (header >> 10) & 3; | |
| 55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 202066 times.
|
202066 | if (sample_rate_index >= FF_ARRAY_ELEMS(ff_mpa_freq_tab)) |
| 56 | ✗ | sample_rate_index = 0; | |
| 57 | 202066 | sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25); | |
| 58 | 202066 | sample_rate_index += 3 * (s->lsf + mpeg25); | |
| 59 | 202066 | s->sample_rate_index = sample_rate_index; | |
| 60 | 202066 | s->error_protection = ((header >> 16) & 1) ^ 1; | |
| 61 | 202066 | s->sample_rate = sample_rate; | |
| 62 | |||
| 63 | 202066 | bitrate_index = (header >> 12) & 0xf; | |
| 64 | 202066 | padding = (header >> 9) & 1; | |
| 65 | //extension = (header >> 8) & 1; | ||
| 66 | 202066 | s->mode = (header >> 6) & 3; | |
| 67 | 202066 | s->mode_ext = (header >> 4) & 3; | |
| 68 | //copyright = (header >> 3) & 1; | ||
| 69 | //original = (header >> 2) & 1; | ||
| 70 | //emphasis = header & 3; | ||
| 71 | |||
| 72 |
2/2✓ Branch 0 taken 82991 times.
✓ Branch 1 taken 119075 times.
|
202066 | if (s->mode == MPA_MONO) |
| 73 | 82991 | s->nb_channels = 1; | |
| 74 | else | ||
| 75 | 119075 | s->nb_channels = 2; | |
| 76 | |||
| 77 |
2/2✓ Branch 0 taken 99805 times.
✓ Branch 1 taken 102261 times.
|
202066 | if (bitrate_index != 0) { |
| 78 | 99805 | frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index]; | |
| 79 | 99805 | s->bit_rate = frame_size * 1000; | |
| 80 |
3/3✓ Branch 0 taken 45658 times.
✓ Branch 1 taken 28770 times.
✓ Branch 2 taken 25377 times.
|
99805 | switch(s->layer) { |
| 81 | 45658 | case 1: | |
| 82 | 45658 | frame_size = (frame_size * 12000) / sample_rate; | |
| 83 | 45658 | frame_size = (frame_size + padding) * 4; | |
| 84 | 45658 | break; | |
| 85 | 28770 | case 2: | |
| 86 | 28770 | frame_size = (frame_size * 144000) / sample_rate; | |
| 87 | 28770 | frame_size += padding; | |
| 88 | 28770 | break; | |
| 89 | 25377 | default: | |
| 90 | case 3: | ||
| 91 | 25377 | frame_size = (frame_size * 144000) / (sample_rate << s->lsf); | |
| 92 | 25377 | frame_size += padding; | |
| 93 | 25377 | break; | |
| 94 | } | ||
| 95 | 99805 | s->frame_size = frame_size; | |
| 96 | } else { | ||
| 97 | /* if no frame size computed, signal it */ | ||
| 98 | 102261 | return 1; | |
| 99 | } | ||
| 100 | |||
| 101 | #if defined(DEBUG) | ||
| 102 | ff_dlog(NULL, "layer%d, %d Hz, %d kbits/s, ", | ||
| 103 | s->layer, s->sample_rate, s->bit_rate); | ||
| 104 | if (s->nb_channels == 2) { | ||
| 105 | if (s->layer == 3) { | ||
| 106 | if (s->mode_ext & MODE_EXT_MS_STEREO) | ||
| 107 | ff_dlog(NULL, "ms-"); | ||
| 108 | if (s->mode_ext & MODE_EXT_I_STEREO) | ||
| 109 | ff_dlog(NULL, "i-"); | ||
| 110 | } | ||
| 111 | ff_dlog(NULL, "stereo"); | ||
| 112 | } else { | ||
| 113 | ff_dlog(NULL, "mono"); | ||
| 114 | } | ||
| 115 | ff_dlog(NULL, "\n"); | ||
| 116 | #endif | ||
| 117 | 99805 | return 0; | |
| 118 | } | ||
| 119 | |||
| 120 | 285692 | int ff_mpa_decode_header(uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate, enum AVCodecID *codec_id) | |
| 121 | { | ||
| 122 | 285692 | MPADecodeHeader s1, *s = &s1; | |
| 123 | |||
| 124 |
2/2✓ Branch 1 taken 267346 times.
✓ Branch 2 taken 18346 times.
|
285692 | if (avpriv_mpegaudio_decode_header(s, head) != 0) { |
| 125 | 267346 | return -1; | |
| 126 | } | ||
| 127 | |||
| 128 |
3/3✓ Branch 0 taken 68 times.
✓ Branch 1 taken 10456 times.
✓ Branch 2 taken 7822 times.
|
18346 | switch(s->layer) { |
| 129 | 68 | case 1: | |
| 130 | 68 | *codec_id = AV_CODEC_ID_MP1; | |
| 131 | 68 | *frame_size = 384; | |
| 132 | 68 | break; | |
| 133 | 10456 | case 2: | |
| 134 | 10456 | *codec_id = AV_CODEC_ID_MP2; | |
| 135 | 10456 | *frame_size = 1152; | |
| 136 | 10456 | break; | |
| 137 | 7822 | default: | |
| 138 | case 3: | ||
| 139 |
1/2✓ Branch 0 taken 7822 times.
✗ Branch 1 not taken.
|
7822 | if (*codec_id != AV_CODEC_ID_MP3ADU) |
| 140 | 7822 | *codec_id = AV_CODEC_ID_MP3; | |
| 141 |
2/2✓ Branch 0 taken 257 times.
✓ Branch 1 taken 7565 times.
|
7822 | if (s->lsf) |
| 142 | 257 | *frame_size = 576; | |
| 143 | else | ||
| 144 | 7565 | *frame_size = 1152; | |
| 145 | 7822 | break; | |
| 146 | } | ||
| 147 | |||
| 148 | 18346 | *sample_rate = s->sample_rate; | |
| 149 | 18346 | *channels = s->nb_channels; | |
| 150 | 18346 | *bit_rate = s->bit_rate; | |
| 151 | 18346 | return s->frame_size; | |
| 152 | } | ||
| 153 |