1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avformat/mm: fix packets pts generation and add seek support

Signed-off-by: Peter Ross <pross@xvid.org>
This commit is contained in:
Paul B Mahol 2024-06-26 09:07:29 +02:00 committed by Peter Ross
parent 7902702762
commit 8050a7955e
2 changed files with 45 additions and 48 deletions

View File

@ -58,10 +58,6 @@
#define MM_PALETTE_COUNT 128
#define MM_PALETTE_SIZE (MM_PALETTE_COUNT*3)
typedef struct MmDemuxContext {
unsigned int audio_pts, video_pts;
} MmDemuxContext;
static int probe(const AVProbeData *p)
{
int len, type, fps, w, h;
@ -88,7 +84,6 @@ static int probe(const AVProbeData *p)
static int read_header(AVFormatContext *s)
{
MmDemuxContext *mm = s->priv_data;
AVIOContext *pb = s->pb;
AVStream *st;
@ -133,30 +128,29 @@ static int read_header(AVFormatContext *s)
avpriv_set_pts_info(st, 64, 1, 8000); /* 8000 hz */
}
mm->audio_pts = 0;
mm->video_pts = 0;
return 0;
}
static int read_packet(AVFormatContext *s,
AVPacket *pkt)
{
MmDemuxContext *mm = s->priv_data;
AVIOContext *pb = s->pb;
unsigned char preamble[MM_PREAMBLE_SIZE];
unsigned int type, length;
int64_t pos = avio_tell(pb);
int ret;
while(1) {
while (1) {
if (avio_feof(pb))
return AVERROR_EOF;
if (avio_read(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) {
if (avio_read(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE)
return AVERROR(EIO);
}
type = AV_RL16(&preamble[0]);
length = AV_RL16(&preamble[2]);
switch(type) {
switch (type) {
case MM_TYPE_RAW :
case MM_TYPE_PALETTE :
case MM_TYPE_INTER :
@ -173,9 +167,12 @@ static int read_packet(AVFormatContext *s,
return AVERROR(EIO);
pkt->size = length + MM_PREAMBLE_SIZE;
pkt->stream_index = 0;
pkt->pts = mm->video_pts;
if (type!=MM_TYPE_PALETTE)
mm->video_pts++;
pkt->duration = 1;
if (type == MM_TYPE_RAW ||
type == MM_TYPE_INTRA)
pkt->flags |= AV_PKT_FLAG_KEY;
pkt->pos = pos;
return 0;
case MM_TYPE_AUDIO :
@ -184,8 +181,8 @@ static int read_packet(AVFormatContext *s,
if ((ret = av_get_packet(s->pb, pkt, length)) < 0)
return ret;
pkt->stream_index = 1;
pkt->pts = mm->audio_pts;
mm->audio_pts += length;
pkt->duration = length;
pkt->pos = pos;
return 0;
default :
@ -200,7 +197,7 @@ static int read_packet(AVFormatContext *s,
const FFInputFormat ff_mm_demuxer = {
.p.name = "mm",
.p.long_name = NULL_IF_CONFIG_SMALL("American Laser Games MM"),
.priv_data_size = sizeof(MmDemuxContext),
.p.flags = AVFMT_GENERIC_INDEX,
.read_probe = probe,
.read_header = read_header,
.read_packet = read_packet,

View File

@ -3,34 +3,34 @@
#codec_id 0: rawvideo
#dimensions 0: 256x160
#sar 0: 0/1
0, 0, 0, 1, 122880, 0x4ed8123f
0, 1, 1, 1, 122880, 0xc4c35304
0, 2, 2, 1, 122880, 0xbd3015fd
0, 3, 3, 1, 122880, 0xece5dbab
0, 4, 4, 1, 122880, 0x13249f3f
0, 5, 5, 1, 122880, 0x58f75895
0, 6, 6, 1, 122880, 0xe6570f7d
0, 7, 7, 1, 122880, 0xcce88145
0, 8, 8, 1, 122880, 0x796f633c
0, 9, 9, 1, 122880, 0x182c3cd3
0, 10, 10, 1, 122880, 0x04b2513b
0, 11, 11, 1, 122880, 0x6b7e2e42
0, 12, 12, 1, 122880, 0x2fa47070
0, 13, 13, 1, 122880, 0x7142919e
0, 14, 14, 1, 122880, 0x8995337e
0, 15, 15, 1, 122880, 0x5146ca20
0, 16, 16, 1, 122880, 0x9aadb491
0, 17, 17, 1, 122880, 0x2d5b0032
0, 18, 18, 1, 122880, 0x5c7c8314
0, 19, 19, 1, 122880, 0x2ba8253c
0, 20, 20, 1, 122880, 0xd19d504b
0, 21, 21, 1, 122880, 0x4ff15fd1
0, 22, 22, 1, 122880, 0x76039f9f
0, 23, 23, 1, 122880, 0xcce84d35
0, 24, 24, 1, 122880, 0x68c5797c
0, 25, 25, 1, 122880, 0xf1da4293
0, 26, 26, 1, 122880, 0xf5f537f3
0, 27, 27, 1, 122880, 0x8d3ffa94
0, 28, 28, 1, 122880, 0x3ca9b69c
0, 29, 29, 1, 122880, 0x21187f6c
0, 30, 30, 1, 122880, 0xe5136e34
0, 1, 1, 1, 122880, 0x4ed8123f
0, 2, 2, 1, 122880, 0xc4c35304
0, 3, 3, 1, 122880, 0xbd3015fd
0, 4, 4, 1, 122880, 0xece5dbab
0, 5, 5, 1, 122880, 0x13249f3f
0, 6, 6, 1, 122880, 0x58f75895
0, 7, 7, 1, 122880, 0xe6570f7d
0, 8, 8, 1, 122880, 0xcce88145
0, 9, 9, 1, 122880, 0x796f633c
0, 10, 10, 1, 122880, 0x182c3cd3
0, 11, 11, 1, 122880, 0x04b2513b
0, 12, 12, 1, 122880, 0x6b7e2e42
0, 13, 13, 1, 122880, 0x2fa47070
0, 14, 14, 1, 122880, 0x7142919e
0, 15, 15, 1, 122880, 0x8995337e
0, 16, 16, 1, 122880, 0x5146ca20
0, 17, 17, 1, 122880, 0x9aadb491
0, 18, 18, 1, 122880, 0x2d5b0032
0, 19, 19, 1, 122880, 0x5c7c8314
0, 20, 20, 1, 122880, 0x2ba8253c
0, 21, 21, 1, 122880, 0xd19d504b
0, 22, 22, 1, 122880, 0x4ff15fd1
0, 23, 23, 1, 122880, 0x76039f9f
0, 24, 24, 1, 122880, 0xcce84d35
0, 25, 25, 1, 122880, 0x68c5797c
0, 26, 26, 1, 122880, 0xf1da4293
0, 27, 27, 1, 122880, 0xf5f537f3
0, 28, 28, 1, 122880, 0x8d3ffa94
0, 29, 29, 1, 122880, 0x3ca9b69c
0, 30, 30, 1, 122880, 0x21187f6c
0, 31, 31, 1, 122880, 0xe5136e34