get rid of the last svn mentions
[libav.git] / libavformat / rawdec.c
CommitLineData
115329f1 1/*
4ca31edc 2 * RAW demuxers
406792e7 3 * Copyright (c) 2001 Fabrice Bellard
84c63c01 4 * Copyright (c) 2005 Alex Beregszaszi
de6d9b64 5 *
b78e7197
DB
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
19720f15
FB
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
b78e7197 11 * version 2.1 of the License, or (at your option) any later version.
de6d9b64 12 *
b78e7197 13 * FFmpeg is distributed in the hope that it will be useful,
de6d9b64 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19720f15
FB
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
de6d9b64 17 *
19720f15 18 * You should have received a copy of the GNU Lesser General Public
b78e7197 19 * License along with FFmpeg; if not, write to the Free Software
5509bffa 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
de6d9b64 21 */
245976da 22
de6d9b64 23#include "avformat.h"
b3db9cee 24#include "avio_internal.h"
4ca31edc 25#include "rawdec.h"
de6d9b64 26
de6d9b64 27/* raw input */
e94204df 28int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
de6d9b64
FB
29{
30 AVStream *st;
0f87b771 31 enum CodecID id;
de6d9b64 32
c9a65ca8 33 st = av_new_stream(s, 0);
de6d9b64 34 if (!st)
769e10f0 35 return AVERROR(ENOMEM);
c04c3282 36
c9a65ca8
FB
37 id = s->iformat->value;
38 if (id == CODEC_ID_RAWVIDEO) {
72415b2a 39 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
de6d9b64 40 } else {
72415b2a 41 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
de6d9b64 42 }
01f4895c 43 st->codec->codec_id = id;
c9a65ca8 44
01f4895c 45 switch(st->codec->codec_type) {
72415b2a 46 case AVMEDIA_TYPE_AUDIO:
01f4895c 47 st->codec->sample_rate = ap->sample_rate;
bf9067cf
MN
48 if(ap->channels) st->codec->channels = ap->channels;
49 else st->codec->channels = 1;
a3d23e15
BC
50 st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
51 assert(st->codec->bits_per_coded_sample > 0);
52 st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;
01f4895c 53 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
de6d9b64 54 break;
72415b2a 55 case AVMEDIA_TYPE_VIDEO:
9de0be61
MN
56 if(ap->time_base.num)
57 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
58 else
59 av_set_pts_info(st, 64, 1, 25);
01f4895c
MN
60 st->codec->width = ap->width;
61 st->codec->height = ap->height;
62 st->codec->pix_fmt = ap->pix_fmt;
63 if(st->codec->pix_fmt == PIX_FMT_NONE)
64 st->codec->pix_fmt= PIX_FMT_YUV420P;
de6d9b64
FB
65 break;
66 default:
27e084bd 67 return -1;
de6d9b64 68 }
de6d9b64
FB
69 return 0;
70}
71
2e93e3aa 72#define RAW_PACKET_SIZE 1024
de6d9b64 73
81f052cb 74int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
e15dec10
LS
75{
76 int ret, size;
77
78 size = RAW_PACKET_SIZE;
79
80 if (av_new_packet(pkt, size) < 0)
c67031e7 81 return AVERROR(ENOMEM);
115329f1 82
a2704c97 83 pkt->pos= avio_tell(s->pb);
e15dec10 84 pkt->stream_index = 0;
b3db9cee 85 ret = ffio_read_partial(s->pb, pkt->data, size);
c3db0bc6 86 if (ret < 0) {
e15dec10 87 av_free_packet(pkt);
c3db0bc6 88 return ret;
e15dec10
LS
89 }
90 pkt->size = ret;
91 return ret;
92}
76d32428 93
6d0678d1 94int ff_raw_audio_read_header(AVFormatContext *s,
a0af2fa4 95 AVFormatParameters *ap)
fda885c7 96{
a0af2fa4 97 AVStream *st = av_new_stream(s, 0);
fda885c7 98 if (!st)
769e10f0 99 return AVERROR(ENOMEM);
72415b2a 100 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
a0af2fa4 101 st->codec->codec_id = s->iformat->value;
57004ff1 102 st->need_parsing = AVSTREAM_PARSE_FULL;
fda885c7 103 /* the parameters will be extracted from the compressed bitstream */
6cde949a 104
fda885c7
MR
105 return 0;
106}
107
fb9f1117 108/* MPEG-1/H.263 input */
b47a5a95 109int ff_raw_video_read_header(AVFormatContext *s,
de6d9b64
FB
110 AVFormatParameters *ap)
111{
112 AVStream *st;
113
c9a65ca8 114 st = av_new_stream(s, 0);
de6d9b64 115 if (!st)
769e10f0 116 return AVERROR(ENOMEM);
de6d9b64 117
72415b2a 118 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
01f4895c 119 st->codec->codec_id = s->iformat->value;
57004ff1 120 st->need_parsing = AVSTREAM_PARSE_FULL;
4986a429 121
fb9f1117
DB
122 /* for MJPEG, specify frame rate */
123 /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
c04c3282 124 if (ap->time_base.num) {
4022fe01 125 st->codec->time_base= ap->time_base;
115329f1 126 } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
01f4895c 127 st->codec->codec_id == CODEC_ID_MPEG4 ||
17ac9f1c 128 st->codec->codec_id == CODEC_ID_DIRAC ||
0cd55b0c 129 st->codec->codec_id == CODEC_ID_DNXHD ||
1c169711 130 st->codec->codec_id == CODEC_ID_VC1 ||
01f4895c 131 st->codec->codec_id == CODEC_ID_H264) {
4022fe01 132 st->codec->time_base= (AVRational){1,25};
27e084bd 133 }
4022fe01 134 av_set_pts_info(st, 64, 1, 1200000);
80ce3254 135
de6d9b64
FB
136 return 0;
137}
138
900eb63d
DB
139/* Note: Do not forget to add new entries to the Makefile as well. */
140
9013560f 141#if CONFIG_G722_DEMUXER
c6610a21 142AVInputFormat ff_g722_demuxer = {
9013560f
MS
143 "g722",
144 NULL_IF_CONFIG_SMALL("raw G.722"),
145 0,
146 NULL,
147 ff_raw_read_header,
148 ff_raw_read_partial_packet,
149 .flags= AVFMT_GENERIC_INDEX,
150 .extensions = "g722,722",
151 .value = CODEC_ID_ADPCM_G722,
152};
153#endif
154
b250f9c6 155#if CONFIG_GSM_DEMUXER
c6610a21 156AVInputFormat ff_gsm_demuxer = {
60711e95 157 "gsm",
b4ee1d39 158 NULL_IF_CONFIG_SMALL("raw GSM"),
60711e95
MN
159 0,
160 NULL,
6d0678d1 161 ff_raw_audio_read_header,
81f052cb 162 ff_raw_read_partial_packet,
60711e95
MN
163 .flags= AVFMT_GENERIC_INDEX,
164 .extensions = "gsm",
165 .value = CODEC_ID_GSM,
166};
7402ee23 167#endif
60711e95 168
b250f9c6 169#if CONFIG_MJPEG_DEMUXER
c6610a21 170AVInputFormat ff_mjpeg_demuxer = {
76d32428 171 "mjpeg",
b4ee1d39 172 NULL_IF_CONFIG_SMALL("raw MJPEG video"),
0da71265 173 0,
76d32428 174 NULL,
b47a5a95 175 ff_raw_video_read_header,
81f052cb 176 ff_raw_read_partial_packet,
e9b78eeb 177 .flags= AVFMT_GENERIC_INDEX,
76d32428
DB
178 .extensions = "mjpg,mjpeg",
179 .value = CODEC_ID_MJPEG,
0da71265 180};
7402ee23 181#endif
0da71265 182
b250f9c6 183#if CONFIG_MLP_DEMUXER
c6610a21 184AVInputFormat ff_mlp_demuxer = {
76d32428
DB
185 "mlp",
186 NULL_IF_CONFIG_SMALL("raw MLP"),
c9a65ca8 187 0,
76d32428 188 NULL,
6d0678d1 189 ff_raw_audio_read_header,
81f052cb 190 ff_raw_read_partial_packet,
e9b78eeb 191 .flags= AVFMT_GENERIC_INDEX,
76d32428
DB
192 .extensions = "mlp",
193 .value = CODEC_ID_MLP,
de6d9b64 194};
7402ee23 195#endif
de6d9b64 196
23d9cc45 197#if CONFIG_TRUEHD_DEMUXER
c6610a21 198AVInputFormat ff_truehd_demuxer = {
23d9cc45
RP
199 "truehd",
200 NULL_IF_CONFIG_SMALL("raw TrueHD"),
201 0,
202 NULL,
6d0678d1 203 ff_raw_audio_read_header,
23d9cc45
RP
204 ff_raw_read_partial_packet,
205 .flags= AVFMT_GENERIC_INDEX,
206 .extensions = "thd",
207 .value = CODEC_ID_TRUEHD,
208};
209#endif
210
b250f9c6 211#if CONFIG_SHORTEN_DEMUXER
c6610a21 212AVInputFormat ff_shorten_demuxer = {
76d32428
DB
213 "shn",
214 NULL_IF_CONFIG_SMALL("raw Shorten"),
215 0,
216 NULL,
6d0678d1 217 ff_raw_audio_read_header,
81f052cb 218 ff_raw_read_partial_packet,
76d32428
DB
219 .flags= AVFMT_GENERIC_INDEX,
220 .extensions = "shn",
221 .value = CODEC_ID_SHORTEN,
222};
7402ee23 223#endif
76d32428 224
b250f9c6 225#if CONFIG_VC1_DEMUXER
c6610a21 226AVInputFormat ff_vc1_demuxer = {
7bb5c2a6 227 "vc1",
bde15e74 228 NULL_IF_CONFIG_SMALL("raw VC-1"),
7bb5c2a6
KS
229 0,
230 NULL /* vc1_probe */,
b47a5a95 231 ff_raw_video_read_header,
81f052cb 232 ff_raw_read_partial_packet,
7bb5c2a6
KS
233 .extensions = "vc1",
234 .value = CODEC_ID_VC1,
235};
7402ee23 236#endif