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;
50 ast->codec.channels = 2;
56 /* XXX: build fake audio stream when DV audio decoder will be finished */
57 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
60 DVDemuxContext *c = s->priv_data;
63 ret = get_buffer(&s->pb, c->buf, 4);
66 dsf = c->buf[3] & 0x80;
68 c->size = NTSC_FRAME_SIZE;
70 c->size = PAL_FRAME_SIZE;
72 ret = get_buffer(&s->pb, c->buf + 4, c->size - 4);
77 if (av_new_packet(pkt, c->size) < 0)
80 pkt->stream_index = c->is_audio;
81 c->is_audio = !c->is_audio;
82 memcpy(pkt->data, c->buf, c->size);
86 static int dv_read_close(AVFormatContext *s)
91 static AVInputFormat dv_iformat = {
94 sizeof(DVDemuxContext),
103 int dv_write_header(struct AVFormatContext *s)
108 int dv_write_packet(struct AVFormatContext *s,
110 unsigned char *buf, int size, int force_pts)
112 put_buffer(&s->pb, buf, size);
113 put_flush_packet(&s->pb);
117 int dv_write_trailer(struct AVFormatContext *s)
122 AVOutputFormat dv_oformat = {
138 av_register_input_format(&dv_iformat);
139 // av_register_output_format(&dv_oformat);