Skip to content

Commit e99d640

Browse files
author
zhenghanchao
committedFeb 7, 2021
ijkplayer: convert pointer to string instead of using av_dict_set_int
1 parent 86e8d33 commit e99d640

File tree

10 files changed

+79
-39
lines changed

10 files changed

+79
-39
lines changed
 

‎ijkmedia/ijkplayer/ff_ffplay.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4144,7 +4144,7 @@ void *ffp_set_ijkio_inject_opaque(FFPlayer *ffp, void *opaque)
41444144
ijkio_manager_destroyp(&ffp->ijkio_manager_ctx);
41454145
ijkio_manager_create(&ffp->ijkio_manager_ctx, ffp);
41464146
ijkio_manager_set_callback(ffp->ijkio_manager_ctx, ijkio_app_func_event);
4147-
ffp_set_option_int(ffp, FFP_OPT_CATEGORY_FORMAT, "ijkiomanager", (int64_t)(intptr_t)ffp->ijkio_manager_ctx);
4147+
ffp_set_option_intptr(ffp, FFP_OPT_CATEGORY_FORMAT, "ijkiomanager", (uintptr_t)ffp->ijkio_manager_ctx);
41484148

41494149
return prev_weak_thiz;
41504150
}
@@ -4158,7 +4158,7 @@ void *ffp_set_inject_opaque(FFPlayer *ffp, void *opaque)
41584158

41594159
av_application_closep(&ffp->app_ctx);
41604160
av_application_open(&ffp->app_ctx, ffp);
4161-
ffp_set_option_int(ffp, FFP_OPT_CATEGORY_FORMAT, "ijkapplication", (int64_t)(intptr_t)ffp->app_ctx);
4161+
ffp_set_option_intptr(ffp, FFP_OPT_CATEGORY_FORMAT, "ijkapplication", (uint64_t)(intptr_t)ffp->app_ctx);
41624162

41634163
ffp->app_ctx->func_on_app_event = app_func_event;
41644164
return prev_weak_thiz;
@@ -4182,6 +4182,15 @@ void ffp_set_option_int(FFPlayer *ffp, int opt_category, const char *name, int64
41824182
av_dict_set_int(dict, name, value, 0);
41834183
}
41844184

4185+
void ffp_set_option_intptr(FFPlayer *ffp, int opt_category, const char *name, uintptr_t value)
4186+
{
4187+
if (!ffp)
4188+
return;
4189+
4190+
AVDictionary **dict = ffp_get_opt_dict(ffp, opt_category);
4191+
av_dict_set_intptr(dict, name, value, 0);
4192+
}
4193+
41854194
void ffp_set_overlay_format(FFPlayer *ffp, int chroma_fourcc)
41864195
{
41874196
switch (chroma_fourcc) {

‎ijkmedia/ijkplayer/ff_ffplay.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void *ffp_set_inject_opaque(FFPlayer *ffp, void *opaque);
5151
void *ffp_set_ijkio_inject_opaque(FFPlayer *ffp, void *opaque);
5252
void ffp_set_option(FFPlayer *ffp, int opt_category, const char *name, const char *value);
5353
void ffp_set_option_int(FFPlayer *ffp, int opt_category, const char *name, int64_t value);
54+
void ffp_set_option_intptr(FFPlayer *ffp, int opt_category, const char *name, uintptr_t value);
5455

5556
int ffp_get_video_codec_info(FFPlayer *ffp, char **codec_info);
5657
int ffp_get_audio_codec_info(FFPlayer *ffp, char **codec_info);

‎ijkmedia/ijkplayer/ijkavformat/ijkasync.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ typedef struct Context {
8484
/* options */
8585
int64_t forwards_capacity;
8686
int64_t backwards_capacity;
87-
int64_t app_ctx_intptr;
87+
char * app_ctx_intptr;
8888
AVApplicationContext *app_ctx;
8989
} Context;
9090

@@ -308,8 +308,8 @@ static int async_open(URLContext *h, const char *arg, int flags, AVDictionary **
308308
goto fifo_fail;
309309

310310
if (c->app_ctx_intptr) {
311-
c->app_ctx = (AVApplicationContext *)(intptr_t)c->app_ctx_intptr;
312-
av_dict_set_int(options, "ijkapplication", c->app_ctx_intptr, 0);
311+
c->app_ctx = (AVApplicationContext *)av_dict_strtoptr(c->app_ctx_intptr);
312+
av_dict_set_intptr(options, "ijkapplication", (uintptr_t )c->app_ctx, 0);
313313
}
314314
/* wrap interrupt callback */
315315
c->interrupt_callback = h->interrupt_callback;
@@ -535,7 +535,7 @@ static const AVOption options[] = {
535535
OFFSET(forwards_capacity), AV_OPT_TYPE_INT64, {.i64 = 128 * 1024}, 128 * 1024, 128 * 1024 * 1024, D },
536536
{ "async-backwards-capacity", "max bytes that may be seek backward without seeking in inner protocol",
537537
OFFSET(backwards_capacity), AV_OPT_TYPE_INT64, {.i64 = 128 * 1024}, 128 * 1024, 128 * 1024 * 1024, D },
538-
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_INT64, { .i64 = 0 }, INT64_MIN, INT64_MAX, .flags = D },
538+
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_STRING, { .str = 0 }, 0, 0, .flags = D },
539539
{NULL},
540540
};
541541

