summarylogtreecommitdiffstats
path: root/0008-Update-to-libmpv-API-2.0.patch
blob: 0d9702a806dc0420126d6b5e2ce812b712c1ef8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
From dc2f2f0c94d59d860dd66a65129deb7eea85c4e5 Mon Sep 17 00:00:00 2001
From: Mia Herkt <mia@0x0.st>
Date: Wed, 14 Dec 2022 23:51:38 +0100
Subject: [PATCH 8/9] Update to libmpv API 2.0

---
 client.pxd |  47 ++++-----------------
 mpv.pyx    | 119 ++++-------------------------------------------------
 2 files changed, 16 insertions(+), 150 deletions(-)

diff --git a/client.pxd b/client.pxd
index befe219..08fb4d0 100644
--- a/client.pxd
+++ b/client.pxd
@@ -106,16 +106,10 @@ cdef extern from "mpv/client.h":
 
     int mpv_initialize(mpv_handle *ctx) nogil
 
-    void mpv_detach_destroy(mpv_handle *ctx) nogil
-
     void mpv_terminate_destroy(mpv_handle *ctx) nogil
 
     int mpv_load_config_file(mpv_handle *ctx, const char *filename) nogil
 
-    void mpv_suspend(mpv_handle *ctx) nogil
-
-    void mpv_resume(mpv_handle *ctx) nogil
-
     int64_t mpv_get_time_us(mpv_handle *ctx) nogil
 
     cdef enum mpv_format:
@@ -200,21 +194,14 @@ cdef extern from "mpv/client.h":
         MPV_EVENT_START_FILE
         MPV_EVENT_END_FILE
         MPV_EVENT_FILE_LOADED
-        MPV_EVENT_TRACKS_CHANGED
-        MPV_EVENT_TRACK_SWITCHED
         MPV_EVENT_IDLE
-        MPV_EVENT_PAUSE
-        MPV_EVENT_UNPAUSE
         MPV_EVENT_TICK
-        MPV_EVENT_SCRIPT_INPUT_DISPATCH
         MPV_EVENT_CLIENT_MESSAGE
         MPV_EVENT_VIDEO_RECONFIG
         MPV_EVENT_AUDIO_RECONFIG
-        MPV_EVENT_METADATA_UPDATE
         MPV_EVENT_SEEK
         MPV_EVENT_PLAYBACK_RESTART
         MPV_EVENT_PROPERTY_CHANGE
-        MPV_EVENT_CHAPTER_CHANGE
 
     const char *mpv_event_name(mpv_event_id event) nogil
 
@@ -282,29 +269,6 @@ cdef extern from "mpv/client.h":
 
     void *mpv_get_sub_api(mpv_handle *ctx, mpv_sub_api sub_api) nogil
 
-cdef extern from "mpv/opengl_cb.h":
-    struct mpv_opengl_cb_context:
-        pass
-
-    ctypedef void (*mpv_opengl_cb_update_fn)(void *cb_ctx) nogil
-    ctypedef void *(*mpv_opengl_cb_get_proc_address_fn)(void *fn_ctx,
-                                                        const char *name) nogil
-
-    void mpv_opengl_cb_set_update_callback(mpv_opengl_cb_context *ctx,
-                                           mpv_opengl_cb_update_fn callback,
-                                           void *callback_ctx) nogil
-
-    int mpv_opengl_cb_init_gl(mpv_opengl_cb_context *ctx, const char *exts,
-                              mpv_opengl_cb_get_proc_address_fn get_proc_address,
-                              void *get_proc_address_ctx) nogil
-
-    int mpv_opengl_cb_draw(mpv_opengl_cb_context *ctx, int fbo, int w, int h) nogil
-
-    int mpv_opengl_cb_report_flip(mpv_opengl_cb_context *ctx, int64_t time) nogil
-
-    int mpv_opengl_cb_uninit_gl(mpv_opengl_cb_context *ctx) nogil
-
-
 cdef extern from "mpv/render.h":
     struct mpv_render_context:
         pass
@@ -325,9 +289,15 @@ cdef extern from "mpv/render.h":
         MPV_RENDER_PARAM_BLOCK_FOR_TARGET_TIME
         MPV_RENDER_PARAM_SKIP_RENDERING
         MPV_RENDER_PARAM_DRM_DISPLAY
-        MPV_RENDER_PARAM_DRM_OSD_SIZE
+        MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE
+        MPV_RENDER_PARAM_DRM_DISPLAY_V2
+        MPV_RENDER_PARAM_SW_SIZE
+        MPV_RENDER_PARAM_SW_FORMAT
+        MPV_RENDER_PARAM_SW_STRIDE
+        MPV_RENDER_PARAM_SW_POINTER
 
     char *MPV_RENDER_API_TYPE_OPENGL
