2009-02-08 03:27:30 +00:00
|
|
|
/*
|
2009-05-04 16:55:05 +00:00
|
|
|
* CoreVideo video output driver
|
2009-03-07 13:45:48 +00:00
|
|
|
* Copyright (c) 2005 Nicolas Plourde <nicolasplourde@gmail.com>
|
|
|
|
*
|
2009-02-08 03:27:30 +00:00
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2009-05-04 16:55:05 +00:00
|
|
|
#import "vo_corevideo.h"
|
2011-12-11 11:26:00 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
// mplayer includes
|
|
|
|
#import "talloc.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#import "vo.h"
|
2011-12-17 19:47:15 +00:00
|
|
|
#import "aspect.h"
|
|
|
|
#import "sub/sub.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#import "core/subopt-helper.h"
|
2011-12-17 19:47:15 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#import "video/csputils.h"
|
|
|
|
#import "video/vfcap.h"
|
|
|
|
#import "video/mp_image.h"
|
2011-12-17 19:47:15 +00:00
|
|
|
|
|
|
|
#import "gl_common.h"
|
2012-10-04 00:48:05 +00:00
|
|
|
#import "gl_osd.h"
|
2011-12-11 11:26:00 +00:00
|
|
|
#import "cocoa_common.h"
|
2005-04-29 11:05:16 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
struct quad {
|
|
|
|
GLfloat lowerLeft[2];
|
|
|
|
GLfloat lowerRight[2];
|
|
|
|
GLfloat upperRight[2];
|
|
|
|
GLfloat upperLeft[2];
|
2005-04-29 11:05:16 +00:00
|
|
|
};
|
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
struct priv {
|
|
|
|
MPGLContext *mpglctx;
|
|
|
|
OSType pixelFormat;
|
|
|
|
unsigned int image_width;
|
|
|
|
unsigned int image_height;
|
|
|
|
struct mp_csp_details colorspace;
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
int ass_border_x, ass_border_y;
|
2011-12-17 19:47:15 +00:00
|
|
|
|
|
|
|
CVPixelBufferRef pixelBuffer;
|
|
|
|
CVOpenGLTextureCacheRef textureCache;
|
|
|
|
CVOpenGLTextureRef texture;
|
|
|
|
struct quad *quad;
|
|
|
|
|
2012-10-04 00:48:05 +00:00
|
|
|
struct mpgl_osd *osd;
|
2011-12-17 19:47:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void resize(struct vo *vo, int width, int height)
|
2011-12-11 11:26:00 +00:00
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2011-12-17 19:47:15 +00:00
|
|
|
GL *gl = p->mpglctx->gl;
|
|
|
|
|
2012-10-21 11:42:52 +00:00
|
|
|
gl->Viewport(0, 0, width, height);
|
2011-12-17 19:47:15 +00:00
|
|
|
gl->MatrixMode(GL_PROJECTION);
|
|
|
|
gl->LoadIdentity();
|
2012-10-21 11:42:52 +00:00
|
|
|
p->ass_border_x = p->ass_border_y = 0;
|
2011-12-17 19:47:15 +00:00
|
|
|
if (aspect_scaling()) {
|
|
|
|
int new_w, new_h;
|
|
|
|
GLdouble scale_x, scale_y;
|
|
|
|
|
|
|
|
aspect(vo, &new_w, &new_h, A_WINZOOM);
|
|
|
|
panscan_calc_windowed(vo);
|
|
|
|
new_w += vo->panscan_x;
|
|
|
|
new_h += vo->panscan_y;
|
2012-10-21 11:42:52 +00:00
|
|
|
scale_x = (GLdouble)new_w / (GLdouble)width;
|
|
|
|
scale_y = (GLdouble)new_h / (GLdouble)height;
|
2011-12-17 19:47:15 +00:00
|
|
|
gl->Scaled(scale_x, scale_y, 1);
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
p->ass_border_x = (vo->dwidth - new_w) / 2;
|
|
|
|
p->ass_border_y = (vo->dheight - new_h) / 2;
|
2011-12-17 19:47:15 +00:00
|
|
|
}
|
2011-12-11 11:26:00 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
gl->Ortho(0, p->image_width, p->image_height, 0, -1.0, 1.0);
|
|
|
|
gl->MatrixMode(GL_MODELVIEW);
|
|
|
|
gl->LoadIdentity();
|
2011-12-11 11:26:00 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
gl->Clear(GL_COLOR_BUFFER_BIT);
|
|
|
|
vo->want_redraw = true;
|
2011-12-11 11:26:00 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
static int init_gl(struct vo *vo, uint32_t d_width, uint32_t d_height)
|
2011-12-11 11:26:00 +00:00
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2011-12-17 19:47:15 +00:00
|
|
|
GL *gl = p->mpglctx->gl;
|
|
|
|
|
|
|
|
const char *vendor = gl->GetString(GL_VENDOR);
|
|
|
|
const char *version = gl->GetString(GL_VERSION);
|
|
|
|
const char *renderer = gl->GetString(GL_RENDERER);
|
|
|
|
|
|
|
|
mp_msg(MSGT_VO, MSGL_V, "[vo_corevideo] Running on OpenGL '%s' by '%s',"
|
|
|
|
" version '%s'\n", renderer, vendor, version);
|
|
|
|
|
|
|
|
gl->Disable(GL_BLEND);
|
|
|
|
gl->Disable(GL_DEPTH_TEST);
|
|
|
|
gl->DepthMask(GL_FALSE);
|
|
|
|
gl->Disable(GL_CULL_FACE);
|
|
|
|
gl->Enable(GL_TEXTURE_2D);
|
|
|
|
gl->DrawBuffer(GL_BACK);
|
|
|
|
gl->TexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
|
2012-10-04 00:48:05 +00:00
|
|
|
if (!p->osd)
|
|
|
|
p->osd = mpgl_osd_init(gl, true);
|
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
resize(vo, d_width, d_height);
|
|
|
|
|
|
|
|
gl->ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
gl->Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
if (gl->SwapInterval)
|
|
|
|
gl->SwapInterval(1);
|
|
|
|
return 1;
|
2011-12-11 11:26:00 +00:00
|
|
|
}
|
|
|
|
|
2012-05-01 12:50:16 +00:00
|
|
|
static void release_cv_entities(struct vo *vo) {
|
|
|
|
struct priv *p = vo->priv;
|
2011-12-17 19:47:15 +00:00
|
|
|
CVPixelBufferRelease(p->pixelBuffer);
|
|
|
|
p->pixelBuffer = NULL;
|
|
|
|
CVOpenGLTextureRelease(p->texture);
|
|
|
|
p->texture = NULL;
|
|
|
|
CVOpenGLTextureCacheRelease(p->textureCache);
|
|
|
|
p->textureCache = NULL;
|
|
|
|
}
|
2011-12-11 10:48:33 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
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)
|
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
|
|
|
release_cv_entities(vo);
|
2011-12-17 19:47:15 +00:00
|
|
|
p->image_width = width;
|
|
|
|
p->image_height = height;
|
2011-12-11 10:48:33 +00:00
|
|
|
|
2012-10-02 23:54:13 +00:00
|
|
|
int mpgl_caps = MPGL_CAP_GL_LEGACY;
|
|
|
|
if (!mpgl_create_window(p->mpglctx, mpgl_caps, d_width, d_height, flags))
|
2011-12-17 19:47:15 +00:00
|
|
|
return -1;
|
2011-12-11 10:48:33 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
init_gl(vo, vo->dwidth, vo->dheight);
|
2011-12-11 10:48:33 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-12-11 10:48:33 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
static void check_events(struct vo *vo)
|
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2011-12-17 19:47:15 +00:00
|
|
|
int e = p->mpglctx->check_events(vo);
|
|
|
|
if (e & VO_EVENT_RESIZE)
|
|
|
|
resize(vo, vo->dwidth, vo->dheight);
|
|
|
|
}
|
2011-12-11 11:26:00 +00:00
|
|
|
|
2012-05-01 12:50:16 +00:00
|
|
|
static void prepare_texture(struct vo *vo)
|
2011-12-11 11:26:00 +00:00
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2011-12-17 19:47:15 +00:00
|
|
|
struct quad *q = p->quad;
|
2012-05-01 12:50:16 +00:00
|
|
|
CVReturn error;
|
2011-12-17 19:47:15 +00:00
|
|
|
|
|
|
|
CVOpenGLTextureRelease(p->texture);
|
|
|
|
error = CVOpenGLTextureCacheCreateTextureFromImage(NULL,
|
|
|
|
p->textureCache, p->pixelBuffer, 0, &p->texture);
|
2011-12-11 11:26:00 +00:00
|
|
|
if(error != kCVReturnSuccess)
|
2011-12-17 19:47:15 +00:00
|
|
|
mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL"
|
|
|
|
" texture(%d)\n", error);
|
2011-12-11 11:26:00 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
CVOpenGLTextureGetCleanTexCoords(p->texture, q->lowerLeft, q->lowerRight,
|
|
|
|
q->upperRight, q->upperLeft);
|
2011-12-11 11:26:00 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
static void do_render(struct vo *vo)
|
2011-12-11 11:26:00 +00:00
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2011-12-17 19:47:15 +00:00
|
|
|
struct quad *q = p->quad;
|
|
|
|
GL *gl = p->mpglctx->gl;
|
2012-05-01 12:50:16 +00:00
|
|
|
prepare_texture(vo);
|
2011-12-17 19:47:15 +00:00
|
|
|
|
|
|
|
float x0 = 0;
|
|
|
|
float y0 = 0;
|
|
|
|
float w = p->image_width;
|
|
|
|
float h = p->image_height;
|
|
|
|
|
|
|
|
// vertically flips the image
|
|
|
|
y0 += h;
|
|
|
|
h = -h;
|
|
|
|
|
|
|
|
float xm = x0 + w;
|
|
|
|
float ym = y0 + h;
|
|
|
|
|
|
|
|
gl->Enable(CVOpenGLTextureGetTarget(p->texture));
|
|
|
|
gl->BindTexture(
|
|
|
|
CVOpenGLTextureGetTarget(p->texture),
|
|
|
|
CVOpenGLTextureGetName(p->texture));
|
|
|
|
|
|
|
|
gl->Begin(GL_QUADS);
|
|
|
|
gl->TexCoord2fv(q->lowerLeft); gl->Vertex2f(x0, y0);
|
|
|
|
gl->TexCoord2fv(q->upperLeft); gl->Vertex2f(x0, ym);
|
|
|
|
gl->TexCoord2fv(q->upperRight); gl->Vertex2f(xm, ym);
|
|
|
|
gl->TexCoord2fv(q->lowerRight); gl->Vertex2f(xm, y0);
|
|
|
|
gl->End();
|
|
|
|
|
|
|
|
gl->Disable(CVOpenGLTextureGetTarget(p->texture));
|
2011-12-11 11:26:00 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
static void flip_page(struct vo *vo)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2011-12-17 19:47:15 +00:00
|
|
|
p->mpglctx->swapGlBuffers(p->mpglctx);
|
|
|
|
p->mpglctx->gl->Clear(GL_COLOR_BUFFER_BIT);
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
static uint32_t draw_image(struct vo *vo, mp_image_t *mpi)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2011-12-17 19:47:15 +00:00
|
|
|
CVReturn error;
|
2005-04-29 11:05:16 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
if (!p->textureCache || !p->pixelBuffer) {
|
2012-09-13 07:32:59 +00:00
|
|
|
error = CVOpenGLTextureCacheCreate(NULL, 0, vo_cocoa_cgl_context(vo),
|
|
|
|
vo_cocoa_cgl_pixel_format(vo), 0, &p->textureCache);
|
2011-12-17 19:47:15 +00:00
|
|
|
if(error != kCVReturnSuccess)
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL"
|
|
|
|
" texture Cache(%d)\n", error);
|
2005-04-29 11:05:16 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
error = CVPixelBufferCreateWithBytes(NULL, mpi->width, mpi->height,
|
|
|
|
p->pixelFormat, mpi->planes[0], mpi->width * mpi->bpp / 8,
|
|
|
|
NULL, NULL, NULL, &p->pixelBuffer);
|
|
|
|
if(error != kCVReturnSuccess)
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel"
|
|
|
|
"Buffer(%d)\n", error);
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
do_render(vo);
|
|
|
|
return VO_TRUE;
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
2012-05-01 12:50:16 +00:00
|
|
|
static int query_format(struct vo *vo, uint32_t format)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2011-12-17 19:47:15 +00:00
|
|
|
const int flags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW |
|
|
|
|
VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN |
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
VOCAP_NOSLICES;
|
2011-12-17 19:47:15 +00:00
|
|
|
switch (format) {
|
2011-12-11 10:48:33 +00:00
|
|
|
case IMGFMT_YUY2:
|
2011-12-17 19:47:15 +00:00
|
|
|
p->pixelFormat = kYUVSPixelFormat;
|
|
|
|
return flags;
|
2011-12-11 10:48:33 +00:00
|
|
|
|
|
|
|
case IMGFMT_RGB24:
|
2011-12-17 19:47:15 +00:00
|
|
|
p->pixelFormat = k24RGBPixelFormat;
|
|
|
|
return flags;
|
2011-12-11 10:48:33 +00:00
|
|
|
|
|
|
|
case IMGFMT_ARGB:
|
2011-12-17 19:47:15 +00:00
|
|
|
p->pixelFormat = k32ARGBPixelFormat;
|
|
|
|
return flags;
|
2011-12-11 10:48:33 +00:00
|
|
|
|
|
|
|
case IMGFMT_BGRA:
|
2011-12-17 19:47:15 +00:00
|
|
|
p->pixelFormat = k32BGRAPixelFormat;
|
|
|
|
return flags;
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
static void uninit(struct vo *vo)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2012-10-04 00:48:05 +00:00
|
|
|
if (p->osd)
|
|
|
|
mpgl_osd_destroy(p->osd);
|
2012-05-01 12:50:16 +00:00
|
|
|
release_cv_entities(vo);
|
2012-10-20 19:01:42 +00:00
|
|
|
mpgl_uninit(p->mpglctx);
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
|
|
|
|
2008-12-19 20:33:54 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
static int preinit(struct vo *vo, const char *arg)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2011-12-11 10:48:33 +00:00
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
*p = (struct priv) {
|
2012-10-02 23:54:13 +00:00
|
|
|
.mpglctx = mpgl_init(GLTYPE_COCOA, vo),
|
2011-12-17 19:47:15 +00:00
|
|
|
.colorspace = MP_CSP_DETAILS_DEFAULTS,
|
|
|
|
.quad = talloc_ptrtype(p, p->quad),
|
|
|
|
};
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2005-04-29 11:05:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
static void draw_osd(struct vo *vo, struct osd_state *osd)
|
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
|
|
|
GL *gl = p->mpglctx->gl;
|
|
|
|
assert(p->osd);
|
|
|
|
|
2012-10-21 11:42:52 +00:00
|
|
|
gl->MatrixMode(GL_PROJECTION);
|
|
|
|
gl->PushMatrix();
|
|
|
|
gl->LoadIdentity();
|
|
|
|
gl->Ortho(0, vo->dwidth, vo->dheight, 0, -1, 1);
|
|
|
|
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
struct mp_osd_res res = {
|
|
|
|
.w = vo->dwidth,
|
|
|
|
.h = vo->dheight,
|
|
|
|
.display_par = vo->monitor_par,
|
|
|
|
.video_par = vo->aspdat.par,
|
|
|
|
};
|
|
|
|
|
2012-10-21 11:42:52 +00:00
|
|
|
if (aspect_scaling()) {
|
|
|
|
res.ml = res.mr = p->ass_border_x;
|
|
|
|
res.mt = res.mb = p->ass_border_y;
|
|
|
|
}
|
|
|
|
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
mpgl_osd_draw_legacy(p->osd, osd, res);
|
2012-10-21 11:42:52 +00:00
|
|
|
|
|
|
|
gl->PopMatrix();
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
}
|
|
|
|
|
2012-05-01 12:50:16 +00:00
|
|
|
static CFStringRef get_cv_csp_matrix(struct vo *vo)
|
2011-12-17 19:47:15 +00:00
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2011-12-17 19:47:15 +00:00
|
|
|
switch (p->colorspace.format) {
|
|
|
|
case MP_CSP_BT_601:
|
|
|
|
return kCVImageBufferYCbCrMatrix_ITU_R_601_4;
|
|
|
|
case MP_CSP_BT_709:
|
|
|
|
return kCVImageBufferYCbCrMatrix_ITU_R_709_2;
|
|
|
|
case MP_CSP_SMPTE_240M:
|
|
|
|
return kCVImageBufferYCbCrMatrix_SMPTE_240M_1995;
|
|
|
|
}
|
|
|
|
return kCVImageBufferYCbCrMatrix_ITU_R_601_4;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_yuv_colorspace(struct vo *vo)
|
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2011-12-17 19:47:15 +00:00
|
|
|
CVBufferSetAttachment(p->pixelBuffer,
|
2012-05-01 12:50:16 +00:00
|
|
|
kCVImageBufferYCbCrMatrixKey, get_cv_csp_matrix(vo),
|
2011-12-17 19:47:15 +00:00
|
|
|
kCVAttachmentMode_ShouldPropagate);
|
|
|
|
vo->want_redraw = true;
|
|
|
|
}
|
|
|
|
|
2012-10-21 14:25:42 +00:00
|
|
|
static int get_image_fmt(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct priv *p = vo->priv;
|
|
|
|
switch (p->pixelFormat) {
|
|
|
|
case kYUVSPixelFormat: return IMGFMT_YUY2;
|
|
|
|
case k24RGBPixelFormat: return IMGFMT_RGB24;
|
|
|
|
case k32ARGBPixelFormat: return IMGFMT_ARGB;
|
|
|
|
case k32BGRAPixelFormat: return IMGFMT_BGRA;
|
|
|
|
}
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "[vo_corevideo] Failed to convert pixel format. "
|
|
|
|
"Please contact the developers. PixelFormat: %d\n", p->pixelFormat);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static mp_image_t *get_screenshot(struct vo *vo)
|
|
|
|
{
|
|
|
|
int img_fmt = get_image_fmt(vo);
|
|
|
|
if (img_fmt < 0) return NULL;
|
|
|
|
|
|
|
|
struct priv *p = vo->priv;
|
|
|
|
void *base = CVPixelBufferGetBaseAddress(p->pixelBuffer);
|
|
|
|
|
|
|
|
size_t width = CVPixelBufferGetWidth(p->pixelBuffer);
|
|
|
|
size_t height = CVPixelBufferGetHeight(p->pixelBuffer);
|
|
|
|
size_t stride = CVPixelBufferGetBytesPerRow(p->pixelBuffer);
|
|
|
|
size_t image_size = stride * height;
|
|
|
|
|
|
|
|
mp_image_t *image = alloc_mpi(width, height, img_fmt);
|
|
|
|
memcpy(image->planes[0], base, image_size);
|
|
|
|
image->stride[0] = stride;
|
|
|
|
|
2012-10-26 18:19:06 +00:00
|
|
|
image->display_w = vo->aspdat.prew;
|
|
|
|
image->display_h = vo->aspdat.preh;
|
2012-10-21 14:25:42 +00:00
|
|
|
|
2012-10-26 17:29:47 +00:00
|
|
|
mp_image_set_colorspace_details(image, &p->colorspace);
|
|
|
|
|
2012-10-21 14:25:42 +00:00
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2011-12-17 19:47:15 +00:00
|
|
|
static int control(struct vo *vo, uint32_t request, void *data)
|
2005-04-29 11:05:16 +00:00
|
|
|
{
|
2012-05-01 12:50:16 +00:00
|
|
|
struct priv *p = vo->priv;
|
2011-12-11 11:26:00 +00:00
|
|
|
switch (request) {
|
2011-12-17 19:47:15 +00:00
|
|
|
case VOCTRL_DRAW_IMAGE:
|
|
|
|
return draw_image(vo, data);
|
|
|
|
case VOCTRL_QUERY_FORMAT:
|
2012-05-01 12:50:16 +00:00
|
|
|
return query_format(vo, *(uint32_t*)data);
|
2011-12-11 11:26:00 +00:00
|
|
|
case VOCTRL_ONTOP:
|
2011-12-17 19:47:15 +00:00
|
|
|
p->mpglctx->ontop(vo);
|
2011-12-11 11:26:00 +00:00
|
|
|
return VO_TRUE;
|
2012-09-16 18:53:04 +00:00
|
|
|
case VOCTRL_PAUSE:
|
|
|
|
if (!p->mpglctx->pause)
|
|
|
|
break;
|
|
|
|
p->mpglctx->pause(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_RESUME:
|
|
|
|
if (!p->mpglctx->resume)
|
|
|
|
break;
|
|
|
|
p->mpglctx->resume(vo);
|
|
|
|
return VO_TRUE;
|
2011-12-11 11:26:00 +00:00
|
|
|
case VOCTRL_FULLSCREEN:
|
2011-12-17 19:47:15 +00:00
|
|
|
p->mpglctx->fullscreen(vo);
|
|
|
|
resize(vo, vo->dwidth, vo->dheight);
|
2011-12-11 11:26:00 +00:00
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_GET_PANSCAN:
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_SET_PANSCAN:
|
2011-12-17 19:47:15 +00:00
|
|
|
resize(vo, vo->dwidth, vo->dheight);
|
2011-12-11 11:26:00 +00:00
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_UPDATE_SCREENINFO:
|
2011-12-17 19:47:15 +00:00
|
|
|
p->mpglctx->update_xinerama_info(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_REDRAW_FRAME:
|
|
|
|
do_render(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_SET_YUV_COLORSPACE:
|
|
|
|
p->colorspace.format = ((struct mp_csp_details *)data)->format;
|
|
|
|
set_yuv_colorspace(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_GET_YUV_COLORSPACE:
|
|
|
|
*(struct mp_csp_details *)data = p->colorspace;
|
|
|
|
return VO_TRUE;
|
2012-10-21 14:25:42 +00:00
|
|
|
case VOCTRL_SCREENSHOT: {
|
|
|
|
struct voctrl_screenshot_args *args = data;
|
|
|
|
if (args->full_window)
|
|
|
|
args->out_image = glGetWindowScreenshot(p->mpglctx->gl);
|
|
|
|
else
|
|
|
|
args->out_image = get_screenshot(vo);
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
2011-12-11 10:48:33 +00:00
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
2005-04-29 11:05:16 +00:00
|
|
|
}
|
2011-12-17 19:47:15 +00:00
|
|
|
|
|
|
|
const struct vo_driver video_out_corevideo = {
|
|
|
|
.is_new = true,
|
|
|
|
.info = &(const vo_info_t) {
|
|
|
|
"Mac OS X Core Video",
|
|
|
|
"corevideo",
|
|
|
|
"Nicolas Plourde <nicolas.plourde@gmail.com> and others",
|
|
|
|
""
|
|
|
|
},
|
|
|
|
.preinit = preinit,
|
|
|
|
.config = config,
|
|
|
|
.control = control,
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
.draw_osd = draw_osd,
|
2011-12-17 19:47:15 +00:00
|
|
|
.flip_page = flip_page,
|
|
|
|
.check_events = check_events,
|
|
|
|
.uninit = uninit,
|
2012-08-08 19:11:43 +00:00
|
|
|
.priv_size = sizeof(struct priv),
|
2011-12-17 19:47:15 +00:00
|
|
|
};
|