FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 FFmpeg.
7  *
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.
12  *
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.
17  *
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
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 #include "libavutil/avassert.h"
31 #include "libavutil/intreadwrite.h"
32 
33 #define RAW_PACKET_SIZE 1024
34 
36 {
37  int ret, size;
38 
39  size = RAW_PACKET_SIZE;
40 
41  if (av_new_packet(pkt, size) < 0)
42  return AVERROR(ENOMEM);
43 
44  pkt->pos= avio_tell(s->pb);
45  pkt->stream_index = 0;
46  ret = ffio_read_partial(s->pb, pkt->data, size);
47  if (ret < 0) {
48  av_free_packet(pkt);
49  return ret;
50  }
51  av_shrink_packet(pkt, ret);
52  return ret;
53 }
54 
56 {
57  AVStream *st = avformat_new_stream(s, NULL);
58  if (!st)
59  return AVERROR(ENOMEM);
63  st->start_time = 0;
64  /* the parameters will be extracted from the compressed bitstream */
65 
66  return 0;
67 }
68 
69 /* MPEG-1/H.263 input */
71 {
72  AVStream *st;
74  int ret = 0;
75 
76 
77  st = avformat_new_stream(s, NULL);
78  if (!st) {
79  ret = AVERROR(ENOMEM);
80  goto fail;
81  }
82 
86 
87  st->codec->framerate = s1->framerate;
88  st->codec->time_base = av_inv_q(s1->framerate);
89  avpriv_set_pts_info(st, 64, 1, 1200000);
90 
91 fail:
92  return ret;
93 }
94 
96 {
97  AVStream *st = avformat_new_stream(s, NULL);
98  if (!st)
99  return AVERROR(ENOMEM);
101  st->codec->codec_id = s->iformat->raw_codec_id;
102  st->start_time = 0;
103  return 0;
104 }
105 
106 /* Note: Do not forget to add new entries to the Makefile as well. */
107 
108 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
109 #define DEC AV_OPT_FLAG_DECODING_PARAM
111  { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, DEC},
112  { NULL },
113 };
114 
115 #if CONFIG_DATA_DEMUXER
116 AVInputFormat ff_data_demuxer = {
117  .name = "data",
118  .long_name = NULL_IF_CONFIG_SMALL("raw data"),
119  .read_header = ff_raw_data_read_header,
120  .read_packet = ff_raw_read_partial_packet,
121  .raw_codec_id = AV_CODEC_ID_NONE,
122 };
123 #endif
124 
125 #if CONFIG_LATM_DEMUXER
126 
127 AVInputFormat ff_latm_demuxer = {
128  .name = "latm",
129  .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
130  .read_header = ff_raw_audio_read_header,
131  .read_packet = ff_raw_read_partial_packet,
132  .flags = AVFMT_GENERIC_INDEX,
133  .extensions = "latm",
134  .raw_codec_id = AV_CODEC_ID_AAC_LATM,
135 };
136 #endif
137 
138 #if CONFIG_MJPEG_DEMUXER
139 static int mjpeg_probe(AVProbeData *p)
140 {
141  int i;
142  int state = -1;
143  int nb_invalid = 0;
144  int nb_frames = 0;
145 
146  for (i=0; i<p->buf_size-2; i++) {
147  int c;
148  if (p->buf[i] != 0xFF)
149  continue;
150  c = p->buf[i+1];
151  switch (c) {
152  case 0xD8:
153  state = 0xD8;
154  break;
155  case 0xC0:
156  case 0xC1:
157  case 0xC2:
158  case 0xC3:
159  case 0xC5:
160  case 0xC6:
161  case 0xC7:
162  case 0xF7:
163  if (state == 0xD8) {
164  state = 0xC0;
165  } else
166  nb_invalid++;
167  break;
168  case 0xDA:
169  if (state == 0xC0) {
170  state = 0xDA;
171  } else
172  nb_invalid++;
173  break;
174  case 0xD9:
175  if (state == 0xDA) {
176  state = 0xD9;
177  nb_frames++;
178  } else
179  nb_invalid++;
180  break;
181  default:
182  if ( (c >= 0x02 && c <= 0xBF)
183  || c == 0xC8) {
184  nb_invalid++;
185  }
186  }
187  }
188 
189  if (nb_invalid*4 + 1 < nb_frames) {
190  static const char ct_jpeg[] = "\r\nContent-Type: image/jpeg\r\n\r\n";
191  int i;
192 
193  for (i=0; i<FFMIN(p->buf_size - sizeof(ct_jpeg), 100); i++)
194  if (!memcmp(p->buf + i, ct_jpeg, sizeof(ct_jpeg) - 1))
196 
197  if (nb_invalid == 0 && nb_frames > 2)
198  return AVPROBE_SCORE_EXTENSION / 2;
199  return AVPROBE_SCORE_EXTENSION / 4;
200  }
201 
202  return 0;
203 }
204 
205 FF_DEF_RAWVIDEO_DEMUXER2(mjpeg, "raw MJPEG video", mjpeg_probe, "mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG, AVFMT_GENERIC_INDEX|AVFMT_NOTIMESTAMPS)
206 #endif
207 
208 #if CONFIG_MLP_DEMUXER
209 AVInputFormat ff_mlp_demuxer = {
210  .name = "mlp",
211  .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
212  .read_header = ff_raw_audio_read_header,
213  .read_packet = ff_raw_read_partial_packet,
214  .flags = AVFMT_GENERIC_INDEX,
215  .extensions = "mlp",
216  .raw_codec_id = AV_CODEC_ID_MLP,
217 };
218 #endif
219 
220 #if CONFIG_TRUEHD_DEMUXER
221 AVInputFormat ff_truehd_demuxer = {
222  .name = "truehd",
223  .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
224  .read_header = ff_raw_audio_read_header,
225  .read_packet = ff_raw_read_partial_packet,
226  .flags = AVFMT_GENERIC_INDEX,
227  .extensions = "thd",
228  .raw_codec_id = AV_CODEC_ID_TRUEHD,
229 };
230 #endif
231 
232 #if CONFIG_SHORTEN_DEMUXER
233 AVInputFormat ff_shorten_demuxer = {
234  .name = "shn",
235  .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
236  .read_header = ff_raw_audio_read_header,
237  .read_packet = ff_raw_read_partial_packet,
239  .extensions = "shn",
240  .raw_codec_id = AV_CODEC_ID_SHORTEN,
241 };
242 #endif
243 
244 #if CONFIG_VC1_DEMUXER
246 #endif