comparison dv.c @ 0:05318cf2e886 libavformat

renamed libav to libavformat
author bellard
date Mon, 25 Nov 2002 19:07:40 +0000
parents
children 64678c053566
comparison
equal deleted inserted replaced
-1:000000000000 0:05318cf2e886
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 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
53 {
54 int ret, size, dsf;
55 uint8_t buf[4];
56
57 ret = get_buffer(&s->pb, buf, 4);
58 if (ret <= 0)
59 return -EIO;
60 dsf = buf[3] & 0x80;
61 if (!dsf)
62 size = NTSC_FRAME_SIZE;
63 else
64 size = PAL_FRAME_SIZE;
65
66 if (av_new_packet(pkt, size) < 0)
67 return -EIO;
68
69 pkt->stream_index = 0;
70 memcpy(pkt->data, buf, 4);
71 ret = get_buffer(&s->pb, pkt->data + 4, size - 4);
72 if (ret <= 0) {
73 av_free_packet(pkt);
74 return -EIO;
75 }
76 return ret;
77 }
78
79 static int dv_read_close(AVFormatContext *s)
80 {
81 return 0;
82 }
83
84 static AVInputFormat dv_iformat = {
85 "dv",
86 "DV video format",
87 sizeof(DVDemuxContext),
88 NULL,
89 dv_read_header,
90 dv_read_packet,
91 dv_read_close,
92 .extensions = "dv",
93 };
94
95 #if 0
96 int dv_write_header(struct AVFormatContext *s)
97 {
98 return 0;
99 }
100
101 int dv_write_packet(struct AVFormatContext *s,
102 int stream_index,
103 unsigned char *buf, int size, int force_pts)
104 {
105 put_buffer(&s->pb, buf, size);
106 put_flush_packet(&s->pb);
107 return 0;
108 }
109
110 int dv_write_trailer(struct AVFormatContext *s)
111 {
112 return 0;
113 }
114
115 AVOutputFormat dv_oformat = {
116 "dv",
117 "DV video format",
118 NULL,
119 "dv",
120 0,
121 CODEC_ID_DVVIDEO,
122 CODEC_ID_DVAUDIO,
123 dv_write_header,
124 dv_write_packet,
125 dv_write_trailer,
126 };
127 #endif
128
129 int dv_init(void)
130 {
131 av_register_input_format(&dv_iformat);
132 // av_register_output_format(&dv_oformat);
133 return 0;
134 }