Commit b67ada98 authored by romansh's avatar romansh

   * enabling seek in raw DV files
   * generic DV demuxer now sets correct pts for every packet


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@2919 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 0157742c
...@@ -33,6 +33,8 @@ struct DVDemuxContext { ...@@ -33,6 +33,8 @@ struct DVDemuxContext {
AVStream* ast[2]; AVStream* ast[2];
AVPacket audio_pkt[2]; AVPacket audio_pkt[2];
int ach; int ach;
int frames;
uint64_t abytes;
}; };
struct DVMuxContext { struct DVMuxContext {
...@@ -720,6 +722,8 @@ DVDemuxContext* dv_init_demux(AVFormatContext *s) ...@@ -720,6 +722,8 @@ DVDemuxContext* dv_init_demux(AVFormatContext *s)
c->fctx = s; c->fctx = s;
c->ast[1] = NULL; c->ast[1] = NULL;
c->ach = 0; c->ach = 0;
c->frames = 0;
c->abytes = 0;
c->audio_pkt[0].size = 0; c->audio_pkt[0].size = 0;
c->audio_pkt[1].size = 0; c->audio_pkt[1].size = 0;
...@@ -732,6 +736,8 @@ DVDemuxContext* dv_init_demux(AVFormatContext *s) ...@@ -732,6 +736,8 @@ DVDemuxContext* dv_init_demux(AVFormatContext *s)
s->ctx_flags |= AVFMTCTX_NOHEADER; s->ctx_flags |= AVFMTCTX_NOHEADER;
av_set_pts_info(s, 64, 1, 30000);
return c; return c;
fail: fail:
...@@ -770,8 +776,9 @@ int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, ...@@ -770,8 +776,9 @@ int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
uint8_t* buf, int buf_size) uint8_t* buf, int buf_size)
{ {
int size, i; int size, i;
const DVprofile* sys = dv_frame_profile(buf);
if (buf_size < 4 || buf_size < dv_frame_profile(buf)->frame_size) if (buf_size < 4 || buf_size < sys->frame_size)
return -1; /* Broken frame, or not enough data */ return -1; /* Broken frame, or not enough data */
/* Queueing audio packet */ /* Queueing audio packet */
...@@ -782,8 +789,11 @@ int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, ...@@ -782,8 +789,11 @@ int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
if (av_new_packet(&c->audio_pkt[i], size) < 0) if (av_new_packet(&c->audio_pkt[i], size) < 0)
return AVERROR_NOMEM; return AVERROR_NOMEM;
c->audio_pkt[i].stream_index = c->ast[i]->index; c->audio_pkt[i].stream_index = c->ast[i]->index;
c->audio_pkt[i].pts = c->abytes * 30000*8 / c->ast[i]->codec.bit_rate;
c->audio_pkt[i].flags |= PKT_FLAG_KEY;
} }
dv_extract_audio(buf, c->audio_pkt[0].data, c->audio_pkt[1].data); dv_extract_audio(buf, c->audio_pkt[0].data, c->audio_pkt[1].data);
c->abytes += size;
/* Now it's time to return video packet */ /* Now it's time to return video packet */
size = dv_extract_video_info(c, buf); size = dv_extract_video_info(c, buf);
...@@ -793,10 +803,21 @@ int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, ...@@ -793,10 +803,21 @@ int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
pkt->size = size; pkt->size = size;
pkt->flags |= PKT_FLAG_KEY; pkt->flags |= PKT_FLAG_KEY;
pkt->stream_index = c->vst->id; pkt->stream_index = c->vst->id;
pkt->pts = c->frames * sys->frame_rate_base * (30000/sys->frame_rate);
c->frames++;
return size; return size;
} }
int64_t dv_frame_offset(DVDemuxContext *c, int64_t timestamp)
{
const DVprofile* sys = dv_codec_profile(&c->vst->codec);
return sys->frame_size * ((timestamp * sys->frame_rate) /
(AV_TIME_BASE * sys->frame_rate_base));
}
/************************************************************ /************************************************************
* Implementation of the easiest DV storage of all -- raw DV. * Implementation of the easiest DV storage of all -- raw DV.
************************************************************/ ************************************************************/
...@@ -837,6 +858,13 @@ static int dv_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -837,6 +858,13 @@ static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
return size; return size;
} }
static int dv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp)
{
RawDVContext *c = s->priv_data;
return url_fseek(&s->pb, dv_frame_offset(c->dv_demux, timestamp), SEEK_SET);
}
static int dv_read_close(AVFormatContext *s) static int dv_read_close(AVFormatContext *s)
{ {
RawDVContext *c = s->priv_data; RawDVContext *c = s->priv_data;
...@@ -892,6 +920,7 @@ static AVInputFormat dv_iformat = { ...@@ -892,6 +920,7 @@ static AVInputFormat dv_iformat = {
dv_read_header, dv_read_header,
dv_read_packet, dv_read_packet,
dv_read_close, dv_read_close,
dv_read_seek,
.extensions = "dv", .extensions = "dv",
}; };
......
...@@ -43,8 +43,6 @@ struct dv1394_data { ...@@ -43,8 +43,6 @@ struct dv1394_data {
int avail; /* Number of frames available for reading */ int avail; /* Number of frames available for reading */
int done; /* Number of completed frames */ int done; /* Number of completed frames */
int64_t pts; /* Current timestamp */
DVDemuxContext* dv_demux; /* Generic DV muxing/demuxing context */ DVDemuxContext* dv_demux; /* Generic DV muxing/demuxing context */
}; };
...@@ -121,8 +119,6 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap ...@@ -121,8 +119,6 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap
goto failed; goto failed;
} }
av_set_pts_info(context, 48, 1, 1000000);
if (dv1394_start(dv) < 0) if (dv1394_start(dv) < 0)
goto failed; goto failed;
...@@ -140,7 +136,7 @@ static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt) ...@@ -140,7 +136,7 @@ static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt)
size = dv_get_packet(dv->dv_demux, pkt); size = dv_get_packet(dv->dv_demux, pkt);
if (size > 0) if (size > 0)
goto out; return size;
if (!dv->avail) { if (!dv->avail) {
struct dv1394_status s; struct dv1394_status s;
...@@ -209,10 +205,7 @@ restart_poll: ...@@ -209,10 +205,7 @@ restart_poll:
DV1394_PAL_FRAME_SIZE); DV1394_PAL_FRAME_SIZE);
dv->index = (dv->index + 1) % DV1394_RING_FRAMES; dv->index = (dv->index + 1) % DV1394_RING_FRAMES;
dv->done++; dv->avail--; dv->done++; dv->avail--;
dv->pts = av_gettime() & ((1LL << 48) - 1);
out:
pkt->pts = dv->pts;
return size; return size;
} }
......
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