use C99 syntax for field init
[libav.git] / libav / dv.c
1 /*
2 * Raw DV format
3 * Copyright (c) 2002 Fabrice Bellard.
4 *
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.
9 *
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.
14 *
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
18 */
19 #include "avformat.h"
20
21 #define NTSC_FRAME_SIZE 120000
22 #define PAL_FRAME_SIZE 144000
23
24 typedef struct DVDemuxContext {
25 int is_audio;
26 } DVDemuxContext;
27
28 /* raw input */
29 static int dv_read_header(AVFormatContext *s,
30 AVFormatParameters *ap)
31 {
32 AVStream *vst, *ast;
33
34 vst = av_new_stream(s, 0);
35 if (!vst)
36 return AVERROR_NOMEM;
37 vst->codec.codec_type = CODEC_TYPE_VIDEO;
38 vst->codec.codec_id = CODEC_ID_DVVIDEO;
39
40 #if 0
41 ast = av_new_stream(s, 1);
42 if (!ast)
43 return AVERROR_NOMEM;
44
45 ast->codec.codec_type = CODEC_TYPE_AUDIO;
46 ast->codec.codec_id = CODEC_ID_DVAUDIO;
47 #endif
48 return 0;
49 }
50
51 /* XXX: build fake audio stream when DV audio decoder will be finished */
52 int dv_read_packet(AVFormatContext *s,
53 AVPacket *pkt)
54 {
55 int ret, size, dsf;
56 uint8_t buf[4];
57
58 ret = get_buffer(&s->pb, buf, 4);
59 if (ret <= 0)
60 return -EIO;
61 dsf = buf[3] & 0x80;
62 if (!dsf)
63 size = NTSC_FRAME_SIZE;
64 else
65 size = PAL_FRAME_SIZE;
66
67 if (av_new_packet(pkt, size) < 0)
68 return -EIO;
69
70 pkt->stream_index = 0;
71 memcpy(pkt->data, buf, 4);
72 ret = get_buffer(&s->pb, pkt->data + 4, size - 4);
73 if (ret <= 0) {
74 av_free_packet(pkt);
75 return -EIO;
76 }
77 return ret;
78 }
79
80 int dv_read_close(AVFormatContext *s)
81 {
82 return 0;
83 }
84
85 AVInputFormat dv_iformat = {
86 "dv",
87 "DV video format",
88 sizeof(DVDemuxContext),
89 NULL,
90 dv_read_header,
91 dv_read_packet,
92 dv_read_close,
93 .extensions = "dv",
94 };
95
96 #if 0
97 int dv_write_header(struct AVFormatContext *s)
98 {
99 return 0;
100 }
101
102 int dv_write_packet(struct AVFormatContext *s,
103 int stream_index,
104 unsigned char *buf, int size, int force_pts)
105 {
106 put_buffer(&s->pb, buf, size);
107 put_flush_packet(&s->pb);
108 return 0;
109 }
110
111 int dv_write_trailer(struct AVFormatContext *s)
112 {
113 return 0;
114 }
115
116 AVOutputFormat dv_oformat = {
117 "dv",
118 "DV video format",
119 NULL,
120 "dv",
121 0,
122 CODEC_ID_DVVIDEO,
123 CODEC_ID_DVAUDIO,
124 dv_write_header,
125 dv_write_packet,
126 dv_write_trailer,
127 };
128 #endif
129
130 int dv_init(void)
131 {
132 av_register_input_format(&dv_iformat);
133 // av_register_output_format(&dv_oformat);
134 return 0;
135 }