From dc0363d3e8ea9cecb0113b5efb52a2cdb66b05fa Mon Sep 17 00:00:00 2001 From: jp9000 Date: Thu, 15 Feb 2018 13:32:35 -0800 Subject: [PATCH] deps/media-playback: Use a struct for media init data Instead of using countless parameters for the media initialization data, use a structure. --- deps/media-playback/media-playback/media.c | 41 ++++++++-------------- deps/media-playback/media-playback/media.h | 29 ++++++++------- plugins/obs-ffmpeg/obs-ffmpeg-source.c | 26 +++++++++----- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/deps/media-playback/media-playback/media.c b/deps/media-playback/media-playback/media.c index e2e0b046d..49a1c8f77 100644 --- a/deps/media-playback/media-playback/media.c +++ b/deps/media-playback/media-playback/media.c @@ -652,9 +652,7 @@ static void *mp_media_thread_start(void *opaque) } static inline bool mp_media_init_internal(mp_media_t *m, - const char *path, - const char *format_name, - bool hw) + const struct mp_media_info *info) { if (pthread_mutex_init(&m->mutex, NULL) != 0) { blog(LOG_WARNING, "MP: Failed to init mutex"); @@ -665,9 +663,9 @@ static inline bool mp_media_init_internal(mp_media_t *m, return false; } - m->path = path ? bstrdup(path) : NULL; - m->format_name = format_name ? bstrdup(format_name) : NULL; - m->hw = hw; + m->path = info->path ? bstrdup(info->path) : NULL; + m->format_name = info->format ? bstrdup(info->format) : NULL; + m->hw = info->hardware_decoding; if (pthread_create(&m->thread, NULL, mp_media_thread_start, m) != 0) { blog(LOG_WARNING, "MP: Could not create media thread"); @@ -678,29 +676,18 @@ static inline bool mp_media_init_internal(mp_media_t *m, return true; } -bool mp_media_init(mp_media_t *media, - const char *path, - const char *format, - int buffering, - void *opaque, - mp_video_cb v_cb, - mp_audio_cb a_cb, - mp_stop_cb stop_cb, - mp_video_cb v_preload_cb, - bool hw_decoding, - bool is_local_file, - enum video_range_type force_range) +bool mp_media_init(mp_media_t *media, const struct mp_media_info *info) { memset(media, 0, sizeof(*media)); pthread_mutex_init_value(&media->mutex); - media->opaque = opaque; - media->v_cb = v_cb; - media->a_cb = a_cb; - media->stop_cb = stop_cb; - media->v_preload_cb = v_preload_cb; - media->force_range = force_range; - media->buffering = buffering; - media->is_local_file = is_local_file; + media->opaque = info->opaque; + media->v_cb = info->v_cb; + media->a_cb = info->a_cb; + media->stop_cb = info->stop_cb; + media->v_preload_cb = info->v_preload_cb; + media->force_range = info->force_range; + media->buffering = info->buffering; + media->is_local_file = info->is_local_file; static bool initialized = false; if (!initialized) { @@ -714,7 +701,7 @@ bool mp_media_init(mp_media_t *media, if (!base_sys_ts) base_sys_ts = (int64_t)os_gettime_ns(); - if (!mp_media_init_internal(media, path, format, hw_decoding)) { + if (!mp_media_init_internal(media, info)) { mp_media_free(media); return false; } diff --git a/deps/media-playback/media-playback/media.h b/deps/media-playback/media-playback/media.h index d72c9820a..65346670a 100644 --- a/deps/media-playback/media-playback/media.h +++ b/deps/media-playback/media-playback/media.h @@ -96,18 +96,23 @@ struct mp_media { typedef struct mp_media mp_media_t; -extern bool mp_media_init(mp_media_t *media, - const char *path, - const char *format, - int buffering, - void *opaque, - mp_video_cb v_cb, - mp_audio_cb a_cb, - mp_stop_cb stop_cb, - mp_video_cb v_preload_cb, - bool hardware_decoding, - bool is_local_file, - enum video_range_type force_range); +struct mp_media_info { + void *opaque; + + mp_video_cb v_cb; + mp_video_cb v_preload_cb; + mp_audio_cb a_cb; + mp_stop_cb stop_cb; + + const char *path; + const char *format; + int buffering; + enum video_range_type force_range; + bool hardware_decoding; + bool is_local_file; +}; + +extern bool mp_media_init(mp_media_t *media, const struct mp_media_info *info); extern void mp_media_free(mp_media_t *media); extern void mp_media_play(mp_media_t *media, bool loop); diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-source.c b/plugins/obs-ffmpeg/obs-ffmpeg-source.c index da2a99288..46b5eeb3d 100644 --- a/plugins/obs-ffmpeg/obs-ffmpeg-source.c +++ b/plugins/obs-ffmpeg/obs-ffmpeg-source.c @@ -241,15 +241,23 @@ static void media_stopped(void *opaque) static void ffmpeg_source_open(struct ffmpeg_source *s) { - if (s->input && *s->input) - s->media_valid = mp_media_init(&s->media, - s->input, s->input_format, - s->buffering_mb * 1024 * 1024, - s, get_frame, get_audio, media_stopped, - preload_frame, - s->is_hw_decoding, - s->is_local_file || s->seekable, - s->range); + if (s->input && *s->input) { + struct mp_media_info info = { + .opaque = s, + .v_cb = get_frame, + .v_preload_cb = preload_frame, + .a_cb = get_audio, + .stop_cb = media_stopped, + .path = s->input, + .format = s->input_format, + .buffering = s->buffering_mb * 1024 * 1024, + .force_range = s->range, + .hardware_decoding = s->is_hw_decoding, + .is_local_file = s->is_local_file || s->seekable + }; + + s->media_valid = mp_media_init(&s->media, &info); + } } static void ffmpeg_source_tick(void *data, float seconds)