FFmpeg
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 
23 #include "libavutil/intreadwrite.h"
24 
25 #include "avcodec.h"
26 #include "internal.h"
27 #include "mathops.h"
28 #include "paf.h"
29 
31 {
32  if (avctx->channels != 2) {
33  av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
34  return AVERROR_INVALIDDATA;
35  }
36 
39 
40  return 0;
41 }
42 
43 static int paf_audio_decode(AVCodecContext *avctx, void *data,
44  int *got_frame, AVPacket *pkt)
45 {
46  AVFrame *frame = data;
47  int16_t *output_samples;
48  const uint8_t *src = pkt->data;
49  int frames, ret, i, j;
50  int16_t cb[256];
51 
53  if (frames < 1)
54  return AVERROR_INVALIDDATA;
55 
56  frame->nb_samples = PAF_SOUND_SAMPLES * frames;
57  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
58  return ret;
59 
60  output_samples = (int16_t *)frame->data[0];
61  // codebook of 256 16-bit samples and 8-bit indices to it
62  for (j = 0; j < frames; j++) {
63  for (i = 0; i < 256; i++)
64  cb[i] = sign_extend(AV_RL16(src + i * 2), 16);
65  src += 256 * 2;
66  // always 2 channels
67  for (i = 0; i < PAF_SOUND_SAMPLES * 2; i++)
68  *output_samples++ = cb[*src++];
69  }
70  *got_frame = 1;
71 
72  return pkt->size;
73 }
74 
76  .name = "paf_audio",
77  .long_name = NULL_IF_CONFIG_SMALL("Amazing Studio Packed Animation File Audio"),
78  .type = AVMEDIA_TYPE_AUDIO,
80  .init = paf_audio_init,
81  .decode = paf_audio_decode,
82  .capabilities = AV_CODEC_CAP_DR1,
83  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
84 };
AVCodec
AVCodec.
Definition: codec.h:202
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:42
AVCodecContext::channel_layout
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1043
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:215
PAF_SOUND_FRAME_SIZE
#define PAF_SOUND_FRAME_SIZE
Definition: paf.h:26
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:373
data
const char data[16]
Definition: mxf.c:143
paf_audio_decode
static int paf_audio_decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *pkt)
Definition: pafaudio.c:43
paf.h
frames
if it could not because there are no more frames
Definition: filter_design.txt:266
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:91
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
intreadwrite.h
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_RL16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:94
src
#define src
Definition: vp8dsp.c:255
mathops.h
paf_audio_init
static av_cold int paf_audio_init(AVCodecContext *avctx)
Definition: pafaudio.c:30
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1652
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:374
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1000
ff_paf_audio_decoder
const AVCodec ff_paf_audio_decoder
Definition: pafaudio.c:75
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:993
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
PAF_SOUND_SAMPLES
#define PAF_SOUND_SAMPLES
Definition: paf.h:25
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:209
avcodec.h
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
AVCodecContext
main external API structure.
Definition: avcodec.h:383
channel_layout.h
sign_extend
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:130
AVPacket
This structure stores compressed data.
Definition: packet.h:350
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AV_CODEC_ID_PAF_AUDIO
@ AV_CODEC_ID_PAF_AUDIO
Definition: codec_id.h:487