提交 e99d640e 编写于 作者: Z zhenghanchao

ijkplayer: convert pointer to string instead of using av_dict_set_int

上级 86e8d338
......@@ -4144,7 +4144,7 @@ void *ffp_set_ijkio_inject_opaque(FFPlayer *ffp, void *opaque)
ijkio_manager_destroyp(&ffp->ijkio_manager_ctx);
ijkio_manager_create(&ffp->ijkio_manager_ctx, ffp);
ijkio_manager_set_callback(ffp->ijkio_manager_ctx, ijkio_app_func_event);
ffp_set_option_int(ffp, FFP_OPT_CATEGORY_FORMAT, "ijkiomanager", (int64_t)(intptr_t)ffp->ijkio_manager_ctx);
ffp_set_option_intptr(ffp, FFP_OPT_CATEGORY_FORMAT, "ijkiomanager", (uintptr_t)ffp->ijkio_manager_ctx);
return prev_weak_thiz;
}
......@@ -4158,7 +4158,7 @@ void *ffp_set_inject_opaque(FFPlayer *ffp, void *opaque)
av_application_closep(&ffp->app_ctx);
av_application_open(&ffp->app_ctx, ffp);
ffp_set_option_int(ffp, FFP_OPT_CATEGORY_FORMAT, "ijkapplication", (int64_t)(intptr_t)ffp->app_ctx);
ffp_set_option_intptr(ffp, FFP_OPT_CATEGORY_FORMAT, "ijkapplication", (uint64_t)(intptr_t)ffp->app_ctx);
ffp->app_ctx->func_on_app_event = app_func_event;
return prev_weak_thiz;
......@@ -4182,6 +4182,15 @@ void ffp_set_option_int(FFPlayer *ffp, int opt_category, const char *name, int64
av_dict_set_int(dict, name, value, 0);
}
void ffp_set_option_intptr(FFPlayer *ffp, int opt_category, const char *name, uintptr_t value)
{
if (!ffp)
return;
AVDictionary **dict = ffp_get_opt_dict(ffp, opt_category);
av_dict_set_intptr(dict, name, value, 0);
}
void ffp_set_overlay_format(FFPlayer *ffp, int chroma_fourcc)
{
switch (chroma_fourcc) {
......
......@@ -51,6 +51,7 @@ void *ffp_set_inject_opaque(FFPlayer *ffp, void *opaque);
void *ffp_set_ijkio_inject_opaque(FFPlayer *ffp, void *opaque);
void ffp_set_option(FFPlayer *ffp, int opt_category, const char *name, const char *value);
void ffp_set_option_int(FFPlayer *ffp, int opt_category, const char *name, int64_t value);
void ffp_set_option_intptr(FFPlayer *ffp, int opt_category, const char *name, uintptr_t value);
int ffp_get_video_codec_info(FFPlayer *ffp, char **codec_info);
int ffp_get_audio_codec_info(FFPlayer *ffp, char **codec_info);
......
......@@ -84,7 +84,7 @@ typedef struct Context {
/* options */
int64_t forwards_capacity;
int64_t backwards_capacity;
int64_t app_ctx_intptr;
char * app_ctx_intptr;
AVApplicationContext *app_ctx;
} Context;
......@@ -308,8 +308,8 @@ static int async_open(URLContext *h, const char *arg, int flags, AVDictionary **
goto fifo_fail;
if (c->app_ctx_intptr) {
c->app_ctx = (AVApplicationContext *)(intptr_t)c->app_ctx_intptr;
av_dict_set_int(options, "ijkapplication", c->app_ctx_intptr, 0);
c->app_ctx = (AVApplicationContext *)av_dict_strtoptr(c->app_ctx_intptr);
av_dict_set_intptr(options, "ijkapplication", (uintptr_t )c->app_ctx, 0);
}
/* wrap interrupt callback */
c->interrupt_callback = h->interrupt_callback;
......@@ -535,7 +535,7 @@ static const AVOption options[] = {
OFFSET(forwards_capacity), AV_OPT_TYPE_INT64, {.i64 = 128 * 1024}, 128 * 1024, 128 * 1024 * 1024, D },
{ "async-backwards-capacity", "max bytes that may be seek backward without seeking in inner protocol",
OFFSET(backwards_capacity), AV_OPT_TYPE_INT64, {.i64 = 128 * 1024}, 128 * 1024, 128 * 1024 * 1024, D },
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_INT64, { .i64 = 0 }, INT64_MIN, INT64_MAX, .flags = D },
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_STRING, { .str = 0 }, 0, 0, .flags = D },
{NULL},
};
......
......@@ -31,7 +31,7 @@
typedef struct Context {
AVClass *class;
int64_t *io_manager_ctx;
char *io_manager_ctx_intptr;
} Context;
static int ijkio_copy_options(IjkAVDictionary **dst, AVDictionary *src) {
......@@ -51,10 +51,10 @@ static int ijkio_open(URLContext *h, const char *arg, int flags, AVDictionary **
Context *c = h->priv_data;
int ret = -1;
if (!c || !c->io_manager_ctx)
if (!c || !c->io_manager_ctx_intptr)
return -1;
IjkIOManagerContext *manager_ctx = (IjkIOManagerContext *)(c->io_manager_ctx);
IjkIOManagerContext *manager_ctx = (IjkIOManagerContext *)av_dict_strtoptr(c->io_manager_ctx_intptr);
manager_ctx->ijkio_interrupt_callback = (IjkAVIOInterruptCB *)&(h->interrupt_callback);
av_strstart(arg, "ijkio:", &arg);
......@@ -77,40 +77,41 @@ static int ijkio_read(URLContext *h, unsigned char *buf, int size)
{
Context *c = h->priv_data;
if (!c || !c->io_manager_ctx)
if (!c || !c->io_manager_ctx_intptr)
return -1;
((IjkIOManagerContext *)(c->io_manager_ctx))->cur_ffmpeg_ctx = c;
return ijkio_manager_io_read((IjkIOManagerContext *)(c->io_manager_ctx), buf, size);
((IjkIOManagerContext *)(av_dict_strtoptr(c->io_manager_ctx_intptr)))->cur_ffmpeg_ctx = c;
return ijkio_manager_io_read((IjkIOManagerContext *)(av_dict_strtoptr(c->io_manager_ctx_intptr)), buf, size);
}
static int64_t ijkio_seek(URLContext *h, int64_t offset, int whence)
{
Context *c = h->priv_data;
if (!c || !c->io_manager_ctx)
if (!c || !c->io_manager_ctx_intptr)
return -1;
((IjkIOManagerContext *)(c->io_manager_ctx))->cur_ffmpeg_ctx = c;
return ijkio_manager_io_seek((IjkIOManagerContext *)(c->io_manager_ctx), offset, whence);
((IjkIOManagerContext *)(av_dict_strtoptr(c->io_manager_ctx_intptr)))->cur_ffmpeg_ctx = c;
return ijkio_manager_io_seek((IjkIOManagerContext *)(av_dict_strtoptr(c->io_manager_ctx_intptr)), offset, whence);
}
static int ijkio_close(URLContext *h)
{
Context *c = h->priv_data;
if (!c || !c->io_manager_ctx)
if (!c || !c->io_manager_ctx_intptr)
return -1;
((IjkIOManagerContext *)(c->io_manager_ctx))->cur_ffmpeg_ctx = c;
return ijkio_manager_io_close((IjkIOManagerContext *)(c->io_manager_ctx));
((IjkIOManagerContext *)(av_dict_strtoptr(c->io_manager_ctx_intptr)))->cur_ffmpeg_ctx = c;
return ijkio_manager_io_close((IjkIOManagerContext *)(av_dict_strtoptr(c->io_manager_ctx_intptr)));
}
#define OFFSET(x) offsetof(Context, x)
#define D AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
{ "ijkiomanager", "IjkIOManagerContext", OFFSET(io_manager_ctx), AV_OPT_TYPE_INT64, { .i64 = 0 }, INT64_MIN, INT64_MAX, .flags = D },
{ "ijkiomanager", "IjkIOManagerContext", OFFSET(io_manager_ctx_intptr), AV_OPT_TYPE_STRING, { .i64 = 0 }, 0, 0, .flags = D },
{ NULL }
};
#undef D
......
......@@ -45,7 +45,6 @@ typedef struct Context {
int segment_index;
int64_t test_fail_point;
int64_t test_fail_point_next;
int64_t app_ctx_intptr;
int abort_request;
AVApplicationContext *app_ctx;
IjkIOApplicationContext *ijkio_app_ctx;
......@@ -175,7 +174,7 @@ static int ijkio_urlhook_init(IjkURLContext *h, const char *arg, int flags, IjkA
if (options)
ijk_av_dict_copy(&c->inner_options, *options, 0);
ijk_av_dict_set_int(&c->inner_options, "ijkapplication", c->app_ctx_intptr, 0);
ijk_av_dict_set_intptr(&c->inner_options, "ijkapplication", (uintptr_t )c->app_ctx, 0);
ijk_av_dict_set_int(&c->inner_options, "ijkinject-segment-index", c->segment_index, 0);
c->app_io_ctrl.size = sizeof(c->app_io_ctrl);
......@@ -266,11 +265,9 @@ static int ijkio_httphook_open(IjkURLContext *h, const char *arg, int flags, Ijk
c->ijkio_app_ctx = h->ijkio_app_ctx;
c->ijkio_interrupt_callback = h->ijkio_app_ctx->ijkio_interrupt_callback;
t = ijk_av_dict_get(*options, "ijkapplication", NULL, IJK_AV_DICT_MATCH_CASE);
if (t) {
c->app_ctx_intptr = (int64_t)strtoll(t->value, NULL, 10);
c->app_ctx = (AVApplicationContext *)(intptr_t)c->app_ctx_intptr;
} else {
c->app_ctx = (AVApplicationContext *)ijk_av_dict_get_intptr(*options, "ijkapplication");
if (!c->app_ctx) {
goto fail;
}
......
......@@ -39,7 +39,7 @@ typedef struct {
/* options */
AVDictionary *open_opts;
int64_t app_ctx_intptr;
char * app_ctx_intptr;
AVApplicationContext *app_ctx;
} Context;
......@@ -191,7 +191,7 @@ static int ijklivehook_read_header(AVFormatContext *avf, AVDictionary **options)
const char *inner_url = NULL;
int ret = -1;
c->app_ctx = (AVApplicationContext *)(intptr_t)c->app_ctx_intptr;
c->app_ctx = (AVApplicationContext *)av_dict_strtoptr(c->app_ctx_intptr);
av_strstart(avf->filename, "ijklivehook:", &inner_url);
c->io_control.size = sizeof(c->io_control);
......@@ -292,7 +292,7 @@ fail:
#define D AV_OPT_FLAG_DECODING_PARAM
static const AVOption options[] = {
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_INT64, { .i64 = 0 }, INT64_MIN, INT64_MAX, .flags = D },
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, .flags = D },
{ NULL }
};
......
......@@ -34,14 +34,14 @@ typedef struct Context {
/* options */
char *http_hook;
int64_t app_ctx_intptr;
char * app_ctx_intptr;
} Context;
static int ijksegment_open(URLContext *h, const char *arg, int flags, AVDictionary **options)
{
Context *c = h->priv_data;
AVAppIOControl io_control = {0};
AVApplicationContext *app_ctx = (AVApplicationContext *)(intptr_t)c->app_ctx_intptr;
AVApplicationContext *app_ctx = (AVApplicationContext *)av_dict_strtoptr(c->app_ctx_intptr);
int ret = -1;
int segment_index = -1;
......@@ -65,7 +65,7 @@ static int ijksegment_open(URLContext *h, const char *arg, int flags, AVDictiona
goto fail;
}
av_dict_set_int(options, "ijkapplication", c->app_ctx_intptr, 0);
av_dict_set_intptr(options, "ijkapplication", (uintptr_t )app_ctx, 0);
av_dict_set_int(options, "ijkinject-segment-index", segment_index, 0);
ret = ffurl_open_whitelist(&c->inner,
......
......@@ -46,7 +46,7 @@ typedef struct Context {
int segment_index;
int64_t test_fail_point;
int64_t test_fail_point_next;
int64_t app_ctx_intptr;
char* app_ctx_intptr;
AVApplicationContext *app_ctx;
} Context;
......@@ -141,7 +141,7 @@ static int ijkurlhook_init(URLContext *h, const char *arg, int flags, AVDictiona
if (options)
av_dict_copy(&c->inner_options, *options, 0);
av_dict_set_int(&c->inner_options, "ijkapplication", c->app_ctx_intptr, 0);
av_dict_set_intptr(&c->inner_options, "ijkapplication", (uintptr_t )c->app_ctx, 0);
av_dict_set_int(&c->inner_options, "ijkinject-segment-index", c->segment_index, 0);
c->app_io_ctrl.size = sizeof(c->app_io_ctrl);
......@@ -162,7 +162,7 @@ static int ijktcphook_open(URLContext *h, const char *arg, int flags, AVDictiona
Context *c = h->priv_data;
int ret = 0;
c->app_ctx = (AVApplicationContext *)(intptr_t)c->app_ctx_intptr;
c->app_ctx = (AVApplicationContext *)av_dict_strtoptr(c->app_ctx_intptr);
c->scheme = "ijktcphook:";
c->inner_scheme = "tcp:";
ret = ijkurlhook_init(h, arg, flags, options);
......@@ -251,7 +251,7 @@ static int ijkhttphook_open(URLContext *h, const char *arg, int flags, AVDiction
Context *c = h->priv_data;
int ret = 0;
c->app_ctx = (AVApplicationContext *)(intptr_t)c->app_ctx_intptr;
c->app_ctx = (AVApplicationContext *)av_dict_strtoptr(c->app_ctx_intptr);
c->scheme = "ijkhttphook:";
if (av_stristart(arg, "ijkhttphook:https:", NULL))
c->inner_scheme = "https:";
......@@ -417,7 +417,7 @@ fail:
static const AVOption ijktcphook_options[] = {
{ "ijktcphook-test-fail-point", "test fail point, in bytes",
OFFSET(test_fail_point), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, D },
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_INT64, { .i64 = 0 }, INT64_MIN, INT64_MAX, .flags = D },
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, .flags = D },
{ NULL }
};
......@@ -427,8 +427,7 @@ static const AVOption ijkhttphook_options[] = {
OFFSET(segment_index), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, D },
{ "ijkhttphook-test-fail-point", "test fail point, in bytes",
OFFSET(test_fail_point), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, D },
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_INT64, { .i64 = 0 }, INT64_MIN, INT64_MAX, .flags = D },
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, .flags = D },
{ NULL }
};
......
......@@ -153,6 +153,35 @@ int ijk_av_dict_set_int(IjkAVDictionary **pm, const char *key, int64_t value,
return ijk_av_dict_set(pm, key, valuestr, flags);
}
int ijk_av_dict_set_intptr(IjkAVDictionary **pm, const char *key, uintptr_t value, int flags) {
char valuestr[22];
snprintf(valuestr, sizeof(valuestr), "%p", value);
flags &= ~IJK_AV_DICT_DONT_STRDUP_VAL;
return ijk_av_dict_set(pm, key, valuestr, flags);
}
uintptr_t ijk_av_dict_strtoptr(char * value) {
uintptr_t ptr = NULL;
char *next = NULL;
if(value[0] !='0' || (value[1]|0x20)!='x') {
return NULL;
}
ptr = strtoll(value, &next, 16);
if (next == value) {
return NULL;
}
return ptr;
}
uintptr_t ijk_av_dict_get_intptr(const IjkAVDictionary *m, const char* key) {
uintptr_t ptr = NULL;
IjkAVDictionaryEntry *t = NULL;
if ((t = av_dict_get(m, key, NULL, 0))) {
return ijk_av_dict_strtoptr(t->value);
}
return NULL;
}
void ijk_av_dict_free(IjkAVDictionary **pm)
{
IjkAVDictionary *m = *pm;
......
......@@ -103,6 +103,10 @@ int ijk_av_dict_set(IjkAVDictionary **pm, const char *key, const char *value, in
*/
int ijk_av_dict_set_int(IjkAVDictionary **pm, const char *key, int64_t value, int flags);
int ijk_av_dict_set_intptr(IjkAVDictionary **pm, const char *key, uintptr_t value, int flags);
uintptr_t ijk_av_dict_get_intptr(const IjkAVDictionary *m, const char* key);
/**
* Copy entries from one AVDictionary struct into another.
* @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册