Mercurial > libavformat.hg
annotate dv.c @ 236:ee98d63dbba7 libavformat
kernel header bug workaround by (Ronald Bultje <rbultje at ronald dot bitfreak dot net>)
author | michaelni |
---|---|
date | Tue, 09 Sep 2003 19:14:05 +0000 |
parents | 184d22d04c84 |
children | 3d92f793fd67 |
rev | line source |
---|---|
0 | 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" | |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
20 #include "dvcore.h" |
0 | 21 |
22 typedef struct DVDemuxContext { | |
37 | 23 int is_audio; |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
24 uint8_t buf[144000]; |
37 | 25 int size; |
0 | 26 } DVDemuxContext; |
27 | |
28 /* raw input */ | |
29 static int dv_read_header(AVFormatContext *s, | |
30 AVFormatParameters *ap) | |
31 { | |
37 | 32 AVStream *vst, *ast; |
33 DVDemuxContext *c = s->priv_data; | |
0 | 34 |
35 vst = av_new_stream(s, 0); | |
36 if (!vst) | |
37 return AVERROR_NOMEM; | |
38 vst->codec.codec_type = CODEC_TYPE_VIDEO; | |
39 vst->codec.codec_id = CODEC_ID_DVVIDEO; | |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
40 vst->codec.bit_rate = 25000000; |
37 | 41 |
0 | 42 ast = av_new_stream(s, 1); |
43 if (!ast) | |
44 return AVERROR_NOMEM; | |
45 | |
46 ast->codec.codec_type = CODEC_TYPE_AUDIO; | |
47 ast->codec.codec_id = CODEC_ID_DVAUDIO; | |
37 | 48 c->is_audio = 0; |
49 | |
0 | 50 return 0; |
51 } | |
52 | |
58 | 53 static void __destruct_pkt(struct AVPacket *pkt) |
54 { | |
55 pkt->data = NULL; pkt->size = 0; | |
56 return; | |
57 } | |
58 | |
0 | 59 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt) |
60 { | |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
61 int ret; |
37 | 62 DVDemuxContext *c = s->priv_data; |
0 | 63 |
37 | 64 if (!c->is_audio) { |
65 ret = get_buffer(&s->pb, c->buf, 4); | |
66 if (ret <= 0) | |
67 return -EIO; | |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
68 c->size = dv_frame_profile(&c->buf[0])->frame_size; |
37 | 69 |
70 ret = get_buffer(&s->pb, c->buf + 4, c->size - 4); | |
71 if (ret <= 0) | |
72 return -EIO; | |
73 } | |
0 | 74 |
58 | 75 av_init_packet(pkt); |
76 pkt->destruct = __destruct_pkt; | |
77 pkt->data = c->buf; | |
78 pkt->size = c->size; | |
37 | 79 pkt->stream_index = c->is_audio; |
119 | 80 pkt->flags |= PKT_FLAG_KEY; |
58 | 81 |
37 | 82 c->is_audio = !c->is_audio; |
58 | 83 return c->size; |
0 | 84 } |
85 | |
86 static int dv_read_close(AVFormatContext *s) | |
87 { | |
88 return 0; | |
89 } | |
90 | |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
91 int dv_write_header(struct AVFormatContext *s) |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
92 { |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
93 DVMuxContext *c = s->priv_data; |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
94 |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
95 if (s->nb_streams != 2 || dv_core_init(c, s->streams) != 0) { |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
96 fprintf(stderr, "Can't initialize DV format!\n" |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
97 "Make sure that you supply exactly two streams:\n" |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
98 " video: 25fps or 29.97fps, audio: 2ch/48Khz/PCM\n"); |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
99 return -1; |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
100 } |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
101 return 0; |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
102 } |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
103 |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
104 int dv_write_packet(struct AVFormatContext *s, |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
105 int stream_index, |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
106 unsigned char *buf, int size, int force_pts) |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
107 { |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
108 DVMuxContext *c = s->priv_data; |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
109 |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
110 if (stream_index == c->vst) |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
111 dv_assemble_frame(c, buf, NULL, 0); |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
112 else |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
113 dv_assemble_frame(c, NULL, buf, size); |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
114 |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
115 if (c->has_audio && c->has_video) { |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
116 put_buffer(&s->pb, &c->frame_buf[0], c->sys->frame_size); |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
117 put_flush_packet(&s->pb); |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
118 } |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
119 |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
120 return 0; |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
121 } |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
122 |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
123 /* |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
124 * We might end up with some extra A/V data without matching counterpart. |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
125 * E.g. video data without enough audio to write the complete frame. |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
126 * Currently we simply drop the last frame. I don't know whether this |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
127 * is the best strategy of all |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
128 */ |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
129 int dv_write_trailer(struct AVFormatContext *s) |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
130 { |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
131 dv_core_delete((DVMuxContext *)s->priv_data); |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
132 return 0; |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
133 } |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
134 |
0 | 135 static AVInputFormat dv_iformat = { |
136 "dv", | |
137 "DV video format", | |
138 sizeof(DVDemuxContext), | |
139 NULL, | |
140 dv_read_header, | |
141 dv_read_packet, | |
142 dv_read_close, | |
143 .extensions = "dv", | |
144 }; | |
145 | |
146 AVOutputFormat dv_oformat = { | |
147 "dv", | |
148 "DV video format", | |
149 NULL, | |
150 "dv", | |
203
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
151 sizeof(DVMuxContext), |
184d22d04c84
* Phase 1 for DV encoding support. Muxing/demuxing of DV streams is now
romansh
parents:
119
diff
changeset
|
152 CODEC_ID_PCM_S16LE, |
0 | 153 CODEC_ID_DVVIDEO, |
154 dv_write_header, | |
155 dv_write_packet, | |
156 dv_write_trailer, | |
157 }; | |
158 | |
159 int dv_init(void) | |
160 { | |
161 av_register_input_format(&dv_iformat); | |
103
68b0e1708839
dv file format support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
99
diff
changeset
|
162 av_register_output_format(&dv_oformat); |
0 | 163 return 0; |
164 } |