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 "codec_internal.h"
27 #include "decode.h"
28 #include "mathops.h"
29 #include "paf.h"
30 
32 {
33  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 
41 
42  return 0;
43 }
44 
46  int *got_frame, AVPacket *pkt)
47 {
48  int16_t *output_samples;
49  const uint8_t *src = pkt->data;
50  int frames, ret, i, j;
51  int16_t cb[256];
52 
54  if (frames < 1)
55  return AVERROR_INVALIDDATA;
56 
58  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
59  return ret;
60 
61  output_samples = (int16_t *)frame->data[0];
62  // codebook of 256 16-bit samples and 8-bit indices to it
63  for (j = 0; j < frames; j++) {
64  for (i = 0; i < 256; i++)
65  cb[i] = sign_extend(AV_RL16(src + i * 2), 16);
66  src += 256 * 2;
67  // always 2 channels
68  for (i = 0; i < PAF_SOUND_SAMPLES * 2; i++)
69  *output_samples++ = cb[*src++];
70  }
71  *got_frame = 1;
72 
73  return pkt->size;
74 }
75 
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,
83  .p.capabilities = AV_CODEC_CAP_DR1,
84 };
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:379
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:241
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:344
AVPacket::data
uint8_t * data
Definition: packet.h:522
FFCodec
Definition: codec_internal.h:127
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:313
paf.h
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:365
ff_paf_audio_decoder
const FFCodec ff_paf_audio_decoder
Definition: pafaudio.c:76
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1065
frames
if it could not because there are no more frames
Definition: filter_design.txt:266
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
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:287
intreadwrite.h
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
decode.h
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
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
mathops.h
paf_audio_init
static av_cold int paf_audio_init(AVCodecContext *avctx)
Definition: pafaudio.c:31
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1569
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:523
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:303
codec_internal.h
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1057
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:424
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
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:58
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
avcodec.h
ret
ret
Definition: filter_design.txt:187
AVCodecContext
main external API structure.
Definition: avcodec.h:445
channel_layout.h
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:432
sign_extend
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:133
paf_audio_decode
static int paf_audio_decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: pafaudio.c:45
AVPacket
This structure stores compressed data.
Definition: packet.h:499
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
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:504