From 02add991fbee7d2e00317cc39c1d05d475a55fc0 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 1 May 2012 14:50:16 +0200 Subject: vo_corevideo, vo_sharedbuffer: put private state in vo->priv These VOs were already using a struct for all private data but the struct variable itself was static. Change them to store the address in vo->priv. Also change them to use the new automatic private data allocation and option parsing mechanism. --- libvo/vo_corevideo.m | 54 +++++++++++++------------ libvo/vo_sharedbuffer.m | 104 ++++++++++++++++++++++-------------------------- 2 files changed, 77 insertions(+), 81 deletions(-) diff --git a/libvo/vo_corevideo.m b/libvo/vo_corevideo.m index 57e93a9326..4c69426e4d 100644 --- a/libvo/vo_corevideo.m +++ b/libvo/vo_corevideo.m @@ -69,10 +69,9 @@ struct priv { struct osd_p *osd; }; -static struct priv *p; - static void resize(struct vo *vo, int width, int height) { + struct priv *p = vo->priv; GL *gl = p->mpglctx->gl; p->image_width = width; p->image_height = height; @@ -110,6 +109,7 @@ static void resize(struct vo *vo, int width, int height) static int init_gl(struct vo *vo, uint32_t d_width, uint32_t d_height) { + struct priv *p = vo->priv; GL *gl = p->mpglctx->gl; const char *vendor = gl->GetString(GL_VENDOR); @@ -136,7 +136,8 @@ static int init_gl(struct vo *vo, uint32_t d_width, uint32_t d_height) return 1; } -static void release_cv_entities(void) { +static void release_cv_entities(struct vo *vo) { + struct priv *p = vo->priv; CVPixelBufferRelease(p->pixelBuffer); p->pixelBuffer = NULL; CVOpenGLTextureRelease(p->texture); @@ -150,7 +151,8 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, uint32_t format) { - release_cv_entities(); + struct priv *p = vo->priv; + release_cv_entities(vo); p->image_width = width; p->image_height = height; @@ -166,6 +168,7 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, static void check_events(struct vo *vo) { + struct priv *p = vo->priv; int e = p->mpglctx->check_events(vo); if (e & VO_EVENT_RESIZE) resize(vo, vo->dwidth, vo->dheight); @@ -175,6 +178,7 @@ static void create_osd_texture(void *ctx, int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) { + struct priv *p = ((struct vo *) ctx)->priv; struct osd_p *osd = p->osd; GL *gl = p->mpglctx->gl; @@ -214,6 +218,7 @@ static void create_osd_texture(void *ctx, int x0, int y0, int w, int h, static void clearOSD(struct vo *vo) { + struct priv *p = vo->priv; struct osd_p *osd = p->osd; GL *gl = p->mpglctx->gl; @@ -225,6 +230,7 @@ static void clearOSD(struct vo *vo) static void draw_osd(struct vo *vo, struct osd_state *osd_s) { + struct priv *p = vo->priv; struct osd_p *osd = p->osd; GL *gl = p->mpglctx->gl; @@ -252,10 +258,11 @@ static void draw_osd(struct vo *vo, struct osd_state *osd_s) } } -static void prepare_texture(void) +static void prepare_texture(struct vo *vo) { - CVReturn error; + struct priv *p = vo->priv; struct quad *q = p->quad; + CVReturn error; CVOpenGLTextureRelease(p->texture); error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, @@ -270,9 +277,10 @@ static void prepare_texture(void) static void do_render(struct vo *vo) { + struct priv *p = vo->priv; struct quad *q = p->quad; GL *gl = p->mpglctx->gl; - prepare_texture(); + prepare_texture(vo); float x0 = 0; float y0 = 0; @@ -303,12 +311,14 @@ static void do_render(struct vo *vo) static void flip_page(struct vo *vo) { + struct priv *p = vo->priv; p->mpglctx->swapGlBuffers(p->mpglctx); p->mpglctx->gl->Clear(GL_COLOR_BUFFER_BIT); } static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) { + struct priv *p = vo->priv; CVReturn error; if (!p->textureCache || !p->pixelBuffer) { @@ -330,8 +340,9 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) return VO_TRUE; } -static int query_format(uint32_t format) +static int query_format(struct vo *vo, uint32_t format) { + struct priv *p = vo->priv; const int flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VOCAP_NOSLICES; @@ -357,27 +368,16 @@ static int query_format(uint32_t format) static void uninit(struct vo *vo) { + struct priv *p = vo->priv; uninit_mpglcontext(p->mpglctx); - release_cv_entities(); - talloc_free(p); + release_cv_entities(vo); } static int preinit(struct vo *vo, const char *arg) { - const opt_t subopts[] = { - {NULL} - }; - - if (subopt_parse(arg, subopts) != 0) { - mp_msg(MSGT_VO, MSGL_FATAL, - "\n-vo corevideo command line help:\n" - "Example: mplayer -vo corevideo\n" - "\n" ); - return -1; - } + struct priv *p = vo->priv; - p = talloc_ptrtype(NULL, p); *p = (struct priv) { .mpglctx = init_mpglcontext(GLTYPE_COCOA, vo), .colorspace = MP_CSP_DETAILS_DEFAULTS, @@ -392,8 +392,9 @@ static int preinit(struct vo *vo, const char *arg) return 0; } -static CFStringRef get_cv_csp_matrix(void) +static CFStringRef get_cv_csp_matrix(struct vo *vo) { + struct priv *p = vo->priv; switch (p->colorspace.format) { case MP_CSP_BT_601: return kCVImageBufferYCbCrMatrix_ITU_R_601_4; @@ -407,19 +408,21 @@ static CFStringRef get_cv_csp_matrix(void) static void set_yuv_colorspace(struct vo *vo) { + struct priv *p = vo->priv; CVBufferSetAttachment(p->pixelBuffer, - kCVImageBufferYCbCrMatrixKey, get_cv_csp_matrix(), + kCVImageBufferYCbCrMatrixKey, get_cv_csp_matrix(vo), kCVAttachmentMode_ShouldPropagate); vo->want_redraw = true; } static int control(struct vo *vo, uint32_t request, void *data) { + struct priv *p = vo->priv; switch (request) { case VOCTRL_DRAW_IMAGE: return draw_image(vo, data); case VOCTRL_QUERY_FORMAT: - return query_format(*(uint32_t*)data); + return query_format(vo, *(uint32_t*)data); case VOCTRL_ONTOP: p->mpglctx->ontop(vo); return VO_TRUE; @@ -464,4 +467,5 @@ const struct vo_driver video_out_corevideo = { .flip_page = flip_page, .check_events = check_events, .uninit = uninit, + .privsize = sizeof(struct priv), }; diff --git a/libvo/vo_sharedbuffer.m b/libvo/vo_sharedbuffer.m index 0b811f1848..40aa170864 100644 --- a/libvo/vo_sharedbuffer.m +++ b/libvo/vo_sharedbuffer.m @@ -18,7 +18,7 @@ */ /* - * This video output was extracted from mplayer's corevideo. It's purpose it + * This video output was extracted from mplayer's corevideo. Its purpose is * to copy mp_image data to a shared buffer using mmap and to do simple * coordination with the GUIs using Distributed Objects. */ @@ -27,7 +27,7 @@ #include "vo_sharedbuffer.h" #include "video_out.h" -#include "subopt-helper.h" +#include "m_option.h" #include "talloc.h" #include "libmpcodecs/vfcap.h" @@ -53,52 +53,30 @@ struct priv { id mposx_proto; }; -struct priv *p; - // implementation static void draw_alpha(void *ctx, int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) { + struct priv *p = ((struct vo *) ctx)->priv; p->vo_draw_alpha_fnc(w, h, src, srca, stride, p->image_data + (x0 + y0 * p->image_width) * p->image_bytespp, p->image_width * p->image_bytespp); } -static unsigned int image_bytes() +static unsigned int image_bytes(struct priv *p) { return p->image_width * p->image_height * p->image_bytespp; } static int preinit(struct vo *vo, const char *arg) { - p = talloc_zero(NULL, struct priv); - - const opt_t subopts[] = { - {"buffer_name", OPT_ARG_MSTRZ, &p->buffer_name, NULL}, - {NULL} - }; - - if (subopt_parse(arg, subopts) != 0) { - mp_msg(MSGT_VO, MSGL_FATAL, - "\n-vo sharedbuffer command line help:\n" - "Example: mplayer -vo shared_buffer:buffer_name=mybuff\n" - "\nOptions:\n" - " buffer_name=\n" - " Name of the shared buffer created with shm_open() as well as\n" - " the name of the NSConnection mplayer2 will try to open.\n" - "Example: mplayer -vo sharedbuffer\n" - "\n" ); - return -1; - } - - if (!p->buffer_name) p->buffer_name = "mplayerosx"; - return 0; } static void flip_page(struct vo *vo) { + struct priv *p = vo->priv; NSAutoreleasePool *pool = [NSAutoreleasePool new]; [p->mposx_proto render]; [pool release]; @@ -108,6 +86,7 @@ static void check_events(struct vo *vo) { } static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) { + struct priv *p = vo->priv; memcpy_pic(p->image_data, mpi->planes[0], (p->image_width) * (p->image_bytespp), p->image_height, (p->image_width) * (p->image_bytespp), mpi->stride[0]); @@ -115,10 +94,11 @@ static uint32_t draw_image(struct vo *vo, mp_image_t *mpi) } static void draw_osd(struct vo *vo, struct osd_state *osd) { + struct priv *p = vo->priv; osd_draw_text(osd, p->image_width, p->image_height, draw_alpha, vo); } -static void free_buffers(void) +static void free_buffers(struct priv *p) { [p->mposx_proto stop]; p->mposx_proto = nil; @@ -126,7 +106,7 @@ static void free_buffers(void) p->mposx_proxy = nil; if (p->image_data) { - if (munmap(p->image_data, image_bytes()) == -1) + if (munmap(p->image_data, image_bytes(p)) == -1) mp_msg(MSGT_VO, MSGL_FATAL, "[vo_sharedbuffer] uninit: munmap " "failed. Error: %s\n", strerror(errno)); @@ -140,8 +120,9 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, uint32_t format) { + struct priv *p = vo->priv; NSAutoreleasePool *pool = [NSAutoreleasePool new]; - free_buffers(); + free_buffers(p); p->image_width = width; p->image_height = height; @@ -158,7 +139,7 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, goto err_out; } - if (ftruncate(shm_fd, image_bytes()) == -1) { + if (ftruncate(shm_fd, image_bytes(p)) == -1) { mp_msg(MSGT_VO, MSGL_FATAL, "[vo_sharedbuffer] failed to size shared memory, possibly " "already in use. Error: %s\n", strerror(errno)); @@ -167,7 +148,7 @@ static int config(struct vo *vo, uint32_t width, uint32_t height, goto err_out; } - p->image_data = mmap(NULL, image_bytes(), + p->image_data = mmap(NULL, image_bytes(p), PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); close(shm_fd); @@ -207,28 +188,29 @@ err_out: return 1; } -static int query_format(uint32_t format) +static int query_format(struct vo *vo, uint32_t format) { - unsigned int image_depth = 0; - switch (format) { - case IMGFMT_YUY2: - p->vo_draw_alpha_fnc = vo_draw_alpha_yuy2; - image_depth = 16; - goto supported; - case IMGFMT_RGB24: - p->vo_draw_alpha_fnc = vo_draw_alpha_rgb24; - image_depth = 24; - goto supported; - case IMGFMT_ARGB: - p->vo_draw_alpha_fnc = vo_draw_alpha_rgb32; - image_depth = 32; - goto supported; - case IMGFMT_BGRA: - p->vo_draw_alpha_fnc = vo_draw_alpha_rgb32; - image_depth = 32; - goto supported; - } - return 0; + struct priv *p = vo->priv; + unsigned int image_depth = 0; + switch (format) { + case IMGFMT_YUY2: + p->vo_draw_alpha_fnc = vo_draw_alpha_yuy2; + image_depth = 16; + goto supported; + case IMGFMT_RGB24: + p->vo_draw_alpha_fnc = vo_draw_alpha_rgb24; + image_depth = 24; + goto supported; + case IMGFMT_ARGB: + p->vo_draw_alpha_fnc = vo_draw_alpha_rgb32; + image_depth = 32; + goto supported; + case IMGFMT_BGRA: + p->vo_draw_alpha_fnc = vo_draw_alpha_rgb32; + image_depth = 32; + goto supported; + } + return 0; supported: p->image_bytespp = (image_depth + 7) / 8; @@ -239,11 +221,13 @@ supported: static void uninit(struct vo *vo) { - free_buffers(); + struct priv *p = vo->priv; + free_buffers(p); } static int control(struct vo *vo, uint32_t request, void *data) { + struct priv *p = vo->priv; switch (request) { case VOCTRL_DRAW_IMAGE: return draw_image(vo, data); @@ -251,7 +235,7 @@ static int control(struct vo *vo, uint32_t request, void *data) [p->mposx_proto toggleFullscreen]; return VO_TRUE; case VOCTRL_QUERY_FORMAT: - return query_format(*(uint32_t*)data); + return query_format(vo, *(uint32_t*)data); case VOCTRL_ONTOP: [p->mposx_proto ontop]; return VO_TRUE; @@ -259,6 +243,9 @@ static int control(struct vo *vo, uint32_t request, void *data) return VO_NOTIMPL; } +#undef OPT_BASE_STRUCT +#define OPT_BASE_STRUCT struct priv + const struct vo_driver video_out_sharedbuffer = { .is_new = true, .info = &(const vo_info_t) { @@ -273,5 +260,10 @@ const struct vo_driver video_out_sharedbuffer = { .flip_page = flip_page, .check_events = check_events, .uninit = uninit, - .draw_osd = draw_osd + .draw_osd = draw_osd, + .privsize = sizeof(struct priv), + .options = (const struct m_option[]) { + OPT_STRING("buffer_name", buffer_name, 0, OPTDEF_STR("mplayerosx")), + {NULL}, + }, }; -- cgit v1.2.3