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
25 #include "avio_internal.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/parseutils.h"
29 #include "libavutil/pixdesc.h"
31 #define RAW_PACKET_SIZE 1024
33 int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
37 size = RAW_PACKET_SIZE;
39 if (av_new_packet(pkt, size) < 0)
40 return AVERROR(ENOMEM);
42 pkt->pos= avio_tell(s->pb);
43 pkt->stream_index = 0;
44 ret = ffio_read_partial(s->pb, pkt->data, size);
48 } else if (ret < size) {
49 /* initialize end of packet for partial reads to avoid reading
50 * uninitialized data on allowed overreads */
51 memset(pkt->data + ret, 0, FF_INPUT_BUFFER_PADDING_SIZE);
57 int ff_raw_audio_read_header(AVFormatContext *s)
59 AVStream *st = avformat_new_stream(s, NULL);
61 return AVERROR(ENOMEM);
62 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
63 st->codec->codec_id = s->iformat->raw_codec_id;
64 st->need_parsing = AVSTREAM_PARSE_FULL;
66 /* the parameters will be extracted from the compressed bitstream */
71 /* MPEG-1/H.263 input */
72 int ff_raw_video_read_header(AVFormatContext *s)
75 FFRawVideoDemuxerContext *s1 = s->priv_data;
80 st = avformat_new_stream(s, NULL);
82 ret = AVERROR(ENOMEM);
86 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
87 st->codec->codec_id = s->iformat->raw_codec_id;
88 st->need_parsing = AVSTREAM_PARSE_FULL;
90 if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {
91 av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
95 #if FF_API_R_FRAME_RATE
98 st->avg_frame_rate = framerate;
99 avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
105 /* Note: Do not forget to add new entries to the Makefile as well. */
107 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
108 #define DEC AV_OPT_FLAG_DECODING_PARAM
109 const AVOption ff_rawvideo_options[] = {
110 { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC},
114 #if CONFIG_LATM_DEMUXER
115 AVInputFormat ff_latm_demuxer = {
117 .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
118 .read_header = ff_raw_audio_read_header,
119 .read_packet = ff_raw_read_partial_packet,
120 .flags = AVFMT_GENERIC_INDEX,
121 .extensions = "latm",
122 .raw_codec_id = AV_CODEC_ID_AAC_LATM,
126 #if CONFIG_MJPEG_DEMUXER
127 FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg", AV_CODEC_ID_MJPEG)
130 #if CONFIG_MLP_DEMUXER
131 AVInputFormat ff_mlp_demuxer = {
133 .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
134 .read_header = ff_raw_audio_read_header,
135 .read_packet = ff_raw_read_partial_packet,
136 .flags = AVFMT_GENERIC_INDEX,
138 .raw_codec_id = AV_CODEC_ID_MLP,
142 #if CONFIG_TRUEHD_DEMUXER
143 AVInputFormat ff_truehd_demuxer = {
145 .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
146 .read_header = ff_raw_audio_read_header,
147 .read_packet = ff_raw_read_partial_packet,
148 .flags = AVFMT_GENERIC_INDEX,
150 .raw_codec_id = AV_CODEC_ID_TRUEHD,
154 #if CONFIG_SHORTEN_DEMUXER
155 AVInputFormat ff_shorten_demuxer = {
157 .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
158 .read_header = ff_raw_audio_read_header,
159 .read_packet = ff_raw_read_partial_packet,
160 .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
162 .raw_codec_id = AV_CODEC_ID_SHORTEN,
166 #if CONFIG_VC1_DEMUXER
167 FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1)