static int64_t ijkio_cache_file_overrang(IjkURLContext *h, int64_t *cur_pos, int size) { IjkIOCacheContext *c = h->priv_data; av_log(NULL, AV_LOG_WARNING, "ijkio_cache_file_overrang will flush file\n"); pthread_mutex_lock(&h->ijkio_app_ctx->mutex); if (!c->ijkio_app_ctx->shared) { ijk_map_remove(c->cache_info_map, (int64_t)c->cur_file_no); ijk_map_traversal_handle(c->cache_info_map, NULL, tree_destroy); ijk_map_clear(c->cache_info_map); memset(c->tree_info, 0, sizeof(IjkCacheTreeInfo)); ijk_map_put(c->cache_info_map, (int64_t)c->cur_file_no, c->tree_info); *c->last_physical_pos = 0; c->cache_physical_pos = 0; c->io_eof_reached = 0; c->file_logical_pos = c->read_logical_pos; *cur_pos = lseek(c->fd, 0, SEEK_SET); if (*cur_pos < 0) { goto fail; } } else { goto fail; } pthread_mutex_unlock(&h->ijkio_app_ctx->mutex); return c->cache_max_capacity; fail: pthread_mutex_unlock(&h->ijkio_app_ctx->mutex); return FILE_RW_ERROR; }
int ijkio_manager_io_close(IjkIOManagerContext *h) { int ret = -1; if (!h) return ret; IjkURLContext *inner = ijk_map_get(h->ijk_ctx_map, (int64_t)(intptr_t)h->cur_ffmpeg_ctx); if (inner) { if (inner->prot && inner->prot->url_close) { ret = inner->prot->url_close(inner); } ijk_map_remove(h->ijk_ctx_map, (int64_t)(intptr_t)h->cur_ffmpeg_ctx); ijk_av_freep(&inner->priv_data); ijk_av_freep(&inner); } return ret; }
int ijkio_manager_io_open(IjkIOManagerContext *h, const char *url, int flags, IjkAVDictionary **options) { int ret = -1; if (!h) return ret; IjkAVDictionaryEntry *t = NULL; t = ijk_av_dict_get(*options, "cache_file_path", t, IJK_AV_DICT_IGNORE_SUFFIX); if (t) { strcpy(h->ijkio_app_ctx->cache_file_path, t->value); } if (h->ijkio_app_ctx == NULL) { return -1; } h->ijkio_app_ctx->ijkio_interrupt_callback = h->ijkio_interrupt_callback; IjkURLContext *inner = NULL; ijkio_alloc_url(&inner, url); if (inner) { inner->ijkio_app_ctx = h->ijkio_app_ctx; if (h->ijk_ctx_map) { ijkio_manager_set_all_ctx_pause(h); inner->state = IJKURL_STARTED; ijk_map_put(h->ijk_ctx_map, (int64_t)(intptr_t)h->cur_ffmpeg_ctx, inner); } ret = inner->prot->url_open2(inner, url, flags, options); if (ret != 0) goto fail; return ret; } fail: if (inner) { if (inner->prot && inner->prot->url_close) ret = inner->prot->url_close(inner); if (h->ijk_ctx_map) { ijk_map_remove(h->ijk_ctx_map, (int64_t)(intptr_t)h->cur_ffmpeg_ctx); } ijk_av_freep(&inner->priv_data); ijk_av_freep(&inner); } return -1; }