long long StreamingRingBuffer::GetRealFileSize(void) const { long long result = -1; rwlock.lockForRead(); if (m_context) result = ffurl_size(m_context); rwlock.unlock(); return result; }
int64_t url_filesize(URLContext *h) { return ffurl_size(h); }
static int open_input(struct variant *var) { struct segment *seg = var->segments[var->cur_seq_no - var->start_seq_no]; int ret; if (seg->key_type == KEY_NONE) { #ifdef AVIO_OPEN2 return ffurl_open(&var->input, seg->url, AVIO_FLAG_READ, &var->parent->interrupt_callback, NULL); #else ret= ffurl_open(&var->input, seg->url, AVIO_FLAG_READ |URL_MINI_BUFFER | URL_NO_LP_BUFFER); av_log(NULL, AV_LOG_ERROR, "hls:open_input %s\n",seg->url); if(var->input) seg->seg_filesize=ffurl_size(var->input); return ret; #endif } else if (seg->key_type == KEY_AES_128) { char iv[33], key[33], url[MAX_URL_SIZE]; int ret; if (strcmp(seg->key, var->key_url)) { URLContext *uc; #ifdef AVIO_OPEN2 ret=ffurl_open(&uc, seg->key, AVIO_FLAG_READ , &var->parent->interrupt_callback, NULL); #else ret=ffurl_open(&uc, seg->key, AVIO_FLAG_READ |URL_MINI_BUFFER | URL_NO_LP_BUFFER); #endif if (ret== 0) { if (ffurl_read_complete(uc, var->key, sizeof(var->key)) != sizeof(var->key)) { av_log(NULL, AV_LOG_ERROR, "Unable to read key file %s\n", seg->key); } ffurl_close(uc); } else { av_log(NULL, AV_LOG_ERROR, "Unable to open key file %s\n", seg->key); } av_strlcpy(var->key_url, seg->key, sizeof(var->key_url)); } ff_data_to_hex(iv, seg->iv, sizeof(seg->iv), 0); ff_data_to_hex(key, var->key, sizeof(var->key), 0); iv[32] = key[32] = '\0'; if (strstr(seg->url, "://")) snprintf(url, sizeof(url), "crypto+%s", seg->url); else snprintf(url, sizeof(url), "crypto:%s", seg->url); #ifdef AVIO_OPEN2 if ((ret = ffurl_alloc(&var->input, url, AVIO_FLAG_READ, &var->parent->interrupt_callback)) < 0) return ret; #else if ((ret = ffurl_alloc(&var->input, url, AVIO_FLAG_READ |URL_MINI_BUFFER | URL_NO_LP_BUFFER)) < 0) return ret; #endif //av_opt_set(var->input->priv_data, "key", key, 0); // av_opt_set(var->input->priv_data, "iv", iv, 0); av_set_string3(var->input->priv_data, "key", key, 0, NULL); av_set_string3(var->input->priv_data, "iv", iv, 0, NULL); if ((ret = ffurl_connect(var->input)) < 0) { ffurl_close(var->input); var->input = NULL; return ret; } if(var->input) seg->seg_filesize=ffurl_size(var->input); return 0; } return AVERROR(ENOSYS); }
static av_cold int concat_open(URLContext *h, const char *uri, int flags) { char *node_uri = NULL; int err = 0; int64_t size; size_t len, i; URLContext *uc; struct concat_data *data = h->priv_data; struct concat_nodes *nodes; if (!av_strstart(uri, "concat:", &uri)) { av_log(h, AV_LOG_ERROR, "URL %s lacks prefix\n", uri); return AVERROR(EINVAL); } for (i = 0, len = 1; uri[i]; i++) { if (uri[i] == *AV_CAT_SEPARATOR) { /* integer overflow */ if (++len == UINT_MAX / sizeof(*nodes)) { av_freep(&h->priv_data); return AVERROR(ENAMETOOLONG); } } } if (!(nodes = av_realloc(NULL, sizeof(*nodes) * len))) return AVERROR(ENOMEM); else data->nodes = nodes; /* handle input */ if (!*uri) err = AVERROR(ENOENT); for (i = 0; *uri; i++) { /* parsing uri */ len = strcspn(uri, AV_CAT_SEPARATOR); if ((err = av_reallocp(&node_uri, len + 1)) < 0) break; av_strlcpy(node_uri, uri, len + 1); uri += len + strspn(uri + len, AV_CAT_SEPARATOR); /* creating URLContext */ err = ffurl_open_whitelist(&uc, node_uri, flags, &h->interrupt_callback, NULL, h->protocol_whitelist); if (err < 0) break; /* creating size */ if ((size = ffurl_size(uc)) < 0) { ffurl_close(uc); err = AVERROR(ENOSYS); break; } /* assembling */ nodes[i].uc = uc; nodes[i].size = size; } av_free(node_uri); data->length = i; if (err < 0) concat_close(h); else if (!(nodes = av_realloc(nodes, data->length * sizeof(*nodes)))) { concat_close(h); err = AVERROR(ENOMEM); } else data->nodes = nodes; return err; }
static av_cold int concat_open(URLContext *h, const char *uri, int flags) { char *node_uri = NULL, *tmp_uri; int err = 0; int64_t size; size_t len, i; URLContext *uc; struct concat_data *data; struct concat_nodes *nodes; av_strstart(uri, "concat:", &uri); /* creating data */ if (!(data = av_mallocz(sizeof(*data)))) return AVERROR(ENOMEM); h->priv_data = data; for (i = 0, len = 1; uri[i]; i++) if (uri[i] == *AV_CAT_SEPARATOR) /* integer overflow */ if (++len == UINT_MAX / sizeof(*nodes)) { av_freep(&h->priv_data); return AVERROR(ENAMETOOLONG); } if (!(nodes = av_malloc(sizeof(*nodes) * len))) { av_freep(&h->priv_data); return AVERROR(ENOMEM); } else data->nodes = nodes; /* handle input */ if (!*uri) err = AVERROR(ENOENT); for (i = 0; *uri; i++) { /* parsing uri */ len = strcspn(uri, AV_CAT_SEPARATOR); if (!(tmp_uri = av_realloc(node_uri, len+1))) { err = AVERROR(ENOMEM); break; } else node_uri = tmp_uri; av_strlcpy(node_uri, uri, len+1); uri += len + strspn(uri+len, AV_CAT_SEPARATOR); /* creating URLContext */ if ((err = ffurl_open(&uc, node_uri, flags)) < 0) break; /* creating size */ if ((size = ffurl_size(uc)) < 0) { ffurl_close(uc); err = AVERROR(ENOSYS); break; } /* assembling */ nodes[i].uc = uc; nodes[i].size = size; } av_free(node_uri); data->length = i; if (err < 0) concat_close(h); else if (!(nodes = av_realloc(nodes, data->length * sizeof(*nodes)))) { concat_close(h); err = AVERROR(ENOMEM); } else data->nodes = nodes; return err; }