mov: simplify mov_read_chapters() by using avio_get_str16be
[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"
4ca31edc 24#include "rawdec.h"
de6d9b64 25
de6d9b64 26/* raw input */
e94204df 27int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
de6d9b64
FB
28{
29 AVStream *st;
0f87b771 30 enum CodecID id;
de6d9b64 31
c9a65ca8 32 st = av_new_stream(s, 0);
de6d9b64 33 if (!st)
769e10f0 34 return AVERROR(ENOMEM);
c04c3282 35
c9a65ca8
FB
36 id = s->iformat->value;
37 if (id == CODEC_ID_RAWVIDEO) {
72415b2a 38 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
de6d9b64 39 } else {
72415b2a 40 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
de6d9b64 41 }
01f4895c 42 st->codec->codec_id = id;
c9a65ca8 43
01f4895c 44 switch(st->codec->codec_type) {
72415b2a 45 case AVMEDIA_TYPE_AUDIO:
01f4895c 46 st->codec->sample_rate = ap->sample_rate;
bf9067cf
MN
47 if(ap->channels) st->codec->channels = ap->channels;
48 else st->codec->channels = 1;
a3d23e15
BC
49 st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
50 assert(st->codec->bits_per_coded_sample > 0);
51 st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;
01f4895c 52 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
de6d9b64 53 break;
72415b2a 54 case AVMEDIA_TYPE_VIDEO:
9de0be61
MN
55 if(ap->time_base.num)
56 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
57 else
58 av_set_pts_info(st, 64, 1, 25);
01f4895c
MN
59 st->codec->width = ap->width;
60 st->codec->height = ap->height;
61 st->codec->pix_fmt = ap->pix_fmt;
62 if(st->codec->pix_fmt == PIX_FMT_NONE)
63 st->codec->pix_fmt= PIX_FMT_YUV420P;
de6d9b64
FB
64 break;
65 default:
27e084bd 66 return -1;
de6d9b64 67 }
de6d9b64
FB
68 return 0;
69}
70
2e93e3aa 71#define RAW_PACKET_SIZE 1024
de6d9b64 72
81f052cb 73int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
e15dec10
LS
74{
75 int ret, size;
76
77 size = RAW_PACKET_SIZE;
78
79 if (av_new_packet(pkt, size) < 0)
c67031e7 80 return AVERROR(ENOMEM);
115329f1 81
899681cd 82 pkt->pos= url_ftell(s->pb);
e15dec10 83 pkt->stream_index = 0;
899681cd 84 ret = get_partial_buffer(s->pb, pkt->data, size);
c3db0bc6 85 if (ret < 0) {
e15dec10 86 av_free_packet(pkt);
c3db0bc6 87 return ret;
e15dec10
LS
88 }
89 pkt->size = ret;
90 return ret;
91}
76d32428 92
6d0678d1 93int ff_raw_audio_read_header(AVFormatContext *s,
a0af2fa4 94 AVFormatParameters *ap)
fda885c7 95{
a0af2fa4 96 AVStream *st = av_new_stream(s, 0);
fda885c7 97 if (!st)
769e10f0 98 return AVERROR(ENOMEM);
72415b2a 99 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
a0af2fa4 100 st->codec->codec_id = s->iformat->value;
57004ff1 101 st->need_parsing = AVSTREAM_PARSE_FULL;
fda885c7 102 /* the parameters will be extracted from the compressed bitstream */
6cde949a 103
fda885c7
MR
104 return 0;
105}
106
fb9f1117 107/* MPEG-1/H.263 input */
b47a5a95 108int ff_raw_video_read_header(AVFormatContext *s,
de6d9b64
FB
109 AVFormatParameters *ap)
110{
111 AVStream *st;
112
c9a65ca8 113 st = av_new_stream(s, 0);
de6d9b64 114 if (!st)
769e10f0 115 return AVERROR(ENOMEM);
de6d9b64 116
72415b2a 117 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
01f4895c 118 st->codec->codec_id = s->iformat->value;
57004ff1 119 st->need_parsing = AVSTREAM_PARSE_FULL;
4986a429 120
fb9f1117
DB
121 /* for MJPEG, specify frame rate */
122 /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
c04c3282 123 if (ap->time_base.num) {
4022fe01 124 st->codec->time_base= ap->time_base;
115329f1 125 } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
01f4895c 126 st->codec->codec_id == CODEC_ID_MPEG4 ||
17ac9f1c 127 st->codec->codec_id == CODEC_ID_DIRAC ||
0cd55b0c 128 st->codec->codec_id == CODEC_ID_DNXHD ||
1c169711 129 st->codec->codec_id == CODEC_ID_VC1 ||
01f4895c 130 st->codec->codec_id == CODEC_ID_H264) {
4022fe01 131 st->codec->time_base= (AVRational){1,25};
27e084bd 132 }
4022fe01 133 av_set_pts_info(st, 64, 1, 1200000);
80ce3254 134
de6d9b64
FB
135 return 0;
136}
137
900eb63d
DB
138/* Note: Do not forget to add new entries to the Makefile as well. */
139
9013560f
MS
140#if CONFIG_G722_DEMUXER
141AVInputFormat g722_demuxer = {
142 "g722",
143 NULL_IF_CONFIG_SMALL("raw G.722"),
144 0,
145 NULL,
146 ff_raw_read_header,
147 ff_raw_read_partial_packet,
148 .flags= AVFMT_GENERIC_INDEX,
149 .extensions = "g722,722",
150 .value = CODEC_ID_ADPCM_G722,
151};
152#endif
153
b250f9c6 154#if CONFIG_GSM_DEMUXER
60711e95
MN
155AVInputFormat gsm_demuxer = {
156 "gsm",
b4ee1d39 157 NULL_IF_CONFIG_SMALL("raw GSM"),
60711e95
MN
158 0,
159 NULL,
6d0678d1 160 ff_raw_audio_read_header,
81f052cb 161 ff_raw_read_partial_packet,
60711e95
MN
162 .flags= AVFMT_GENERIC_INDEX,
163 .extensions = "gsm",
164 .value = CODEC_ID_GSM,
165};
7402ee23 166#endif
60711e95 167
b250f9c6 168#if CONFIG_MJPEG_DEMUXER
76d32428
DB
169AVInputFormat mjpeg_demuxer = {
170 "mjpeg",
b4ee1d39 171 NULL_IF_CONFIG_SMALL("raw MJPEG video"),
0da71265 172 0,
76d32428 173 NULL,
b47a5a95 174 ff_raw_video_read_header,
81f052cb 175 ff_raw_read_partial_packet,
e9b78eeb 176 .flags= AVFMT_GENERIC_INDEX,
76d32428
DB
177 .extensions = "mjpg,mjpeg",
178 .value = CODEC_ID_MJPEG,
0da71265 179};
7402ee23 180#endif
0da71265 181
b250f9c6 182#if CONFIG_MLP_DEMUXER
76d32428
DB
183AVInputFormat mlp_demuxer = {
184 "mlp",
185 NULL_IF_CONFIG_SMALL("raw MLP"),
c9a65ca8 186 0,
76d32428 187 NULL,
6d0678d1 188 ff_raw_audio_read_header,
81f052cb 189 ff_raw_read_partial_packet,
e9b78eeb 190 .flags= AVFMT_GENERIC_INDEX,
76d32428
DB
191 .extensions = "mlp",
192 .value = CODEC_ID_MLP,
de6d9b64 193};
7402ee23 194#endif
de6d9b64 195
23d9cc45
RP
196#if CONFIG_TRUEHD_DEMUXER
197AVInputFormat truehd_demuxer = {
198 "truehd",
199 NULL_IF_CONFIG_SMALL("raw TrueHD"),
200 0,
201 NULL,
6d0678d1 202 ff_raw_audio_read_header,
23d9cc45
RP
203 ff_raw_read_partial_packet,
204 .flags= AVFMT_GENERIC_INDEX,
205 .extensions = "thd",
206 .value = CODEC_ID_TRUEHD,
207};
208#endif
209
b250f9c6 210#if CONFIG_SHORTEN_DEMUXER
76d32428
DB
211AVInputFormat shorten_demuxer = {
212 "shn",
213 NULL_IF_CONFIG_SMALL("raw Shorten"),
214 0,
215 NULL,
6d0678d1 216 ff_raw_audio_read_header,
81f052cb 217 ff_raw_read_partial_packet,
76d32428
DB
218 .flags= AVFMT_GENERIC_INDEX,
219 .extensions = "shn",
220 .value = CODEC_ID_SHORTEN,
221};
7402ee23 222#endif
76d32428 223
b250f9c6 224#if CONFIG_VC1_DEMUXER
7bb5c2a6
KS
225AVInputFormat vc1_demuxer = {
226 "vc1",
bde15e74 227 NULL_IF_CONFIG_SMALL("raw VC-1"),
7bb5c2a6
KS
228 0,
229 NULL /* vc1_probe */,
b47a5a95 230 ff_raw_video_read_header,
81f052cb 231 ff_raw_read_partial_packet,
7bb5c2a6
KS
232 .extensions = "vc1",
233 .value = CODEC_ID_VC1,
234};
7402ee23 235#endif