提交 a82531dc 编写于 作者: R raymondzheng

ijkplayer: ijkio fix ijkio file issue

上级 83080edc
......@@ -47,6 +47,7 @@ struct IjkIOApplicationContext {
void *cache_info_map;
void *opaque;
int64_t cache_count_bytes;
int fd;
int (*func_ijkio_on_app_event)(IjkIOApplicationContext *h, int event_type ,void *obj, int size);
};
......
......@@ -168,15 +168,15 @@ static int ijkio_cache_file_error(IjkURLContext *h) {
c->file_logical_pos = c->fifo_logical_pos;
close(c->fd);
c->fd = -1;
c->ijkio_app_ctx->fd = -1;
if (c->file_error_count > 3) {
c->fifo_pos_reset = 1;
c->cache_file_close = 1;
close(c->fd);
remove(c->cache_file_path);
c->fd = -1;
return 0;
}
c->fd = open(c->cache_file_path, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, 0600);
c->ijkio_app_ctx->fd = c->fd;
if (c->fd >= 0) {
c->file_handle_retry_count = 0;
c->tree_info = calloc(1, sizeof(IjkCacheTreeInfo));
......@@ -691,7 +691,12 @@ static int ijkio_cache_open(IjkURLContext *h, const char *url, int flags, IjkAVD
if (!c->cache_file_close) {
do {
c->fd = open(c->cache_file_path, O_RDWR | O_BINARY | O_CREAT, 0600);
if (c->ijkio_app_ctx->fd >= 0) {
c->fd = c->ijkio_app_ctx->fd;
} else {
c->fd = open(c->cache_file_path, O_RDWR | O_BINARY | O_CREAT, 0600);
c->ijkio_app_ctx->fd = c->fd;
}
if (c->fd < 0) {
c->cache_file_close = 1;
break;
......@@ -701,6 +706,8 @@ static int ijkio_cache_open(IjkURLContext *h, const char *url, int flags, IjkAVD
if (seek_ret < 0) {
c->cache_file_close = 1;
close(c->fd);
c->fd = -1;
c->ijkio_app_ctx->fd = -1;
break;
} else {
c->cache_physical_pos = *c->last_physical_pos;
......@@ -890,8 +897,6 @@ static int ijkio_cache_close(IjkURLContext *h) {
pthread_cond_destroy(&c->cond_wakeup_exit);
pthread_mutex_destroy(&c->mutex);
close(c->fd);
ret = c->inner->prot->url_close(c->inner);
ijk_av_fifo_freep(&c->fifo);
......@@ -913,8 +918,6 @@ static int ijkio_cache_pause(IjkURLContext *h) {
if (c->task_is_running) {
pthread_cond_wait(&c->cond_wakeup_exit, &c->mutex);
}
close(c->fd);
c->fd = -1;
pthread_mutex_unlock(&c->mutex);
if (c->inner->prot->url_pause) {
......@@ -933,15 +936,12 @@ static int ijkio_cache_resume(IjkURLContext *h) {
if (c->cache_file_path == NULL || 0 == strlen(c->cache_file_path)) {
c->cache_file_close = 1;
} else {
c->fd = open(c->cache_file_path, O_RDWR | O_BINARY | O_CREAT, 0600);
if (c->fd < 0) {
c->cache_file_close = 1;
}
int64_t seek_ret = lseek(c->fd, *c->last_physical_pos, SEEK_SET);
if (seek_ret < 0) {
c->cache_file_close = 1;
close(c->fd);
c->fd = -1;
c->ijkio_app_ctx->fd = -1;
} else {
c->cache_physical_pos = *c->last_physical_pos;
}
......
......@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
static int ijkio_manager_alloc(IjkIOManagerContext **ph, void *opaque)
{
......@@ -44,6 +45,7 @@ static int ijkio_manager_alloc(IjkIOManagerContext **ph, void *opaque)
h->ijkio_app_ctx->threadpool_ctx = ijk_threadpool_create(5, 5, 0);
h->ijkio_app_ctx->cache_info_map = ijk_map_create();
h->ijkio_app_ctx->fd = -1;
*ph = h;
return 0;
}
......@@ -80,6 +82,9 @@ void ijkio_manager_destroy(IjkIOManagerContext *h)
}
if (0 != strlen(h->ijkio_app_ctx->cache_file_path)) {
if (h->ijkio_app_ctx->fd >= 0) {
close(h->ijkio_app_ctx->fd);
}
remove(h->ijkio_app_ctx->cache_file_path);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册