]> git.sesse.net Git - ffmpeg/blob - libavformat/rawdec.c
1c9aabd6fdc0b54341925efb81bdda85deaeb822
[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     }
49     pkt->size = ret;
50     return ret;
51 }
52
53 int ff_raw_audio_read_header(AVFormatContext *s)
54 {
55     AVStream *st = avformat_new_stream(s, NULL);
56     if (!st)
57         return AVERROR(ENOMEM);
58     st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
59     st->codec->codec_id = s->iformat->raw_codec_id;
60     st->need_parsing = AVSTREAM_PARSE_FULL;
61     st->start_time = 0;
62     /* the parameters will be extracted from the compressed bitstream */
63
64     return 0;
65 }
66
67 /* MPEG-1/H.263 input */
68 int ff_raw_video_read_header(AVFormatContext *s)
69 {
70     AVStream *st;
71     FFRawVideoDemuxerContext *s1 = s->priv_data;
72     AVRational framerate;
73     int ret = 0;
74
75
76     st = avformat_new_stream(s, NULL);
77     if (!st) {
78         ret = AVERROR(ENOMEM);
79         goto fail;
80     }
81
82     st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
83     st->codec->codec_id = s->iformat->raw_codec_id;
84     st->need_parsing = AVSTREAM_PARSE_FULL;
85
86     if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {
87         av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
88         goto fail;
89     }
90
91 #if FF_API_R_FRAME_RATE
92     st->r_frame_rate =
93 #endif
94     st->avg_frame_rate = framerate;
95     avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
96
97 fail:
98     return ret;
99 }
100
101 /* Note: Do not forget to add new entries to the Makefile as well. */
102
103 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
104 #define DEC AV_OPT_FLAG_DECODING_PARAM
105 const AVOption ff_rawvideo_options[] = {
106     { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC},
107     { NULL },
108 };
109
110 #if CONFIG_LATM_DEMUXER
111 AVInputFormat ff_latm_demuxer = {
112     .name           = "latm",
113     .long_name      = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
114     .read_header    = ff_raw_audio_read_header,
115     .read_packet    = ff_raw_read_partial_packet,
116     .flags          = AVFMT_GENERIC_INDEX,
117     .extensions     = "latm",
118     .raw_codec_id   = AV_CODEC_ID_AAC_LATM,
119 };
120 #endif
121
122 #if CONFIG_MJPEG_DEMUXER
123 FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg", AV_CODEC_ID_MJPEG)
124 #endif
125
126 #if CONFIG_MLP_DEMUXER
127 AVInputFormat ff_mlp_demuxer = {
128     .name           = "mlp",
129     .long_name      = NULL_IF_CONFIG_SMALL("raw MLP"),
130     .read_header    = ff_raw_audio_read_header,
131     .read_packet    = ff_raw_read_partial_packet,
132     .flags          = AVFMT_GENERIC_INDEX,
133     .extensions     = "mlp",
134     .raw_codec_id   = AV_CODEC_ID_MLP,
135 };
136 #endif
137
138 #if CONFIG_TRUEHD_DEMUXER
139 AVInputFormat ff_truehd_demuxer = {
140     .name           = "truehd",
141     .long_name      = NULL_IF_CONFIG_SMALL("raw TrueHD"),
142     .read_header    = ff_raw_audio_read_header,
143     .read_packet    = ff_raw_read_partial_packet,
144     .flags          = AVFMT_GENERIC_INDEX,
145     .extensions     = "thd",
146     .raw_codec_id   = AV_CODEC_ID_TRUEHD,
147 };
148 #endif
149
150 #if CONFIG_SHORTEN_DEMUXER
151 AVInputFormat ff_shorten_demuxer = {
152     .name           = "shn",
153     .long_name      = NULL_IF_CONFIG_SMALL("raw Shorten"),
154     .read_header    = ff_raw_audio_read_header,
155     .read_packet    = ff_raw_read_partial_packet,
156     .flags          = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
157     .extensions     = "shn",
158     .raw_codec_id   = AV_CODEC_ID_SHORTEN,
159 };
160 #endif
161
162 #if CONFIG_VC1_DEMUXER
163 FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1)
164 #endif