0002-vaapi-Use-libva-message-callbacks.patch 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. From 2ecf240b1cd20875991a5b18efafbe799864ff7f Mon Sep 17 00:00:00 2001
  2. From: Mark Thompson <sw@jkqxz.net>
  3. Date: Mon, 9 Oct 2017 20:10:26 +0100
  4. Subject: vaapi: Use libva2 message callbacks
  5. They are no longer global, so they work vaguely sensibly.
  6. ---
  7. video/vaapi.c | 32 +++++++++++++++++++++++++++++---
  8. 1 file changed, 29 insertions(+), 3 deletions(-)
  9. diff --git a/video/vaapi.c b/video/vaapi.c
  10. index 6bedbbaa18..3b1cb9cc41 100644
  11. --- a/video/vaapi.c
  12. +++ b/video/vaapi.c
  13. @@ -40,9 +40,27 @@ int va_get_colorspace_flag(enum mp_csp csp)
  14. return 0;
  15. }
  16. -// VA message callbacks are global and do not have a context parameter, so it's
  17. -// impossible to know from which VADisplay they originate. Try to route them
  18. -// to existing mpv/libmpv instances within this process.
  19. +#if VA_CHECK_VERSION(1, 0, 0)
  20. +static void va_message_callback(void *context, const char *msg, int mp_level)
  21. +{
  22. + struct mp_vaapi_ctx *res = context;
  23. + mp_msg(res->log, mp_level, "libva: %s", msg);
  24. +}
  25. +
  26. +static void va_error_callback(void *context, const char *msg)
  27. +{
  28. + va_message_callback(context, msg, MSGL_ERR);
  29. +}
  30. +
  31. +static void va_info_callback(void *context, const char *msg)
  32. +{
  33. + va_message_callback(context, msg, MSGL_V);
  34. +}
  35. +#else
  36. +// Pre-libva2 VA message callbacks are global and do not have a context
  37. +// parameter, so it's impossible to know from which VADisplay they
  38. +// originate. Try to route them to existing mpv/libmpv instances within
  39. +// this process.
  40. static pthread_mutex_t va_log_mutex = PTHREAD_MUTEX_INITIALIZER;
  41. static struct mp_vaapi_ctx **va_mpv_clients;
  42. static int num_va_mpv_clients;
  43. @@ -77,6 +95,7 @@ static void va_info_callback(const char *msg)
  44. {
  45. va_message_callback(msg, MSGL_V);
  46. }
  47. +#endif
  48. static void open_lavu_vaapi_device(struct mp_vaapi_ctx *ctx)
  49. {
  50. @@ -108,6 +127,10 @@ struct mp_vaapi_ctx *va_initialize(VADisplay *display, struct mp_log *plog,
  51. },
  52. };
  53. +#if VA_CHECK_VERSION(1, 0, 0)
  54. + vaSetErrorCallback(display, va_error_callback, res);
  55. + vaSetInfoCallback(display, va_info_callback, res);
  56. +#else
  57. pthread_mutex_lock(&va_log_mutex);
  58. MP_TARRAY_APPEND(NULL, va_mpv_clients, num_va_mpv_clients, res);
  59. pthread_mutex_unlock(&va_log_mutex);
  60. @@ -117,6 +140,7 @@ struct mp_vaapi_ctx *va_initialize(VADisplay *display, struct mp_log *plog,
  61. #ifdef VA_FOURCC_I010
  62. vaSetErrorCallback(va_error_callback);
  63. vaSetInfoCallback(va_info_callback);
  64. +#endif
  65. #endif
  66. int major, minor;
  67. @@ -154,6 +178,7 @@ void va_destroy(struct mp_vaapi_ctx *ctx)
  68. if (ctx->destroy_native_ctx)
  69. ctx->destroy_native_ctx(ctx->native_ctx);
  70. +#if !VA_CHECK_VERSION(1, 0, 0)
  71. pthread_mutex_lock(&va_log_mutex);
  72. for (int n = 0; n < num_va_mpv_clients; n++) {
  73. if (va_mpv_clients[n] == ctx) {
  74. @@ -164,6 +189,7 @@ void va_destroy(struct mp_vaapi_ctx *ctx)
  75. if (num_va_mpv_clients == 0)
  76. TA_FREEP(&va_mpv_clients); // avoid triggering leak detectors
  77. pthread_mutex_unlock(&va_log_mutex);
  78. +#endif
  79. talloc_free(ctx);
  80. }
  81. --
  82. cgit v1.1-22-g1649