]> git.sesse.net Git - ffmpeg/blob - libavformat/rawdec.c
latm: Always reconfigure if no extradata was set previously
[ffmpeg] / libavformat / rawdec.c
1 /*
2  * RAW demuxers
3  * Copyright (c) 2001 Fabrice Bellard
4  * Copyright (c) 2005 Alex Beregszaszi
5  *
6  * This file is part of Libav.
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include "avformat.h"
24 #include "internal.h"
25 #include "avio_internal.h"
26 #include "rawdec.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/parseutils.h"
29 #include "libavutil/pixdesc.h"
30
31 #define RAW_PACKET_SIZE 1024
32
33 int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
34 {
35     int ret, size;
36
37     size = RAW_PACKET_SIZE;
38
39     if (av_new_packet(pkt, size) < 0)
40         return AVERROR(ENOMEM);
41
42     pkt->pos= avio_tell(s->pb);
43     pkt->stream_index = 0;
44     ret = ffio_read_partial(s->pb, pkt->data, size);
45     if (ret < 0) {
46         av_free_packet(pkt);
47         return ret;
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);
52     }
53     pkt->size = ret;
54     return ret;
55 }
56
57 int ff_raw_audio_read_header(AVFormatContext *s)
58 {
59     AVStream *st = avformat_new_stream(s, NULL);
60     if (!st)
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;
65     st->start_time = 0;
66     /* the parameters will be extracted from the compressed bitstream */
67
68     return 0;
69 }
70
71 /* MPEG-1/H.263 input */
72 int ff_raw_video_read_header(AVFormatContext *s)
73 {
74     AVStream *st;
75     FFRawVideoDemuxerContext *s1 = s->priv_data;
76     AVRational framerate;
77     int ret = 0;
78
79
80     st = avformat_new_stream(s, NULL);
81     if (!st) {
82         ret = AVERROR(ENOMEM);
83         goto fail;
84     }
85
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;
89
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);
92         goto fail;
93     }
94
95     st->avg_frame_rate = framerate;
96     avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
97
98 fail:
99     return ret;
100 }
101
102 /* Note: Do not forget to add new entries to the Makefile as well. */
103
104 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
105 #define DEC AV_OPT_FLAG_DECODING_PARAM
106 const AVOption ff_rawvideo_options[] = {
107     { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC},
108     { NULL },
109 };
110
111 #if CONFIG_LATM_DEMUXER
112 AVInputFormat ff_latm_demuxer = {
113     .name           = "latm",
114     .long_name      = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
115     .read_header    = ff_raw_audio_read_header,
116     .read_packet    = ff_raw_read_partial_packet,
117     .flags          = AVFMT_GENERIC_INDEX,
118     .extensions     = "latm",
119     .raw_codec_id   = AV_CODEC_ID_AAC_LATM,
120 };
121 #endif
122
123 #if CONFIG_MJPEG_DEMUXER
124 FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg", AV_CODEC_ID_MJPEG)
125 #endif
126
127 #if CONFIG_MLP_DEMUXER
128 AVInputFormat ff_mlp_demuxer = {
129     .name           = "mlp",
130     .long_name      = NULL_IF_CONFIG_SMALL("raw MLP"),
131     .read_header    = ff_raw_audio_read_header,
132     .read_packet    = ff_raw_read_partial_packet,
133     .flags          = AVFMT_GENERIC_INDEX,
134     .extensions     = "mlp",
135     .raw_codec_id   = AV_CODEC_ID_MLP,
136 };
137 #endif
138
139 #if CONFIG_TRUEHD_DEMUXER
140 AVInputFormat ff_truehd_demuxer = {
141     .name           = "truehd",
142     .long_name      = NULL_IF_CONFIG_SMALL("raw TrueHD"),
143     .read_header    = ff_raw_audio_read_header,
144     .read_packet    = ff_raw_read_partial_packet,
145     .flags          = AVFMT_GENERIC_INDEX,
146     .extensions     = "thd",
147     .raw_codec_id   = AV_CODEC_ID_TRUEHD,
148 };
149 #endif
150
151 #if CONFIG_SHORTEN_DEMUXER
152 AVInputFormat ff_shorten_demuxer = {
153     .name           = "shn",
154     .long_name      = NULL_IF_CONFIG_SMALL("raw Shorten"),
155     .read_header    = ff_raw_audio_read_header,
156     .read_packet    = ff_raw_read_partial_packet,
157     .flags          = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
158     .extensions     = "shn",
159     .raw_codec_id   = AV_CODEC_ID_SHORTEN,
160 };
161 #endif
162
163 #if CONFIG_VC1_DEMUXER
164 FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1)
165 #endif