+    char *MPV_RENDER_API_TYPE_SW
 
     enum mpv_render_frame_info_flag:
         MPV_RENDER_FRAME_INFO_PRESENT
@@ -373,7 +343,6 @@ cdef extern from "mpv/render_gl.h":
     struct mpv_opengl_init_params:
         void *(*get_proc_address)(void *ctx, const char *name)
         void *get_proc_address_ctx
-        const char *extra_exts
 
     struct mpv_opengl_fbo:
         int fbo
@@ -391,6 +360,6 @@ cdef extern from "mpv/render_gl.h":
         _drmModeAtomicReq **atomic_request_ptr
         int render_fd
 
-    struct mpv_opengl_drm_osd_size:
+    struct mpv_opengl_drm_draw_surface_size:
         int width
         int height
diff --git a/mpv.pyx b/mpv.pyx
index 604a088..dd4f6c1 100644
--- a/mpv.pyx
+++ b/mpv.pyx
@@ -32,8 +32,8 @@ from client cimport *
 __version__ = "0.3.0"
 __author__ = "Andre D"
 
-_REQUIRED_CAPI_MAJOR = 1
-_MIN_CAPI_MINOR = 9
+_REQUIRED_CAPI_MAJOR = 2
+_MIN_CAPI_MINOR = 0
 
 cdef unsigned long _CAPI_VERSION
 with nogil:
@@ -107,21 +107,14 @@ class Events:
     start_file = MPV_EVENT_START_FILE
     end_file = MPV_EVENT_END_FILE
     file_loaded = MPV_EVENT_FILE_LOADED
-    tracks_changed = MPV_EVENT_TRACKS_CHANGED
-    tracks_switched = MPV_EVENT_TRACK_SWITCHED
     idle = MPV_EVENT_IDLE
-    pause = MPV_EVENT_PAUSE
-    unpause = MPV_EVENT_UNPAUSE
     tick = MPV_EVENT_TICK
-    script_input_dispatch = MPV_EVENT_SCRIPT_INPUT_DISPATCH
     client_message = MPV_EVENT_CLIENT_MESSAGE
     video_reconfig = MPV_EVENT_VIDEO_RECONFIG
     audio_reconfig = MPV_EVENT_AUDIO_RECONFIG
-    metadata_update = MPV_EVENT_METADATA_UPDATE
     seek = MPV_EVENT_SEEK
     playback_restart = MPV_EVENT_PLAYBACK_RESTART
     property_change = MPV_EVENT_PROPERTY_CHANGE
-    chapter_change = MPV_EVENT_CHAPTER_CHANGE
 
 
 class LogLevels:
@@ -159,19 +152,6 @@ cdef class EndOfFileReached(object):
         return self
 
 
-cdef class InputDispatch(object):
-    """Data field for MPV_EVENT_SCRIPT_INPUT_DISPATCH events.
-
-    Wraps: mpv_event_script_input_dispatch
-    """
-    cdef public object arg0, type
-
-    cdef _init(self, mpv_event_script_input_dispatch* input):
-        self.arg0 = input.arg0
-        self.type = _strdec(input.type)
-        return self
-
-
 cdef class LogMessage(object):
     """Data field for MPV_EVENT_LOG_MESSAGE events.
 
@@ -269,8 +249,6 @@ cdef class Event(object):
             return Property()._init(<mpv_event_property*>data)
         elif self.id == MPV_EVENT_LOG_MESSAGE:
             return LogMessage()._init(<mpv_event_log_message*>data)
-        elif self.id == MPV_EVENT_SCRIPT_INPUT_DISPATCH:
-            return InputDispatch()._init(<mpv_event_script_input_dispatch*>data)
         elif self.id == MPV_EVENT_CLIENT_MESSAGE:
             climsg = <mpv_event_client_message*>data
             args = []
@@ -385,18 +363,6 @@ cdef class Context(object):
             time = mpv_get_time_us(self._ctx)
         return time
 
-    def suspend(self):
-        """Wraps: mpv_suspend"""
-        assert self._ctx
-        with nogil:
-            mpv_suspend(self._ctx)
-
-    def resume(self):
-        """Wraps: mpv_resume"""
-        assert self._ctx
-        with nogil:
-            mpv_resume(self._ctx)
-
     @_errors
     def request_event(self, event, enable):
         """Enable or disable a given event.
