summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libavformat/bethsoftvid.c47
-rw-r--r--tests/ref/fate/bethsoft-vid141
2 files changed, 100 insertions, 88 deletions
diff --git a/libavformat/bethsoftvid.c b/libavformat/bethsoftvid.c
index 1092299874..3e6ec5fa6d 100644
--- a/libavformat/bethsoftvid.c
+++ b/libavformat/bethsoftvid.c
@@ -40,6 +40,8 @@ typedef struct BVID_DemuxContext
{
int nframes;
int sample_rate; /**< audio sample rate */
+ int width; /**< video width */
+ int height; /**< video height */
/** delay value between frames, added to individual frame delay.
* custom units, which will be added to other custom units (~=16ms according
* to free, unofficial documentation) */
@@ -65,7 +67,6 @@ static int vid_read_header(AVFormatContext *s)
{
BVID_DemuxContext *vid = s->priv_data;
AVIOContext *pb = s->pb;
- AVStream *stream;
/* load main header. Contents:
* bytes: 'V' 'I' 'D'
@@ -73,23 +74,15 @@ static int vid_read_header(AVFormatContext *s)
*/
avio_skip(pb, 5);
vid->nframes = avio_rl16(pb);
-
- stream = avformat_new_stream(s, NULL);
- if (!stream)
- return AVERROR(ENOMEM);
- vid->video_index = stream->index;
- stream->start_time = 0;
- avpriv_set_pts_info(stream, 32, 1, 60); // 16 ms increments, i.e. 60 fps
- stream->codec->codec_type = AVMEDIA_TYPE_VIDEO;
- stream->codec->codec_id = CODEC_ID_BETHSOFTVID;
- stream->codec->width = avio_rl16(pb);
- stream->codec->height = avio_rl16(pb);
- stream->codec->pix_fmt = PIX_FMT_PAL8;
+ vid->width = avio_rl16(pb);
+ vid->height = avio_rl16(pb);
vid->bethsoft_global_delay = avio_rl16(pb);
avio_rl16(pb);
- // wait until the first audio packet to create the audio stream
+ // wait until the first packet to create each stream
+ vid->video_index = -1;
vid->audio_index = -1;
+ vid->sample_rate = DEFAULT_SAMPLE_RATE;
s->ctx_flags |= AVFMTCTX_NOHEADER;
return 0;
@@ -97,15 +90,34 @@ static int vid_read_header(AVFormatContext *s)
#define BUFFER_PADDING_SIZE 1000
static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt,
- uint8_t block_type, AVFormatContext *s, int npixels)
+ uint8_t block_type, AVFormatContext *s)
{
uint8_t * vidbuf_start = NULL;
int vidbuf_nbytes = 0;
int code;
int bytes_copied = 0;
- int position, duration;
+ int position, duration, npixels;
unsigned int vidbuf_capacity;
int ret = 0;
+ AVStream *st;
+
+ if (vid->video_index < 0) {
+ st = avformat_new_stream(s, NULL);
+ if (!st)
+ return AVERROR(ENOMEM);
+ vid->video_index = st->index;
+ if (vid->audio_index < 0) {
+ av_log_ask_for_sample(s, "No audio packet before first video "
+ "packet. Using default video time base.\n");
+ }
+ avpriv_set_pts_info(st, 64, 185, vid->sample_rate);
+ st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
+ st->codec->codec_id = CODEC_ID_BETHSOFTVID;
+ st->codec->width = vid->width;
+ st->codec->height = vid->height;
+ }
+ st = s->streams[vid->video_index];
+ npixels = st->codec->width * st->codec->height;
vidbuf_start = av_malloc(vidbuf_capacity = BUFFER_PADDING_SIZE);
if(!vidbuf_start)
@@ -248,8 +260,7 @@ static int vid_read_packet(AVFormatContext *s,
case VIDEO_P_FRAME:
case VIDEO_YOFF_P_FRAME:
case VIDEO_I_FRAME:
- return read_frame(vid, pb, pkt, block_type, s,
- s->streams[0]->codec->width * s->streams[0]->codec->height);
+ return read_frame(vid, pb, pkt, block_type, s);
case EOF_BLOCK:
if(vid->nframes != 0)
diff --git a/tests/ref/fate/bethsoft-vid b/tests/ref/fate/bethsoft-vid
index e6b1451e39..394d7e93ea 100644
--- a/tests/ref/fate/bethsoft-vid
+++ b/tests/ref/fate/bethsoft-vid
@@ -1,143 +1,144 @@
-#tb 0: 1/60
+#tb 0: 12/553
#tb 1: 1/11111
0, 0, 0, 1, 192000, 0x00000000
1, 0, 0, 740, 1480, 0x00000000
+0, 3, 3, 1, 192000, 0x01a6cf45
1, 740, 740, 740, 1480, 0x20a92bd4
-0, 4, 4, 1, 192000, 0x01a6cf45
+0, 6, 6, 1, 192000, 0xd07d57e9
1, 1480, 1480, 925, 1850, 0xa9e48a74
-0, 8, 8, 1, 192000, 0xd07d57e9
1, 2405, 2405, 740, 1480, 0x23ecd018
-0, 13, 13, 1, 192000, 0x3cb1dff5
+0, 10, 10, 1, 192000, 0x3cb1dff5
+0, 13, 13, 1, 192000, 0xd1aaa8fb
1, 3145, 3145, 740, 1480, 0x206bb915
-0, 17, 17, 1, 192000, 0xd1aaa8fb
+0, 16, 16, 1, 192000, 0x75f526cd
1, 3885, 3885, 925, 1850, 0xb0e10e75
-0, 21, 21, 1, 192000, 0x75f526cd
1, 4810, 4810, 740, 1480, 0x8d9baedd
-0, 26, 26, 1, 192000, 0x0f673577
+0, 20, 20, 1, 192000, 0x0f673577
+0, 23, 23, 1, 192000, 0x897b6781
1, 5550, 5550, 740, 1480, 0xb802aae1
-0, 30, 30, 1, 192000, 0x897b6781
+0, 26, 26, 1, 192000, 0x81e6b7f7
1, 6290, 6290, 740, 1480, 0xecd7b5cc
-0, 34, 34, 1, 192000, 0x81e6b7f7
+0, 29, 29, 1, 192000, 0x1f45ce61
1, 7030, 7030, 925, 1850, 0x16861355
-0, 38, 38, 1, 192000, 0x1f45ce61
1, 7955, 7955, 740, 1480, 0xa51690bd
-0, 43, 43, 1, 192000, 0x5a0772a6
+0, 33, 33, 1, 192000, 0x5a0772a6
+0, 36, 36, 1, 192000, 0xf78732b3
1, 8695, 8695, 740, 1480, 0xdd0b90d1
-0, 47, 47, 1, 192000, 0xf78732b3
+0, 39, 39, 1, 192000, 0x8427f9e5
1, 9435, 9435, 925, 1850, 0x3ce6e333
-0, 51, 51, 1, 192000, 0x8427f9e5
1, 10360, 10360, 740, 1480, 0xf8ce8ea3
-0, 56, 56, 1, 192000, 0x40473f11
+0, 43, 43, 1, 192000, 0x40473f11
+0, 46, 46, 1, 192000, 0x173ceebe
1, 11100, 11100, 740, 1480, 0xda4597af
-0, 60, 60, 1, 192000, 0x173ceebe
+0, 49, 49, 1, 192000, 0x136b9516
1, 11840, 11840, 740, 1480, 0x918f7cb3
-0, 64, 64, 1, 192000, 0x136b9516
+0, 52, 52, 1, 192000, 0x138d11ae
1, 12580, 12580, 925, 1850, 0xca6edb15
-0, 68, 68, 1, 192000, 0x138d11ae
+0, 56, 56, 1, 192000, 0x063dbff3
1, 13505, 13505, 740, 1480, 0xba279597
-0, 73, 73, 1, 192000, 0x063dbff3
+0, 59, 59, 1, 192000, 0x5280852f
1, 14245, 14245, 740, 1480, 0xc5a38a9e
-0, 77, 77, 1, 192000, 0x5280852f
+0, 62, 62, 1, 192000, 0x99943a8f
1, 14985, 14985, 925, 1850, 0x8147eef5
-0, 81, 81, 1, 192000, 0x99943a8f
1, 15910, 15910, 740, 1480, 0xce2c7cb5
-0, 86, 86, 1, 192000, 0x0330a728
+0, 66, 66, 1, 192000, 0x0330a728
+0, 69, 69, 1, 192000, 0x5d35467d
1, 16650, 16650, 740, 1480, 0x4282819f
-0, 90, 90, 1, 192000, 0x5d35467d
+0, 72, 72, 1, 192000, 0xfd436343
1, 17390, 17390, 740, 1480, 0xbdbb8da6
-0, 94, 94, 1, 192000, 0xfd436343
+0, 75, 75, 1, 192000, 0xc323fcfe
1, 18130, 18130, 925, 1850, 0xdbbeea10
-0, 98, 98, 1, 192000, 0xc323fcfe
+0, 79, 79, 1, 192000, 0x2a1530a0
1, 19055, 19055, 740, 1480, 0xbe6a77c2
-0, 103, 103, 1, 192000, 0x2a1530a0
+0, 82, 82, 1, 192000, 0xbd43bb60
1, 19795, 19795, 740, 1480, 0xa85c75b2
-0, 107, 107, 1, 192000, 0xbd43bb60
+0, 85, 85, 1, 192000, 0xa47f5eab
1, 20535, 20535, 925, 1850, 0xa45bde21
-0, 111, 111, 1, 192000, 0xa47f5eab
+0, 89, 89, 1, 192000, 0xff17f5f7
1, 21460, 21460, 740, 1480, 0x84aa7895
-0, 116, 116, 1, 192000, 0xff17f5f7
+0, 92, 92, 1, 192000, 0xb4140b55
1, 22200, 22200, 740, 1480, 0x147f7d9f
-0, 120, 120, 1, 192000, 0xb4140b55
+0, 95, 95, 1, 192000, 0xb8782cc4
1, 22940, 22940, 740, 1480, 0xc8e77b85
-0, 124, 124, 1, 192000, 0xb8782cc4
+0, 98, 98, 1, 192000, 0x92975b8b
1, 23680, 23680, 925, 1850, 0x10d4d81b
-0, 128, 128, 1, 192000, 0x92975b8b
+0, 102, 102, 1, 192000, 0xf42a64d6
1, 24605, 24605, 740, 1480, 0xb4ae8bb1
-0, 133, 133, 1, 192000, 0xf42a64d6
+0, 105, 105, 1, 192000, 0x2cc7077d
1, 25345, 25345, 740, 1480, 0x3ef782a5
-0, 137, 137, 1, 192000, 0x2cc7077d
+0, 108, 108, 1, 192000, 0x00080cc8
1, 26085, 26085, 925, 1850, 0xdeebda14
-0, 141, 141, 1, 192000, 0x00080cc8
+0, 112, 112, 1, 192000, 0x584b48f3
1, 27010, 27010, 740, 1480, 0x4c7e7bbb
-0, 146, 146, 1, 192000, 0x584b48f3
+0, 115, 115, 1, 192000, 0xd68f57da
1, 27750, 27750, 740, 1480, 0x0e0e9198
-0, 150, 150, 1, 192000, 0xd68f57da
+0, 118, 118, 1, 192000, 0x60158422
1, 28490, 28490, 740, 1480, 0x5c1f819f
-0, 154, 154, 1, 192000, 0x60158422
+0, 121, 121, 1, 192000, 0xd7fb89e6
1, 29230, 29230, 925, 1850, 0x0e4cf6ff
-0, 158, 158, 1, 192000, 0xd7fb89e6
+0, 125, 125, 1, 192000, 0x97f1c76a
1, 30155, 30155, 740, 1480, 0x374388a7
-0, 163, 163, 1, 192000, 0x97f1c76a
+0, 128, 128, 1, 192000, 0x46c4bb9e
1, 30895, 30895, 740, 1480, 0xed729389
-0, 167, 167, 1, 192000, 0x46c4bb9e
+0, 131, 131, 1, 192000, 0xd32f9b66
1, 31635, 31635, 925, 1850, 0xe0f1e43f
-0, 171, 171, 1, 192000, 0xd32f9b66
+0, 135, 135, 1, 192000, 0x74f43886
1, 32560, 32560, 740, 1480, 0x3b27839a
-0, 176, 176, 1, 192000, 0x74f43886
+0, 138, 138, 1, 192000, 0x3c4e47df
1, 33300, 33300, 740, 1480, 0xe6287e94
-0, 180, 180, 1, 192000, 0x3c4e47df
+0, 141, 141, 1, 192000, 0xb5ac0a58
1, 34040, 34040, 740, 1480, 0x7e0d84b5
-0, 184, 184, 1, 192000, 0xb5ac0a58
+0, 144, 144, 1, 192000, 0xcc572b31
1, 34780, 34780, 925, 1850, 0xf08bebf7
-0, 188, 188, 1, 192000, 0xcc572b31
+0, 148, 148, 1, 192000, 0xb1739d26
1, 35705, 35705, 740, 1480, 0x94cf73a0
-0, 193, 193, 1, 192000, 0xb1739d26
+0, 151, 151, 1, 192000, 0x73da5473
1, 36445, 36445, 740, 1480, 0xfef384ae
-0, 197, 197, 1, 192000, 0x73da5473
+0, 154, 154, 1, 192000, 0x5f79f5bc
1, 37185, 37185, 925, 1850, 0x3b93e0f7
-0, 201, 201, 1, 192000, 0x5f79f5bc
+0, 158, 158, 1, 192000, 0x0affc0a0
1, 38110, 38110, 740, 1480, 0x28d27bae
-0, 206, 206, 1, 192000, 0x0affc0a0
+0, 161, 161, 1, 192000, 0x2b4d5c1c
1, 38850, 38850, 740, 1480, 0x94d57da5
-0, 210, 210, 1, 192000, 0x2b4d5c1c
+0, 164, 164, 1, 192000, 0x309b41bc
1, 39590, 39590, 740, 1480, 0xc9327db5
-0, 214, 214, 1, 192000, 0x309b41bc
+0, 167, 167, 1, 192000, 0xd42b6424
1, 40330, 40330, 925, 1850, 0xe781f604
-0, 218, 218, 1, 192000, 0xd42b6424
+0, 171, 171, 1, 192000, 0x4795c948
1, 41255, 41255, 740, 1480, 0x752f8c5b
-0, 223, 223, 1, 192000, 0x4795c948
+0, 174, 174, 1, 192000, 0xbc1a3a8b
1, 41995, 41995, 740, 1480, 0x30068032
-0, 227, 227, 1, 192000, 0xbc1a3a8b
+0, 177, 177, 1, 192000, 0x16529c5b
1, 42735, 42735, 925, 1850, 0x7895023e
-0, 231, 231, 1, 192000, 0x16529c5b
+0, 181, 181, 1, 192000, 0x6b1b31ba
1, 43660, 43660, 740, 1480, 0xa1e0a6e1
-0, 236, 236, 1, 192000, 0x6b1b31ba
+0, 184, 184, 1, 192000, 0x569182ce
1, 44400, 44400, 740, 1480, 0x6af4b500
-0, 240, 240, 1, 192000, 0x569182ce
+0, 187, 187, 1, 192000, 0xe6ea9866
1, 45140, 45140, 740, 1480, 0xc26ea4c7
-0, 244, 244, 1, 192000, 0xe6ea9866
+0, 190, 190, 1, 192000, 0x102c6076
1, 45880, 45880, 925, 1850, 0x16a72419
-0, 248, 248, 1, 192000, 0x102c6076
+0, 194, 194, 1, 192000, 0xb29f527a
1, 46805, 46805, 740, 1480, 0x1794aacc
-0, 253, 253, 1, 192000, 0xb29f527a
+0, 197, 197, 1, 192000, 0x040b4eee
1, 47545, 47545, 740, 1480, 0x2ecad8d0
-0, 257, 257, 1, 192000, 0x040b4eee
+0, 200, 200, 1, 192000, 0x92574f4a
1, 48285, 48285, 925, 1850, 0x2e645e07
-0, 261, 261, 1, 192000, 0x92574f4a
+0, 204, 204, 1, 192000, 0x1e8acdce
1, 49210, 49210, 740, 1480, 0x1c54dfe7
-0, 266, 266, 1, 192000, 0x1e8acdce
+0, 207, 207, 1, 192000, 0x1becf516
1, 49950, 49950, 740, 1480, 0xbd35feec
-0, 270, 270, 1, 192000, 0x1becf516
+0, 210, 210, 1, 192000, 0xb62e9776
1, 50690, 50690, 740, 1480, 0x419403d6
-0, 274, 274, 1, 192000, 0xb62e9776
+0, 213, 213, 1, 192000, 0xed37a08e
1, 51430, 51430, 925, 1850, 0x78699d2a
-0, 278, 278, 1, 192000, 0xed37a08e
+0, 217, 217, 1, 192000, 0xc0719912
1, 52355, 52355, 740, 1480, 0x74ec68e0
-0, 283, 283, 1, 192000, 0xc0719912
+0, 220, 220, 1, 192000, 0x24cf7a7e
1, 53095, 53095, 740, 1480, 0x76af64d9
-0, 287, 287, 1, 192000, 0x24cf7a7e
+0, 223, 223, 1, 192000, 0x0307f62f
1, 53835, 53835, 925, 1850, 0x5a303d1a
-0, 291, 291, 1, 192000, 0x0307f62f
+0, 227, 227, 1, 192000, 0x79b7417b
1, 54760, 54760, 537, 1074, 0x142ce7ba
-0, 296, 296, 1, 192000, 0x79b7417b
1, 55297, 55297, 925, 1850, 0x7ff682f7
+0, 230, 230, 1, 192000, 0x468d8db4