FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pafaudio.c
Go to the documentation of this file.
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/intreadwrite.h"
23 
24 #include "avcodec.h"
25 #include "internal.h"
26 #include "mathops.h"
27 #include "paf.h"
28 
30 {
31  if (avctx->channels != 2) {
32  av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
33  return AVERROR_INVALIDDATA;
34  }
35 
38 
39  return 0;
40 }
41 
42 static int paf_audio_decode(AVCodecContext *avctx, void *data,
43  int *got_frame, AVPacket *pkt)
44 {
45  AVFrame *frame = data;
46  int16_t *output_samples;
47  const uint8_t *src = pkt->data;
48  int frames, ret, i, j;
49  int16_t cb[256];
50 
51  frames = pkt->size / PAF_SOUND_FRAME_SIZE;
52  if (frames < 1)
53  return AVERROR_INVALIDDATA;
54 
56  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
57  return ret;
58 
59  output_samples = (int16_t *)frame->data[0];
60  // codebook of 256 16-bit samples and 8-bit indices to it
61  for (j = 0; j < frames; j++) {
62  for (i = 0; i < 256; i++)
63  cb[i] = sign_extend(AV_RL16(src + i * 2), 16);
64  src += 256 * 2;
65  // always 2 channels
66  for (i = 0; i < PAF_SOUND_SAMPLES * 2; i++)
67  *output_samples++ = cb[*src++];
68  }
69  *got_frame = 1;
70 
71  return pkt->size;
72 }
73 
75  .name = "paf_audio",
76  .long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Audio"),
77  .type = AVMEDIA_TYPE_AUDIO,
79  .init = paf_audio_init,
80  .decode = paf_audio_decode,
81  .capabilities = AV_CODEC_CAP_DR1,
82 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
#define PAF_SOUND_FRAME_SIZE
Definition: paf.h:26
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
int size
Definition: avcodec.h:1602
static AVPacket pkt
#define AV_CH_LAYOUT_STEREO
AVCodec.
Definition: avcodec.h:3600
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:87
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:97
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2446
uint8_t
#define av_cold
Definition: attributes.h:82
static int paf_audio_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *pkt)
Definition: pafaudio.c:42
static AVFrame * frame
uint8_t * data
Definition: avcodec.h:1601
#define av_log(a,...)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
const char * name
Name of the codec implementation.
Definition: avcodec.h:3607
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2489
int frames
Definition: movenc.c:65
#define src
Definition: vp9dsp.c:530
Libavcodec external API header.
main external API structure.
Definition: avcodec.h:1676
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:947
#define PAF_SOUND_SAMPLES
Definition: paf.h:25
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:139
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
AVCodec ff_paf_audio_decoder
Definition: pafaudio.c:74
static av_cold int paf_audio_init(AVCodecContext *avctx)
Definition: pafaudio.c:29
common internal api header.
signed 16 bits
Definition: samplefmt.h:61
int channels
number of audio channels
Definition: avcodec.h:2439
This structure stores compressed data.
Definition: avcodec.h:1578
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:241
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:959
for(j=16;j >0;--j)