@@ -787,18 +753,6 @@ cdef class Context(object):
         self.reply_userdata = None
         self._ctx = NULL
 
-    def opengl_cb_api(self):
-        cdef void *cb
-
-        _ctx = mpv_get_sub_api(self._ctx, MPV_SUB_API_OPENGL_CB)
-        if not _ctx:
-            raise MPVError("OpenGL API not available")
-
-        ctx = OpenGLContext()
-        ctx._ctx = <mpv_opengl_cb_context*>_ctx
-
-        return ctx
-
     def __dealloc__(self):
         self.shutdown()
 
@@ -808,63 +762,6 @@ cdef void *_c_getprocaddress(void *ctx, const char *name) with gil:
 cdef void _c_updatecb(void *ctx) with gil:
     (<object>ctx)()
 
-cdef class OpenGLContext(object):
-    cdef:
-        mpv_opengl_cb_context *_ctx
-        bint inited
-        object update_cb
-
-    def __init__(self):
-        self.inited = False
-        warnings.warn("OpenGLContext is deprecated, please switch to RenderContext", DeprecationWarning)
-
-    def init_gl(self, exts, get_proc_address):
-        exts = _strenc(exts) if exts is not None else None
-        cdef char* extsc = NULL
-        if exts is not None:
-            extsc = exts
-        with nogil:
-            err = mpv_opengl_cb_init_gl(self._ctx, extsc, &_c_getprocaddress,
-                                        <void *>get_proc_address)
-        if err < 0:
-            raise MPVError(err)
-
-        self.inited = True
-
-    def set_update_callback(self, cb):
-        self.update_cb = cb
-        with nogil:
-            mpv_opengl_cb_set_update_callback(self._ctx, &_c_updatecb, <void *>cb)
-
-    def draw(self, fbo, w, h):
-        cdef:
-            int fboc = fbo
-            int wc = w
-            int hc = h
-        with nogil:
-            err = mpv_opengl_cb_draw(self._ctx, fboc, wc, hc)
-        if err < 0:
-            raise MPVError(err)
-
-    def report_flip(self, time):
-        cdef int64_t ctime = time
-        with nogil:
-            err = mpv_opengl_cb_report_flip(self._ctx, ctime)
-        if err < 0:
-            raise MPVError(err)
-
-    def uninit_gl(self):
-        if not self.inited:
-            return
-        with nogil:
-            err = mpv_opengl_cb_uninit_gl(self._ctx)
-        if err < 0:
-            raise MPVError(err)
-        self.inited = False
-
-    def __dealloc__(self):
-        self.uninit_gl()
-
 DEF MAX_RENDER_PARAMS = 32
 
 cdef class _RenderParams(object):
@@ -943,19 +840,19 @@ cdef class RenderContext(object):
                  x11_display=None,
                  wl_display=None,
                  drm_display=None,
-                 drm_osd_size=None
+                 drm_draw_surface_size=None
                  ):
 
         cdef:
             mpv_opengl_init_params gl_params
             mpv_opengl_drm_params drm_params
-            mpv_opengl_drm_osd_size _drm_osd_size
+            mpv_opengl_drm_draw_surface_size _drm_draw_surface_size
 
         self._mpv = mpv
 
         memset(&gl_params, 0, sizeof(gl_params))
         memset(&drm_params, 0, sizeof(drm_params))
-        memset(&_drm_osd_size, 0, sizeof(_drm_osd_size))
+        memset(&_drm_draw_surface_size, 0, sizeof(_drm_draw_surface_size))
 
         params = _RenderParams()
 
@@ -986,9 +883,9 @@ cdef class RenderContext(object):
                 drm_params.atomic_request_ptr = <_drmModeAtomicReq **>get_pointer(arp, "drmModeAtomicReq*")
             drm_params.render_fd = drm_display.get("render_fd", -1)
             params.add_voidp(MPV_RENDER_PARAM_DRM_DISPLAY, &drm_params)
-        if drm_osd_size:
-            _drm_osd_size.width, _drm_osd_size.height = drm_osd_size
-            params.add_voidp(MPV_RENDER_PARAM_DRM_OSD_SIZE, &_drm_osd_size)
+        if drm_draw_surface_size:
+            _drm_draw_surface_size.width, _drm_draw_surface_size.height = drm_draw_surface_size
+            params.add_voidp(MPV_RENDER_PARAM_DRM_DRAW_SURFACE_SIZE, &_drm_draw_surface_size)
 
         err = mpv_render_context_create(&self._ctx, self._mpv._ctx, params.params)
         if err < 0:
-- 
2.40.1