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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * Raw DV format
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2002 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 typedef struct DVDemuxContext {
37
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
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
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
25 int size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 } DVDemuxContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 /* raw input */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 static int dv_read_header(AVFormatContext *s,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 {
37
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
32 AVStream *vst, *ast;
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
33 DVDemuxContext *c = s->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 vst = av_new_stream(s, 0);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 if (!vst)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 return AVERROR_NOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 vst->codec.codec_type = CODEC_TYPE_VIDEO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
41
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 ast = av_new_stream(s, 1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 if (!ast)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 return AVERROR_NOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 ast->codec.codec_type = CODEC_TYPE_AUDIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 ast->codec.codec_id = CODEC_ID_DVAUDIO;
37
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
48 c->is_audio = 0;
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
49
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52
58
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
53 static void __destruct_pkt(struct AVPacket *pkt)
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
54 {
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
55 pkt->data = NULL; pkt->size = 0;
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
56 return;
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
57 }
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
58
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
62 DVDemuxContext *c = s->priv_data;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63
37
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
64 if (!c->is_audio) {
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
65 ret = get_buffer(&s->pb, c->buf, 4);
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
66 if (ret <= 0)
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
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
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
69
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
70 ret = get_buffer(&s->pb, c->buf + 4, c->size - 4);
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
71 if (ret <= 0)
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
72 return -EIO;
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
73 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74
58
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
75 av_init_packet(pkt);
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
76 pkt->destruct = __destruct_pkt;
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
77 pkt->data = c->buf;
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
78 pkt->size = c->size;
37
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
79 pkt->stream_index = c->is_audio;
119
602546f3cbea Complete support for OpenDML AVIs and AVIs > 2Gb.
romansh
parents: 103
diff changeset
80 pkt->flags |= PKT_FLAG_KEY;
58
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
81
37
8f76666c71c2 DV audio decoder by Roman Shaposhnick
bellard
parents: 28
diff changeset
82 c->is_audio = !c->is_audio;
58
b1dd147434af DV packet copy fix by Roman Shaposhnick
bellard
parents: 37
diff changeset
83 return c->size;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 static int dv_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 static AVInputFormat dv_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 "dv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 "DV video format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 sizeof(DVDemuxContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 dv_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 dv_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 dv_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 .extensions = "dv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 AVOutputFormat dv_oformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 "dv",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 "DV video format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 NULL,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 CODEC_ID_DVVIDEO,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 dv_write_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 dv_write_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 dv_write_trailer,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 int dv_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
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
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 }