AVStream* vst;
AVStream* ast[2];
AVPacket audio_pkt[2];
+ uint8_t audio_buf[2][8192];
int ach;
int frames;
uint64_t abytes;
dv_audio_rectime = 0x53,
dv_video_source = 0x60,
dv_video_control = 0x61,
- dv_viedo_recdate = 0x62,
+ dv_video_recdate = 0x62,
dv_video_rectime = 0x63,
dv_unknown_pack = 0xff,
};
0x7f; /* genre category */
break;
case dv_audio_recdate:
- case dv_viedo_recdate: /* VAUX recording date */
+ case dv_video_recdate: /* VAUX recording date */
ct = c->start_time + (time_t)(c->frames /
((float)c->sys->frame_rate / (float)c->sys->frame_rate_base));
brktimegm(ct, &tc);
as_pack = dv_extract_pack(frame, dv_audio_source);
if (!as_pack || !sys) { /* No audio ? */
c->ach = 0;
- return -1;
+ return 0;
}
smpls = as_pack[1] & 0x3f; /* samples in this frame - min. samples */
if (!c->ast[i])
break;
av_set_pts_info(c->ast[i], 64, 1, 30000);
- c->ast[i]->codec.codec_type = CODEC_TYPE_AUDIO;
- c->ast[i]->codec.codec_id = CODEC_ID_PCM_S16LE;
+ c->ast[i]->codec->codec_type = CODEC_TYPE_AUDIO;
+ c->ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE;
+
+ av_init_packet(&c->audio_pkt[i]);
+ c->audio_pkt[i].size = 0;
+ c->audio_pkt[i].data = c->audio_buf[i];
+ c->audio_pkt[i].stream_index = c->ast[i]->index;
+ c->audio_pkt[i].flags |= PKT_FLAG_KEY;
}
- c->ast[i]->codec.sample_rate = dv_audio_frequency[freq];
- c->ast[i]->codec.channels = 2;
- c->ast[i]->codec.bit_rate = 2 * dv_audio_frequency[freq] * 16;
+ c->ast[i]->codec->sample_rate = dv_audio_frequency[freq];
+ c->ast[i]->codec->channels = 2;
+ c->ast[i]->codec->bit_rate = 2 * dv_audio_frequency[freq] * 16;
c->ast[i]->start_time = 0;
}
c->ach = i;
sys = dv_frame_profile(frame);
if (sys) {
- avctx = &c->vst->codec;
+ avctx = c->vst->codec;
- avctx->frame_rate = sys->frame_rate;
- avctx->frame_rate_base = sys->frame_rate_base;
- avctx->width = sys->width;
- avctx->height = sys->height;
+ av_set_pts_info(c->vst, 64, sys->frame_rate_base, sys->frame_rate);
+ avctx->time_base= (AVRational){sys->frame_rate_base, sys->frame_rate};
+ if(!avctx->width){
+ avctx->width = sys->width;
+ avctx->height = sys->height;
+ }
avctx->pix_fmt = sys->pix_fmt;
/* finding out SAR is a little bit messy */
c->has_video = 0;
}
- if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
+ if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
/* FIXME: we have to have more sensible approach than this one */
if (c->has_video)
- av_log(&st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames);
+ av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames);
dv_inject_video(c, data, *frame);
c->has_video = 1;
reqasize = 4 * dv_audio_frame_size(c->sys, c->frames);
fsize = fifo_size(&c->audio_data, c->audio_data.rptr);
- if (st->codec.codec_type == CODEC_TYPE_AUDIO || (c->has_video && fsize >= reqasize)) {
+ if (st->codec->codec_type == CODEC_TYPE_AUDIO || (c->has_video && fsize >= reqasize)) {
if (fsize + data_size >= reqasize && !c->has_audio) {
if (fsize >= reqasize) {
fifo_read(&c->audio_data, &pcm[0], reqasize, &c->audio_data.rptr);
/* FIXME: we have to have more sensible approach than this one */
if (fifo_size(&c->audio_data, c->audio_data.rptr) + data_size >= 100*AVCODEC_MAX_AUDIO_FRAME_SIZE)
- av_log(&st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames);
+ av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames);
fifo_write(&c->audio_data, (uint8_t *)data, data_size, &c->audio_data.wptr);
}
/* We have to sort out where audio and where video stream is */
for (i=0; i<s->nb_streams; i++) {
- switch (s->streams[i]->codec.codec_type) {
+ switch (s->streams[i]->codec->codec_type) {
case CODEC_TYPE_VIDEO:
vst = s->streams[i];
break;
}
/* Some checks -- DV format is very picky about its incoming streams */
- if (!vst || vst->codec.codec_id != CODEC_ID_DVVIDEO)
+ if (!vst || vst->codec->codec_id != CODEC_ID_DVVIDEO)
goto bail_out;
- if (ast && (ast->codec.codec_id != CODEC_ID_PCM_S16LE ||
- ast->codec.sample_rate != 48000 ||
- ast->codec.channels != 2))
+ if (ast && (ast->codec->codec_id != CODEC_ID_PCM_S16LE ||
+ ast->codec->sample_rate != 48000 ||
+ ast->codec->channels != 2))
goto bail_out;
- c->sys = dv_codec_profile(&vst->codec);
+ c->sys = dv_codec_profile(vst->codec);
if (!c->sys)
goto bail_out;
c->has_video = 0;
c->start_time = (time_t)s->timestamp;
c->aspect = 0; /* 4:3 is the default */
- if ((int)(av_q2d(vst->codec.sample_aspect_ratio) * vst->codec.width / vst->codec.height * 10) == 17) /* 16:9 */
+ if ((int)(av_q2d(vst->codec->sample_aspect_ratio) * vst->codec->width / vst->codec->height * 10) == 17) /* 16:9 */
c->aspect = 0x07;
if (ast && fifo_init(&c->audio_data, 100*AVCODEC_MAX_AUDIO_FRAME_SIZE) < 0)
av_free(c);
return NULL;
}
- av_set_pts_info(c->vst, 64, 1, 30000);
c->fctx = s;
c->ast[0] = c->ast[1] = NULL;
c->ach = 0;
c->frames = 0;
c->abytes = 0;
- c->audio_pkt[0].size = 0;
- c->audio_pkt[1].size = 0;
-
- c->vst->codec.codec_type = CODEC_TYPE_VIDEO;
- c->vst->codec.codec_id = CODEC_ID_DVVIDEO;
- c->vst->codec.bit_rate = 25000000;
+
+ c->vst->codec->codec_type = CODEC_TYPE_VIDEO;
+ c->vst->codec->codec_id = CODEC_ID_DVVIDEO;
+ c->vst->codec->bit_rate = 25000000;
c->vst->start_time = 0;
return c;
}
-static void __destruct_pkt(struct AVPacket *pkt)
-{
- pkt->data = NULL; pkt->size = 0;
- return;
-}
-
int dv_get_packet(DVDemuxContext *c, AVPacket *pkt)
{
int size = -1;
/* Queueing audio packet */
/* FIXME: in case of no audio/bad audio we have to do something */
size = dv_extract_audio_info(c, buf);
- c->audio_pkt[0].data = c->audio_pkt[1].data = NULL;
for (i=0; i<c->ach; i++) {
- if (av_new_packet(&c->audio_pkt[i], size) < 0)
- return AVERROR_NOMEM;
- 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;
+ c->audio_pkt[i].size = size;
+ c->audio_pkt[i].pts = c->abytes * 30000*8 / c->ast[i]->codec->bit_rate;
}
- dv_extract_audio(buf, c->audio_pkt[0].data, c->audio_pkt[1].data);
+ dv_extract_audio(buf, c->audio_buf[0], c->audio_buf[1]);
c->abytes += size;
/* Now it's time to return video packet */
size = dv_extract_video_info(c, buf);
av_init_packet(pkt);
- pkt->destruct = __destruct_pkt;
pkt->data = buf;
pkt->size = size;
pkt->flags |= PKT_FLAG_KEY;
pkt->stream_index = c->vst->id;
- pkt->pts = c->frames * sys->frame_rate_base * (30000/sys->frame_rate);
+ pkt->pts = c->frames;
c->frames++;
return size;
}
-int64_t dv_frame_offset(DVDemuxContext *c, int64_t timestamp)
+static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c,
+ int64_t timestamp, int flags)
{
- const DVprofile* sys;
- int64_t frame_number, offset;
-
// FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk)
- sys = dv_codec_profile(&c->vst->codec);
-
- // timestamp was scaled by time_base/AV_BASE_RATE by av_seek_frame()
- frame_number = (timestamp * sys->frame_rate) /
- ((int64_t) 30000 * sys->frame_rate_base);
+ const DVprofile* sys = dv_codec_profile(c->vst->codec);
+ int64_t offset;
+ int64_t size = url_fsize(&s->pb);
+ int64_t max_offset = ((size-1) / sys->frame_size) * sys->frame_size;
- // offset must be a multiple of frame_size else dv_read_packet() will fail
- offset = (int64_t) sys->frame_size * frame_number;
+ offset = sys->frame_size * timestamp;
+
+ if (offset > max_offset) offset = max_offset;
+ else if (offset < 0) offset = 0;
return offset;
}
+void dv_flush_audio_packets(DVDemuxContext *c)
+{
+ c->audio_pkt[0].size = c->audio_pkt[1].size = 0;
+}
+
/************************************************************
* Implementation of the easiest DV storage of all -- raw DV.
************************************************************/
return size;
}
-static int dv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp)
+static int dv_read_seek(AVFormatContext *s, int stream_index,
+ int64_t timestamp, int flags)
{
- RawDVContext *c = s->priv_data;
-
- return url_fseek(&s->pb, dv_frame_offset(c->dv_demux, timestamp), SEEK_SET);
+ RawDVContext *r = s->priv_data;
+ DVDemuxContext *c = r->dv_demux;
+ int64_t offset= dv_frame_offset(s, c, timestamp, flags);
+ const DVprofile* sys = dv_codec_profile(c->vst->codec);
+
+ c->frames= offset / sys->frame_size;
+ if (c->ach)
+ c->abytes= av_rescale(c->frames,
+ c->ast[0]->codec->bit_rate * (int64_t)sys->frame_rate_base,
+ 8*sys->frame_rate);
+
+ dv_flush_audio_packets(c);
+ return url_fseek(&s->pb, offset, SEEK_SET);
}
static int dv_read_close(AVFormatContext *s)