annotate dv.c @ 52:2a60f406fccc libavformat

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