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 ast->codec.channels = 2;
|
|
51 c->is_audio = 0;
|
|
52
|
0
|
53 return 0;
|
|
54 }
|
|
55
|
|
56 /* XXX: build fake audio stream when DV audio decoder will be finished */
|
|
57 static int dv_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
58 {
|
37
|
59 int ret, dsf;
|
|
60 DVDemuxContext *c = s->priv_data;
|
0
|
61
|
37
|
62 if (!c->is_audio) {
|
|
63 ret = get_buffer(&s->pb, c->buf, 4);
|
|
64 if (ret <= 0)
|
|
65 return -EIO;
|
|
66 dsf = c->buf[3] & 0x80;
|
|
67 if (!dsf)
|
|
68 c->size = NTSC_FRAME_SIZE;
|
|
69 else
|
|
70 c->size = PAL_FRAME_SIZE;
|
|
71
|
|
72 ret = get_buffer(&s->pb, c->buf + 4, c->size - 4);
|
|
73 if (ret <= 0)
|
|
74 return -EIO;
|
|
75 }
|
0
|
76
|
37
|
77 if (av_new_packet(pkt, c->size) < 0)
|
0
|
78 return -EIO;
|
|
79
|
37
|
80 pkt->stream_index = c->is_audio;
|
|
81 c->is_audio = !c->is_audio;
|
|
82 memcpy(pkt->data, c->buf, c->size);
|
0
|
83 return ret;
|
|
84 }
|
|
85
|
|
86 static int dv_read_close(AVFormatContext *s)
|
|
87 {
|
|
88 return 0;
|
|
89 }
|
|
90
|
|
91 static AVInputFormat dv_iformat = {
|
|
92 "dv",
|
|
93 "DV video format",
|
|
94 sizeof(DVDemuxContext),
|
|
95 NULL,
|
|
96 dv_read_header,
|
|
97 dv_read_packet,
|
|
98 dv_read_close,
|
|
99 .extensions = "dv",
|
|
100 };
|
|
101
|
|
102 #if 0
|
|
103 int dv_write_header(struct AVFormatContext *s)
|
|
104 {
|
|
105 return 0;
|
|
106 }
|
|
107
|
|
108 int dv_write_packet(struct AVFormatContext *s,
|
|
109 int stream_index,
|
|
110 unsigned char *buf, int size, int force_pts)
|
|
111 {
|
|
112 put_buffer(&s->pb, buf, size);
|
|
113 put_flush_packet(&s->pb);
|
|
114 return 0;
|
|
115 }
|
|
116
|
|
117 int dv_write_trailer(struct AVFormatContext *s)
|
|
118 {
|
|
119 return 0;
|
|
120 }
|
|
121
|
|
122 AVOutputFormat dv_oformat = {
|
|
123 "dv",
|
|
124 "DV video format",
|
|
125 NULL,
|
|
126 "dv",
|
|
127 0,
|
|
128 CODEC_ID_DVVIDEO,
|
|
129 CODEC_ID_DVAUDIO,
|
|
130 dv_write_header,
|
|
131 dv_write_packet,
|
|
132 dv_write_trailer,
|
|
133 };
|
|
134 #endif
|
|
135
|
|
136 int dv_init(void)
|
|
137 {
|
|
138 av_register_input_format(&dv_iformat);
|
|
139 // av_register_output_format(&dv_oformat);
|
|
140 return 0;
|
|
141 }
|