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
21 #define NTSC_FRAME_SIZE 120000
22 #define PAL_FRAME_SIZE 144000
24 typedef struct DVDemuxContext {
26 uint8_t buf[PAL_FRAME_SIZE];
31 static int dv_read_header(AVFormatContext *s,
32 AVFormatParameters *ap)
35 DVDemuxContext *c = s->priv_data;
37 vst = av_new_stream(s, 0);
40 vst->codec.codec_type = CODEC_TYPE_VIDEO;
41 vst->codec.codec_id = CODEC_ID_DVVIDEO;
44 ast = av_new_stream(s, 1);
48 ast->codec.codec_type = CODEC_TYPE_AUDIO;
49 ast->codec.codec_id = CODEC_ID_DVAUDIO;
55 static void __destruct_pkt(struct AVPacket *pkt)
57 pkt->data = NULL; pkt->size = 0;
61 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
64 DVDemuxContext *c = s->priv_data;
67 ret = get_buffer(&s->pb, c->buf, 4);
70 dsf = c->buf[3] & 0x80;
72 c->size = NTSC_FRAME_SIZE;
74 c->size = PAL_FRAME_SIZE;
76 ret = get_buffer(&s->pb, c->buf + 4, c->size - 4);
82 pkt->destruct = __destruct_pkt;
85 pkt->stream_index = c->is_audio;
86 pkt->flags |= PKT_FLAG_KEY;
88 c->is_audio = !c->is_audio;
92 static int dv_read_close(AVFormatContext *s)
97 static AVInputFormat dv_iformat = {
100 sizeof(DVDemuxContext),
109 int dv_write_header(struct AVFormatContext *s)
114 int dv_write_packet(struct AVFormatContext *s,
116 unsigned char *buf, int size, int force_pts)
118 put_buffer(&s->pb, buf, size);
119 put_flush_packet(&s->pb);
123 int dv_write_trailer(struct AVFormatContext *s)
128 AVOutputFormat dv_oformat = {
143 av_register_input_format(&dv_iformat);
144 av_register_output_format(&dv_oformat);