MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / data_open

Function data_open

libavformat/data_uri.c:35–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33} DataContext;
34
35static av_cold int data_open(URLContext *h, const char *uri, int flags)
36{
37 DataContext *dc = h->priv_data;
38 const char *data, *opt, *next;
39 char *ddata;
40 int ret, base64 = 0;
41 size_t in_size;
42
43 /* data:content/type[;base64],payload */
44
45 av_strstart(uri, "data:", &uri);
46 data = strchr(uri, ',');
47 if (!data) {
48 av_log(h, AV_LOG_ERROR, "No ',' delimiter in URI\n");
49 return AVERROR(EINVAL);
50 }
51 opt = uri;
52 while (opt < data) {
53 next = av_x_if_null(memchr(opt, ';', data - opt), data);
54 if (opt == uri) {
55 if (!memchr(opt, '/', next - opt)) { /* basic validity check */
56 av_log(h, AV_LOG_ERROR, "Invalid content-type '%.*s'\n",
57 (int)(next - opt), opt);
58 return AVERROR(EINVAL);
59 }
60 av_log(h, AV_LOG_VERBOSE, "Content-type: %.*s\n",
61 (int)(next - opt), opt);
62 } else {
63 if (!av_strncasecmp(opt, "base64", next - opt)) {
64 base64 = 1;
65 } else {
66 av_log(h, AV_LOG_VERBOSE, "Ignoring option '%.*s'\n",
67 (int)(next - opt), opt);
68 }
69 }
70 opt = next + 1;
71 }
72
73 data++;
74 in_size = strlen(data);
75 if (base64) {
76 size_t out_size = 3 * (in_size / 4) + 1;
77
78 if (out_size > INT_MAX || !(ddata = av_malloc(out_size)))
79 return AVERROR(ENOMEM);
80 if ((ret = av_base64_decode(ddata, data, out_size)) < 0) {
81 av_free(ddata);
82 av_log(h, AV_LOG_ERROR, "Invalid base64 in URI\n");
83 return ret;
84 }
85 dc->data = dc->tofree = ddata;
86 dc->size = ret;
87 } else {
88 dc->data = data;
89 dc->size = in_size;
90 }
91 return 0;
92}

Callers

nothing calls this directly

Calls 7

av_strstartFunction · 0.85
av_logFunction · 0.85
av_x_if_nullFunction · 0.85
av_strncasecmpFunction · 0.85
av_base64_decodeFunction · 0.85
av_mallocFunction · 0.50
av_freeFunction · 0.50

Tested by

no test coverage detected