rawdec.c
Go to the documentation of this file.
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 
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 
58 {
60  if (!st)
61  return AVERROR(ENOMEM);
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 */
73 {
74  AVStream *st;
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 
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 #if FF_API_R_FRAME_RATE
96  st->r_frame_rate =
97 #endif
98  st->avg_frame_rate = framerate;
99  avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
100 
101 fail:
102  return ret;
103 }
104 
105 /* Note: Do not forget to add new entries to the Makefile as well. */
106 
107 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
108 #define DEC AV_OPT_FLAG_DECODING_PARAM
110  { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC},
111  { NULL },
112 };
113 
114 #if CONFIG_LATM_DEMUXER
115 AVInputFormat ff_latm_demuxer = {
116  .name = "latm",
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,
123 };
124 #endif
125 
126 #if CONFIG_MJPEG_DEMUXER
127 FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg", AV_CODEC_ID_MJPEG)
128 #endif
129 
130 #if CONFIG_MLP_DEMUXER
131 AVInputFormat ff_mlp_demuxer = {
132  .name = "mlp",
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,
137  .extensions = "mlp",
138  .raw_codec_id = AV_CODEC_ID_MLP,
139 };
140 #endif
141 
142 #if CONFIG_TRUEHD_DEMUXER
143 AVInputFormat ff_truehd_demuxer = {
144  .name = "truehd",
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,
149  .extensions = "thd",
150  .raw_codec_id = AV_CODEC_ID_TRUEHD,
151 };
152 #endif
153 
154 #if CONFIG_SHORTEN_DEMUXER
155 AVInputFormat ff_shorten_demuxer = {
156  .name = "shn",
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,
161  .extensions = "shn",
162  .raw_codec_id = AV_CODEC_ID_SHORTEN,
163 };
164 #endif
165 
166 #if CONFIG_VC1_DEMUXER
167 FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1)
168 #endif