Skip to content
This repository was archived by the owner on Sep 3, 2019. It is now read-only.

Commit ca9e637

Browse files
swarrenaaronp24
authored andcommitted
Implement workarounds for Adobe Flash bugs
Implement two workarounds: 1) Swap U and V planes to VdpVideoSurfacePutBitsYCbCr to fix blue-tinged videos. 2) Disable VdpPresentationQueueSetBackgroundColor, so that Flash doesn't set the background to pure black or pure white, which would cause the VDPAU image to bleed through to other parts of the desktop with those very common colors. These workarounds are only enabled when running under Flash player, and may be individually controlled via /etc/vdpau_wrapper.cfg, should they ever need to be disabled. Note that this code stores the VDPAU backend function pointers as global variables, which is technically incorrect. However, the likelihood of any known VDPAU implementation ever returning different values for these pointers within a single process is zero. If this becomes a problem, a hash table of VdpDevice to the stored pointers should be implemented. Signed-off-by: Stephen Warren <[email protected]> Reviewed-by: Aaron Plattner <[email protected]> Signed-off-by: Aaron Plattner <[email protected]> [[email protected]: fixed distcheck by changing it to dist_libvdpausysconf_DATA]
1 parent 4262513 commit ca9e637

File tree

3 files changed

+174
-2
lines changed

3 files changed

+174
-2
lines changed

src/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
AM_CFLAGS = \
22
-I$(top_srcdir)/include \
33
-DVDPAU_MODULEDIR="\"$(moduledir)\"" \
4+
-DVDPAU_SYSCONFDIR="\"$(sysconfdir)\"" \
45
$(X11_CFLAGS) \
56
$(XEXT_CFLAGS)
67

@@ -26,3 +27,6 @@ libvdpauincludedir = $(includedir)/vdpau
2627
libvdpauinclude_HEADERS = \
2728
$(top_srcdir)/include/vdpau/vdpau.h \
2829
$(top_srcdir)/include/vdpau/vdpau_x11.h
30+
31+
libvdpausysconfdir=$(sysconfdir)
32+
dist_libvdpausysconf_DATA = vdpau_wrapper.cfg

src/vdpau_wrapper.c

Lines changed: 168 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,163 @@ static void _vdp_close_driver(void)
210210
_vdp_imp_device_create_x11_proc = NULL;
211211
}
212212

