OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <dlfcn.h> | 5 #include <dlfcn.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 do { \ | 26 do { \ |
27 if ((va_res) != VA_STATUS_SUCCESS) { \ | 27 if ((va_res) != VA_STATUS_SUCCESS) { \ |
28 DVLOG(1) << err_msg \ | 28 DVLOG(1) << err_msg \ |
29 << " VA error: " << VAAPI_ErrorStr(va_res); \ | 29 << " VA error: " << VAAPI_ErrorStr(va_res); \ |
30 return (ret); \ | 30 return (ret); \ |
31 } \ | 31 } \ |
32 } while (0) | 32 } while (0) |
33 | 33 |
34 namespace content { | 34 namespace content { |
35 | 35 |
36 void *vaapi_handle = NULL; | 36 void *vaapi_handle = dlopen("libva.so", RTLD_NOW); |
37 void *vaapi_x11_handle = NULL; | 37 void *vaapi_x11_handle = dlopen("libva-x11.so", RTLD_NOW); |
38 | 38 |
39 typedef VADisplay (*VaapiGetDisplay)(Display *dpy); | 39 typedef VADisplay (*VaapiGetDisplay)(Display *dpy); |
40 typedef int (*VaapiDisplayIsValid)(VADisplay dpy); | 40 typedef int (*VaapiDisplayIsValid)(VADisplay dpy); |
41 typedef VAStatus (*VaapiInitialize)(VADisplay dpy, | 41 typedef VAStatus (*VaapiInitialize)(VADisplay dpy, |
42 int *major_version, | 42 int *major_version, |
43 int *minor_version); | 43 int *minor_version); |
44 typedef VAStatus (*VaapiTerminate)(VADisplay dpy); | 44 typedef VAStatus (*VaapiTerminate)(VADisplay dpy); |
45 typedef VAStatus (*VaapiGetConfigAttributes)(VADisplay dpy, | 45 typedef VAStatus (*VaapiGetConfigAttributes)(VADisplay dpy, |
46 VAProfile profile, | 46 VAProfile profile, |
47 VAEntrypoint entrypoint, | 47 VAEntrypoint entrypoint, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 typedef VAStatus (*VaapiCreateBuffer)(VADisplay dpy, | 98 typedef VAStatus (*VaapiCreateBuffer)(VADisplay dpy, |
99 VAContextID context, | 99 VAContextID context, |
100 VABufferType type, | 100 VABufferType type, |
101 unsigned int size, | 101 unsigned int size, |
102 unsigned int num_elements, | 102 unsigned int num_elements, |
103 void *data, | 103 void *data, |
104 VABufferID *buf_id); | 104 VABufferID *buf_id); |
105 typedef VAStatus (*VaapiDestroyBuffer)(VADisplay dpy, VABufferID buffer_id); | 105 typedef VAStatus (*VaapiDestroyBuffer)(VADisplay dpy, VABufferID buffer_id); |
106 typedef const char* (*VaapiErrorStr)(VAStatus error_status); | 106 typedef const char* (*VaapiErrorStr)(VAStatus error_status); |
107 | 107 |
108 #define VAAPI_SYM(name, handle) Vaapi##name VAAPI_##name = NULL | 108 #define VAAPI_DLSYM(name, handle) \ |
| 109 Vaapi##name VAAPI_##name = \ |
| 110 reinterpret_cast<Vaapi##name>(dlsym((handle), "va"#name)) |
109 | 111 |
110 VAAPI_SYM(GetDisplay, vaapi_x11_handle); | 112 VAAPI_DLSYM(GetDisplay, vaapi_x11_handle); |
111 VAAPI_SYM(DisplayIsValid, vaapi_handle); | 113 VAAPI_DLSYM(DisplayIsValid, vaapi_handle); |
112 VAAPI_SYM(Initialize, vaapi_handle); | 114 VAAPI_DLSYM(Initialize, vaapi_handle); |
113 VAAPI_SYM(Terminate, vaapi_handle); | 115 VAAPI_DLSYM(Terminate, vaapi_handle); |
114 VAAPI_SYM(GetConfigAttributes, vaapi_handle); | 116 VAAPI_DLSYM(GetConfigAttributes, vaapi_handle); |
115 VAAPI_SYM(CreateConfig, vaapi_handle); | 117 VAAPI_DLSYM(CreateConfig, vaapi_handle); |
116 VAAPI_SYM(DestroyConfig, vaapi_handle); | 118 VAAPI_DLSYM(DestroyConfig, vaapi_handle); |
117 VAAPI_SYM(CreateSurfaces, vaapi_handle); | 119 VAAPI_DLSYM(CreateSurfaces, vaapi_handle); |
118 VAAPI_SYM(DestroySurfaces, vaapi_handle); | 120 VAAPI_DLSYM(DestroySurfaces, vaapi_handle); |
119 VAAPI_SYM(CreateContext, vaapi_handle); | 121 VAAPI_DLSYM(CreateContext, vaapi_handle); |
120 VAAPI_SYM(DestroyContext, vaapi_handle); | 122 VAAPI_DLSYM(DestroyContext, vaapi_handle); |
121 VAAPI_SYM(PutSurface, vaapi_x11_handle); | 123 VAAPI_DLSYM(PutSurface, vaapi_x11_handle); |
122 VAAPI_SYM(SyncSurface, vaapi_x11_handle); | 124 VAAPI_DLSYM(SyncSurface, vaapi_x11_handle); |
123 VAAPI_SYM(BeginPicture, vaapi_handle); | 125 VAAPI_DLSYM(BeginPicture, vaapi_handle); |
124 VAAPI_SYM(RenderPicture, vaapi_handle); | 126 VAAPI_DLSYM(RenderPicture, vaapi_handle); |
125 VAAPI_SYM(EndPicture, vaapi_handle); | 127 VAAPI_DLSYM(EndPicture, vaapi_handle); |
126 VAAPI_SYM(CreateBuffer, vaapi_handle); | 128 VAAPI_DLSYM(CreateBuffer, vaapi_handle); |
127 VAAPI_SYM(DestroyBuffer, vaapi_handle); | 129 VAAPI_DLSYM(DestroyBuffer, vaapi_handle); |
128 VAAPI_SYM(ErrorStr, vaapi_handle); | 130 VAAPI_DLSYM(ErrorStr, vaapi_handle); |
129 | 131 |
130 // static | 132 static bool AreVaapiFunctionPointersInitialized() { |
131 bool VaapiH264Decoder::pre_sandbox_init_done_ = false; | 133 return VAAPI_GetDisplay && |
| 134 VAAPI_DisplayIsValid && |
| 135 VAAPI_Initialize && |
| 136 VAAPI_Terminate && |
| 137 VAAPI_GetConfigAttributes && |
| 138 VAAPI_CreateConfig && |
| 139 VAAPI_DestroyConfig && |
| 140 VAAPI_CreateSurfaces && |
| 141 VAAPI_DestroySurfaces && |
| 142 VAAPI_CreateContext && |
| 143 VAAPI_DestroyContext && |
| 144 VAAPI_PutSurface && |
| 145 VAAPI_SyncSurface && |
| 146 VAAPI_BeginPicture && |
| 147 VAAPI_RenderPicture && |
| 148 VAAPI_EndPicture && |
| 149 VAAPI_CreateBuffer && |
| 150 VAAPI_DestroyBuffer && |
| 151 VAAPI_ErrorStr; |
| 152 } |
132 | 153 |
133 class VaapiH264Decoder::DecodeSurface { | 154 class VaapiH264Decoder::DecodeSurface { |
134 public: | 155 public: |
135 DecodeSurface(const GLXFBConfig& fb_config, | 156 DecodeSurface(const GLXFBConfig& fb_config, |
136 Display* x_display, | 157 Display* x_display, |
137 VADisplay va_display, | 158 VADisplay va_display, |
138 const base::Callback<bool(void)>& make_context_current, | 159 const base::Callback<bool(void)>& make_context_current, |
139 VASurfaceID va_surface_id, | 160 VASurfaceID va_surface_id, |
140 int32 picture_buffer_id, | 161 int32 picture_buffer_id, |
141 uint32 texture_id, | 162 uint32 texture_id, |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 make_context_current_ = make_context_current; | 489 make_context_current_ = make_context_current; |
469 | 490 |
470 if (!make_context_current_.Run()) | 491 if (!make_context_current_.Run()) |
471 return false; | 492 return false; |
472 | 493 |
473 if (!SetProfile(profile)) { | 494 if (!SetProfile(profile)) { |
474 DVLOG(1) << "Unsupported profile"; | 495 DVLOG(1) << "Unsupported profile"; |
475 return false; | 496 return false; |
476 } | 497 } |
477 | 498 |
| 499 if (!AreVaapiFunctionPointersInitialized()) { |
| 500 DVLOG(1) << "Could not load libva"; |
| 501 return false; |
| 502 } |
| 503 |
478 if (!InitializeFBConfig()) { | 504 if (!InitializeFBConfig()) { |
479 DVLOG(1) << "Could not get a usable FBConfig"; | 505 DVLOG(1) << "Could not get a usable FBConfig"; |
480 return false; | 506 return false; |
481 } | 507 } |
482 | 508 |
483 va_display_ = VAAPI_GetDisplay(x_display_); | 509 va_display_ = VAAPI_GetDisplay(x_display_); |
484 if (!VAAPI_DisplayIsValid(va_display_)) { | 510 if (!VAAPI_DisplayIsValid(va_display_)) { |
485 DVLOG(1) << "Could not get a valid VA display"; | 511 DVLOG(1) << "Could not get a valid VA display"; |
486 return false; | 512 return false; |
487 } | 513 } |
(...skipping 1577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2065 return kDecodedFrame; | 2091 return kDecodedFrame; |
2066 } | 2092 } |
2067 } | 2093 } |
2068 } | 2094 } |
2069 | 2095 |
2070 // static | 2096 // static |
2071 size_t VaapiH264Decoder::GetRequiredNumOfPictures() { | 2097 size_t VaapiH264Decoder::GetRequiredNumOfPictures() { |
2072 return kNumReqPictures; | 2098 return kNumReqPictures; |
2073 } | 2099 } |
2074 | 2100 |
2075 // static | |
2076 void VaapiH264Decoder::PreSandboxInitialization() { | |
2077 DCHECK(!pre_sandbox_init_done_); | |
2078 vaapi_handle = dlopen("libva.so", RTLD_NOW); | |
2079 vaapi_x11_handle = dlopen("libva-x11.so", RTLD_NOW); | |
2080 pre_sandbox_init_done_ = vaapi_handle && vaapi_x11_handle; | |
2081 } | |
2082 | |
2083 // static | |
2084 bool VaapiH264Decoder::PostSandboxInitialization() { | |
2085 if (!pre_sandbox_init_done_) | |
2086 return false; | |
2087 #define VAAPI_DLSYM(name, handle) \ | |
2088 VAAPI_##name = reinterpret_cast<Vaapi##name>(dlsym((handle), "va"#name)) \ | |
2089 | |
2090 VAAPI_DLSYM(GetDisplay, vaapi_x11_handle); | |
2091 VAAPI_DLSYM(DisplayIsValid, vaapi_handle); | |
2092 VAAPI_DLSYM(Initialize, vaapi_handle); | |
2093 VAAPI_DLSYM(Terminate, vaapi_handle); | |
2094 VAAPI_DLSYM(GetConfigAttributes, vaapi_handle); | |
2095 VAAPI_DLSYM(CreateConfig, vaapi_handle); | |
2096 VAAPI_DLSYM(DestroyConfig, vaapi_handle); | |
2097 VAAPI_DLSYM(CreateSurfaces, vaapi_handle); | |
2098 VAAPI_DLSYM(DestroySurfaces, vaapi_handle); | |
2099 VAAPI_DLSYM(CreateContext, vaapi_handle); | |
2100 VAAPI_DLSYM(DestroyContext, vaapi_handle); | |
2101 VAAPI_DLSYM(PutSurface, vaapi_x11_handle); | |
2102 VAAPI_DLSYM(SyncSurface, vaapi_x11_handle); | |
2103 VAAPI_DLSYM(BeginPicture, vaapi_handle); | |
2104 VAAPI_DLSYM(RenderPicture, vaapi_handle); | |
2105 VAAPI_DLSYM(EndPicture, vaapi_handle); | |
2106 VAAPI_DLSYM(CreateBuffer, vaapi_handle); | |
2107 VAAPI_DLSYM(DestroyBuffer, vaapi_handle); | |
2108 VAAPI_DLSYM(ErrorStr, vaapi_handle); | |
2109 #undef VAAPI_DLSYM | |
2110 | |
2111 return VAAPI_GetDisplay && | |
2112 VAAPI_DisplayIsValid && | |
2113 VAAPI_Initialize && | |
2114 VAAPI_Terminate && | |
2115 VAAPI_GetConfigAttributes && | |
2116 VAAPI_CreateConfig && | |
2117 VAAPI_DestroyConfig && | |
2118 VAAPI_CreateSurfaces && | |
2119 VAAPI_DestroySurfaces && | |
2120 VAAPI_CreateContext && | |
2121 VAAPI_DestroyContext && | |
2122 VAAPI_PutSurface && | |
2123 VAAPI_SyncSurface && | |
2124 VAAPI_BeginPicture && | |
2125 VAAPI_RenderPicture && | |
2126 VAAPI_EndPicture && | |
2127 VAAPI_CreateBuffer && | |
2128 VAAPI_DestroyBuffer && | |
2129 VAAPI_ErrorStr; | |
2130 } | |
2131 | |
2132 } // namespace content | 2101 } // namespace content |
OLD | NEW |