‎ijkmedia/ijkplayer/ijkavformat/ijkio.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
typedef struct Context {
3333
AVClass *class;
34-
int64_t *io_manager_ctx;
34+
char *io_manager_ctx_intptr;
3535
} Context;
3636

3737
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 **
5151
Context *c = h->priv_data;
5252
int ret = -1;
5353

54-
if (!c || !c->io_manager_ctx)
54+
if (!c || !c->io_manager_ctx_intptr)
5555
return -1;
5656

57-
IjkIOManagerContext *manager_ctx = (IjkIOManagerContext *)(c->io_manager_ctx);
57+
IjkIOManagerContext *manager_ctx = (IjkIOManagerContext *)av_dict_strtoptr(c->io_manager_ctx_intptr);
5858
manager_ctx->ijkio_interrupt_callback = (IjkAVIOInterruptCB *)&(h->interrupt_callback);
5959

6060
av_strstart(arg, "ijkio:", &arg);
@@ -77,40 +77,41 @@ static int ijkio_read(URLContext *h, unsigned char *buf, int size)
7777
{
7878
Context *c = h->priv_data;
7979

80-
if (!c || !c->io_manager_ctx)
80+
if (!c || !c->io_manager_ctx_intptr)
8181
return -1;
8282

83-
((IjkIOManagerContext *)(c->io_manager_ctx))->cur_ffmpeg_ctx = c;
84-
return ijkio_manager_io_read((IjkIOManagerContext *)(c->io_manager_ctx), buf, size);
83+
((IjkIOManagerContext *)(av_dict_strtoptr(c->io_manager_ctx_intptr)))->cur_ffmpeg_ctx = c;
84+
return ijkio_manager_io_read((IjkIOManagerContext *)(av_dict_strtoptr(c->io_manager_ctx_intptr)), buf, size);
8585
}
8686

8787
static int64_t ijkio_seek(URLContext *h, int64_t offset, int whence)
8888
{
8989
Context *c = h->priv_data;
9090

91-
if (!c || !c->io_manager_ctx)
91+
if (!c || !c->io_manager_ctx_intptr)
9292
return -1;
9393

94-
((IjkIOManagerContext *)(c->io_manager_ctx))->cur_ffmpeg_ctx = c;
95-
return ijkio_manager_io_seek((IjkIOManagerContext *)(c->io_manager_ctx), offset, whence);
94+
((IjkIOManagerContext *)(av_dict_strtoptr(c->io_manager_ctx_intptr)))->cur_ffmpeg_ctx = c;
95+
return ijkio_manager_io_seek((IjkIOManagerContext *)(av_dict_strtoptr(c->io_manager_ctx_intptr)), offset, whence);
9696
}
9797

