summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-12-31 19:12:44 +0100
committerwm4 <wm4@nowhere>2014-12-31 19:12:44 +0100
commit65f2c6c71676e4359d313ecf27744e525b662134 (patch)
tree59c62ef844f7428306fbcf77113cabb1c58c3bcb /video/out
parent282e3202d52a84b868f6972532f10d97ee23c594 (diff)
downloadmpv-65f2c6c71676e4359d313ecf27744e525b662134.tar.bz2
mpv-65f2c6c71676e4359d313ecf27744e525b662134.tar.xz
vo_opengl_cb: pass context directly
This is simpler than setting the context after VO creation, which requires the code to check for the context on every entrypoint.
Diffstat (limited to 'video/out')
-rw-r--r--video/out/vo.h3
-rw-r--r--video/out/vo_opengl_cb.c98
2 files changed, 42 insertions, 59 deletions
diff --git a/video/out/vo.h b/video/out/vo.h
index 60982c9d65..3d4d654738 100644
--- a/video/out/vo.h
+++ b/video/out/vo.h
@@ -105,8 +105,6 @@ enum mp_voctrl {
VOCTRL_GET_RECENT_FLIP_TIME, // int64_t* (using mp_time_us())
VOCTRL_GET_PREF_DEINT, // int*
-
- VOCTRL_SET_LIBMPV_OPENGL_CB_CONTEXT,// struct mpv_opengl_cb_context*
};
// VOCTRL_SET_EQUALIZER
@@ -169,6 +167,7 @@ struct vo_extra {
struct input_ctx *input_ctx;
struct osd_state *osd;
struct encode_lavc_context *encode_lavc_ctx;
+ struct mpv_opengl_cb_context *opengl_cb_context;
};
struct vo_driver {
diff --git a/video/out/vo_opengl_cb.c b/video/out/vo_opengl_cb.c
index f431880ecb..d2d4221e94 100644
--- a/video/out/vo_opengl_cb.c
+++ b/video/out/vo_opengl_cb.c
@@ -236,26 +236,24 @@ int mpv_opengl_cb_render(struct mpv_opengl_cb_context *ctx, int fbo, int vp[4])
static void draw_image(struct vo *vo, mp_image_t *mpi)
{
struct vo_priv *p = vo->priv;
- if (p->ctx) {
- pthread_mutex_lock(&p->ctx->lock);
- mp_image_setrefp(&p->ctx->waiting_frame, mpi);
- pthread_mutex_unlock(&p->ctx->lock);
- }
+
+ pthread_mutex_lock(&p->ctx->lock);
+ mp_image_setrefp(&p->ctx->waiting_frame, mpi);
talloc_free(mpi);
+ pthread_mutex_unlock(&p->ctx->lock);
}
static void flip_page(struct vo *vo)
{
struct vo_priv *p = vo->priv;
- if (p->ctx) {
- pthread_mutex_lock(&p->ctx->lock);
- mp_image_unrefp(&p->ctx->next_frame);
- p->ctx->next_frame = p->ctx->waiting_frame;
- p->ctx->waiting_frame = NULL;
- if (p->ctx->update_cb)
- p->ctx->update_cb(p->ctx->update_cb_ctx);
- pthread_mutex_unlock(&p->ctx->lock);
- }
+
+ pthread_mutex_lock(&p->ctx->lock);
+ mp_image_unrefp(&p->ctx->next_frame);
+ p->ctx->next_frame = p->ctx->waiting_frame;
+ p->ctx->waiting_frame = NULL;
+ if (p->ctx->update_cb)
+ p->ctx->update_cb(p->ctx->update_cb_ctx);
+ pthread_mutex_unlock(&p->ctx->lock);
}
static int query_format(struct vo *vo, uint32_t format)
@@ -263,12 +261,10 @@ static int query_format(struct vo *vo, uint32_t format)
struct vo_priv *p = vo->priv;
bool ok = false;
- if (p->ctx) {
- pthread_mutex_lock(&p->ctx->lock);
- if (format >= IMGFMT_START && format < IMGFMT_END)
- ok = p->ctx->imgfmt_supported[format - IMGFMT_START];
- pthread_mutex_unlock(&p->ctx->lock);
- }
+ pthread_mutex_lock(&p->ctx->lock);
+ if (format >= IMGFMT_START && format < IMGFMT_END)
+ ok = p->ctx->imgfmt_supported[format - IMGFMT_START];
+ pthread_mutex_unlock(&p->ctx->lock);
return ok ? VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW : 0;
}
@@ -276,15 +272,11 @@ static int reconfig(struct vo *vo, struct mp_image_params *params, int flags)
{
struct vo_priv *p = vo->priv;
- if (p->ctx) {
- pthread_mutex_lock(&p->ctx->lock);
- mp_image_unrefp(&p->ctx->next_frame);
- p->ctx->img_params = *params;
- p->ctx->reconfigured = true;
- pthread_mutex_unlock(&p->ctx->lock);
- } else {
- return -1;
- }
+ pthread_mutex_lock(&p->ctx->lock);
+ mp_image_unrefp(&p->ctx->next_frame);
+ p->ctx->img_params = *params;
+ p->ctx->reconfigured = true;
+ pthread_mutex_unlock(&p->ctx->lock);
return 0;
}
@@ -294,25 +286,6 @@ static int control(struct vo *vo, uint32_t request, void *data)
struct vo_priv *p = vo->priv;
switch (request) {
- case VOCTRL_SET_LIBMPV_OPENGL_CB_CONTEXT: {
- if (p->ctx)
- return VO_FALSE;
- struct mpv_opengl_cb_context *nctx = data;
- if (nctx) {
- pthread_mutex_lock(&nctx->lock);
- if (nctx->active) {
- MP_FATAL(vo, "There is already a VO using the OpenGL context.\n");
- } else {
- nctx->active = vo;
- nctx->reconfigured = true;
- p->ctx = nctx;
- assert(vo->osd == p->ctx->osd);
- copy_vo_opts(vo);
- }
- pthread_mutex_unlock(&nctx->lock);
- }
- return VO_TRUE;
- }
case VOCTRL_GET_PANSCAN:
return VO_TRUE;
case VOCTRL_SET_PANSCAN:
@@ -341,21 +314,32 @@ static void uninit(struct vo *vo)
{
struct vo_priv *p = vo->priv;
- if (p->ctx) {
- pthread_mutex_lock(&p->ctx->lock);
- mp_image_unrefp(&p->ctx->next_frame);
- mp_image_unrefp(&p->ctx->waiting_frame);
- p->ctx->img_params = (struct mp_image_params){0};
- p->ctx->reconfigured = true;
- p->ctx->active = NULL;
- pthread_mutex_unlock(&p->ctx->lock);
- }
+ pthread_mutex_lock(&p->ctx->lock);
+ mp_image_unrefp(&p->ctx->next_frame);
+ mp_image_unrefp(&p->ctx->waiting_frame);
+ p->ctx->img_params = (struct mp_image_params){0};
+ p->ctx->reconfigured = true;
+ p->ctx->active = NULL;
+ pthread_mutex_unlock(&p->ctx->lock);
}
static int preinit(struct vo *vo)
{
struct vo_priv *p = vo->priv;
p->vo = vo;
+ p->ctx = vo->extra.opengl_cb_context;
+ if (!p->ctx) {
+ MP_FATAL(vo, "No context set.\n");
+ return -1;
+ }
+
+ pthread_mutex_lock(&p->ctx->lock);
+ p->ctx->active = vo;
+ p->ctx->reconfigured = true;
+ assert(vo->osd == p->ctx->osd);
+ copy_vo_opts(vo);
+ pthread_mutex_unlock(&p->ctx->lock);
+
return 0;
}