26
26
#include "libavutil/bswap.h"
27
27
#include "libavutil/intreadwrite.h"
28
28
#include "avformat.h"
30
31
#define SMACKER_PAL 0x01
31
32
#define SMACKER_FLAG_RING_FRAME 0x01
34
SMK_AUD_PACKED = 0x80000000,
35
SMK_AUD_16BITS = 0x20000000,
36
SMK_AUD_STEREO = 0x10000000,
37
SMK_AUD_BINKAUD = 0x08000000,
38
SMK_AUD_USEDCT = 0x04000000
35
SMK_AUD_PACKED = 0x80,
36
SMK_AUD_16BITS = 0x20,
37
SMK_AUD_STEREO = 0x10,
38
SMK_AUD_BINKAUD = 0x08,
41
42
typedef struct SmackerContext {
129
131
smk->mclr_size = avio_rl32(pb);
130
132
smk->full_size = avio_rl32(pb);
131
133
smk->type_size = avio_rl32(pb);
132
for(i = 0; i < 7; i++)
133
smk->rates[i] = avio_rl32(pb);
134
for(i = 0; i < 7; i++) {
135
smk->rates[i] = avio_rl24(pb);
136
smk->aflags[i] = avio_r8(pb);
134
138
smk->pad = avio_rl32(pb);
136
140
if(smk->frames > 0xFFFFFF) {
168
172
smk->pts_inc *= 100;
170
174
av_reduce(&tbase, &smk->pts_inc, tbase, smk->pts_inc, (1UL<<31)-1);
171
av_set_pts_info(st, 33, smk->pts_inc, tbase);
175
avpriv_set_pts_info(st, 33, smk->pts_inc, tbase);
172
176
st->duration = smk->frames;
173
177
/* handle possible audio streams */
174
178
for(i = 0; i < 7; i++) {
175
179
smk->indexes[i] = -1;
176
if(smk->rates[i] & 0xFFFFFF){
177
ast[i] = av_new_stream(s, 0);
181
ast[i] = avformat_new_stream(s, NULL);
178
182
smk->indexes[i] = ast[i]->index;
179
183
ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO;
180
if (smk->rates[i] & SMK_AUD_BINKAUD) {
184
if (smk->aflags[i] & SMK_AUD_BINKAUD) {
181
185
ast[i]->codec->codec_id = CODEC_ID_BINKAUDIO_RDFT;
182
} else if (smk->rates[i] & SMK_AUD_USEDCT) {
186
} else if (smk->aflags[i] & SMK_AUD_USEDCT) {
183
187
ast[i]->codec->codec_id = CODEC_ID_BINKAUDIO_DCT;
184
} else if (smk->rates[i] & SMK_AUD_PACKED){
188
} else if (smk->aflags[i] & SMK_AUD_PACKED){
185
189
ast[i]->codec->codec_id = CODEC_ID_SMACKAUDIO;
186
190
ast[i]->codec->codec_tag = MKTAG('S', 'M', 'K', 'A');
188
192
ast[i]->codec->codec_id = CODEC_ID_PCM_U8;
190
ast[i]->codec->channels = (smk->rates[i] & SMK_AUD_STEREO) ? 2 : 1;
191
ast[i]->codec->sample_rate = smk->rates[i] & 0xFFFFFF;
192
ast[i]->codec->bits_per_coded_sample = (smk->rates[i] & SMK_AUD_16BITS) ? 16 : 8;
194
ast[i]->codec->channels = (smk->aflags[i] & SMK_AUD_STEREO) ? 2 : 1;
195
ast[i]->codec->sample_rate = smk->rates[i];
196
ast[i]->codec->bits_per_coded_sample = (smk->aflags[i] & SMK_AUD_16BITS) ? 16 : 8;
193
197
if(ast[i]->codec->bits_per_coded_sample == 16 && ast[i]->codec->codec_id == CODEC_ID_PCM_U8)
194
198
ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE;
195
av_set_pts_info(ast[i], 64, 1, ast[i]->codec->sample_rate
199
avpriv_set_pts_info(ast[i], 64, 1, ast[i]->codec->sample_rate
196
200
* ast[i]->codec->channels * ast[i]->codec->bits_per_coded_sample / 8);
286
290
for(i = 0; i < 7; i++) {
289
295
size = avio_rl32(s->pb) - 4;
290
296
frame_size -= size;
292
298
smk->curstream++;
293
smk->bufs[smk->curstream] = av_realloc(smk->bufs[smk->curstream], size);
299
tmpbuf = av_realloc(smk->bufs[smk->curstream], size);
301
return AVERROR(ENOMEM);
302
smk->bufs[smk->curstream] = tmpbuf;
294
303
smk->buf_sizes[smk->curstream] = size;
295
304
ret = avio_read(s->pb, smk->bufs[smk->curstream], size);
342
353
AVInputFormat ff_smacker_demuxer = {
344
NULL_IF_CONFIG_SMALL("Smacker video"),
345
sizeof(SmackerContext),
355
.long_name = NULL_IF_CONFIG_SMALL("Smacker video"),
356
.priv_data_size = sizeof(SmackerContext),
357
.read_probe = smacker_probe,
358
.read_header = smacker_read_header,
359
.read_packet = smacker_read_packet,
360
.read_close = smacker_read_close,