213+
static VdpGetProcAddress * _imp_get_proc_address;
214+
static VdpVideoSurfacePutBitsYCbCr * _imp_vid_put_bits_y_cb_cr;
215+
static VdpPresentationQueueSetBackgroundColor * _imp_pq_set_bg_color;
216+
static int _inited_fixes;
217+
static int _running_under_flash;
218+
static int _enable_flash_uv_swap = 1;
219+
static int _disable_flash_pq_bg_color = 1;
220+
221+
static VdpStatus vid_put_bits_y_cb_cr_swapped(
222+
VdpVideoSurface surface,
223+
VdpYCbCrFormat source_ycbcr_format,
224+
void const * const * source_data,
225+
uint32_t const * source_pitches
226+
)
227+
{
228+
void const * data_reordered[3];
229+
void const * const * data;
230+
231+
if (source_ycbcr_format == VDP_YCBCR_FORMAT_YV12) {
232+
data_reordered[0] = source_data[0];
233+
data_reordered[1] = source_data[2];
234+
data_reordered[2] = source_data[1];
235+
/*
236+
* source_pitches[1] and source_pitches[2] should be equal,
237+
* so no need to re-order.
238+
*/
239+
data = data_reordered;
240+
}
241+
else {
242+
data = source_data;
243+
}
244+
245+
return _imp_vid_put_bits_y_cb_cr(
246+
surface,
247+
source_ycbcr_format,
248+
data,
249+
source_pitches
250+
);
251+
}
252+
253+
static VdpStatus pq_set_bg_color_noop(
254+
VdpPresentationQueue presentation_queue,
255+
VdpColor * const background_color
256+
)
257+
{
258+
return VDP_STATUS_OK;
259+
}
260+
261+
static VdpStatus vdp_wrapper_get_proc_address(
262+
VdpDevice device,
263+
VdpFuncId function_id,
264+
/* output parameters follow */
265+
void * * function_pointer
266+
)
267+
{
268+
VdpStatus status;
269+
270+
status = _imp_get_proc_address(device, function_id, function_pointer);
271+
if (status != VDP_STATUS_OK) {
272+
return status;
273+
}
274+
275+
if (_running_under_flash) {
276+
switch (function_id) {
277+
case VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR:
278+
if (_enable_flash_uv_swap) {
279+
_imp_vid_put_bits_y_cb_cr = *function_pointer;
280+
*function_pointer = vid_put_bits_y_cb_cr_swapped;
281+
}
282+
break;
283+
case VDP_FUNC_ID_PRESENTATION_QUEUE_SET_BACKGROUND_COLOR:
284+
if (_disable_flash_pq_bg_color) {
285+
_imp_pq_set_bg_color = *function_pointer;
286+
*function_pointer = pq_set_bg_color_noop;
287+
}
288+
break;
289+
default:
290+
break;
291+
}
292+
}
293+
294+
return VDP_STATUS_OK;
295+
}
296+
297+
static void init_running_under_flash(void)
298+
{
299+
FILE *fp;
300+
char buffer[1024];
301+
int ret, i;
302+
303+
fp = fopen("/proc/self/cmdline", "r");
304+
if (!fp) {
305+
return;
306+
}
307+
ret = fread(buffer, 1, sizeof(buffer) - 1, fp);
308+
fclose(fp);
309+
if (ret < 0) {
310+
return;
311+
}
312+
/*
313+
* Sometimes the file contains null between arguments. Wipe these out so
314+
* strstr doesn't stop early.
315+
*/
316+
for (i = 0; i < ret; i++) {
317+
if (buffer[i] == '\0') {
318+
buffer[i] = 'x';
319+
}
320+
}
321+
buffer[ret] = '\0';
322+
323+
if (strstr(buffer, "libflashplayer") != NULL) {
324+
_running_under_flash = 1;
325+
}
326+
}
327+
328+
void init_config(void)
329+
{
330+
FILE *fp;
331+
char buffer[1024];
332+
int ret;
333+
334+
fp = fopen(VDPAU_SYSCONFDIR "/vdpau_wrapper.cfg", "r");
335+
if (!fp) {
336+
return;
337+
}
338+
339+
while (fgets(buffer, sizeof(buffer), fp) != NULL) {
340+
char * equals = strchr(buffer, '=');
341+
char * param;
342+
343+
if (equals == NULL) {
344+
continue;
345+
}
346+
347+
*equals = '\0';
348+
param = equals + 1;
349+
350+
if (!strcmp(buffer, "enable_flash_uv_swap")) {
351+
_enable_flash_uv_swap = atoi(param);
352+
}
353+
else if (!strcmp(buffer, "disable_flash_pq_bg_color")) {
354+
_disable_flash_pq_bg_color = atoi(param);
355+
}
356+
}
357+
}
358+
359+
void init_fixes(void)
360+
{
361+
if (_inited_fixes) {
362+
return;
363+
}
364+
_inited_fixes = 1;
365+
366+
init_running_under_flash();
367+
init_config();
368+
}
369+
213370
VdpStatus vdp_device_create_x11(
214371
Display * display,
215372
int screen,
@@ -220,6 +377,8 @@ VdpStatus vdp_device_create_x11(
220377
{
221378
VdpStatus status;
222379

380+
init_fixes();
381+
223382
if (!_vdp_imp_device_create_x11_proc) {
224383
status = _vdp_open_driver(display, screen);
225384
if (status != VDP_STATUS_OK) {
@@ -228,10 +387,17 @@ VdpStatus vdp_device_create_x11(
228387
}
229388
}
230389

231-
return _vdp_imp_device_create_x11_proc(
390+
status = _vdp_imp_device_create_x11_proc(
232391
display,
233392
screen,
234393
device,
235-
get_proc_address
394+
&_imp_get_proc_address
236395
);
396+
if (status != VDP_STATUS_OK) {
397+
return status;
398+
}
399+
400+
*get_proc_address = vdp_wrapper_get_proc_address;
401+
402+
return VDP_STATUS_OK;
237403
}

src/vdpau_wrapper.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
enable_flash_uv_swap=1
2+
disable_flash_pq_bg_color=1

0 commit comments

Comments
 (0)