Mercurial > libavformat.hg
annotate dv.c @ 194:37e7cd3d544d libavformat
support for older real audio files (<= version 3)
author | bellard |
---|---|
date | Mon, 11 Aug 2003 16:16:49 +0000 |
parents | 602546f3cbea |
children | 184d22d04c84 |
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" | |
20 | |
21 #define NTSC_FRAME_SIZE 120000 | |
22 #define PAL_FRAME_SIZE 144000 | |
23 | |
24 typedef struct DVDemuxContext { | |
37 | 25 int is_audio; |
26 uint8_t buf[PAL_FRAME_SIZE]; | |
27 int size; | |
0 | 28 } DVDemuxContext; |
29 | |
30 /* raw input */ | |
31 static int dv_read_header(AVFormatContext *s, | |
32 AVFormatParameters *ap) | |
33 { | |
37 | 34 AVStream *vst, *ast; |
35 DVDemuxContext *c = s->priv_data; | |
0 | 36 |
37 vst = av_new_stream(s, 0); | |
38 if (!vst) | |
39 return AVERROR_NOMEM; | |
40 vst->codec.codec_type = CODEC_TYPE_VIDEO; | |
41 vst->codec.codec_id = CODEC_ID_DVVIDEO; | |
42 | |
37 | 43 |
0 | 44 ast = av_new_stream(s, 1); |
45 if (!ast) | |
46 return AVERROR_NOMEM; | |
47 | |
48 ast->codec.codec_type = CODEC_TYPE_AUDIO; | |
49 ast->codec.codec_id = CODEC_ID_DVAUDIO; | |
37 | 50 c->is_audio = 0; |
51 | |
0 | 52 return 0; |
53 } | |
54 | |
58 | 55 static void __destruct_pkt(struct AVPacket *pkt) |
56 { | |
57 pkt->data = NULL; pkt->size = 0; | |
58 return; | |
59 } | |
60 | |
0 | 61 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt) |
62 { | |
37 | 63 int ret, dsf; |
64 DVDemuxContext *c = s->priv_data; | |
0 | 65 |
37 | 66 if (!c->is_audio) { |
67 ret = get_buffer(&s->pb, c->buf, 4); | |
68 if (ret <= 0) | |
69 return -EIO; | |
70 dsf = c->buf[3] & 0x80; | |
71 if (!dsf) | |
72 c->size = NTSC_FRAME_SIZE; | |
73 else | |
74 c->size = PAL_FRAME_SIZE; | |
75 | |
76 ret = get_buffer(&s->pb, c->buf + 4, c->size - 4); | |
77 if (ret <= 0) | |
78 return -EIO; | |
79 } | |
0 | 80 |
58 | 81 av_init_packet(pkt); |
82 pkt->destruct = __destruct_pkt; | |
83 pkt->data = c->buf; | |
84 pkt->size = c->size; | |
37 | 85 pkt->stream_index = c->is_audio; |
119 | 86 pkt->flags |= PKT_FLAG_KEY; |
58 | 87 |
37 | 88 c->is_audio = !c->is_audio; |
58 | 89 return c->size; |
0 | 90 } |
91 | |
92 static int dv_read_close(AVFormatContext *s) | |
93 { | |
94 return 0; | |
95 } | |
96 | |
97 static AVInputFormat dv_iformat = { | |
98 "dv", | |
99 "DV video format", | |
100 sizeof(DVDemuxContext), | |
101 NULL, | |
102 dv_read_header, | |
103 dv_read_packet, | |
104 dv_read_close, | |
105 .extensions = "dv", | |
106 }; | |
107 | |
103
68b0e1708839
dv file format support patch by (Roman Shaposhnick <rvs at sun dot com>)
michaelni
parents:
99
diff
changeset
|
108 |
0 | 109 int dv_write_header(struct AVFormatContext *s) |
110 { | |
111 return 0; | |
112 } | |
113 | |
114 int dv_write_packet(struct AVFormatContext *s, | |
115 int stream_index, | |
116 unsigned char *buf, int size, int force_pts) | |
117 { | |
118 put_buffer(&s->pb, buf, size); | |
119 put_flush_packet(&s->pb); | |
120 return 0; | |
121 } | |
122 | |
123 int dv_write_trailer(struct AVFormatContext *s) | |
124 { | |
125 return 0; | |
126 } | |
127 | |
128 AVOutputFormat dv_oformat = { | |
129 "dv", | |
130 "DV video format", | |
131 NULL, | |
132 "dv", | |
133 0, | |
134 CODEC_ID_DVVIDEO, | |
135 CODEC_ID_DVAUDIO, | |
136 dv_write_header, | |
137 dv_write_packet, | |
138 dv_write_trailer, | |
139 }; | |
140 | |
141 int dv_init(void) | |
142 { | |
143 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
|
144 av_register_output_format(&dv_oformat); |
0 | 145 return 0; |
146 } |