rawdec: don't set codec timebase.
[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 *
2912e87a 6 * This file is part of Libav.
b78e7197 7 *
2912e87a 8 * Libav 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 *
2912e87a 13 * Libav 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
2912e87a 19 * License along with Libav; 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"
c3f9ebf7 24#include "internal.h"
b3db9cee 25#include "avio_internal.h"
4ca31edc 26#include "rawdec.h"
5b3865fc 27#include "libavutil/opt.h"
973f686a 28#include "libavutil/parseutils.h"
2a85f218 29#include "libavutil/pixdesc.h"
de6d9b64 30
de6d9b64 31/* raw input */
e94204df 32int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
de6d9b64
FB
33{
34 AVStream *st;
0f87b771 35 enum CodecID id;
de6d9b64 36
3b3bbdd3 37 st = avformat_new_stream(s, NULL);
de6d9b64 38 if (!st)
769e10f0 39 return AVERROR(ENOMEM);
c04c3282 40
c9a65ca8
FB
41 id = s->iformat->value;
42 if (id == CODEC_ID_RAWVIDEO) {
72415b2a 43 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
de6d9b64 44 } else {
72415b2a 45 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
de6d9b64 46 }
01f4895c 47 st->codec->codec_id = id;
c9a65ca8 48
01f4895c 49 switch(st->codec->codec_type) {
5b3865fc
AK
50 case AVMEDIA_TYPE_AUDIO: {
51 RawAudioDemuxerContext *s1 = s->priv_data;
52
c14fe6bc 53 st->codec->channels = 1;
5b3865fc 54
d906f49a
AK
55 if (id == CODEC_ID_ADPCM_G722)
56 st->codec->sample_rate = 16000;
57
58 if (s1 && s1->sample_rate)
5b3865fc 59 st->codec->sample_rate = s1->sample_rate;
d906f49a 60 if (s1 && s1->channels)
5b3865fc
AK
61 st->codec->channels = s1->channels;
62
a3d23e15
BC
63 st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
64 assert(st->codec->bits_per_coded_sample > 0);
65 st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;
c3f9ebf7 66 avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
de6d9b64 67 break;
5b3865fc 68 }
973f686a
AK
69 case AVMEDIA_TYPE_VIDEO: {
70 FFRawVideoDemuxerContext *s1 = s->priv_data;
1f94c31f 71 int width = 0, height = 0, ret = 0;
2a85f218 72 enum PixelFormat pix_fmt;
e762b1ce 73 AVRational framerate;
2a85f218 74
2a85f218
AK
75 if (s1->video_size && (ret = av_parse_video_size(&width, &height, s1->video_size)) < 0) {
76 av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n");
77 goto fail;
78 }
79 if ((pix_fmt = av_get_pix_fmt(s1->pixel_format)) == PIX_FMT_NONE) {
80 av_log(s, AV_LOG_ERROR, "No such pixel format: %s.\n", s1->pixel_format);
81 ret = AVERROR(EINVAL);
82 goto fail;
973f686a 83 }
e762b1ce
AK
84 if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {
85 av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
86 goto fail;
87 }
c3f9ebf7 88 avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
973f686a
AK
89 st->codec->width = width;
90 st->codec->height = height;
2a85f218 91 st->codec->pix_fmt = pix_fmt;
2a85f218 92fail:
2a85f218 93 return ret;
973f686a 94 }
de6d9b64 95 default:
27e084bd 96 return -1;
de6d9b64 97 }
de6d9b64
FB
98 return 0;
99}
100
2e93e3aa 101#define RAW_PACKET_SIZE 1024
de6d9b64 102
81f052cb 103int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
e15dec10
LS
104{
105 int ret, size;
106
107 size = RAW_PACKET_SIZE;
108
109 if (av_new_packet(pkt, size) < 0)
c67031e7 110 return AVERROR(ENOMEM);
115329f1 111
a2704c97 112 pkt->pos= avio_tell(s->pb);
e15dec10 113 pkt->stream_index = 0;
b3db9cee 114 ret = ffio_read_partial(s->pb, pkt->data, size);
c3db0bc6 115 if (ret < 0) {
e15dec10 116 av_free_packet(pkt);
c3db0bc6 117 return ret;
e15dec10
LS
118 }
119 pkt->size = ret;
120 return ret;
121}
76d32428 122
6d0678d1 123int ff_raw_audio_read_header(AVFormatContext *s,
a0af2fa4 124 AVFormatParameters *ap)
fda885c7 125{
3b3bbdd3 126 AVStream *st = avformat_new_stream(s, NULL);
fda885c7 127 if (!st)
769e10f0 128 return AVERROR(ENOMEM);
72415b2a 129 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
a0af2fa4 130 st->codec->codec_id = s->iformat->value;
57004ff1 131 st->need_parsing = AVSTREAM_PARSE_FULL;
fda885c7 132 /* the parameters will be extracted from the compressed bitstream */
6cde949a 133
fda885c7
MR
134 return 0;
135}
136
fb9f1117 137/* MPEG-1/H.263 input */
b47a5a95 138int ff_raw_video_read_header(AVFormatContext *s,
de6d9b64
FB
139 AVFormatParameters *ap)
140{
141 AVStream *st;
e762b1ce
AK
142 FFRawVideoDemuxerContext *s1 = s->priv_data;
143 AVRational framerate;
144 int ret = 0;
145
de6d9b64 146
3b3bbdd3 147 st = avformat_new_stream(s, NULL);
e762b1ce
AK
148 if (!st) {
149 ret = AVERROR(ENOMEM);
150 goto fail;
151 }
de6d9b64 152
72415b2a 153 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
01f4895c 154 st->codec->codec_id = s->iformat->value;
57004ff1 155 st->need_parsing = AVSTREAM_PARSE_FULL;
4986a429 156
e762b1ce
AK
157 if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {
158 av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
159 goto fail;
27e084bd 160 }
e762b1ce 161
e745d752 162 st->r_frame_rate = st->avg_frame_rate = framerate;
c3f9ebf7 163 avpriv_set_pts_info(st, 64, 1, 1200000);
80ce3254 164
e762b1ce 165fail:
e762b1ce 166 return ret;
de6d9b64
FB
167}
168
900eb63d
DB
169/* Note: Do not forget to add new entries to the Makefile as well. */
170
973f686a
AK
171#define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
172#define DEC AV_OPT_FLAG_DECODING_PARAM
85d982f1 173const AVOption ff_rawvideo_options[] = {
145f741e 174 { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC},
973f686a
AK
175 { NULL },
176};
973f686a 177
9013560f 178#if CONFIG_G722_DEMUXER
c6610a21 179AVInputFormat ff_g722_demuxer = {
dfc2c4d9
AK
180 .name = "g722",
181 .long_name = NULL_IF_CONFIG_SMALL("raw G.722"),
dfc2c4d9
AK
182 .read_header = ff_raw_read_header,
183 .read_packet = ff_raw_read_partial_packet,
9013560f
MS
184 .flags= AVFMT_GENERIC_INDEX,
185 .extensions = "g722,722",
186 .value = CODEC_ID_ADPCM_G722,
187};
188#endif
189
dcb9f6a2
JG
190#if CONFIG_LATM_DEMUXER
191AVInputFormat ff_latm_demuxer = {
192 .name = "latm",
193 .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
194 .read_header = ff_raw_audio_read_header,
195 .read_packet = ff_raw_read_partial_packet,
196 .flags= AVFMT_GENERIC_INDEX,
197 .extensions = "latm",
198 .value = CODEC_ID_AAC_LATM,
199};
200#endif
201
b250f9c6 202#if CONFIG_MJPEG_DEMUXER
fa4924a3 203FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg", CODEC_ID_MJPEG)
7402ee23 204#endif
0da71265 205
b250f9c6 206#if CONFIG_MLP_DEMUXER
c6610a21 207AVInputFormat ff_mlp_demuxer = {
dfc2c4d9
AK
208 .name = "mlp",
209 .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
210 .read_header = ff_raw_audio_read_header,
211 .read_packet = ff_raw_read_partial_packet,
e9b78eeb 212 .flags= AVFMT_GENERIC_INDEX,
76d32428
DB
213 .extensions = "mlp",
214 .value = CODEC_ID_MLP,
de6d9b64 215};
7402ee23 216#endif
de6d9b64 217
23d9cc45 218#if CONFIG_TRUEHD_DEMUXER
c6610a21 219AVInputFormat ff_truehd_demuxer = {
dfc2c4d9
AK
220 .name = "truehd",
221 .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
222 .read_header = ff_raw_audio_read_header,
223 .read_packet = ff_raw_read_partial_packet,
23d9cc45
RP
224 .flags= AVFMT_GENERIC_INDEX,
225 .extensions = "thd",
226 .value = CODEC_ID_TRUEHD,
227};
228#endif
229
b250f9c6 230#if CONFIG_SHORTEN_DEMUXER
c6610a21 231AVInputFormat ff_shorten_demuxer = {
dfc2c4d9
AK
232 .name = "shn",
233 .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
234 .read_header = ff_raw_audio_read_header,
235 .read_packet = ff_raw_read_partial_packet,
e32dfdaa 236 .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
76d32428
DB
237 .extensions = "shn",
238 .value = CODEC_ID_SHORTEN,
239};
7402ee23 240#endif
76d32428 241
b250f9c6 242#if CONFIG_VC1_DEMUXER
fa4924a3 243FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", CODEC_ID_VC1)
7402ee23 244#endif