1 /*
2 * SMPTE 302M decoder
3 * Copyright (c) 2008 Laurent Aimar <fenrir@videolan.org>
4 * Copyright (c) 2009 Baptiste Coudurier <baptiste.coudurier@gmail.com>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
29
30 #define AES3_HEADER_LEN 4
31
36
38 int buf_size)
39 {
42
46 }
47
48 /*
49 * AES3 header :
50 * size: 16
51 * number channels 2
52 * channel_id 8
53 * bits per samples 2
54 * alignments 4
55 */
56
58 frame_size = (h >> 16) & 0xffff;
59 channels = ((h >> 14) & 0x0003) * 2 + 2;
60 bits = ((h >> 4) & 0x0003) * 4 + 16;
61
65 }
66
67 /* Set output properties */
69 if (bits > 16)
71 else
73
75 switch(channels) {
76 case 2:
78 break;
79 case 4:
81 break;
82 case 6:
84 break;
85 case 8:
87 }
88
90 }
91
94 {
98 int buf_size = avpkt->
size;
99 int block_size, ret;
100 int i;
101 int non_pcm_data_type = -1;
102
104 if (frame_size < 0)
106
109
110 /* get output buffer */
114 return ret;
115
119
121 uint32_t *o = (uint32_t *)frame->
data[0];
122 for (; buf_size > 6; buf_size -= 7) {
126 *o++ = ((unsigned)
ff_reverse[buf[6] & 0xf0] << 28) |
130 buf += 7;
131 }
132 o = (uint32_t *)frame->
data[0];
134 for (i=0; i<frame->
nb_samples * 2 - 6; i+=2) {
135 if (o[i] || o[i+1] || o[i+2] || o[i+3])
136 break;
137 if (o[i+4] == 0x96F87200U && o[i+5] == 0xA54E1F00) {
138 non_pcm_data_type = (o[i+6] >> 16) & 0x1F;
139 break;
140 }
141 }
143 uint32_t *o = (uint32_t *)frame->
data[0];
144 for (; buf_size > 5; buf_size -= 6) {
145 *o++ = ((unsigned)
ff_reverse[buf[2] & 0xf0] << 28) |
148 *o++ = ((unsigned)
ff_reverse[buf[5] & 0xf0] << 28) |
151 buf += 6;
152 }
153 o = (uint32_t *)frame->
data[0];
155 for (i=0; i<frame->
nb_samples * 2 - 6; i+=2) {
156 if (o[i] || o[i+1] || o[i+2] || o[i+3])
157 break;
158 if (o[i+4] == 0x6F872000U && o[i+5] == 0x54E1F000) {
159 non_pcm_data_type = (o[i+6] >> 16) & 0x1F;
160 break;
161 }
162 }
163 } else {
164 uint16_t *o = (uint16_t *)frame->
data[0];
165 for (; buf_size > 4; buf_size -= 5) {
171 buf += 5;
172 }
173 o = (uint16_t *)frame->
data[0];
175 for (i=0; i<frame->
nb_samples * 2 - 6; i+=2) {
176 if (o[i] || o[i+1] || o[i+2] || o[i+3])
177 break;
178 if (o[i+4] == 0xF872U && o[i+5] == 0x4E1F) {
179 non_pcm_data_type = (o[i+6] & 0x1F);
180 break;
181 }
182 }
183 }
184
185 if (non_pcm_data_type != -1) {
188 "S302 non PCM mode with data type %d not supported\n",
189 non_pcm_data_type);
191 }
194 }
195 }
196
198
199 *got_frame_ptr = 1;
200
202 }
203
204 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_DECODING_PARAM
206 {
"non_pcm_mode",
"Chooses what to do with NON-PCM", offsetof(
S302Context, non_pcm_mode),
AV_OPT_TYPE_INT, {.i64 = 3}, 0, 3,
FLAGS,
"non_pcm_mode"},
207 {
"copy" ,
"Pass NON-PCM through unchanged" , 0,
AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 3,
FLAGS,
"non_pcm_mode"},
209 {
"decode_copy" ,
"Decode if possible else passthrough", 0,
AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 3,
FLAGS,
"non_pcm_mode"},
210 {
"decode_drop" ,
"Decode if possible else drop" , 0,
AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 3,
FLAGS,
"non_pcm_mode"},
212 };
213
219 };
220
229 .priv_class = &s302m_class,
230 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
int64_t bit_rate
the average bitrate
#define LIBAVUTIL_VERSION_INT
static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
const uint8_t ff_reverse[256]
const char * av_default_item_name(void *ptr)
Return the context name.
static const AVOption s302m_options[]
#define AV_CH_LAYOUT_STEREO
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
enum AVSampleFormat sample_fmt
audio sample format
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_CH_LAYOUT_QUAD
const char * name
Name of the codec implementation.
uint64_t channel_layout
Audio channel layout.
static const AVClass s302m_class
#define AV_CH_LAYOUT_STEREO_DOWNMIX
#define AV_CH_LAYOUT_5POINT1_BACK
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Libavcodec external API header.
int sample_rate
samples per second
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Describe the class of an AVClass context structure.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
int channels
number of audio channels
static int s302m_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.