/* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <assert.h>
#include "common/common.h"
#include "common/msg.h"
#include "common/msg_control.h"
#include "input/input.h"
#include "input/cmd_list.h"
#include "misc/ctype.h"
#include "misc/dispatch.h"
#include "options/m_config.h"
#include "options/m_option.h"
#include "options/m_property.h"
#include "options/path.h"
#include "options/parse_configfile.h"
#include "osdep/threads.h"
#include "osdep/timer.h"
#include "osdep/io.h"
#include "stream/stream.h"
#include "command.h"
#include "core.h"
#include "client.h"
#include "config.h"
/*
* Locking hierarchy:
*
* MPContext > mp_client_api.lock > mpv_handle.lock > * > mpv_handle.wakeup_lock
*
* MPContext strictly speaking has no locks, and instead is implicitly managed
* by MPContext.dispatch, which basically stops the playback thread at defined
* points in order to let clients access it in a synchronized manner. Since
* MPContext code accesses the client API, it's on top of the lock hierarchy.
*
*/
struct mp_client_api {
struct MPContext *mpctx;
pthread_mutex_t lock;
// -- protected by lock
struct mpv_handle **clients;
int num_clients;
uint64_t event_masks; // combined events of all clients, or 0 if unknown
};
struct observe_property {
char *name;
int id; // ==mp_get_property_id(name)
uint64_t event_mask; // ==mp_get_property_event_mask(name)
int64_t reply_id;
mpv_format format;
bool changed; // property change should be signaled to user
bool need_new_value; // a new value should be retrieved
bool updating; // a new value is being retrieved
bool dead; // property unobserved while retrieving value
bool new_value_valid, user_value_valid;
union m_option_value new_value, user_value;
struct mpv_handle *client;
};
struct mpv_handle {
// -- immmutable
char name[MAX_CLIENT_NAME];
bool owner;
struct mp_log *log;
struct MPContext *mpctx;
struct mp_client_api *clients;
// -- not thread-safe
struct mpv_event *cur_event;
struct mpv_event_property cur_property_event;
pthread_mutex_t lock;
pthread_mutex_t wakeup_lock;
pthread_cond_t wakeup;
// -- protected by wakeup_lock
bool need_wakeup;
void (*wakeup_cb)(void *d);
void *wakeup_cb_ctx;
int wakeup_pipe[2];
// -- protected by lock
uint64_t event_mask;
bool queued_wakeup;
bool choke_warning;
mpv_event *events; // ringbuffer of max_even
|