Commit f0349df7 authored by Paul B Mahol's avatar Paul B Mahol

avformat/vpk: add seeking support

parent e35f9668
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "internal.h" #include "internal.h"
typedef struct VPKDemuxContext { typedef struct VPKDemuxContext {
unsigned data_start;
unsigned block_count; unsigned block_count;
unsigned current_block; unsigned current_block;
unsigned last_block_size; unsigned last_block_size;
...@@ -70,6 +71,7 @@ static int vpk_read_header(AVFormatContext *s) ...@@ -70,6 +71,7 @@ static int vpk_read_header(AVFormatContext *s)
if (offset < avio_tell(s->pb)) if (offset < avio_tell(s->pb))
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
avio_skip(s->pb, offset - avio_tell(s->pb)); avio_skip(s->pb, offset - avio_tell(s->pb));
vpk->data_start = offset;
avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
return 0; return 0;
...@@ -85,6 +87,7 @@ static int vpk_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -85,6 +87,7 @@ static int vpk_read_packet(AVFormatContext *s, AVPacket *pkt)
if (vpk->current_block == vpk->block_count) { if (vpk->current_block == vpk->block_count) {
unsigned size = vpk->last_block_size / par->channels; unsigned size = vpk->last_block_size / par->channels;
unsigned skip = (par->block_align - vpk->last_block_size) / par->channels; unsigned skip = (par->block_align - vpk->last_block_size) / par->channels;
uint64_t pos = avio_tell(s->pb);
ret = av_new_packet(pkt, vpk->last_block_size); ret = av_new_packet(pkt, vpk->last_block_size);
if (ret < 0) if (ret < 0)
...@@ -96,6 +99,7 @@ static int vpk_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -96,6 +99,7 @@ static int vpk_read_packet(AVFormatContext *s, AVPacket *pkt)
return AVERROR(EIO); return AVERROR(EIO);
} }
} }
pkt->pos = pos;
pkt->stream_index = 0; pkt->stream_index = 0;
} else if (vpk->current_block < vpk->block_count) { } else if (vpk->current_block < vpk->block_count) {
ret = av_get_packet(s->pb, pkt, par->block_align); ret = av_get_packet(s->pb, pkt, par->block_align);
...@@ -107,6 +111,26 @@ static int vpk_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -107,6 +111,26 @@ static int vpk_read_packet(AVFormatContext *s, AVPacket *pkt)
return ret; return ret;
} }
static int vpk_read_seek(AVFormatContext *s, int stream_index,
int64_t timestamp, int flags)
{
AVStream *st = s->streams[stream_index];
AVCodecParameters *par = st->codecpar;
VPKDemuxContext *vpk = s->priv_data;
int samples_per_block;
int64_t ret = 0;
samples_per_block = av_get_audio_frame_duration2(par, par->block_align);
timestamp /= samples_per_block;
ret = avio_seek(s->pb, vpk->data_start + timestamp * par->block_align, SEEK_SET);
if (ret < 0)
return ret;
vpk->current_block = timestamp;
ff_update_cur_dts(s, st, timestamp * samples_per_block);
return 0;
}
AVInputFormat ff_vpk_demuxer = { AVInputFormat ff_vpk_demuxer = {
.name = "vpk", .name = "vpk",
.long_name = NULL_IF_CONFIG_SMALL("Sony PS2 VPK"), .long_name = NULL_IF_CONFIG_SMALL("Sony PS2 VPK"),
...@@ -114,5 +138,6 @@ AVInputFormat ff_vpk_demuxer = { ...@@ -114,5 +138,6 @@ AVInputFormat ff_vpk_demuxer = {
.read_probe = vpk_probe, .read_probe = vpk_probe,
.read_header = vpk_read_header, .read_header = vpk_read_header,
.read_packet = vpk_read_packet, .read_packet = vpk_read_packet,
.read_seek = vpk_read_seek,
.extensions = "vpk", .extensions = "vpk",
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment