2006-03-21 19:27:47 +02:00
|
|
|
/*
|
2006-10-23 11:57:54 +03:00
|
|
|
* Smacker demuxer
|
2009-01-19 17:46:40 +02:00
|
|
|
* Copyright (c) 2006 Konstantin Shishkov
|
2006-03-21 19:27:47 +02:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2006-03-21 19:27:47 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 18:30:46 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2006-03-21 19:27:47 +02:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2006-03-21 19:27:47 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 18:30:46 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-03-21 19:27:47 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Based on http://wiki.multimedia.cx/index.php?title=Smacker
|
|
|
|
*/
|
|
|
|
|
2014-03-10 17:35:59 +03:00
|
|
|
#include <inttypes.h>
|
|
|
|
|
2012-04-08 01:36:49 +03:00
|
|
|
#include "libavutil/channel_layout.h"
|
2009-01-12 00:19:48 +02:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2006-03-21 19:27:47 +02:00
|
|
|
#include "avformat.h"
|
2020-03-29 06:40:57 +02:00
|
|
|
#include "avio_internal.h"
|
2011-11-29 21:28:15 +03:00
|
|
|
#include "internal.h"
|
2006-03-21 19:27:47 +02:00
|
|
|
|
|
|
|
#define SMACKER_PAL 0x01
|
2007-08-23 09:59:19 +03:00
|
|
|
#define SMACKER_FLAG_RING_FRAME 0x01
|
2006-03-21 19:27:47 +02:00
|
|
|
|
|
|
|
enum SAudFlags {
|
2011-09-21 18:34:26 +03:00
|
|
|
SMK_AUD_PACKED = 0x80,
|
|
|
|
SMK_AUD_16BITS = 0x20,
|
|
|
|
SMK_AUD_STEREO = 0x10,
|
|
|
|
SMK_AUD_BINKAUD = 0x08,
|
|
|
|
SMK_AUD_USEDCT = 0x04
|
2006-03-21 19:27:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct SmackerContext {
|
|
|
|
uint32_t frames;
|
|
|
|
/* frame info */
|
|
|
|
uint32_t *frm_size;
|
|
|
|
uint8_t *frm_flags;
|
|
|
|
/* internal variables */
|
2020-06-23 17:23:57 +02:00
|
|
|
int64_t next_frame_pos;
|
2006-03-21 19:27:47 +02:00
|
|
|
int cur_frame;
|
2020-06-24 13:53:10 +02:00
|
|
|
int videoindex;
|
|
|
|
int indexes[7];
|
2006-03-21 19:27:47 +02:00
|
|
|
/* current frame for demuxing */
|
2020-06-23 17:23:57 +02:00
|
|
|
uint32_t frame_size;
|
|
|
|
int flags;
|
|
|
|
int next_audio_index;
|
|
|
|
int new_palette;
|
2006-03-21 19:27:47 +02:00
|
|
|
uint8_t pal[768];
|
2006-05-17 06:05:34 +03:00
|
|
|
int64_t aud_pts[7];
|
2006-03-21 19:27:47 +02:00
|
|
|
} SmackerContext;
|
|
|
|
|
|
|
|
/* palette used in Smacker */
|
|
|
|
static const uint8_t smk_pal[64] = {
|
|
|
|
0x00, 0x04, 0x08, 0x0C, 0x10, 0x14, 0x18, 0x1C,
|
|
|
|
0x20, 0x24, 0x28, 0x2C, 0x30, 0x34, 0x38, 0x3C,
|
|
|
|
0x41, 0x45, 0x49, 0x4D, 0x51, 0x55, 0x59, 0x5D,
|
|
|
|
0x61, 0x65, 0x69, 0x6D, 0x71, 0x75, 0x79, 0x7D,
|
|
|
|
0x82, 0x86, 0x8A, 0x8E, 0x92, 0x96, 0x9A, 0x9E,
|
|
|
|
0xA2, 0xA6, 0xAA, 0xAE, 0xB2, 0xB6, 0xBA, 0xBE,
|
|
|
|
0xC3, 0xC7, 0xCB, 0xCF, 0xD3, 0xD7, 0xDB, 0xDF,
|
|
|
|
0xE3, 0xE7, 0xEB, 0xEF, 0xF3, 0xF7, 0xFB, 0xFF
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-03-21 02:18:37 +02:00
|
|
|
static int smacker_probe(const AVProbeData *p)
|
2006-03-21 19:27:47 +02:00
|
|
|
{
|
2013-11-12 21:37:37 +03:00
|
|
|
if ( AV_RL32(p->buf) != MKTAG('S', 'M', 'K', '2')
|
|
|
|
&& AV_RL32(p->buf) != MKTAG('S', 'M', 'K', '4'))
|
2006-03-21 19:27:47 +02:00
|
|
|
return 0;
|
2013-11-12 21:37:37 +03:00
|
|
|
|
|
|
|
if (AV_RL32(p->buf+4) > 32768U || AV_RL32(p->buf+8) > 32768U)
|
|
|
|
return AVPROBE_SCORE_MAX/4;
|
|
|
|
|
|
|
|
return AVPROBE_SCORE_MAX;
|
2006-03-21 19:27:47 +02:00
|
|
|
}
|
|
|
|
|
2012-01-12 15:20:36 +03:00
|
|
|
static int smacker_read_header(AVFormatContext *s)
|
2006-03-21 19:27:47 +02:00
|
|
|
{
|
2011-02-20 12:04:12 +02:00
|
|
|
AVIOContext *pb = s->pb;
|
2007-04-08 23:24:16 +03:00
|
|
|
SmackerContext *smk = s->priv_data;
|
2020-03-29 08:19:45 +02:00
|
|
|
AVStream *st;
|
2020-03-29 10:28:29 +02:00
|
|
|
AVCodecParameters *par;
|
2020-03-29 08:42:15 +02:00
|
|
|
uint32_t magic, width, height, flags, treesize;
|
|
|
|
int i, ret, pts_inc;
|
2006-03-21 19:27:47 +02:00
|
|
|
int tbase;
|
|
|
|
|
|
|
|
/* read and check header */
|
2020-03-29 08:42:15 +02:00
|
|
|
magic = avio_rl32(pb);
|
|
|
|
if (magic != MKTAG('S', 'M', 'K', '2') && magic != MKTAG('S', 'M', 'K', '4'))
|
2012-12-06 21:06:52 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
2020-03-29 08:42:15 +02:00
|
|
|
width = avio_rl32(pb);
|
|
|
|
height = avio_rl32(pb);
|
2011-02-21 17:43:01 +02:00
|
|
|
smk->frames = avio_rl32(pb);
|
2020-03-29 08:42:15 +02:00
|
|
|
pts_inc = avio_rl32(pb);
|
|
|
|
if (pts_inc > INT_MAX / 100) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "pts_inc %d is too large\n", pts_inc);
|
2015-12-05 14:06:16 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2020-03-29 08:42:15 +02:00
|
|
|
flags = avio_rl32(pb);
|
|
|
|
if (flags & SMACKER_FLAG_RING_FRAME)
|
2007-08-23 09:59:19 +03:00
|
|
|
smk->frames++;
|
2020-03-29 06:40:57 +02:00
|
|
|
if (smk->frames > 0xFFFFFF) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "Too many frames: %"PRIu32"\n", smk->frames);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2006-05-13 14:37:56 +03:00
|
|
|
|
2020-03-29 08:42:15 +02:00
|
|
|
avio_skip(pb, 28); /* Unused audio related data */
|
|
|
|
|
|
|
|
treesize = avio_rl32(pb);
|
|
|
|
if (treesize >= UINT_MAX/4) {
|
|
|
|
// treesize + 16 must not overflow (this check is probably redundant)
|
2006-05-13 14:37:56 +03:00
|
|
|
av_log(s, AV_LOG_ERROR, "treesize too large\n");
|
2012-12-06 21:06:52 +03:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-05-13 14:37:56 +03:00
|
|
|
}
|
|
|
|
|
2020-03-29 06:40:57 +02:00
|
|
|
st = avformat_new_stream(s, NULL);
|
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
2020-03-29 10:28:29 +02:00
|
|
|
smk->videoindex = st->index;
|
2020-03-29 08:42:15 +02:00
|
|
|
/* Smacker uses 100000 as internal timebase */
|
|
|
|
if (pts_inc < 0)
|
|
|
|
pts_inc = -pts_inc;
|
|
|
|
else
|
|
|
|
pts_inc *= 100;
|
|
|
|
tbase = 100000;
|
|
|
|
av_reduce(&tbase, &pts_inc, tbase, pts_inc, (1UL << 31) - 1);
|
|
|
|
avpriv_set_pts_info(st, 33, pts_inc, tbase);
|
2020-03-29 10:28:29 +02:00
|
|
|
st->duration = smk->frames;
|
2020-03-29 08:42:15 +02:00
|
|
|
|
|
|
|
/* init video codec */
|
2020-03-29 10:28:29 +02:00
|
|
|
par = st->codecpar;
|
|
|
|
par->width = width;
|
|
|
|
par->height = height;
|
|
|
|
par->format = AV_PIX_FMT_PAL8;
|
|
|
|
par->codec_type = AVMEDIA_TYPE_VIDEO;
|
|
|
|
par->codec_id = AV_CODEC_ID_SMACKVIDEO;
|
|
|
|
par->codec_tag = magic;
|
|
|
|
|
|
|
|
if ((ret = ff_alloc_extradata(par, treesize + 16)) < 0) {
|
2020-03-29 06:40:57 +02:00
|
|
|
av_log(s, AV_LOG_ERROR,
|
|
|
|
"Cannot allocate %"PRIu32" bytes of extradata\n",
|
2020-03-29 08:42:15 +02:00
|
|
|
treesize + 16);
|
2020-03-29 06:40:57 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2020-03-29 10:28:29 +02:00
|
|
|
if ((ret = ffio_read_size(pb, par->extradata, 16)) < 0)
|
2020-03-29 06:40:57 +02:00
|
|
|
return ret;
|
|
|
|
|
2020-03-29 08:19:45 +02:00
|
|
|
/* handle possible audio streams */
|
2020-03-29 10:28:29 +02:00
|
|
|
for (i = 0; i < 7; i++) {
|
2020-03-29 08:19:45 +02:00
|
|
|
uint32_t rate = avio_rl24(pb);
|
|
|
|
uint8_t aflag = avio_r8(pb);
|
|
|
|
|
|
|
|
smk->indexes[i] = -1;
|
|
|
|
|
|
|
|
if (rate) {
|
|
|
|
AVStream *ast = avformat_new_stream(s, NULL);
|
2020-03-29 10:28:29 +02:00
|
|
|
AVCodecParameters *par;
|
2020-03-29 08:19:45 +02:00
|
|
|
if (!ast)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
smk->indexes[i] = ast->index;
|
2020-03-29 10:28:29 +02:00
|
|
|
par = ast->codecpar;
|
|
|
|
par->codec_type = AVMEDIA_TYPE_AUDIO;
|
2020-03-29 08:19:45 +02:00
|
|
|
if (aflag & SMK_AUD_BINKAUD) {
|
2020-03-29 10:28:29 +02:00
|
|
|
par->codec_id = AV_CODEC_ID_BINKAUDIO_RDFT;
|
2020-03-29 08:19:45 +02:00
|
|
|
} else if (aflag & SMK_AUD_USEDCT) {
|
2020-03-29 10:28:29 +02:00
|
|
|
par->codec_id = AV_CODEC_ID_BINKAUDIO_DCT;
|
2020-03-29 08:19:45 +02:00
|
|
|
} else if (aflag & SMK_AUD_PACKED) {
|
2020-03-29 10:28:29 +02:00
|
|
|
par->codec_id = AV_CODEC_ID_SMACKAUDIO;
|
|
|
|
par->codec_tag = MKTAG('S', 'M', 'K', 'A');
|
2020-03-29 08:19:45 +02:00
|
|
|
} else {
|
2020-03-29 10:28:29 +02:00
|
|
|
par->codec_id = AV_CODEC_ID_PCM_U8;
|
2020-03-29 08:19:45 +02:00
|
|
|
}
|
|
|
|
if (aflag & SMK_AUD_STEREO) {
|
2020-03-29 10:28:29 +02:00
|
|
|
par->channels = 2;
|
|
|
|
par->channel_layout = AV_CH_LAYOUT_STEREO;
|
2020-03-29 08:19:45 +02:00
|
|
|
} else {
|
2020-03-29 10:28:29 +02:00
|
|
|
par->channels = 1;
|
|
|
|
par->channel_layout = AV_CH_LAYOUT_MONO;
|
2020-03-29 08:19:45 +02:00
|
|
|
}
|
2020-03-29 10:28:29 +02:00
|
|
|
par->sample_rate = rate;
|
|
|
|
par->bits_per_coded_sample = (aflag & SMK_AUD_16BITS) ? 16 : 8;
|
|
|
|
if (par->bits_per_coded_sample == 16 &&
|
|
|
|
par->codec_id == AV_CODEC_ID_PCM_U8)
|
|
|
|
par->codec_id = AV_CODEC_ID_PCM_S16LE;
|
|
|
|
avpriv_set_pts_info(ast, 64, 1, par->sample_rate * par->channels
|
|
|
|
* par->bits_per_coded_sample / 8);
|
2020-03-29 08:19:45 +02:00
|
|
|
}
|
2011-09-21 18:34:26 +03:00
|
|
|
}
|
2020-03-29 10:28:29 +02:00
|
|
|
|
2020-03-29 08:42:15 +02:00
|
|
|
avio_rl32(pb); /* padding */
|
2020-03-29 10:28:29 +02:00
|
|
|
|
2006-03-21 19:27:47 +02:00
|
|
|
/* setup data */
|
2020-06-22 04:48:49 +02:00
|
|
|
st->priv_data = av_malloc_array(smk->frames, sizeof(*smk->frm_size) +
|
2020-06-22 04:06:37 +02:00
|
|
|
sizeof(*smk->frm_flags));
|
2020-06-22 04:48:49 +02:00
|
|
|
if (!st->priv_data)
|
2013-09-16 21:20:08 +03:00
|
|
|
return AVERROR(ENOMEM);
|
2020-06-22 04:48:49 +02:00
|
|
|
smk->frm_size = st->priv_data;
|
2020-06-22 04:06:37 +02:00
|
|
|
smk->frm_flags = (void*)(smk->frm_size + smk->frames);
|
2006-03-21 19:27:47 +02:00
|
|
|
|
|
|
|
/* read frame info */
|
2020-03-29 10:28:29 +02:00
|
|
|
for (i = 0; i < smk->frames; i++) {
|
2011-02-21 17:43:01 +02:00
|
|
|
smk->frm_size[i] = avio_rl32(pb);
|
2006-03-21 19:27:47 +02:00
|
|
|
}
|
2020-06-22 04:25:22 +02:00
|
|
|
if ((ret = ffio_read_size(pb, smk->frm_flags, smk->frames)) < 0 ||
|
|
|
|
/* load trees to extradata, they will be unpacked by decoder */
|
|
|
|
(ret = ffio_read_size(pb, par->extradata + 16,
|
|
|
|
par->extradata_size - 16)) < 0) {
|
|
|
|
return ret;
|
2006-03-21 19:27:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
2007-04-08 23:24:16 +03:00
|
|
|
SmackerContext *smk = s->priv_data;
|
2006-03-21 19:27:47 +02:00
|
|
|
int flags;
|
|
|
|
int ret;
|
|
|
|
|
2014-08-07 23:12:41 +03:00
|
|
|
if (avio_feof(s->pb) || smk->cur_frame >= smk->frames)
|
2010-06-24 09:55:53 +03:00
|
|
|
return AVERROR_EOF;
|
2006-03-21 19:27:47 +02:00
|
|
|
|
|
|
|
/* if we demuxed all streams, pass another frame */
|
2020-06-23 17:23:57 +02:00
|
|
|
if (!smk->next_audio_index) {
|
|
|
|
smk->frame_size = smk->frm_size[smk->cur_frame] & (~3);
|
|
|
|
smk->next_frame_pos = avio_tell(s->pb) + smk->frame_size;
|
2006-03-21 19:27:47 +02:00
|
|
|
flags = smk->frm_flags[smk->cur_frame];
|
2020-06-23 17:23:57 +02:00
|
|
|
smk->flags = flags >> 1;
|
2006-03-21 19:27:47 +02:00
|
|
|
/* handle palette change event */
|
2020-06-24 13:53:10 +02:00
|
|
|
if (flags & SMACKER_PAL) {
|
2006-03-21 19:27:47 +02:00
|
|
|
int size, sz, t, off, j, pos;
|
|
|
|
uint8_t *pal = smk->pal;
|
|
|
|
uint8_t oldpal[768];
|
|
|
|
|
|
|
|
memcpy(oldpal, pal, 768);
|
2011-02-21 17:43:01 +02:00
|
|
|
size = avio_r8(s->pb);
|
2020-06-23 17:23:57 +02:00
|
|
|
size = size * 4;
|
|
|
|
if (size > smk->frame_size) {
|
2020-06-23 13:34:02 +02:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto next_frame;
|
|
|
|
}
|
2020-06-23 17:23:57 +02:00
|
|
|
smk->frame_size -= size--;
|
2006-03-21 19:27:47 +02:00
|
|
|
sz = 0;
|
2011-03-03 21:11:45 +02:00
|
|
|
pos = avio_tell(s->pb) + size;
|
2020-06-24 13:53:10 +02:00
|
|
|
while (sz < 256) {
|
2011-02-21 17:43:01 +02:00
|
|
|
t = avio_r8(s->pb);
|
2020-06-24 13:53:10 +02:00
|
|
|
if (t & 0x80) { /* skip palette entries */
|
|
|
|
sz += (t & 0x7F) + 1;
|
2006-03-21 19:27:47 +02:00
|
|
|
pal += ((t & 0x7F) + 1) * 3;
|
2020-06-24 13:53:10 +02:00
|
|
|
} else if (t & 0x40) { /* copy with offset */
|
2012-03-07 04:24:20 +03:00
|
|
|
off = avio_r8(s->pb);
|
2006-03-21 19:27:47 +02:00
|
|
|
j = (t & 0x3F) + 1;
|
2013-05-27 07:26:28 +03:00
|
|
|
if (off + j > 0x100) {
|
2012-03-07 04:24:20 +03:00
|
|
|
av_log(s, AV_LOG_ERROR,
|
|
|
|
"Invalid palette update, offset=%d length=%d extends beyond palette size\n",
|
|
|
|
off, j);
|
2020-06-23 13:34:02 +02:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto next_frame;
|
2012-03-07 04:24:20 +03:00
|
|
|
}
|
|
|
|
off *= 3;
|
2020-06-24 13:53:10 +02:00
|
|
|
while (j-- && sz < 256) {
|
2006-03-21 19:27:47 +02:00
|
|
|
*pal++ = oldpal[off + 0];
|
|
|
|
*pal++ = oldpal[off + 1];
|
|
|
|
*pal++ = oldpal[off + 2];
|
|
|
|
sz++;
|
|
|
|
off += 3;
|
|
|
|
}
|
|
|
|
} else { /* new entries */
|
|
|
|
*pal++ = smk_pal[t];
|
2011-02-21 17:43:01 +02:00
|
|
|
*pal++ = smk_pal[avio_r8(s->pb) & 0x3F];
|
|
|
|
*pal++ = smk_pal[avio_r8(s->pb) & 0x3F];
|
2006-03-21 19:27:47 +02:00
|
|
|
sz++;
|
|
|
|
}
|
|
|
|
}
|
2011-02-28 15:57:54 +02:00
|
|
|
avio_seek(s->pb, pos, 0);
|
2020-06-23 17:23:57 +02:00
|
|
|
smk->new_palette = 1;
|
2006-03-21 19:27:47 +02:00
|
|
|
}
|
2020-06-23 17:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = smk->next_audio_index; i < 7; i++) {
|
|
|
|
if (smk->flags & (1 << i)) {
|
2020-06-24 13:53:10 +02:00
|
|
|
uint32_t size;
|
2011-09-12 10:40:42 +03:00
|
|
|
|
2020-06-24 13:53:10 +02:00
|
|
|
size = avio_rl32(s->pb);
|
2020-06-23 17:23:57 +02:00
|
|
|
if ((int)size < 8 || size > smk->frame_size) {
|
2020-06-24 13:53:10 +02:00
|
|
|
av_log(s, AV_LOG_ERROR, "Invalid audio part size\n");
|
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto next_frame;
|
|
|
|
}
|
2020-06-23 17:23:57 +02:00
|
|
|
smk->frame_size -= size;
|
2020-06-24 13:53:10 +02:00
|
|
|
size -= 4;
|
2020-06-23 17:23:57 +02:00
|
|
|
|
|
|
|
if (smk->indexes[i] < 0) {
|
|
|
|
avio_skip(s->pb, size);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((ret = av_get_packet(s->pb, pkt, size)) != size) {
|
|
|
|
ret = ret < 0 ? ret : AVERROR_INVALIDDATA;
|
2020-06-24 13:53:10 +02:00
|
|
|
goto next_frame;
|
|
|
|
}
|
2020-06-23 17:23:57 +02:00
|
|
|
pkt->stream_index = smk->indexes[i];
|
2020-06-24 12:17:46 +02:00
|
|
|
pkt->pts = smk->aud_pts[i];
|
|
|
|
smk->aud_pts[i] += AV_RL32(pkt->data);
|
2020-06-23 17:23:57 +02:00
|
|
|
smk->next_audio_index = i + 1;
|
|
|
|
return 0;
|
2006-03-21 19:27:47 +02:00
|
|
|
}
|
2020-06-24 13:53:10 +02:00
|
|
|
}
|
2020-06-23 17:23:57 +02:00
|
|
|
|
|
|
|
if (smk->frame_size >= INT_MAX/2) {
|
2020-06-24 13:53:10 +02:00
|
|
|
ret = AVERROR_INVALIDDATA;
|
|
|
|
goto next_frame;
|
|
|
|
}
|
2020-06-23 17:23:57 +02:00
|
|
|
if ((ret = av_new_packet(pkt, smk->frame_size + 769)) < 0)
|
2020-06-24 13:53:10 +02:00
|
|
|
goto next_frame;
|
2020-06-23 17:23:57 +02:00
|
|
|
flags = smk->new_palette;
|
2020-06-24 13:53:10 +02:00
|
|
|
if (smk->frm_size[smk->cur_frame] & 1)
|
2020-06-23 17:23:57 +02:00
|
|
|
flags |= 2;
|
|
|
|
pkt->data[0] = flags;
|
2020-06-24 13:53:10 +02:00
|
|
|
memcpy(pkt->data + 1, smk->pal, 768);
|
2020-06-23 17:23:57 +02:00
|
|
|
ret = ffio_read_size(s->pb, pkt->data + 769, smk->frame_size);
|
2020-06-24 13:53:10 +02:00
|
|
|
if (ret < 0)
|
|
|
|
goto next_frame;
|
|
|
|
pkt->stream_index = smk->videoindex;
|
|
|
|
pkt->pts = smk->cur_frame;
|
2020-06-23 17:23:57 +02:00
|
|
|
smk->next_audio_index = 0;
|
|
|
|
smk->new_palette = 0;
|
2020-06-24 13:53:10 +02:00
|
|
|
smk->cur_frame++;
|
2006-03-21 19:27:47 +02:00
|
|
|
|
|
|
|
return 0;
|
2020-06-23 13:34:02 +02:00
|
|
|
next_frame:
|
2020-06-23 17:23:57 +02:00
|
|
|
avio_seek(s->pb, smk->next_frame_pos, SEEK_SET);
|
|
|
|
smk->next_audio_index = 0;
|
2020-06-23 13:34:02 +02:00
|
|
|
smk->cur_frame++;
|
|
|
|
return ret;
|
2006-03-21 19:27:47 +02:00
|
|
|
}
|
|
|
|
|
2011-01-26 00:03:28 +02:00
|
|
|
AVInputFormat ff_smacker_demuxer = {
|
2011-07-16 23:18:12 +03:00
|
|
|
.name = "smk",
|
2012-07-29 05:22:09 +03:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Smacker"),
|
2011-07-16 23:18:12 +03:00
|
|
|
.priv_data_size = sizeof(SmackerContext),
|
|
|
|
.read_probe = smacker_probe,
|
|
|
|
.read_header = smacker_read_header,
|
|
|
|
.read_packet = smacker_read_packet,
|
2006-03-21 19:27:47 +02:00
|
|
|
};
|