3 * Copyright (c) 2002 Fabrice Bellard.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 typedef struct DVDemuxContext {
29 static int dv_read_header(AVFormatContext *s,
30 AVFormatParameters *ap)
33 DVDemuxContext *c = s->priv_data;
35 vst = av_new_stream(s, 0);
38 vst->codec.codec_type = CODEC_TYPE_VIDEO;
39 vst->codec.codec_id = CODEC_ID_DVVIDEO;
40 vst->codec.bit_rate = 25000000;
42 ast = av_new_stream(s, 1);
46 ast->codec.codec_type = CODEC_TYPE_AUDIO;
47 ast->codec.codec_id = CODEC_ID_DVAUDIO;
53 static void __destruct_pkt(struct AVPacket *pkt)
55 pkt->data = NULL; pkt->size = 0;
59 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
62 DVDemuxContext *c = s->priv_data;
65 ret = get_buffer(&s->pb, c->buf, 4);
68 c->size = dv_frame_profile(&c->buf[0])->frame_size;
70 ret = get_buffer(&s->pb, c->buf + 4, c->size - 4);
76 pkt->destruct = __destruct_pkt;
79 pkt->stream_index = c->is_audio;
80 pkt->flags |= PKT_FLAG_KEY;
82 c->is_audio = !c->is_audio;
86 static int dv_read_close(AVFormatContext *s)
91 int dv_write_header(struct AVFormatContext *s)
93 DVMuxContext *c = s->priv_data;
95 if (s->nb_streams != 2 || dv_core_init(c, s->streams) != 0) {
96 fprintf(stderr, "Can't initialize DV format!\n"
97 "Make sure that you supply exactly two streams:\n"
98 " video: 25fps or 29.97fps, audio: 2ch/48Khz/PCM\n");
104 int dv_write_packet(struct AVFormatContext *s,
106 const uint8_t *buf, int size, int64_t pts)
108 DVMuxContext *c = s->priv_data;
110 if (stream_index == c->vst)
111 dv_assemble_frame(c, buf, NULL, 0);
113 dv_assemble_frame(c, NULL, buf, size);
115 if (c->has_audio && c->has_video) {
116 put_buffer(&s->pb, &c->frame_buf[0], c->sys->frame_size);
117 put_flush_packet(&s->pb);
124 * We might end up with some extra A/V data without matching counterpart.
125 * E.g. video data without enough audio to write the complete frame.
126 * Currently we simply drop the last frame. I don't know whether this
127 * is the best strategy of all
129 int dv_write_trailer(struct AVFormatContext *s)
131 dv_core_delete((DVMuxContext *)s->priv_data);
135 static AVInputFormat dv_iformat = {
138 sizeof(DVDemuxContext),
146 AVOutputFormat dv_oformat = {
151 sizeof(DVMuxContext),
161 av_register_input_format(&dv_iformat);
162 av_register_output_format(&dv_oformat);