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