9898
static int ijkio_close(URLContext *h)
9999
{
100100
Context *c = h->priv_data;
101101

102-
if (!c || !c->io_manager_ctx)
102+
if (!c || !c->io_manager_ctx_intptr)
103103
return -1;
104104

105-
((IjkIOManagerContext *)(c->io_manager_ctx))->cur_ffmpeg_ctx = c;
106-
return ijkio_manager_io_close((IjkIOManagerContext *)(c->io_manager_ctx));
105+
((IjkIOManagerContext *)(av_dict_strtoptr(c->io_manager_ctx_intptr)))->cur_ffmpeg_ctx = c;
106+
return ijkio_manager_io_close((IjkIOManagerContext *)(av_dict_strtoptr(c->io_manager_ctx_intptr)));
107107
}
108108

109109
#define OFFSET(x) offsetof(Context, x)
110110
#define D AV_OPT_FLAG_DECODING_PARAM
111111

112112
static const AVOption options[] = {
113-
{ "ijkiomanager", "IjkIOManagerContext", OFFSET(io_manager_ctx), AV_OPT_TYPE_INT64, { .i64 = 0 }, INT64_MIN, INT64_MAX, .flags = D },
113+
{ "ijkiomanager", "IjkIOManagerContext", OFFSET(io_manager_ctx_intptr), AV_OPT_TYPE_STRING, { .i64 = 0 }, 0, 0, .flags = D },
114+
{ NULL }
114115
};
115116

116117
#undef D

