| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Packed Animation File audio decoder | ||
| 3 | * Copyright (c) 2012 Paul B Mahol | ||
| 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 | #include "libavutil/channel_layout.h" | ||
| 23 | #include "libavutil/intreadwrite.h" | ||
| 24 | |||
| 25 | #include "avcodec.h" | ||
| 26 | #include "codec_internal.h" | ||
| 27 | #include "decode.h" | ||
| 28 | #include "mathops.h" | ||
| 29 | #include "paf.h" | ||
| 30 | |||
| 31 | 4 | static av_cold int paf_audio_init(AVCodecContext *avctx) | |
| 32 | { | ||
| 33 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (avctx->ch_layout.nb_channels != 2) { |
| 34 | ✗ | av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n"); | |
| 35 | ✗ | return AVERROR_INVALIDDATA; | |
| 36 | } | ||
| 37 | |||
| 38 | 4 | av_channel_layout_uninit(&avctx->ch_layout); | |
| 39 | 4 | avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; | |
| 40 | 4 | avctx->sample_fmt = AV_SAMPLE_FMT_S16; | |
| 41 | |||
| 42 | 4 | return 0; | |
| 43 | } | ||
| 44 | |||
| 45 | 6 | static int paf_audio_decode(AVCodecContext *avctx, AVFrame *frame, | |
| 46 | int *got_frame, AVPacket *pkt) | ||
| 47 | { | ||
| 48 | int16_t *output_samples; | ||
| 49 | 6 | const uint8_t *src = pkt->data; | |
| 50 | int frames, ret, i, j; | ||
| 51 | int16_t cb[256]; | ||
| 52 | |||
| 53 | 6 | frames = pkt->size / PAF_SOUND_FRAME_SIZE; | |
| 54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (frames < 1) |
| 55 | ✗ | return AVERROR_INVALIDDATA; | |
| 56 | |||
| 57 | 6 | frame->nb_samples = PAF_SOUND_SAMPLES * frames; | |
| 58 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) |
| 59 | ✗ | return ret; | |
| 60 | |||
| 61 | 6 | output_samples = (int16_t *)frame->data[0]; | |
| 62 | // codebook of 256 16-bit samples and 8-bit indices to it | ||
| 63 |
2/2✓ Branch 0 taken 156 times.
✓ Branch 1 taken 6 times.
|
162 | for (j = 0; j < frames; j++) { |
| 64 |
2/2✓ Branch 0 taken 39936 times.
✓ Branch 1 taken 156 times.
|
40092 | for (i = 0; i < 256; i++) |
| 65 | 39936 | cb[i] = sign_extend(AV_RL16(src + i * 2), 16); | |
| 66 | 156 | src += 256 * 2; | |
| 67 | // always 2 channels | ||
| 68 |
2/2✓ Branch 0 taken 687960 times.
✓ Branch 1 taken 156 times.
|
688116 | for (i = 0; i < PAF_SOUND_SAMPLES * 2; i++) |
| 69 | 687960 | *output_samples++ = cb[*src++]; | |
| 70 | } | ||
| 71 | 6 | *got_frame = 1; | |
| 72 | |||
| 73 | 6 | return pkt->size; | |
| 74 | } | ||
| 75 | |||
| 76 | const FFCodec ff_paf_audio_decoder = { | ||
| 77 | .p.name = "paf_audio", | ||
| 78 | CODEC_LONG_NAME("Amazing Studio Packed Animation File Audio"), | ||
| 79 | .p.type = AVMEDIA_TYPE_AUDIO, | ||
| 80 | .p.id = AV_CODEC_ID_PAF_AUDIO, | ||
| 81 | .init = paf_audio_init, | ||
| 82 | FF_CODEC_DECODE_CB(paf_audio_decode), | ||
| 83 | .p.capabilities = AV_CODEC_CAP_DR1, | ||
| 84 | }; | ||
| 85 |