summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/hwdec.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-08-10 17:48:33 +0200
committerwm4 <wm4@nowhere>2017-08-10 21:24:31 +0200
commitc6fafbffaca16959dfa2b4bf1eb97861ad66b5ef (patch)
treedecef889171128c27f3a8cb2fcfb552f1b7297be /video/out/opengl/hwdec.h
parentb2fb3f1340ed7ceb9b3fc8ba4ddec107e3a41a13 (diff)
downloadmpv-c6fafbffaca16959dfa2b4bf1eb97861ad66b5ef.tar.bz2
mpv-c6fafbffaca16959dfa2b4bf1eb97861ad66b5ef.tar.xz
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.)
Diffstat (limited to 'video/out/opengl/hwdec.h')
-rw-r--r--video/out/opengl/hwdec.h122
1 files changed, 77 insertions, 45 deletions
diff --git a/video/out/opengl/hwdec.h b/video/out/opengl/hwdec.h
index 6d4dc5d591..f978b70018 100644
--- a/video/out/opengl/hwdec.h
+++ b/video/out/opengl/hwdec.h
@@ -2,13 +2,14 @@
#define MPGL_HWDEC_H_
#include "common.h"
+#include "ra.h"
#include "video/hwdec.h"
-struct gl_hwdec {
- const struct gl_hwdec_driver *driver;
+struct ra_hwdec {
+ const struct ra_hwdec_driver *driver;
struct mp_log *log;
struct mpv_global *global;
- GL *gl;
+ struct ra *ra;
struct mp_hwdec_devices *devs;
// GLSL extensions required to sample textures from this.
const char **glsl_extensions;
@@ -20,79 +21,110 @@ struct gl_hwdec {
float overlay_colorkey[4];
};
-struct gl_hwdec_plane {
- GLuint gl_texture;
- GLenum gl_target;
- // Like struct gl_format.format (GL_RED etc.). Currently to detect
- // GL_LUMINANCE_ALPHA and integer formats - can be left to 0 otherwise.
- GLenum gl_format;
- int tex_w, tex_h; // allocated texture size
-};
+struct ra_hwdec_mapper {
+ const struct ra_hwdec_mapper_driver *driver;
+ struct mp_log *log;
+ struct ra *ra;
+ void *priv;
+ struct ra_hwdec *owner;
+ // Input frame parameters. (Set before init(), immutable.)
+ struct mp_image_params src_params;
+ // Output frame parameters (represents the format the textures return). Must
+ // be set by init(), immutable afterwards,
+ struct mp_image_params dst_params;
+
+ // The currently mapped source image (or the image about to be mapped in
+ // ->map()). NULL if unmapped. The mapper can also clear this reference if
+ // the mapped textures contain a full copy.
+ struct mp_image *src;
-struct gl_hwdec_frame {
- struct gl_hwdec_plane planes[4];
+ // The mapped textures and metadata about them. These fields change if a
+ // new frame is mapped (or unmapped), but otherwise remain constant.
+ // The common code won't mess with these, so you can e.g. set them in the
+ // .init() callback.
+ struct ra_tex *tex[4];
bool vdpau_fields;
};
-struct gl_hwdec_driver {
+// This can be used to map frames of a specific hw format as GL textures.
+struct ra_hwdec_mapper_driver {
+ // Used to create ra_hwdec_mapper.priv.
+ size_t priv_size;
+
+ // Init the mapper implementation. At this point, the field src_params,
+ // fns, devs, priv are initialized.
+ int (*init)(struct ra_hwdec_mapper *mapper);
+ // Destroy the mapper. unmap is called before this.
+ void (*uninit)(struct ra_hwdec_mapper *mapper);
+
+ // Map mapper->src as texture, and set mapper->frame to textures using it.
+ // It is expected that that the textures remain valid until the next unmap
+ // or uninit call.
+ // The function is allowed to unref mapper->src if it's not needed (i.e.
+ // this function creates a copy).
+ // The underlying format can change, so you might need to do some form
+ // of change detection. You also must reject unsupported formats with an
+ // error.
+ // On error, returns negative value on error and remains unmapped.
+ int (*map)(struct ra_hwdec_mapper *mapper);
+ // Unmap the frame. Does nothing if already unmapped. Optional.
+ void (*unmap)(struct ra_hwdec_mapper *mapper);
+};
+
+struct ra_hwdec_driver {
// Name of the interop backend. This is used for informational purposes only.
const char *name;
+ // Used to create ra_hwdec.priv.
+ size_t priv_size;
// Used to explicitly request a specific API.
enum hwdec_type api;
- // The hardware surface IMGFMT_ that must be passed to map_image later.
- // If the test_format callback is set, this field is ignored!
- int imgfmt;
+ // One of the hardware surface IMGFMT_ that must be passed to map_image later.
+ // Terminated with a 0 entry. (Extend the array size as needed.)
+ const int imgfmts[3];
// Dosn't load this unless requested by name.
bool testing_only;
+
// Create the hwdec device. It must add it to hw->devs, if applicable.
- int (*create)(struct gl_hwdec *hw);
- // Prepare for rendering video. (E.g. create textures.)
- // Called on initialization, and every time the video size changes.
- // *params must be set to the format the hw textures return.
- int (*reinit)(struct gl_hwdec *hw, struct mp_image_params *params);
- // Return textures that contain a copy or reference of the given hw_image.
- // The textures mirror the format returned by the reinit params argument.
- // The textures must remain valid until unmap is called.
- // hw_image remains referenced by the caller until unmap is called.
- int (*map_frame)(struct gl_hwdec *hw, struct mp_image *hw_image,
- struct gl_hwdec_frame *out_frame);
- // Must be idempotent.
- void (*unmap)(struct gl_hwdec *hw);
-
- void (*destroy)(struct gl_hwdec *hw);
-
- // Optional callback for checking input format support.
- bool (*test_format)(struct gl_hwdec *hw, int imgfmt);
-
- // The following functions provide an alternative API. Each gl_hwdec_driver
- // must have either map_frame or overlay_frame set (not both or none), and
+ int (*init)(struct ra_hwdec *hw);
+ void (*uninit)(struct ra_hwdec *hw);
+
+ // This will be used to create a ra_hwdec_mapper from ra_hwdec.
+ const struct ra_hwdec_mapper_driver *mapper;
+
+ // The following function provides an alternative API. Each ra_hwdec_driver
+ // must have either provide a mapper or overlay_frame (not both or none), and
// if overlay_frame is set, it operates in overlay mode. In this mode,
// OSD etc. is rendered via OpenGL, but the video is rendered as a separate
// layer below it.
// Non-overlay mode is strictly preferred, so try not to use overlay mode.
-
// Set the given frame as overlay, replacing the previous one. This can also
// just change the position of the overlay.
// hw_image==src==dst==NULL is passed to clear the overlay.
- int (*overlay_frame)(struct gl_hwdec *hw, struct mp_image *hw_image,
+ int (*overlay_frame)(struct ra_hwdec *hw, struct mp_image *hw_image,
struct mp_rect *src, struct mp_rect *dst, bool newframe);
};
-struct gl_hwdec *gl_hwdec_load_api(struct mp_log *log, GL *gl,
+struct ra_hwdec *ra_hwdec_load_api(struct mp_log *log, struct ra *ra,
struct mpv_global *g,
struct mp_hwdec_devices *devs,
enum hwdec_type api);
-struct gl_hwdec *gl_hwdec_load(struct mp_log *log, GL *gl,
+struct ra_hwdec *ra_hwdec_load(struct mp_log *log, struct ra *ra,
struct mpv_global *g,
struct mp_hwdec_devices *devs,
const char *name);
-int gl_hwdec_validate_opt(struct mp_log *log, const m_option_t *opt,
+int ra_hwdec_validate_opt(struct mp_log *log, const m_option_t *opt,
struct bstr name, struct bstr param);
-void gl_hwdec_uninit(struct gl_hwdec *hwdec);
+void ra_hwdec_uninit(struct ra_hwdec *hwdec);
+
+bool ra_hwdec_test_format(struct ra_hwdec *hwdec, int imgfmt);
-bool gl_hwdec_test_format(struct gl_hwdec *hwdec, int imgfmt);
+struct ra_hwdec_mapper *ra_hwdec_mapper_create(struct ra_hwdec *hwdec,
+ struct mp_image_params *params);
+void ra_hwdec_mapper_free(struct ra_hwdec_mapper **mapper);
+void ra_hwdec_mapper_unmap(struct ra_hwdec_mapper *mapper);
+int ra_hwdec_mapper_map(struct ra_hwdec_mapper *mapper, struct mp_image *img);
#endif