2016-09-12 13:08:38 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <bcm_host.h>
|
|
|
|
#include <interface/mmal/mmal.h>
|
|
|
|
#include <interface/mmal/util/mmal_util.h>
|
|
|
|
#include <interface/mmal/util/mmal_default_components.h>
|
|
|
|
#include <interface/mmal/vc/mmal_vc_api.h>
|
|
|
|
|
|
|
|
#include <libavutil/rational.h>
|
|
|
|
|
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/msg.h"
|
|
|
|
#include "video/mp_image.h"
|
vo_opengl: refactor into vo_gpu
This is done in several steps:
1. refactor MPGLContext -> struct ra_ctx
2. move GL-specific stuff in vo_opengl into opengl/context.c
3. generalize context creation to support other APIs, and add --gpu-api
4. rename all of the --opengl- options that are no longer opengl-specific
5. move all of the stuff from opengl/* that isn't GL-specific into gpu/
(note: opengl/gl_utils.h became opengl/utils.h)
6. rename vo_opengl to vo_gpu
7. to handle window screenshots, the short-term approach was to just add
it to ra_swchain_fns. Long term (and for vulkan) this has to be moved to
ra itself (and vo_gpu altered to compensate), but this was a stop-gap
measure to prevent this commit from getting too big
8. move ra->fns->flush to ra_gl_ctx instead
9. some other minor changes that I've probably already forgotten
Note: This is one half of a major refactor, the other half of which is
provided by rossy's following commit. This commit enables support for
all linux platforms, while his version enables support for all non-linux
platforms.
Note 2: vo_opengl_cb.c also re-uses ra_gl_ctx so it benefits from the
--opengl- options like --opengl-early-flush, --opengl-finish etc. Should
be a strict superset of the old functionality.
Disclaimer: Since I have no way of compiling mpv on all platforms, some
of these ports were done blindly. Specifically, the blind ports included
context_mali_fbdev.c and context_rpi.c. Since they're both based on
egl_helpers, the port should have gone smoothly without any major
changes required. But if somebody complains about a compile error on
those platforms (assuming anybody actually uses them), you know where to
complain.
2017-09-14 06:04:55 +00:00
|
|
|
#include "video/out/gpu/hwdec.h"
|
2016-09-12 13:08:38 +00:00
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
struct priv {
|
|
|
|
struct mp_log *log;
|
|
|
|
|
|
|
|
struct mp_image_params params;
|
|
|
|
|
|
|
|
MMAL_COMPONENT_T *renderer;
|
|
|
|
bool renderer_enabled;
|
|
|
|
|
|
|
|
// for RAM input
|
|
|
|
MMAL_POOL_T *swpool;
|
|
|
|
|
|
|
|
struct mp_image *current_frame;
|
|
|
|
|
|
|
|
struct mp_rect src, dst;
|
|
|
|
int cur_window[4]; // raw user params
|
|
|
|
};
|
|
|
|
|
|
|
|
// Magic alignments (in pixels) expected by the MMAL internals.
|
|
|
|
#define ALIGN_W 32
|
|
|
|
#define ALIGN_H 16
|
|
|
|
|
|
|
|
// Make mpi point to buffer, assuming MMAL_ENCODING_I420.
|
|
|
|
// buffer can be NULL.
|
|
|
|
// Return the required buffer space.
|
|
|
|
static size_t layout_buffer(struct mp_image *mpi, MMAL_BUFFER_HEADER_T *buffer,
|
|
|
|
struct mp_image_params *params)
|
|
|
|
{
|
|
|
|
assert(params->imgfmt == IMGFMT_420P);
|
|
|
|
mp_image_set_params(mpi, params);
|
|
|
|
int w = MP_ALIGN_UP(params->w, ALIGN_W);
|
|
|
|
int h = MP_ALIGN_UP(params->h, ALIGN_H);
|
|
|
|
uint8_t *cur = buffer ? buffer->data : NULL;
|
|
|
|
size_t size = 0;
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
int div = i ? 2 : 1;
|
|
|
|
mpi->planes[i] = cur;
|
|
|
|
mpi->stride[i] = w / div;
|
|
|
|
size_t plane_size = h / div * mpi->stride[i];
|
|
|
|
if (cur)
|
|
|
|
cur += plane_size;
|
|
|
|
size += plane_size;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MMAL_FOURCC_T map_csp(enum mp_csp csp)
|
|
|
|
{
|
|
|
|
switch (csp) {
|
|
|
|
case MP_CSP_BT_601: return MMAL_COLOR_SPACE_ITUR_BT601;
|
|
|
|
case MP_CSP_BT_709: return MMAL_COLOR_SPACE_ITUR_BT709;
|
|
|
|
case MP_CSP_SMPTE_240M: return MMAL_COLOR_SPACE_SMPTE240M;
|
|
|
|
default: return MMAL_COLOR_SPACE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void control_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
|
|
|
|
{
|
|
|
|
mmal_buffer_header_release(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void input_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
|
|
|
|
{
|
|
|
|
struct mp_image *mpi = buffer->user_data;
|
|
|
|
talloc_free(mpi);
|
|
|
|
}
|
|
|
|
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
static void disable_renderer(struct ra_hwdec *hw)
|
2016-09-12 13:08:38 +00:00
|
|
|
{
|
|
|
|
struct priv *p = hw->priv;
|
|
|
|
|
|
|
|
if (p->renderer_enabled) {
|
|
|
|
mmal_port_disable(p->renderer->control);
|
|
|
|
mmal_port_disable(p->renderer->input[0]);
|
|
|
|
|
|
|
|
mmal_port_flush(p->renderer->control);
|
|
|
|
mmal_port_flush(p->renderer->input[0]);
|
|
|
|
|
|
|
|
mmal_component_disable(p->renderer);
|
|
|
|
}
|
|
|
|
mmal_pool_destroy(p->swpool);
|
|
|
|
p->swpool = NULL;
|
|
|
|
p->renderer_enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check_window_only: assume params and dst/src rc are unchanged
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
static void update_overlay(struct ra_hwdec *hw, bool check_window_only)
|
2016-09-12 13:08:38 +00:00
|
|
|
{
|
|
|
|
struct priv *p = hw->priv;
|
|
|
|
MMAL_PORT_T *input = p->renderer->input[0];
|
|
|
|
struct mp_rect src = p->src;
|
|
|
|
struct mp_rect dst = p->dst;
|
|
|
|
|
|
|
|
int defs[4] = {0, 0, 0, 0};
|
client API: add a new way to pass X11 Display etc. to render API
Hardware decoding things often need access to additional handles from
the windowing system, such as the X11 or Wayland display when using
vaapi. The opengl-cb had nothing dedicated for this, and used the weird
GL_MP_MPGetNativeDisplay GL extension (which was mpv specific and not
officially registered with OpenGL).
This was awkward, and a pain due to having to emulate GL context
behavior (like needing a TLS variable to store context for the pseudo GL
extension function). In addition (and not inherently due to this), we
could pass only one resource from mpv builtin context backends to
hwdecs. It was also all GL specific.
Replace this with a newer mechanism. It works for all RA backends, not
just GL. the API user can explicitly pass the objects at init time via
mpv_render_context_create(). Multiple resources are naturally possible.
The API uses MPV_RENDER_PARAM_* defines, but internally we use strings.
This is done for 2 reasons: 1. trying to leave libmpv and internal
mechanisms decoupled, 2. not having to add public API for some of the
internal resource types (especially D3D/GL interop stuff).
To remain sane, drop support for obscure half-working opengl-cb things,
like the DRM interop (was missing necessary things), the RPI window
thing (nobody used it), and obscure D3D interop things (not needed with
ANGLE, others were undocumented). In order not to break ABI and the C
API, we don't remove the associated structs from opengl_cb.h.
The parts which are still needed (in particular DRM interop) needs to be
ported to the render API.
2018-03-22 16:05:01 +00:00
|
|
|
int *z = ra_get_native_resource(hw->ra, "MPV_RPI_WINDOW");
|
2016-10-04 14:36:20 +00:00
|
|
|
if (!z)
|
|
|
|
z = defs;
|
2016-09-12 13:08:38 +00:00
|
|
|
|
|
|
|
// As documented in the libmpv openglcb headers.
|
|
|
|
int display = z[0];
|
|
|
|
int layer = z[1];
|
|
|
|
int x = z[2];
|
|
|
|
int y = z[3];
|
|
|
|
|
|
|
|
if (check_window_only && memcmp(z, p->cur_window, sizeof(p->cur_window)) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memcpy(p->cur_window, z, sizeof(p->cur_window));
|
|
|
|
|
|
|
|
int rotate[] = {MMAL_DISPLAY_ROT0,
|
|
|
|
MMAL_DISPLAY_ROT90,
|
|
|
|
MMAL_DISPLAY_ROT180,
|
|
|
|
MMAL_DISPLAY_ROT270};
|
|
|
|
|
|
|
|
int src_w = src.x1 - src.x0, src_h = src.y1 - src.y0,
|
|
|
|
dst_w = dst.x1 - dst.x0, dst_h = dst.y1 - dst.y0;
|
|
|
|
int p_x, p_y;
|
|
|
|
av_reduce(&p_x, &p_y, dst_w * src_h, src_w * dst_h, 16000);
|
|
|
|
MMAL_DISPLAYREGION_T dr = {
|
|
|
|
.hdr = { .id = MMAL_PARAMETER_DISPLAYREGION,
|
|
|
|
.size = sizeof(MMAL_DISPLAYREGION_T), },
|
|
|
|
.src_rect = { .x = src.x0, .y = src.y0,
|
|
|
|
.width = src_w, .height = src_h },
|
|
|
|
.dest_rect = { .x = dst.x0 + x, .y = dst.y0 + y,
|
|
|
|
.width = dst_w, .height = dst_h },
|
|
|
|
.layer = layer - 1, // under the GL layer
|
|
|
|
.display_num = display,
|
|
|
|
.pixel_x = p_x,
|
|
|
|
.pixel_y = p_y,
|
|
|
|
.transform = rotate[p->params.rotate / 90],
|
|
|
|
.fullscreen = 0,
|
|
|
|
.set = MMAL_DISPLAY_SET_SRC_RECT | MMAL_DISPLAY_SET_DEST_RECT |
|
|
|
|
MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_NUM |
|
|
|
|
MMAL_DISPLAY_SET_PIXEL | MMAL_DISPLAY_SET_TRANSFORM |
|
|
|
|
MMAL_DISPLAY_SET_FULLSCREEN,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (p->params.rotate % 180 == 90) {
|
|
|
|
MPSWAP(int, dr.src_rect.x, dr.src_rect.y);
|
|
|
|
MPSWAP(int, dr.src_rect.width, dr.src_rect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mmal_port_parameter_set(input, &dr.hdr))
|
|
|
|
MP_WARN(p, "could not set video rectangle\n");
|
|
|
|
}
|
|
|
|
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
static int enable_renderer(struct ra_hwdec *hw)
|
2016-09-12 13:08:38 +00:00
|
|
|
{
|
|
|
|
struct priv *p = hw->priv;
|
|
|
|
MMAL_PORT_T *input = p->renderer->input[0];
|
|
|
|
struct mp_image_params *params = &p->params;
|
|
|
|
|
|
|
|
if (p->renderer_enabled)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!params->imgfmt)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
bool opaque = params->imgfmt == IMGFMT_MMAL;
|
|
|
|
|
|
|
|
input->format->encoding = opaque ? MMAL_ENCODING_OPAQUE : MMAL_ENCODING_I420;
|
|
|
|
input->format->es->video.width = MP_ALIGN_UP(params->w, ALIGN_W);
|
|
|
|
input->format->es->video.height = MP_ALIGN_UP(params->h, ALIGN_H);
|
|
|
|
input->format->es->video.crop = (MMAL_RECT_T){0, 0, params->w, params->h};
|
|
|
|
input->format->es->video.par = (MMAL_RATIONAL_T){params->p_w, params->p_h};
|
|
|
|
input->format->es->video.color_space = map_csp(params->color.space);
|
|
|
|
|
|
|
|
if (mmal_port_format_commit(input))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
input->buffer_num = MPMAX(input->buffer_num_min,
|
|
|
|
input->buffer_num_recommended) + 3;
|
|
|
|
input->buffer_size = MPMAX(input->buffer_size_min,
|
|
|
|
input->buffer_size_recommended);
|
|
|
|
|
|
|
|
if (!opaque) {
|
|
|
|
size_t size = layout_buffer(&(struct mp_image){0}, NULL, params);
|
|
|
|
if (input->buffer_size != size) {
|
|
|
|
MP_FATAL(hw, "We disagree with MMAL about buffer sizes.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->swpool = mmal_pool_create(input->buffer_num, input->buffer_size);
|
|
|
|
if (!p->swpool) {
|
|
|
|
MP_FATAL(hw, "Could not allocate buffer pool.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update_overlay(hw, false);
|
|
|
|
|
|
|
|
p->renderer_enabled = true;
|
|
|
|
|
|
|
|
if (mmal_port_enable(p->renderer->control, control_port_cb))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (mmal_port_enable(input, input_port_cb))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (mmal_component_enable(p->renderer)) {
|
|
|
|
MP_FATAL(hw, "Failed to enable video renderer.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_mmal_buffer(void *arg)
|
|
|
|
{
|
|
|
|
MMAL_BUFFER_HEADER_T *buffer = arg;
|
|
|
|
mmal_buffer_header_release(buffer);
|
|
|
|
}
|
|
|
|
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
static struct mp_image *upload(struct ra_hwdec *hw, struct mp_image *hw_image)
|
2016-09-12 13:08:38 +00:00
|
|
|
{
|
|
|
|
struct priv *p = hw->priv;
|
|
|
|
|
|
|
|
MMAL_BUFFER_HEADER_T *buffer = mmal_queue_wait(p->swpool->queue);
|
|
|
|
if (!buffer) {
|
|
|
|
MP_ERR(hw, "Can't allocate buffer.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
mmal_buffer_header_reset(buffer);
|
|
|
|
|
|
|
|
struct mp_image *new_ref = mp_image_new_custom_ref(NULL, buffer,
|
|
|
|
free_mmal_buffer);
|
|
|
|
if (!new_ref) {
|
|
|
|
mmal_buffer_header_release(buffer);
|
|
|
|
MP_ERR(hw, "Out of memory.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_image_setfmt(new_ref, IMGFMT_MMAL);
|
|
|
|
new_ref->planes[3] = (void *)buffer;
|
|
|
|
|
|
|
|
struct mp_image dmpi = {0};
|
|
|
|
buffer->length = layout_buffer(&dmpi, buffer, &p->params);
|
|
|
|
mp_image_copy(&dmpi, hw_image);
|
|
|
|
|
|
|
|
return new_ref;
|
|
|
|
}
|
|
|
|
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
static int overlay_frame(struct ra_hwdec *hw, struct mp_image *hw_image,
|
2017-08-09 18:57:37 +00:00
|
|
|
struct mp_rect *src, struct mp_rect *dst, bool newframe)
|
2016-09-12 13:08:38 +00:00
|
|
|
{
|
|
|
|
struct priv *p = hw->priv;
|
|
|
|
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
if (hw_image && !mp_image_params_equal(&p->params, &hw_image->params)) {
|
2017-08-11 11:02:13 +00:00
|
|
|
p->params = hw_image->params;
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
|
|
|
|
disable_renderer(hw);
|
|
|
|
mp_image_unrefp(&p->current_frame);
|
|
|
|
|
|
|
|
if (enable_renderer(hw) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-08-09 18:57:37 +00:00
|
|
|
if (hw_image && p->current_frame && !newframe) {
|
|
|
|
if (!mp_rect_equals(&p->src, src) ||mp_rect_equals(&p->dst, dst)) {
|
|
|
|
p->src = *src;
|
|
|
|
p->dst = *dst;
|
|
|
|
update_overlay(hw, false);
|
|
|
|
}
|
2017-08-11 11:02:13 +00:00
|
|
|
return 0; // don't reupload
|
2017-08-09 18:57:37 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 13:08:38 +00:00
|
|
|
mp_image_unrefp(&p->current_frame);
|
|
|
|
|
|
|
|
if (!hw_image) {
|
|
|
|
disable_renderer(hw);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enable_renderer(hw) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
update_overlay(hw, true);
|
|
|
|
|
2016-09-30 11:53:12 +00:00
|
|
|
struct mp_image *mpi = NULL;
|
|
|
|
if (hw_image->imgfmt == IMGFMT_MMAL) {
|
|
|
|
mpi = mp_image_new_ref(hw_image);
|
|
|
|
} else {
|
2016-09-12 13:08:38 +00:00
|
|
|
mpi = upload(hw, hw_image);
|
2016-09-30 11:53:12 +00:00
|
|
|
}
|
2016-09-12 13:08:38 +00:00
|
|
|
|
|
|
|
if (!mpi) {
|
|
|
|
disable_renderer(hw);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
MMAL_BUFFER_HEADER_T *ref = (void *)mpi->planes[3];
|
|
|
|
|
|
|
|
// Assume this field is free for use by us.
|
|
|
|
ref->user_data = mpi;
|
|
|
|
|
|
|
|
if (mmal_port_send_buffer(p->renderer->input[0], ref)) {
|
|
|
|
MP_ERR(hw, "could not queue picture!\n");
|
|
|
|
talloc_free(mpi);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
static void destroy(struct ra_hwdec *hw)
|
2016-09-12 13:08:38 +00:00
|
|
|
{
|
|
|
|
struct priv *p = hw->priv;
|
|
|
|
|
|
|
|
disable_renderer(hw);
|
|
|
|
|
|
|
|
if (p->renderer)
|
|
|
|
mmal_component_release(p->renderer);
|
|
|
|
|
|
|
|
mmal_vc_deinit();
|
|
|
|
}
|
|
|
|
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
static int create(struct ra_hwdec *hw)
|
2016-09-12 13:08:38 +00:00
|
|
|
{
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
struct priv *p = hw->priv;
|
2016-09-12 13:08:38 +00:00
|
|
|
p->log = hw->log;
|
|
|
|
|
|
|
|
bcm_host_init();
|
|
|
|
|
|
|
|
if (mmal_vc_init()) {
|
|
|
|
MP_FATAL(hw, "Could not initialize MMAL.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mmal_component_create(MMAL_COMPONENT_DEFAULT_VIDEO_RENDERER, &p->renderer))
|
|
|
|
{
|
|
|
|
MP_FATAL(hw, "Could not create MMAL renderer.\n");
|
|
|
|
mmal_vc_deinit();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
const struct ra_hwdec_driver ra_hwdec_rpi_overlay = {
|
2016-09-12 13:08:38 +00:00
|
|
|
.name = "rpi-overlay",
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
.priv_size = sizeof(struct priv),
|
|
|
|
.imgfmts = {IMGFMT_MMAL, IMGFMT_420P, 0},
|
|
|
|
.init = create,
|
2016-09-12 13:08:38 +00:00
|
|
|
.overlay_frame = overlay_frame,
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
.uninit = destroy,
|
2016-09-12 13:08:38 +00:00
|
|
|
};
|