3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2005 Alex Beregszaszi
6 * This file is part of Libav.
8 * Libav is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * Libav is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "avio_internal.h"
26 #include "libavutil/opt.h"
29 int ff_raw_read_header(AVFormatContext
*s
, AVFormatParameters
*ap
)
34 st
= av_new_stream(s
, 0);
36 return AVERROR(ENOMEM
);
38 id
= s
->iformat
->value
;
39 if (id
== CODEC_ID_RAWVIDEO
) {
40 st
->codec
->codec_type
= AVMEDIA_TYPE_VIDEO
;
42 st
->codec
->codec_type
= AVMEDIA_TYPE_AUDIO
;
44 st
->codec
->codec_id
= id
;
46 switch(st
->codec
->codec_type
) {
47 case AVMEDIA_TYPE_AUDIO
: {
48 RawAudioDemuxerContext
*s1
= s
->priv_data
;
50 #if FF_API_FORMAT_PARAMETERS
52 st
->codec
->sample_rate
= ap
->sample_rate
;
54 st
->codec
->channels
= ap
->channels
;
55 else st
->codec
->channels
= 1;
59 st
->codec
->sample_rate
= s1
->sample_rate
;
61 st
->codec
->channels
= s1
->channels
;
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;
66 av_set_pts_info(st
, 64, 1, st
->codec
->sample_rate
);
69 case AVMEDIA_TYPE_VIDEO
:
71 av_set_pts_info(st
, 64, ap
->time_base
.num
, ap
->time_base
.den
);
73 av_set_pts_info(st
, 64, 1, 25);
74 st
->codec
->width
= ap
->width
;
75 st
->codec
->height
= ap
->height
;
76 st
->codec
->pix_fmt
= ap
->pix_fmt
;
77 if(st
->codec
->pix_fmt
== PIX_FMT_NONE
)
78 st
->codec
->pix_fmt
= PIX_FMT_YUV420P
;
86 #define RAW_PACKET_SIZE 1024
88 int ff_raw_read_partial_packet(AVFormatContext
*s
, AVPacket
*pkt
)
92 size
= RAW_PACKET_SIZE
;
94 if (av_new_packet(pkt
, size
) < 0)
95 return AVERROR(ENOMEM
);
97 pkt
->pos
= avio_tell(s
->pb
);
98 pkt
->stream_index
= 0;
99 ret
= ffio_read_partial(s
->pb
, pkt
->data
, size
);
108 int ff_raw_audio_read_header(AVFormatContext
*s
,
109 AVFormatParameters
*ap
)
111 AVStream
*st
= av_new_stream(s
, 0);
113 return AVERROR(ENOMEM
);
114 st
->codec
->codec_type
= AVMEDIA_TYPE_AUDIO
;
115 st
->codec
->codec_id
= s
->iformat
->value
;
116 st
->need_parsing
= AVSTREAM_PARSE_FULL
;
117 /* the parameters will be extracted from the compressed bitstream */
122 /* MPEG-1/H.263 input */
123 int ff_raw_video_read_header(AVFormatContext
*s
,
124 AVFormatParameters
*ap
)
128 st
= av_new_stream(s
, 0);
130 return AVERROR(ENOMEM
);
132 st
->codec
->codec_type
= AVMEDIA_TYPE_VIDEO
;
133 st
->codec
->codec_id
= s
->iformat
->value
;
134 st
->need_parsing
= AVSTREAM_PARSE_FULL
;
136 /* for MJPEG, specify frame rate */
137 /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
138 if (ap
->time_base
.num
) {
139 st
->codec
->time_base
= ap
->time_base
;
140 } else if ( st
->codec
->codec_id
== CODEC_ID_MJPEG
||
141 st
->codec
->codec_id
== CODEC_ID_MPEG4
||
142 st
->codec
->codec_id
== CODEC_ID_DIRAC
||
143 st
->codec
->codec_id
== CODEC_ID_DNXHD
||
144 st
->codec
->codec_id
== CODEC_ID_VC1
||
145 st
->codec
->codec_id
== CODEC_ID_H264
) {
146 st
->codec
->time_base
= (AVRational
){1,25};
148 av_set_pts_info(st
, 64, 1, 1200000);
153 /* Note: Do not forget to add new entries to the Makefile as well. */
155 static const AVOption audio_options
[] = {
156 { "sample_rate", "", offsetof(RawAudioDemuxerContext
, sample_rate
), FF_OPT_TYPE_INT
, {.dbl
= 0}, 0, INT_MAX
, AV_OPT_FLAG_DECODING_PARAM
},
157 { "channels", "", offsetof(RawAudioDemuxerContext
, channels
), FF_OPT_TYPE_INT
, {.dbl
= 0}, 0, INT_MAX
, AV_OPT_FLAG_DECODING_PARAM
},
161 const AVClass ff_rawaudio_demuxer_class
= {
162 .class_name
= "rawaudio demuxer",
163 .item_name
= av_default_item_name
,
164 .option
= audio_options
,
165 .version
= LIBAVUTIL_VERSION_INT
,
168 #if CONFIG_G722_DEMUXER
169 AVInputFormat ff_g722_demuxer
= {
171 NULL_IF_CONFIG_SMALL("raw G.722"),
172 sizeof(RawAudioDemuxerContext
),
175 ff_raw_read_partial_packet
,
176 .flags
= AVFMT_GENERIC_INDEX
,
177 .extensions
= "g722,722",
178 .value
= CODEC_ID_ADPCM_G722
,
179 .priv_class
= &ff_rawaudio_demuxer_class
,
183 #if CONFIG_GSM_DEMUXER
184 AVInputFormat ff_gsm_demuxer
= {
186 NULL_IF_CONFIG_SMALL("raw GSM"),
189 ff_raw_audio_read_header
,
190 ff_raw_read_partial_packet
,
191 .flags
= AVFMT_GENERIC_INDEX
,
193 .value
= CODEC_ID_GSM
,
197 #if CONFIG_MJPEG_DEMUXER
198 AVInputFormat ff_mjpeg_demuxer
= {
200 NULL_IF_CONFIG_SMALL("raw MJPEG video"),
203 ff_raw_video_read_header
,
204 ff_raw_read_partial_packet
,
205 .flags
= AVFMT_GENERIC_INDEX
,
206 .extensions
= "mjpg,mjpeg",
207 .value
= CODEC_ID_MJPEG
,
211 #if CONFIG_MLP_DEMUXER
212 AVInputFormat ff_mlp_demuxer
= {
214 NULL_IF_CONFIG_SMALL("raw MLP"),
217 ff_raw_audio_read_header
,
218 ff_raw_read_partial_packet
,
219 .flags
= AVFMT_GENERIC_INDEX
,
221 .value
= CODEC_ID_MLP
,
225 #if CONFIG_TRUEHD_DEMUXER
226 AVInputFormat ff_truehd_demuxer
= {
228 NULL_IF_CONFIG_SMALL("raw TrueHD"),
231 ff_raw_audio_read_header
,
232 ff_raw_read_partial_packet
,
233 .flags
= AVFMT_GENERIC_INDEX
,
235 .value
= CODEC_ID_TRUEHD
,
239 #if CONFIG_SHORTEN_DEMUXER
240 AVInputFormat ff_shorten_demuxer
= {
242 NULL_IF_CONFIG_SMALL("raw Shorten"),
245 ff_raw_audio_read_header
,
246 ff_raw_read_partial_packet
,
247 .flags
= AVFMT_GENERIC_INDEX
,
249 .value
= CODEC_ID_SHORTEN
,
253 #if CONFIG_VC1_DEMUXER
254 AVInputFormat ff_vc1_demuxer
= {
256 NULL_IF_CONFIG_SMALL("raw VC-1"),
258 NULL
/* vc1_probe */,
259 ff_raw_video_read_header
,
260 ff_raw_read_partial_packet
,
262 .value
= CODEC_ID_VC1
,