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

Function url_alloc_for_protocol

libavformat/avio.c:118–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116}
117
118static int url_alloc_for_protocol(URLContext **puc, const URLProtocol *up,
119 const char *filename, int flags,
120 const AVIOInterruptCB *int_cb)
121{
122 URLContext *uc;
123 int err;
124
125#if CONFIG_NETWORK
126 if (up->flags & URL_PROTOCOL_FLAG_NETWORK && !ff_network_init())
127 return AVERROR(EIO);
128#endif
129 if ((flags & AVIO_FLAG_READ) && !up->url_read) {
130 av_log(NULL, AV_LOG_ERROR,
131 "Impossible to open the '%s' protocol for reading\n", up->name);
132 return AVERROR(EIO);
133 }
134 if ((flags & AVIO_FLAG_WRITE) && !up->url_write) {
135 av_log(NULL, AV_LOG_ERROR,
136 "Impossible to open the '%s' protocol for writing\n", up->name);
137 return AVERROR(EIO);
138 }
139 uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1);
140 if (!uc) {
141 err = AVERROR(ENOMEM);
142 goto fail;
143 }
144 uc->av_class = &url_context_class;
145 uc->filename = (char *)&uc[1];
146 strcpy(uc->filename, filename);
147 uc->prot = up;
148 uc->flags = flags;
149 uc->is_streamed = 0; /* default = not streamed */
150 uc->max_packet_size = 0; /* default: stream file */
151 if (up->priv_data_size) {
152 uc->priv_data = av_mallocz(up->priv_data_size);
153 if (!uc->priv_data) {
154 err = AVERROR(ENOMEM);
155 goto fail;
156 }
157 if (up->priv_data_class) {
158 char *start;
159 *(const AVClass **)uc->priv_data = up->priv_data_class;
160 av_opt_set_defaults(uc->priv_data);
161 if (av_strstart(uc->filename, up->name, (const char**)&start) && *start == ',') {
162 int ret= 0;
163 char *p= start;
164 char sep= *++p;
165 char *key, *val;
166 p++;
167
168 if (strcmp(up->name, "subfile"))
169 ret = AVERROR(EINVAL);
170
171 while(ret >= 0 && (key= strchr(p, sep)) && p<key && (val = strchr(key+1, sep))){
172 *val= *key= 0;
173 ret = av_opt_set(uc->priv_data, p, key+1, 0);
174 if (ret == AVERROR_OPTION_NOT_FOUND)
175 av_log(uc, AV_LOG_ERROR, "Key '%s' not found.\n", p);

Callers 1

ffurl_allocFunction · 0.85

Calls 8

ff_network_initFunction · 0.85
av_logFunction · 0.85
av_opt_set_defaultsFunction · 0.85
av_strstartFunction · 0.85
av_opt_setFunction · 0.85
av_freepFunction · 0.85
ff_network_closeFunction · 0.85
av_malloczFunction · 0.50

Tested by

no test coverage detected