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
23 #include "config_components.h"
29 #include "libavutil/opt.h"
31 #define RAW_PACKET_SIZE 1024
33 int ff_raw_read_partial_packet(AVFormatContext
*s
, AVPacket
*pkt
)
35 FFRawDemuxerContext
*raw
= s
->priv_data
;
38 size
= raw
->raw_packet_size
;
40 if ((ret
= av_new_packet(pkt
, size
)) < 0)
43 pkt
->pos
= avio_tell(s
->pb
);
44 pkt
->stream_index
= 0;
45 ret
= avio_read_partial(s
->pb
, pkt
->data
, size
);
50 av_shrink_packet(pkt
, ret
);
54 int ff_raw_audio_read_header(AVFormatContext
*s
)
56 AVStream
*st
= avformat_new_stream(s
, NULL
);
58 return AVERROR(ENOMEM
);
59 st
->codecpar
->codec_type
= AVMEDIA_TYPE_AUDIO
;
60 st
->codecpar
->codec_id
= ffifmt(s
->iformat
)->raw_codec_id
;
61 ffstream(st
)->need_parsing
= AVSTREAM_PARSE_FULL_RAW
;
63 /* the parameters will be extracted from the compressed bitstream */
68 /* MPEG-1/H.263 input */
69 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
);
84 st
->codecpar
->codec_type
= AVMEDIA_TYPE_VIDEO
;
85 st
->codecpar
->codec_id
= ffifmt(s
->iformat
)->raw_codec_id
;
86 sti
->need_parsing
= AVSTREAM_PARSE_FULL_RAW
;
88 st
->avg_frame_rate
= s1
->framerate
;
89 avpriv_set_pts_info(st
, 64, 1, 1200000);
95 int ff_raw_subtitle_read_header(AVFormatContext
*s
)
97 AVStream
*st
= avformat_new_stream(s
, NULL
);
99 return AVERROR(ENOMEM
);
100 st
->codecpar
->codec_type
= AVMEDIA_TYPE_SUBTITLE
;
101 st
->codecpar
->codec_id
= ffifmt(s
->iformat
)->raw_codec_id
;
106 static int raw_data_read_header(AVFormatContext
*s
)
108 AVStream
*st
= avformat_new_stream(s
, NULL
);
110 return AVERROR(ENOMEM
);
111 st
->codecpar
->codec_type
= AVMEDIA_TYPE_DATA
;
112 st
->codecpar
->codec_id
= ffifmt(s
->iformat
)->raw_codec_id
;
117 /* Note: Do not forget to add new entries to the Makefile as well. */
119 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
120 #define DEC AV_OPT_FLAG_DECODING_PARAM
121 static const AVOption rawvideo_options
[] = {
122 { "framerate", "", OFFSET(framerate
), AV_OPT_TYPE_VIDEO_RATE
, {.str
= "25"}, 0, INT_MAX
, DEC
},
123 { "raw_packet_size", "", OFFSET(raw_packet_size
), AV_OPT_TYPE_INT
, {.i64
= RAW_PACKET_SIZE
}, 1, INT_MAX
, DEC
},
128 const AVClass ff_rawvideo_demuxer_class
= {
129 .class_name
= "generic raw video demuxer",
130 .item_name
= av_default_item_name
,
131 .option
= rawvideo_options
,
132 .version
= LIBAVUTIL_VERSION_INT
,
135 #define OFFSET(x) offsetof(FFRawDemuxerContext, x)
136 static const AVOption raw_options
[] = {
137 { "raw_packet_size", "", OFFSET(raw_packet_size
), AV_OPT_TYPE_INT
, {.i64
= RAW_PACKET_SIZE
}, 1, INT_MAX
, DEC
},
141 const AVClass ff_raw_demuxer_class
= {
142 .class_name
= "generic raw demuxer",
143 .item_name
= av_default_item_name
,
144 .option
= raw_options
,
145 .version
= LIBAVUTIL_VERSION_INT
,
148 #if CONFIG_DATA_DEMUXER
149 const FFInputFormat ff_data_demuxer
= {
151 .p
.long_name
= NULL_IF_CONFIG_SMALL("raw data"),
152 .p
.flags
= AVFMT_NOTIMESTAMPS
,
153 .p
.priv_class
= &ff_raw_demuxer_class
,
154 .read_header
= raw_data_read_header
,
155 .read_packet
= ff_raw_read_partial_packet
,
156 .raw_codec_id
= AV_CODEC_ID_NONE
,
157 .priv_data_size
= sizeof(FFRawDemuxerContext
),\
161 #if CONFIG_MJPEG_DEMUXER
162 static int mjpeg_probe(const AVProbeData
*p
)
169 for (i
= 0; i
< p
->buf_size
- 1; i
++) {
171 if (p
->buf
[i
] != 0xFF)
205 if ( (c
>= 0x02 && c
<= 0xBF)
212 if (nb_invalid
*4 + 1 < nb_frames
) {
213 static const char ct_jpeg
[] = "\r\nContent-Type: image/jpeg\r\n";
216 for (i
=0; i
<FFMIN(p
->buf_size
- (int)sizeof(ct_jpeg
), 100); i
++)
217 if (!memcmp(p
->buf
+ i
, ct_jpeg
, sizeof(ct_jpeg
) - 1))
218 return AVPROBE_SCORE_EXTENSION
;
220 if (nb_invalid
== 0 && nb_frames
> 2)
221 return AVPROBE_SCORE_EXTENSION
/ 2;
222 return AVPROBE_SCORE_EXTENSION
/ 4;
224 if (!nb_invalid
&& nb_frames
)
225 return AVPROBE_SCORE_EXTENSION
/ 4;
230 FF_DEF_RAWVIDEO_DEMUXER2(mjpeg
, "raw MJPEG video", mjpeg_probe
, "mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG
, AVFMT_GENERIC_INDEX
|AVFMT_NOTIMESTAMPS
)