FFmpeg: libavformat/mpjpegdec.c Source File
Go to the documentation of this file. 1 /*
2 * Multipart JPEG format
3 * Copyright (c) 2015 Luca Barbato
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
24
28
29
30
38
39
41 {
42 char *end;
43
44 if (!p || !*p)
45 return;
46
47 end = p + strlen(p);
49 *(--end) = '0円';
50 }
51
53 {
55
58
61
63 return 0;
64 }
65
66
67
69 {
71 int foundData = 0;
72
75
76
77 while (*p != '0円' && *p != ':') {
79 foundData = 1;
80 }
81 p++;
82 }
83 if (*p != ':')
85
86 *p = '0円';
89
90 p++;
91
93 p++;
94
97
98 return 0;
99 }
100
103 const char* expected_boundary,
104 void *log_ctx);
105
107 {
111 return 0;
112 }
113
115 {
119
121 return 0;
122
124
126
128 }
129
131 {
133 char boundary[70 + 2 + 1] = {0};
136
137 do {
141 } while (!boundary[0]);
142
143 if (strncmp(boundary, "--", 2))
145
147 if (!st)
149
152
154
156
157 return 0;
158 }
159
161 {
163
164 if (
val == LONG_MIN ||
val == LONG_MAX)
169 }
170
173 const char* expected_boundary,
174 void *log_ctx)
175 {
177 int found_content_type = 0;
179
181
182 // get the CRLF as empty string
186
187 /* some implementation do not provide the required
188 * initial CRLF (see rfc1341 7.2.1)
189 */
194 }
195
197 if (log_ctx)
200 "Expected boundary '%s' not found, instead found a line of %"SIZE_SPECIFIER " bytes\n",
201 expected_boundary,
203
205 }
206
209
213 break;
215 }
216
218 break;
219
224 break;
225
228 if (log_ctx)
230 "Unexpected %s : %s\n",
233 } else
234 found_content_type = 1;
238 if (log_ctx)
240 "Invalid Content-Length value : %s\n",
242 }
243 }
244
246 }
247
248
250 {
251 uint8_t *mime_type =
NULL;
252 const char *start;
253 const char *end;
256
257 /* get MIME type, and skip to the first parameter */
259 start = mime_type;
260 while (start !=
NULL && *start !=
'0円') {
261 start = strchr(start, ';');
262 if (!start)
263 break;
264
265 start = start+1;
266
268 start++;
269
271 end = strchr(start, ';');
272 if (end)
273 len = end - start - 1;
274 else
276
277 /* some endpoints may enclose the boundary
278 in Content-Type in quotes */
279 if (
len>2 && *start ==
'"' && start[
len-1] ==
'"' ) {
280 start++;
282 }
284 break;
285 }
286 }
287
289 return res;
290 }
291
292
294 {
297
300 uint8_t* boundary =
NULL;
303 }
304 if (boundary !=
NULL) {
308 } else {
311 }
316 }
318 }
319
321
322
325
327 /* size has been provided to us in MIME header */
329 } else {
330 /* no size was given -- we read until the next boundary or end-of-file */
332
334
336
339 /* scan the new data */
340 char *start;
341
344 do {
346 // got the boundary! rewind the stream
350 }
352 start++;
356 }
357
358 /* error or EOF occurred */
361 }
362 }
363
365 }
366
367 #define OFFSET(x) offsetof(MPJPEGDemuxContext, x)
368
369 #define DEC AV_OPT_FLAG_DECODING_PARAM
371 {
"strict_mime_boundary",
"require MIME boundaries match",
OFFSET(strict_mime_boundary),
AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,
DEC },
373 };
374
375
381 };
382
386 .mime_type = "multipart/x-mixed-replace",
387 .extensions = "mjpg",
395 };
396
397
#define AV_LOG_WARNING
Something somehow does not look correct.
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
enum AVMediaType codec_type
General type of the encoded data.
#define AVERROR_EOF
End of file.
char * av_asprintf(const char *fmt,...)
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
int error
contains the error code or 0 if no error happened
int buf_size
Size of buf except extra allocated bytes.
static av_cold int read_close(AVFormatContext *ctx)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static double val(void *priv, double ch)
static int get_line(AVIOContext *pb, char *line, int line_size)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static char * mpjpeg_get_boundary(AVIOContext *pb)
static void trim_right(char *p)
const AVInputFormat ff_mpjpeg_demuxer
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
static int read_chunk(AVFormatContext *s)
int av_stristart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str independent of case.
static int parse_multipart_header(AVIOContext *pb, int *size, const char *expected_boundary, void *log_ctx)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
static int read_header(FFV1Context *f)
Describe the class of an AVClass context structure.
const char * av_default_item_name(void *ptr)
Return the context name.
This structure contains the data a format has to probe a file.
static const AVClass mpjpeg_demuxer_class
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
static int mpjpeg_read_probe(const AVProbeData *p)
static int mpjpeg_read_close(AVFormatContext *s)
static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt)
static const AVOption mpjpeg_options[]
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
void ffio_init_context(FFIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
static int split_tag_value(char **tag, char **value, char *line)
static int parse_content_length(const char *value)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int eof_reached
true if was unable to read due to error or eof
static int mpjpeg_read_header(AVFormatContext *s)
char * av_strdup(const char *s)
Duplicate a string.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
int64_t pos
byte position in stream, -1 if unknown
#define flags(name, subs,...)
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
Generated on Wed Aug 24 2022 21:38:25 for FFmpeg by
doxygen
1.8.17