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"
28 #include "libavutil/opt.h"
30 #define RAW_PACKET_SIZE 1024
32 int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
34 FFRawDemuxerContext *raw = s->priv_data;
37 size = raw->raw_packet_size;
39 if ((ret = av_new_packet(pkt, size)) < 0)
42 pkt->pos= avio_tell(s->pb);
43 pkt->stream_index = 0;
44 ret = avio_read_partial(s->pb, pkt->data, size);
49 av_shrink_packet(pkt, ret);
53 int ff_raw_audio_read_header(AVFormatContext *s)
55 AVStream *st = avformat_new_stream(s, NULL);
57 return AVERROR(ENOMEM);
58 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
59 st->codecpar->codec_id = s->iformat->raw_codec_id;
60 ffstream(st)->need_parsing = AVSTREAM_PARSE_FULL_RAW;
62 /* the parameters will be extracted from the compressed bitstream */
67 /* MPEG-1/H.263 input */
68 int ff_raw_video_read_header(AVFormatContext *s)
72 FFRawVideoDemuxerContext *s1 = s->priv_data;
76 st = avformat_new_stream(s, NULL);
78 ret = AVERROR(ENOMEM);
83 st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
84 st->codecpar->codec_id = s->iformat->raw_codec_id;
85 sti->need_parsing = AVSTREAM_PARSE_FULL_RAW;
87 st->avg_frame_rate = s1->framerate;
88 avpriv_set_pts_info(st, 64, 1, 1200000);
94 int ff_raw_subtitle_read_header(AVFormatContext *s)
96 AVStream *st = avformat_new_stream(s, NULL);
98 return AVERROR(ENOMEM);
99 st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
100 st->codecpar->codec_id = s->iformat->raw_codec_id;
105 static int raw_data_read_header(AVFormatContext *s)
107 AVStream *st = avformat_new_stream(s, NULL);
109 return AVERROR(ENOMEM);
110 st->codecpar->codec_type = AVMEDIA_TYPE_DATA;
111 st->codecpar->codec_id = s->iformat->raw_codec_id;
116 /* Note: Do not forget to add new entries to the Makefile as well. */
118 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
119 #define DEC AV_OPT_FLAG_DECODING_PARAM
120 static const AVOption rawvideo_options[] = {
121 { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC},
122 { "raw_packet_size", "", OFFSET(raw_packet_size), AV_OPT_TYPE_INT, {.i64 = RAW_PACKET_SIZE }, 1, INT_MAX, DEC},
127 const AVClass ff_rawvideo_demuxer_class = {
128 .class_name = "generic raw video demuxer",
129 .item_name = av_default_item_name,
130 .option = rawvideo_options,
131 .version = LIBAVUTIL_VERSION_INT,
134 #define OFFSET(x) offsetof(FFRawDemuxerContext, x)
135 static const AVOption raw_options[] = {
136 { "raw_packet_size", "", OFFSET(raw_packet_size), AV_OPT_TYPE_INT, {.i64 = RAW_PACKET_SIZE }, 1, INT_MAX, DEC},
140 const AVClass ff_raw_demuxer_class = {
141 .class_name = "generic raw demuxer",
142 .item_name = av_default_item_name,
143 .option = raw_options,
144 .version = LIBAVUTIL_VERSION_INT,
147 #if CONFIG_DATA_DEMUXER
148 const AVInputFormat ff_data_demuxer = {
150 .long_name = NULL_IF_CONFIG_SMALL("raw data"),
151 .read_header = raw_data_read_header,
152 .read_packet = ff_raw_read_partial_packet,
153 .raw_codec_id = AV_CODEC_ID_NONE,
154 .flags = AVFMT_NOTIMESTAMPS,
155 .priv_data_size = sizeof(FFRawDemuxerContext),\
156 .priv_class = &ff_raw_demuxer_class,
160 #if CONFIG_MJPEG_DEMUXER
161 static int mjpeg_probe(const AVProbeData *p)
168 for (i = 0; i < p->buf_size - 1; i++) {
170 if (p->buf[i] != 0xFF)
204 if ( (c >= 0x02 && c <= 0xBF)
211 if (nb_invalid*4 + 1 < nb_frames) {
212 static const char ct_jpeg[] = "\r\nContent-Type: image/jpeg\r\n";
215 for (i=0; i<FFMIN(p->buf_size - (int)sizeof(ct_jpeg), 100); i++)
216 if (!memcmp(p->buf + i, ct_jpeg, sizeof(ct_jpeg) - 1))
217 return AVPROBE_SCORE_EXTENSION;
219 if (nb_invalid == 0 && nb_frames > 2)
220 return AVPROBE_SCORE_EXTENSION / 2;
221 return AVPROBE_SCORE_EXTENSION / 4;
223 if (!nb_invalid && nb_frames)
224 return AVPROBE_SCORE_EXTENSION / 4;
229 FF_DEF_RAWVIDEO_DEMUXER2(mjpeg, "raw MJPEG video", mjpeg_probe, "mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG, AVFMT_GENERIC_INDEX|AVFMT_NOTIMESTAMPS)