FFmpeg
bmvaudio.c
Go to the documentation of this file.
1 /*
2  * Discworld II BMV audio decoder
3  * Copyright (c) 2011 Konstantin Shishkov
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/common.h"
24 
25 #include "avcodec.h"
26 #include "codec_internal.h"
27 #include "decode.h"
28 
29 static const int bmv_aud_mults[16] = {
30  16512, 8256, 4128, 2064, 1032, 516, 258, 192, 129, 88, 64, 56, 48, 40, 36, 32
31 };
32 
34 {
38 
39  return 0;
40 }
41 
43  int *got_frame_ptr, AVPacket *avpkt)
44 {
45  const uint8_t *buf = avpkt->data;
46  int buf_size = avpkt->size;
47  int blocks = 0, total_blocks, i;
48  int ret;
49  int16_t *output_samples;
50  int scale[2];
51 
52  total_blocks = *buf++;
53  if (buf_size < total_blocks * 65 + 1) {
54  av_log(avctx, AV_LOG_ERROR, "expected %d bytes, got %d\n",
55  total_blocks * 65 + 1, buf_size);
56  return AVERROR_INVALIDDATA;
57  }
58 
59  /* get output buffer */
60  frame->nb_samples = total_blocks * 32;
61  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
62  return ret;
63  output_samples = (int16_t *)frame->data[0];
64 
65  for (blocks = 0; blocks < total_blocks; blocks++) {
66  uint8_t code = *buf++;
67  code = (code >> 1) | (code << 7);
68  scale[0] = bmv_aud_mults[code & 0xF];
69  scale[1] = bmv_aud_mults[code >> 4];
70  for (i = 0; i < 32; i++) {
71  *output_samples++ = av_clip_int16((scale[0] * (int8_t)*buf++) >> 5);
72  *output_samples++ = av_clip_int16((scale[1] * (int8_t)*buf++) >> 5);
73  }
74  }
75 
76  *got_frame_ptr = 1;
77 
78  return buf_size;
79 }
80 
82  .p.name = "bmv_audio",
83  CODEC_LONG_NAME("Discworld II BMV audio"),
84  .p.type = AVMEDIA_TYPE_AUDIO,
85  .p.id = AV_CODEC_ID_BMV_AUDIO,
86  .init = bmv_aud_decode_init,
88  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_CHANNEL_CONF,
89 };
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:387
bmv_aud_decode_init
static av_cold int bmv_aud_decode_init(AVCodecContext *avctx)
Definition: bmvaudio.c:33
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
AVPacket::data
uint8_t * data
Definition: packet.h:539
FFCodec
Definition: codec_internal.h:127
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1071
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
av_cold
#define av_cold
Definition: attributes.h:90
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:311
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
decode.h
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
av_clip_int16
#define av_clip_int16
Definition: common.h:115
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:106
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1692
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:540
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:311
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:1063
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
common.h
AV_CODEC_ID_BMV_AUDIO
@ AV_CODEC_ID_BMV_AUDIO
Definition: codec_id.h:501
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
bmv_aud_decode_frame
static int bmv_aud_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: bmvaudio.c:42
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
bmv_aud_mults
static const int bmv_aud_mults[16]
Definition: bmvaudio.c:29
ff_bmv_audio_decoder
const FFCodec ff_bmv_audio_decoder
Definition: bmvaudio.c:81
AVCodecContext
main external API structure.
Definition: avcodec.h:451
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:437
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
AVPacket
This structure stores compressed data.
Definition: packet.h:516
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