2013-11-13 20:59:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Stefano Pigozzi <stefano.pigozzi@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
2016-01-19 17:36:34 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2013-11-13 20:59:11 +00:00
|
|
|
*
|
|
|
|
* mpv 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
|
2016-01-19 17:36:34 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-11-13 20:59:11 +00:00
|
|
|
*
|
2016-01-19 17:36:34 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2013-11-13 20:59:11 +00:00
|
|
|
*/
|
|
|
|
|
2015-09-24 21:48:57 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2013-11-13 20:59:11 +00:00
|
|
|
#include <IOSurface/IOSurface.h>
|
|
|
|
#include <CoreVideo/CoreVideo.h>
|
|
|
|
#include <OpenGL/OpenGL.h>
|
2014-01-02 21:42:16 +00:00
|
|
|
#include <OpenGL/CGLIOSurface.h>
|
2013-11-13 20:59:11 +00:00
|
|
|
|
2015-01-22 16:47:14 +00:00
|
|
|
#include "video/mp_image_pool.h"
|
2015-08-29 02:12:56 +00:00
|
|
|
#include "hwdec.h"
|
2015-11-17 20:07:41 +00:00
|
|
|
#include "common/global.h"
|
|
|
|
#include "options/options.h"
|
2013-11-13 20:59:11 +00:00
|
|
|
|
2015-09-28 20:02:53 +00:00
|
|
|
struct vt_gl_plane_format {
|
2015-04-11 15:17:52 +00:00
|
|
|
GLenum gl_format;
|
|
|
|
GLenum gl_type;
|
|
|
|
GLenum gl_internal_format;
|
vo_opengl: refactor how hwdec interop exports textures
Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a
struct gl_hwdec_frame describing the exact texture layout. This gives
more flexibility to what the hwdec interop can export. In particular, it
can export strange component orders/permutations and textures with
padded size. (The latter originating from cropped video.)
The way gl_hwdec_frame works is in the spirit of the rest of the
vo_opengl video processing code, which tends to put as much information
in immediate state (as part of the dataflow), instead of declaring it
globally. To some degree this duplicates the texplane and img_tex
structs, but until we somehow unify those, it's better to give the hwdec
state its own struct. The fact that changing the hwdec struct would
require changes and testing on at least 4 platform/GPU combinations
makes duplicating it almost a requirement to avoid pain later.
Make gl_hwdec_driver.reinit set the new image format and remove the
gl_hwdec.converted_imgfmt field.
Likewise, gl_hwdec.gl_texture_target is replaced with
gl_hwdec_plane.gl_target.
Split out a init_image_desc function from init_format. The latter is not
called in the hwdec case at all anymore. Setting up most of struct
texplane is also completely separate in the hwdec and normal cases.
video.c does not check whether the hwdec "mapped" image format is
supported. This should not really happen anyway, and if it does, the
hwdec interop backend must fail at creation time, so this is not an
issue.
2016-05-10 16:29:10 +00:00
|
|
|
char swizzle[5];
|
2015-04-11 15:17:52 +00:00
|
|
|
};
|
|
|
|
|
2015-09-28 20:02:53 +00:00
|
|
|
struct vt_format {
|
2015-04-11 15:17:52 +00:00
|
|
|
uint32_t cvpixfmt;
|
|
|
|
int imgfmt;
|
|
|
|
int planes;
|
2015-09-28 20:02:53 +00:00
|
|
|
struct vt_gl_plane_format gl[MP_MAX_PLANES];
|
2015-04-11 15:17:52 +00:00
|
|
|
};
|
|
|
|
|
2013-11-13 20:59:11 +00:00
|
|
|
struct priv {
|
2016-05-09 17:42:03 +00:00
|
|
|
struct mp_hwdec_ctx hwctx;
|
|
|
|
struct mp_vt_ctx vtctx;
|
|
|
|
|
2013-11-13 20:59:11 +00:00
|
|
|
CVPixelBufferRef pbuf;
|
2015-04-11 15:17:52 +00:00
|
|
|
GLuint gl_planes[MP_MAX_PLANES];
|
2013-11-13 20:59:11 +00:00
|
|
|
};
|
|
|
|
|
2015-09-28 20:02:53 +00:00
|
|
|
static struct vt_format vt_formats[] = {
|
2015-04-11 15:17:52 +00:00
|
|
|
{
|
|
|
|
.cvpixfmt = kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
|
|
|
|
.imgfmt = IMGFMT_NV12,
|
|
|
|
.planes = 2,
|
|
|
|
.gl = {
|
|
|
|
{ GL_RED, GL_UNSIGNED_BYTE, GL_RED },
|
|
|
|
{ GL_RG, GL_UNSIGNED_BYTE, GL_RG } ,
|
|
|
|
}
|
2015-11-17 20:07:41 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.cvpixfmt = kCVPixelFormatType_422YpCbCr8,
|
|
|
|
.imgfmt = IMGFMT_UYVY,
|
|
|
|
.planes = 1,
|
|
|
|
.gl = {
|
vo_opengl: refactor how hwdec interop exports textures
Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a
struct gl_hwdec_frame describing the exact texture layout. This gives
more flexibility to what the hwdec interop can export. In particular, it
can export strange component orders/permutations and textures with
padded size. (The latter originating from cropped video.)
The way gl_hwdec_frame works is in the spirit of the rest of the
vo_opengl video processing code, which tends to put as much information
in immediate state (as part of the dataflow), instead of declaring it
globally. To some degree this duplicates the texplane and img_tex
structs, but until we somehow unify those, it's better to give the hwdec
state its own struct. The fact that changing the hwdec struct would
require changes and testing on at least 4 platform/GPU combinations
makes duplicating it almost a requirement to avoid pain later.
Make gl_hwdec_driver.reinit set the new image format and remove the
gl_hwdec.converted_imgfmt field.
Likewise, gl_hwdec.gl_texture_target is replaced with
gl_hwdec_plane.gl_target.
Split out a init_image_desc function from init_format. The latter is not
called in the hwdec case at all anymore. Setting up most of struct
texplane is also completely separate in the hwdec and normal cases.
video.c does not check whether the hwdec "mapped" image format is
supported. This should not really happen anyway, and if it does, the
hwdec interop backend must fail at creation time, so this is not an
issue.
2016-05-10 16:29:10 +00:00
|
|
|
{ GL_RGB_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, GL_RGB, "gbra" }
|
2015-11-17 20:07:41 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cvpixfmt = kCVPixelFormatType_32BGRA,
|
|
|
|
.imgfmt = IMGFMT_RGB0,
|
|
|
|
.planes = 1,
|
|
|
|
.gl = {
|
|
|
|
{ GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, GL_RGBA }
|
|
|
|
}
|
|
|
|
},
|
2015-04-11 15:17:52 +00:00
|
|
|
};
|
|
|
|
|
2015-09-28 20:02:53 +00:00
|
|
|
static struct vt_format *vt_get_gl_format(uint32_t cvpixfmt)
|
2015-04-11 15:17:52 +00:00
|
|
|
{
|
2015-09-28 20:02:53 +00:00
|
|
|
for (int i = 0; i < MP_ARRAY_SIZE(vt_formats); i++) {
|
|
|
|
if (vt_formats[i].cvpixfmt == cvpixfmt)
|
|
|
|
return &vt_formats[i];
|
2015-04-11 15:17:52 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-28 20:02:53 +00:00
|
|
|
static struct vt_format *vt_get_gl_format_from_imgfmt(uint32_t imgfmt)
|
2015-04-11 15:17:52 +00:00
|
|
|
{
|
2015-09-28 20:02:53 +00:00
|
|
|
for (int i = 0; i < MP_ARRAY_SIZE(vt_formats); i++) {
|
|
|
|
if (vt_formats[i].imgfmt == imgfmt)
|
|
|
|
return &vt_formats[i];
|
2015-04-11 15:17:52 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-01-22 16:47:14 +00:00
|
|
|
static struct mp_image *download_image(struct mp_hwdec_ctx *ctx,
|
|
|
|
struct mp_image *hw_image,
|
|
|
|
struct mp_image_pool *swpool)
|
|
|
|
{
|
2015-09-28 20:02:53 +00:00
|
|
|
if (hw_image->imgfmt != IMGFMT_VIDEOTOOLBOX)
|
2015-01-22 16:47:14 +00:00
|
|
|
return NULL;
|
|
|
|
|
2016-04-07 17:55:51 +00:00
|
|
|
struct mp_image *image = NULL;
|
2015-01-22 16:47:14 +00:00
|
|
|
CVPixelBufferRef pbuf = (CVPixelBufferRef)hw_image->planes[3];
|
2016-04-07 17:55:51 +00:00
|
|
|
CVPixelBufferLockBaseAddress(pbuf, kCVPixelBufferLock_ReadOnly);
|
2015-01-22 16:47:14 +00:00
|
|
|
size_t width = CVPixelBufferGetWidth(pbuf);
|
|
|
|
size_t height = CVPixelBufferGetHeight(pbuf);
|
2015-04-11 15:17:52 +00:00
|
|
|
uint32_t cvpixfmt = CVPixelBufferGetPixelFormatType(pbuf);
|
2015-09-28 20:02:53 +00:00
|
|
|
struct vt_format *f = vt_get_gl_format(cvpixfmt);
|
2016-04-07 17:55:51 +00:00
|
|
|
if (!f)
|
|
|
|
goto unlock;
|
2015-01-22 16:47:14 +00:00
|
|
|
|
|
|
|
struct mp_image img = {0};
|
2015-04-11 15:17:52 +00:00
|
|
|
mp_image_setfmt(&img, f->imgfmt);
|
2015-01-22 16:47:14 +00:00
|
|
|
mp_image_set_size(&img, width, height);
|
2015-04-11 15:17:52 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < f->planes; i++) {
|
|
|
|
void *base = CVPixelBufferGetBaseAddressOfPlane(pbuf, i);
|
|
|
|
size_t stride = CVPixelBufferGetBytesPerRowOfPlane(pbuf, i);
|
|
|
|
img.planes[i] = base;
|
|
|
|
img.stride[i] = stride;
|
|
|
|
}
|
|
|
|
|
2015-01-22 16:47:14 +00:00
|
|
|
mp_image_copy_attributes(&img, hw_image);
|
|
|
|
|
2016-04-07 17:55:51 +00:00
|
|
|
image = mp_image_pool_new_copy(swpool, &img);
|
|
|
|
|
|
|
|
unlock:
|
|
|
|
CVPixelBufferUnlockBaseAddress(pbuf, kCVPixelBufferLock_ReadOnly);
|
2015-01-22 16:47:14 +00:00
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2013-11-13 20:59:11 +00:00
|
|
|
static bool check_hwdec(struct gl_hwdec *hw)
|
|
|
|
{
|
2015-09-01 13:20:33 +00:00
|
|
|
if (hw->gl->version < 300) {
|
|
|
|
MP_ERR(hw, "need >= OpenGL 3.0 for core rectangle texture support\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-03 20:02:33 +00:00
|
|
|
if (!CGLGetCurrentContext()) {
|
2013-11-13 20:59:11 +00:00
|
|
|
MP_ERR(hw, "need cocoa opengl backend to be active");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-09 17:42:03 +00:00
|
|
|
static uint32_t get_vt_fmt(struct mp_vt_ctx *vtctx)
|
2016-04-07 16:47:03 +00:00
|
|
|
{
|
2016-05-09 17:42:03 +00:00
|
|
|
struct gl_hwdec *hw = vtctx->priv;
|
2016-04-07 16:47:03 +00:00
|
|
|
struct vt_format *f =
|
|
|
|
vt_get_gl_format_from_imgfmt(hw->global->opts->videotoolbox_format);
|
|
|
|
return f ? f->cvpixfmt : (uint32_t)-1;
|
|
|
|
}
|
|
|
|
|
2015-09-28 20:02:53 +00:00
|
|
|
static int create(struct gl_hwdec *hw)
|
2013-11-13 20:59:11 +00:00
|
|
|
{
|
|
|
|
if (!check_hwdec(hw))
|
|
|
|
return -1;
|
|
|
|
|
2015-09-28 20:02:53 +00:00
|
|
|
struct priv *p = talloc_zero(hw, struct priv);
|
|
|
|
hw->priv = p;
|
2015-07-11 15:21:39 +00:00
|
|
|
|
2015-09-28 20:02:53 +00:00
|
|
|
hw->gl->GenTextures(MP_MAX_PLANES, p->gl_planes);
|
|
|
|
|
2016-05-09 17:42:03 +00:00
|
|
|
p->vtctx = (struct mp_vt_ctx){
|
|
|
|
.priv = hw,
|
|
|
|
.get_vt_fmt = get_vt_fmt,
|
|
|
|
};
|
|
|
|
p->hwctx = (struct mp_hwdec_ctx){
|
|
|
|
.type = HWDEC_VIDEOTOOLBOX,
|
|
|
|
.download_image = download_image,
|
|
|
|
.ctx = &p->vtctx,
|
|
|
|
};
|
|
|
|
hwdec_devices_add(hw->devs, &p->hwctx);
|
|
|
|
|
2015-07-11 15:21:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-29 18:53:49 +00:00
|
|
|
static int reinit(struct gl_hwdec *hw, struct mp_image_params *params)
|
2013-11-13 20:59:11 +00:00
|
|
|
{
|
2015-09-24 21:48:57 +00:00
|
|
|
assert(params->imgfmt == hw->driver->imgfmt);
|
2016-04-07 16:47:03 +00:00
|
|
|
|
2016-07-15 09:54:44 +00:00
|
|
|
struct vt_format *f = vt_get_gl_format_from_imgfmt(params->hw_subfmt);
|
2016-04-07 16:47:03 +00:00
|
|
|
if (!f) {
|
|
|
|
MP_ERR(hw, "Unsupported CVPixelBuffer format.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
vo_opengl: refactor how hwdec interop exports textures
Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a
struct gl_hwdec_frame describing the exact texture layout. This gives
more flexibility to what the hwdec interop can export. In particular, it
can export strange component orders/permutations and textures with
padded size. (The latter originating from cropped video.)
The way gl_hwdec_frame works is in the spirit of the rest of the
vo_opengl video processing code, which tends to put as much information
in immediate state (as part of the dataflow), instead of declaring it
globally. To some degree this duplicates the texplane and img_tex
structs, but until we somehow unify those, it's better to give the hwdec
state its own struct. The fact that changing the hwdec struct would
require changes and testing on at least 4 platform/GPU combinations
makes duplicating it almost a requirement to avoid pain later.
Make gl_hwdec_driver.reinit set the new image format and remove the
gl_hwdec.converted_imgfmt field.
Likewise, gl_hwdec.gl_texture_target is replaced with
gl_hwdec_plane.gl_target.
Split out a init_image_desc function from init_format. The latter is not
called in the hwdec case at all anymore. Setting up most of struct
texplane is also completely separate in the hwdec and normal cases.
video.c does not check whether the hwdec "mapped" image format is
supported. This should not really happen anyway, and if it does, the
hwdec interop backend must fail at creation time, so this is not an
issue.
2016-05-10 16:29:10 +00:00
|
|
|
params->imgfmt = f->imgfmt;
|
2016-07-15 10:01:30 +00:00
|
|
|
params->hw_subfmt = 0;
|
2013-11-13 20:59:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
vo_opengl: refactor how hwdec interop exports textures
Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a
struct gl_hwdec_frame describing the exact texture layout. This gives
more flexibility to what the hwdec interop can export. In particular, it
can export strange component orders/permutations and textures with
padded size. (The latter originating from cropped video.)
The way gl_hwdec_frame works is in the spirit of the rest of the
vo_opengl video processing code, which tends to put as much information
in immediate state (as part of the dataflow), instead of declaring it
globally. To some degree this duplicates the texplane and img_tex
structs, but until we somehow unify those, it's better to give the hwdec
state its own struct. The fact that changing the hwdec struct would
require changes and testing on at least 4 platform/GPU combinations
makes duplicating it almost a requirement to avoid pain later.
Make gl_hwdec_driver.reinit set the new image format and remove the
gl_hwdec.converted_imgfmt field.
Likewise, gl_hwdec.gl_texture_target is replaced with
gl_hwdec_plane.gl_target.
Split out a init_image_desc function from init_format. The latter is not
called in the hwdec case at all anymore. Setting up most of struct
texplane is also completely separate in the hwdec and normal cases.
video.c does not check whether the hwdec "mapped" image format is
supported. This should not really happen anyway, and if it does, the
hwdec interop backend must fail at creation time, so this is not an
issue.
2016-05-10 16:29:10 +00:00
|
|
|
static int map_frame(struct gl_hwdec *hw, struct mp_image *hw_image,
|
|
|
|
struct gl_hwdec_frame *out_frame)
|
2013-11-13 20:59:11 +00:00
|
|
|
{
|
|
|
|
struct priv *p = hw->priv;
|
2014-12-03 20:02:33 +00:00
|
|
|
GL *gl = hw->gl;
|
2013-11-13 20:59:11 +00:00
|
|
|
|
|
|
|
CVPixelBufferRelease(p->pbuf);
|
|
|
|
p->pbuf = (CVPixelBufferRef)hw_image->planes[3];
|
|
|
|
CVPixelBufferRetain(p->pbuf);
|
|
|
|
IOSurfaceRef surface = CVPixelBufferGetIOSurface(p->pbuf);
|
2015-11-17 14:22:47 +00:00
|
|
|
if (!surface) {
|
|
|
|
MP_ERR(hw, "CVPixelBuffer has no IOSurface\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-11-13 20:59:11 +00:00
|
|
|
|
2015-04-11 15:17:52 +00:00
|
|
|
uint32_t cvpixfmt = CVPixelBufferGetPixelFormatType(p->pbuf);
|
2015-09-28 20:02:53 +00:00
|
|
|
struct vt_format *f = vt_get_gl_format(cvpixfmt);
|
2015-04-11 15:17:52 +00:00
|
|
|
if (!f) {
|
|
|
|
MP_ERR(hw, "CVPixelBuffer has unsupported format type\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool planar = CVPixelBufferIsPlanar(p->pbuf);
|
|
|
|
const int planes = CVPixelBufferGetPlaneCount(p->pbuf);
|
|
|
|
assert(planar && planes == f->planes || f->planes == 1);
|
2013-11-13 20:59:11 +00:00
|
|
|
|
vo_opengl: refactor how hwdec interop exports textures
Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a
struct gl_hwdec_frame describing the exact texture layout. This gives
more flexibility to what the hwdec interop can export. In particular, it
can export strange component orders/permutations and textures with
padded size. (The latter originating from cropped video.)
The way gl_hwdec_frame works is in the spirit of the rest of the
vo_opengl video processing code, which tends to put as much information
in immediate state (as part of the dataflow), instead of declaring it
globally. To some degree this duplicates the texplane and img_tex
structs, but until we somehow unify those, it's better to give the hwdec
state its own struct. The fact that changing the hwdec struct would
require changes and testing on at least 4 platform/GPU combinations
makes duplicating it almost a requirement to avoid pain later.
Make gl_hwdec_driver.reinit set the new image format and remove the
gl_hwdec.converted_imgfmt field.
Likewise, gl_hwdec.gl_texture_target is replaced with
gl_hwdec_plane.gl_target.
Split out a init_image_desc function from init_format. The latter is not
called in the hwdec case at all anymore. Setting up most of struct
texplane is also completely separate in the hwdec and normal cases.
video.c does not check whether the hwdec "mapped" image format is
supported. This should not really happen anyway, and if it does, the
hwdec interop backend must fail at creation time, so this is not an
issue.
2016-05-10 16:29:10 +00:00
|
|
|
GLenum gl_target = GL_TEXTURE_RECTANGLE;
|
|
|
|
|
2015-04-11 15:17:52 +00:00
|
|
|
for (int i = 0; i < f->planes; i++) {
|
vo_opengl: refactor how hwdec interop exports textures
Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a
struct gl_hwdec_frame describing the exact texture layout. This gives
more flexibility to what the hwdec interop can export. In particular, it
can export strange component orders/permutations and textures with
padded size. (The latter originating from cropped video.)
The way gl_hwdec_frame works is in the spirit of the rest of the
vo_opengl video processing code, which tends to put as much information
in immediate state (as part of the dataflow), instead of declaring it
globally. To some degree this duplicates the texplane and img_tex
structs, but until we somehow unify those, it's better to give the hwdec
state its own struct. The fact that changing the hwdec struct would
require changes and testing on at least 4 platform/GPU combinations
makes duplicating it almost a requirement to avoid pain later.
Make gl_hwdec_driver.reinit set the new image format and remove the
gl_hwdec.converted_imgfmt field.
Likewise, gl_hwdec.gl_texture_target is replaced with
gl_hwdec_plane.gl_target.
Split out a init_image_desc function from init_format. The latter is not
called in the hwdec case at all anymore. Setting up most of struct
texplane is also completely separate in the hwdec and normal cases.
video.c does not check whether the hwdec "mapped" image format is
supported. This should not really happen anyway, and if it does, the
hwdec interop backend must fail at creation time, so this is not an
issue.
2016-05-10 16:29:10 +00:00
|
|
|
gl->BindTexture(gl_target, p->gl_planes[i]);
|
2013-11-13 20:59:11 +00:00
|
|
|
|
2015-04-11 15:17:52 +00:00
|
|
|
CGLError err = CGLTexImageIOSurface2D(
|
vo_opengl: refactor how hwdec interop exports textures
Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a
struct gl_hwdec_frame describing the exact texture layout. This gives
more flexibility to what the hwdec interop can export. In particular, it
can export strange component orders/permutations and textures with
padded size. (The latter originating from cropped video.)
The way gl_hwdec_frame works is in the spirit of the rest of the
vo_opengl video processing code, which tends to put as much information
in immediate state (as part of the dataflow), instead of declaring it
globally. To some degree this duplicates the texplane and img_tex
structs, but until we somehow unify those, it's better to give the hwdec
state its own struct. The fact that changing the hwdec struct would
require changes and testing on at least 4 platform/GPU combinations
makes duplicating it almost a requirement to avoid pain later.
Make gl_hwdec_driver.reinit set the new image format and remove the
gl_hwdec.converted_imgfmt field.
Likewise, gl_hwdec.gl_texture_target is replaced with
gl_hwdec_plane.gl_target.
Split out a init_image_desc function from init_format. The latter is not
called in the hwdec case at all anymore. Setting up most of struct
texplane is also completely separate in the hwdec and normal cases.
video.c does not check whether the hwdec "mapped" image format is
supported. This should not really happen anyway, and if it does, the
hwdec interop backend must fail at creation time, so this is not an
issue.
2016-05-10 16:29:10 +00:00
|
|
|
CGLGetCurrentContext(), gl_target,
|
2015-04-11 15:17:52 +00:00
|
|
|
f->gl[i].gl_internal_format,
|
|
|
|
IOSurfaceGetWidthOfPlane(surface, i),
|
|
|
|
IOSurfaceGetHeightOfPlane(surface, i),
|
|
|
|
f->gl[i].gl_format, f->gl[i].gl_type, surface, i);
|
2013-11-13 20:59:11 +00:00
|
|
|
|
2015-04-11 15:17:52 +00:00
|
|
|
if (err != kCGLNoError)
|
|
|
|
MP_ERR(hw, "error creating IOSurface texture for plane %d: %s (%x)\n",
|
|
|
|
i, CGLErrorString(err), gl->GetError());
|
|
|
|
|
vo_opengl: refactor how hwdec interop exports textures
Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a
struct gl_hwdec_frame describing the exact texture layout. This gives
more flexibility to what the hwdec interop can export. In particular, it
can export strange component orders/permutations and textures with
padded size. (The latter originating from cropped video.)
The way gl_hwdec_frame works is in the spirit of the rest of the
vo_opengl video processing code, which tends to put as much information
in immediate state (as part of the dataflow), instead of declaring it
globally. To some degree this duplicates the texplane and img_tex
structs, but until we somehow unify those, it's better to give the hwdec
state its own struct. The fact that changing the hwdec struct would
require changes and testing on at least 4 platform/GPU combinations
makes duplicating it almost a requirement to avoid pain later.
Make gl_hwdec_driver.reinit set the new image format and remove the
gl_hwdec.converted_imgfmt field.
Likewise, gl_hwdec.gl_texture_target is replaced with
gl_hwdec_plane.gl_target.
Split out a init_image_desc function from init_format. The latter is not
called in the hwdec case at all anymore. Setting up most of struct
texplane is also completely separate in the hwdec and normal cases.
video.c does not check whether the hwdec "mapped" image format is
supported. This should not really happen anyway, and if it does, the
hwdec interop backend must fail at creation time, so this is not an
issue.
2016-05-10 16:29:10 +00:00
|
|
|
gl->BindTexture(gl_target, 0);
|
2015-04-11 15:17:52 +00:00
|
|
|
|
vo_opengl: refactor how hwdec interop exports textures
Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a
struct gl_hwdec_frame describing the exact texture layout. This gives
more flexibility to what the hwdec interop can export. In particular, it
can export strange component orders/permutations and textures with
padded size. (The latter originating from cropped video.)
The way gl_hwdec_frame works is in the spirit of the rest of the
vo_opengl video processing code, which tends to put as much information
in immediate state (as part of the dataflow), instead of declaring it
globally. To some degree this duplicates the texplane and img_tex
structs, but until we somehow unify those, it's better to give the hwdec
state its own struct. The fact that changing the hwdec struct would
require changes and testing on at least 4 platform/GPU combinations
makes duplicating it almost a requirement to avoid pain later.
Make gl_hwdec_driver.reinit set the new image format and remove the
gl_hwdec.converted_imgfmt field.
Likewise, gl_hwdec.gl_texture_target is replaced with
gl_hwdec_plane.gl_target.
Split out a init_image_desc function from init_format. The latter is not
called in the hwdec case at all anymore. Setting up most of struct
texplane is also completely separate in the hwdec and normal cases.
video.c does not check whether the hwdec "mapped" image format is
supported. This should not really happen anyway, and if it does, the
hwdec interop backend must fail at creation time, so this is not an
issue.
2016-05-10 16:29:10 +00:00
|
|
|
out_frame->planes[i] = (struct gl_hwdec_plane){
|
|
|
|
.gl_texture = p->gl_planes[i],
|
|
|
|
.gl_target = gl_target,
|
|
|
|
.tex_w = IOSurfaceGetWidthOfPlane(surface, i),
|
|
|
|
.tex_h = IOSurfaceGetHeightOfPlane(surface, i),
|
|
|
|
};
|
2016-05-10 19:11:58 +00:00
|
|
|
snprintf(out_frame->planes[i].swizzle, sizeof(out_frame->planes[i].swizzle),
|
|
|
|
"%s", f->gl[i].swizzle);
|
2015-04-11 15:17:52 +00:00
|
|
|
}
|
2013-11-13 20:59:11 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy(struct gl_hwdec *hw)
|
|
|
|
{
|
|
|
|
struct priv *p = hw->priv;
|
2014-12-03 20:02:33 +00:00
|
|
|
GL *gl = hw->gl;
|
2013-11-13 20:59:11 +00:00
|
|
|
|
|
|
|
CVPixelBufferRelease(p->pbuf);
|
2015-04-11 15:17:52 +00:00
|
|
|
gl->DeleteTextures(MP_MAX_PLANES, p->gl_planes);
|
2016-05-09 17:42:03 +00:00
|
|
|
|
|
|
|
hwdec_devices_remove(hw->devs, &p->hwctx);
|
2013-11-13 20:59:11 +00:00
|
|
|
}
|
|
|
|
|
2015-07-11 15:21:39 +00:00
|
|
|
const struct gl_hwdec_driver gl_hwdec_videotoolbox = {
|
2016-02-01 19:02:52 +00:00
|
|
|
.name = "videotoolbox",
|
|
|
|
.api = HWDEC_VIDEOTOOLBOX,
|
2015-07-11 15:21:39 +00:00
|
|
|
.imgfmt = IMGFMT_VIDEOTOOLBOX,
|
2015-08-17 21:49:07 +00:00
|
|
|
.create = create,
|
2015-07-11 15:21:39 +00:00
|
|
|
.reinit = reinit,
|
vo_opengl: refactor how hwdec interop exports textures
Rename gl_hwdec_driver.map_image to map_frame, and let it fill out a
struct gl_hwdec_frame describing the exact texture layout. This gives
more flexibility to what the hwdec interop can export. In particular, it
can export strange component orders/permutations and textures with
padded size. (The latter originating from cropped video.)
The way gl_hwdec_frame works is in the spirit of the rest of the
vo_opengl video processing code, which tends to put as much information
in immediate state (as part of the dataflow), instead of declaring it
globally. To some degree this duplicates the texplane and img_tex
structs, but until we somehow unify those, it's better to give the hwdec
state its own struct. The fact that changing the hwdec struct would
require changes and testing on at least 4 platform/GPU combinations
makes duplicating it almost a requirement to avoid pain later.
Make gl_hwdec_driver.reinit set the new image format and remove the
gl_hwdec.converted_imgfmt field.
Likewise, gl_hwdec.gl_texture_target is replaced with
gl_hwdec_plane.gl_target.
Split out a init_image_desc function from init_format. The latter is not
called in the hwdec case at all anymore. Setting up most of struct
texplane is also completely separate in the hwdec and normal cases.
video.c does not check whether the hwdec "mapped" image format is
supported. This should not really happen anyway, and if it does, the
hwdec interop backend must fail at creation time, so this is not an
issue.
2016-05-10 16:29:10 +00:00
|
|
|
.map_frame = map_frame,
|
2015-07-11 15:21:39 +00:00
|
|
|
.destroy = destroy,
|
|
|
|
};
|