deps/media-playback: Use a struct for media init data

Instead of using countless parameters for the media initialization data,
use a structure.
This commit is contained in:
jp9000
2018-02-15 13:32:35 -08:00
parent f0f0d2c8f6
commit dc0363d3e8
3 changed files with 48 additions and 48 deletions

View File

@@ -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;
}

View File

@@ -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);