‎ijkmedia/ijkplayer/ijkavformat/ijkiourlhook.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ typedef struct Context {
4545
int segment_index;
4646
int64_t test_fail_point;
4747
int64_t test_fail_point_next;
48-
int64_t app_ctx_intptr;
4948
int abort_request;
5049
AVApplicationContext *app_ctx;
5150
IjkIOApplicationContext *ijkio_app_ctx;
@@ -175,7 +174,7 @@ static int ijkio_urlhook_init(IjkURLContext *h, const char *arg, int flags, IjkA
175174
if (options)
176175
ijk_av_dict_copy(&c->inner_options, *options, 0);
177176

178-
ijk_av_dict_set_int(&c->inner_options, "ijkapplication", c->app_ctx_intptr, 0);
177+
ijk_av_dict_set_intptr(&c->inner_options, "ijkapplication", (uintptr_t )c->app_ctx, 0);
179178
ijk_av_dict_set_int(&c->inner_options, "ijkinject-segment-index", c->segment_index, 0);
180179

181180
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
266265
c->ijkio_app_ctx = h->ijkio_app_ctx;
267266
c->ijkio_interrupt_callback = h->ijkio_app_ctx->ijkio_interrupt_callback;
268267

269-
t = ijk_av_dict_get(*options, "ijkapplication", NULL, IJK_AV_DICT_MATCH_CASE);
270-
if (t) {
271-
c->app_ctx_intptr = (int64_t)strtoll(t->value, NULL, 10);
272-
c->app_ctx = (AVApplicationContext *)(intptr_t)c->app_ctx_intptr;
273-
} else {
268+
c->app_ctx = (AVApplicationContext *)ijk_av_dict_get_intptr(*options, "ijkapplication");
269+
270+
if (!c->app_ctx) {
274271
goto fail;
275272
}
276273

‎ijkmedia/ijkplayer/ijkavformat/ijklivehook.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ typedef struct {
3939

4040
/* options */
4141
AVDictionary *open_opts;
42-
int64_t app_ctx_intptr;
42+
char * app_ctx_intptr;
4343
AVApplicationContext *app_ctx;
4444
} Context;
4545

@@ -191,7 +191,7 @@ static int ijklivehook_read_header(AVFormatContext *avf, AVDictionary **options)
191191
const char *inner_url = NULL;
192192
int ret = -1;
193193

194-
c->app_ctx = (AVApplicationContext *)(intptr_t)c->app_ctx_intptr;
194+
c->app_ctx = (AVApplicationContext *)av_dict_strtoptr(c->app_ctx_intptr);
195195
av_strstart(avf->filename, "ijklivehook:", &inner_url);
196196

197197
c->io_control.size = sizeof(c->io_control);
@@ -292,7 +292,7 @@ static int ijklivehook_read_packet(AVFormatContext *avf, AVPacket *pkt)
292292
#define D AV_OPT_FLAG_DECODING_PARAM
293293

294294
static const AVOption options[] = {
295-
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_INT64, { .i64 = 0 }, INT64_MIN, INT64_MAX, .flags = D },
295+
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, .flags = D },
296296
{ NULL }
297297
};
298298

‎ijkmedia/ijkplayer/ijkavformat/ijksegment.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ typedef struct Context {
3434

3535
/* options */
3636
char *http_hook;
37-
int64_t app_ctx_intptr;
37+
char * app_ctx_intptr;
3838
} Context;
3939

4040
static int ijksegment_open(URLContext *h, const char *arg, int flags, AVDictionary **options)
4141
{
4242
Context *c = h->priv_data;
4343
AVAppIOControl io_control = {0};
44-
AVApplicationContext *app_ctx = (AVApplicationContext *)(intptr_t)c->app_ctx_intptr;
44+
AVApplicationContext *app_ctx = (AVApplicationContext *)av_dict_strtoptr(c->app_ctx_intptr);
4545
int ret = -1;
4646
int segment_index = -1;
4747

@@ -65,7 +65,7 @@ static int ijksegment_open(URLContext *h, const char *arg, int flags, AVDictiona
6565
goto fail;
6666
}
6767

68-
av_dict_set_int(options, "ijkapplication", c->app_ctx_intptr, 0);
68+
av_dict_set_intptr(options, "ijkapplication", (uintptr_t )app_ctx, 0);
6969
av_dict_set_int(options, "ijkinject-segment-index", segment_index, 0);
7070

7171
ret = ffurl_open_whitelist(&c->inner,

‎ijkmedia/ijkplayer/ijkavformat/ijkurlhook.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef struct Context {
4646
int segment_index;
4747
int64_t test_fail_point;
4848
int64_t test_fail_point_next;
49-
int64_t app_ctx_intptr;
49+
char* app_ctx_intptr;
5050
AVApplicationContext *app_ctx;
5151
} Context;
5252

@@ -141,7 +141,7 @@ static int ijkurlhook_init(URLContext *h, const char *arg, int flags, AVDictiona
141141
if (options)
142142
av_dict_copy(&c->inner_options, *options, 0);
143143

144-
av_dict_set_int(&c->inner_options, "ijkapplication", c->app_ctx_intptr, 0);
144+
av_dict_set_intptr(&c->inner_options, "ijkapplication", (uintptr_t )c->app_ctx, 0);
145145
av_dict_set_int(&c->inner_options, "ijkinject-segment-index", c->segment_index, 0);
146146

147147
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
162162
Context *c = h->priv_data;
163163
int ret = 0;
164164

165-
c->app_ctx = (AVApplicationContext *)(intptr_t)c->app_ctx_intptr;
165+
c->app_ctx = (AVApplicationContext *)av_dict_strtoptr(c->app_ctx_intptr);
166166
c->scheme = "ijktcphook:";
167167
c->inner_scheme = "tcp:";
168168
ret = ijkurlhook_init(h, arg, flags, options);
@@ -251,7 +251,7 @@ static int ijkhttphook_open(URLContext *h, const char *arg, int flags, AVDiction
251251
Context *c = h->priv_data;
252252
int ret = 0;
253253

254-
c->app_ctx = (AVApplicationContext *)(intptr_t)c->app_ctx_intptr;
254+
c->app_ctx = (AVApplicationContext *)av_dict_strtoptr(c->app_ctx_intptr);
255255
c->scheme = "ijkhttphook:";
256256
if (av_stristart(arg, "ijkhttphook:https:", NULL))
257257
c->inner_scheme = "https:";
@@ -417,7 +417,7 @@ static int64_t ijkhttphook_seek(URLContext *h, int64_t pos, int whence)
417417
static const AVOption ijktcphook_options[] = {
418418
{ "ijktcphook-test-fail-point", "test fail point, in bytes",
419419
OFFSET(test_fail_point), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, D },
420-
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_INT64, { .i64 = 0 }, INT64_MIN, INT64_MAX, .flags = D },
420+
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, .flags = D },
421421

422422
{ NULL }
423423
};
@@ -427,8 +427,7 @@ static const AVOption ijkhttphook_options[] = {
427427
OFFSET(segment_index), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, D },
428428
{ "ijkhttphook-test-fail-point", "test fail point, in bytes",
429429
OFFSET(test_fail_point), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, D },
430-
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_INT64, { .i64 = 0 }, INT64_MIN, INT64_MAX, .flags = D },
431-
430+
{ "ijkapplication", "AVApplicationContext", OFFSET(app_ctx_intptr), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, .flags = D },
432431
{ NULL }
433432
};
434433

‎ijkmedia/ijkplayer/ijkavutil/ijkdict.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,35 @@ int ijk_av_dict_set_int(IjkAVDictionary **pm, const char *key, int64_t value,
153153
return ijk_av_dict_set(pm, key, valuestr, flags);
154154
}
155155

156+
int ijk_av_dict_set_intptr(IjkAVDictionary **pm, const char *key, uintptr_t value, int flags) {
157+
char valuestr[22];
158+
snprintf(valuestr, sizeof(valuestr), "%p", value);
159+
flags &= ~IJK_AV_DICT_DONT_STRDUP_VAL;
160+
return ijk_av_dict_set(pm, key, valuestr, flags);
161+
}
162+
163+
uintptr_t ijk_av_dict_strtoptr(char * value) {
164+
uintptr_t ptr = NULL;
165+
char *next = NULL;
166+
if(value[0] !='0' || (value[1]|0x20)!='x') {
167+
return NULL;
168+
}
169+
ptr = strtoll(value, &next, 16);
170+
if (next == value) {
171+
return NULL;
172+
}
173+
return ptr;
174+
}
175+
176+
uintptr_t ijk_av_dict_get_intptr(const IjkAVDictionary *m, const char* key) {
177+
uintptr_t ptr = NULL;
178+
IjkAVDictionaryEntry *t = NULL;
179+
if ((t = av_dict_get(m, key, NULL, 0))) {
180+
return ijk_av_dict_strtoptr(t->value);
181+
}
182+
return NULL;
183+
}
184+
156185
void ijk_av_dict_free(IjkAVDictionary **pm)
157186
{
158187
IjkAVDictionary *m = *pm;

‎ijkmedia/ijkplayer/ijkavutil/ijkdict.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ int ijk_av_dict_set(IjkAVDictionary **pm, const char *key, const char *value, in
103103
*/
104104
int ijk_av_dict_set_int(IjkAVDictionary **pm, const char *key, int64_t value, int flags);
105105

106+
int ijk_av_dict_set_intptr(IjkAVDictionary **pm, const char *key, uintptr_t value, int flags);
107+
108+
uintptr_t ijk_av_dict_get_intptr(const IjkAVDictionary *m, const char* key);
109+
106110
/**
107111
* Copy entries from one AVDictionary struct into another.
108112
* @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL,

0 commit comments

Comments
 (0)