3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2005 Alex Beregszaszi
6 * This file is part of FFmpeg.
8 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "avio_internal.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/parseutils.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/avassert.h"
31 #include "libavutil/intreadwrite.h"
33 #define RAW_PACKET_SIZE 1024
35 int ff_raw_read_partial_packet(AVFormatContext
*s
, AVPacket
*pkt
)
39 size
= RAW_PACKET_SIZE
;
41 if (av_new_packet(pkt
, size
) < 0)
42 return AVERROR(ENOMEM
);
44 pkt
->pos
= avio_tell(s
->pb
);
45 pkt
->stream_index
= 0;
46 ret
= ffio_read_partial(s
->pb
, pkt
->data
, size
);
51 av_shrink_packet(pkt
, ret
);
55 int ff_raw_audio_read_header(AVFormatContext
*s
)
57 AVStream
*st
= avformat_new_stream(s
, NULL
);
59 return AVERROR(ENOMEM
);
60 st
->codec
->codec_type
= AVMEDIA_TYPE_AUDIO
;
61 st
->codec
->codec_id
= s
->iformat
->raw_codec_id
;
62 st
->need_parsing
= AVSTREAM_PARSE_FULL_RAW
;
64 /* the parameters will be extracted from the compressed bitstream */
69 /* MPEG-1/H.263 input */
70 int ff_raw_video_read_header(AVFormatContext
*s
)
73 FFRawVideoDemuxerContext
*s1
= s
->priv_data
;
77 st
= avformat_new_stream(s
, NULL
);
79 ret
= AVERROR(ENOMEM
);
83 st
->codec
->codec_type
= AVMEDIA_TYPE_VIDEO
;
84 st
->codec
->codec_id
= s
->iformat
->raw_codec_id
;
85 st
->need_parsing
= AVSTREAM_PARSE_FULL_RAW
;
87 st
->codec
->framerate
= s1
->framerate
;
88 st
->codec
->time_base
= av_inv_q(s1
->framerate
);
89 avpriv_set_pts_info(st
, 64, 1, 1200000);
95 static int ff_raw_data_read_header(AVFormatContext
*s
)
97 AVStream
*st
= avformat_new_stream(s
, NULL
);
99 return AVERROR(ENOMEM
);
100 st
->codec
->codec_type
= AVMEDIA_TYPE_DATA
;
101 st
->codec
->codec_id
= s
->iformat
->raw_codec_id
;
106 /* Note: Do not forget to add new entries to the Makefile as well. */
108 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
109 #define DEC AV_OPT_FLAG_DECODING_PARAM
110 const AVOption ff_rawvideo_options
[] = {
111 { "framerate", "", OFFSET(framerate
), AV_OPT_TYPE_VIDEO_RATE
, {.str
= "25"}, 0, 0, DEC
},
115 #if CONFIG_DATA_DEMUXER
116 AVInputFormat ff_data_demuxer
= {
118 .long_name
= NULL_IF_CONFIG_SMALL("raw data"),
119 .read_header
= ff_raw_data_read_header
,
120 .read_packet
= ff_raw_read_partial_packet
,
121 .raw_codec_id
= AV_CODEC_ID_NONE
,
122 .flags
= AVFMT_NOTIMESTAMPS
,
126 #if CONFIG_LATM_DEMUXER
128 AVInputFormat ff_latm_demuxer
= {
130 .long_name
= NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
131 .read_header
= ff_raw_audio_read_header
,
132 .read_packet
= ff_raw_read_partial_packet
,
133 .flags
= AVFMT_GENERIC_INDEX
| AVFMT_NOTIMESTAMPS
,
134 .extensions
= "latm",
135 .raw_codec_id
= AV_CODEC_ID_AAC_LATM
,
139 #if CONFIG_MJPEG_DEMUXER
140 static int mjpeg_probe(AVProbeData
*p
)
147 for (i
=0; i
<p
->buf_size
-2; i
++) {
149 if (p
->buf
[i
] != 0xFF)
183 if ( (c
>= 0x02 && c
<= 0xBF)
190 if (nb_invalid
*4 + 1 < nb_frames
) {
191 static const char ct_jpeg
[] = "\r\nContent-Type: image/jpeg\r\n\r\n";
194 for (i
=0; i
<FFMIN(p
->buf_size
- sizeof(ct_jpeg
), 100); i
++)
195 if (!memcmp(p
->buf
+ i
, ct_jpeg
, sizeof(ct_jpeg
) - 1))
196 return AVPROBE_SCORE_EXTENSION
;
198 if (nb_invalid
== 0 && nb_frames
> 2)
199 return AVPROBE_SCORE_EXTENSION
/ 2;
200 return AVPROBE_SCORE_EXTENSION
/ 4;
206 FF_DEF_RAWVIDEO_DEMUXER2(mjpeg
, "raw MJPEG video", mjpeg_probe
, "mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG
, AVFMT_GENERIC_INDEX
|AVFMT_NOTIMESTAMPS
)
209 #if CONFIG_MLP_DEMUXER
210 AVInputFormat ff_mlp_demuxer
= {
212 .long_name
= NULL_IF_CONFIG_SMALL("raw MLP"),
213 .read_header
= ff_raw_audio_read_header
,
214 .read_packet
= ff_raw_read_partial_packet
,
215 .flags
= AVFMT_GENERIC_INDEX
| AVFMT_NOTIMESTAMPS
,
217 .raw_codec_id
= AV_CODEC_ID_MLP
,
221 #if CONFIG_TRUEHD_DEMUXER
222 AVInputFormat ff_truehd_demuxer
= {
224 .long_name
= NULL_IF_CONFIG_SMALL("raw TrueHD"),
225 .read_header
= ff_raw_audio_read_header
,
226 .read_packet
= ff_raw_read_partial_packet
,
227 .flags
= AVFMT_GENERIC_INDEX
| AVFMT_NOTIMESTAMPS
,
229 .raw_codec_id
= AV_CODEC_ID_TRUEHD
,
233 #if CONFIG_SHORTEN_DEMUXER
234 AVInputFormat ff_shorten_demuxer
= {
236 .long_name
= NULL_IF_CONFIG_SMALL("raw Shorten"),
237 .read_header
= ff_raw_audio_read_header
,
238 .read_packet
= ff_raw_read_partial_packet
,
239 .flags
= AVFMT_NOBINSEARCH
| AVFMT_NOGENSEARCH
| AVFMT_NO_BYTE_SEEK
|AVFMT_NOTIMESTAMPS
,
241 .raw_codec_id
= AV_CODEC_ID_SHORTEN
,
245 #if CONFIG_VC1_DEMUXER
246 FF_DEF_RAWVIDEO_DEMUXER2(vc1
, "raw VC-1", NULL
, "vc1", AV_CODEC_ID_VC1
, AVFMT_GENERIC_INDEX
|AVFMT_NOTIMESTAMPS
)