Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: content/common/gpu/media/vaapi_wrapper.cc

Issue 27498002: Add vaapi_h264_decoder_test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add gfx_geometry dependency Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/common/gpu/media/vaapi_wrapper.h ('k') | content/content_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "content/common/gpu/media/vaapi_wrapper.h" 9 #include "content/common/gpu/media/vaapi_wrapper.h"
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 int num_surfaces, 69 int num_surfaces,
70 VASurfaceID *surfaces); 70 VASurfaceID *surfaces);
71 typedef VAStatus (*VaapiCreateSurfaces8)(VADisplay dpy, 71 typedef VAStatus (*VaapiCreateSurfaces8)(VADisplay dpy,
72 unsigned int format, 72 unsigned int format,
73 unsigned int width, 73 unsigned int width,
74 unsigned int height, 74 unsigned int height,
75 VASurfaceID *surfaces, 75 VASurfaceID *surfaces,
76 unsigned int num_surfaces, 76 unsigned int num_surfaces,
77 VASurfaceAttrib *attrib_list, 77 VASurfaceAttrib *attrib_list,
78 unsigned int num_attribs); 78 unsigned int num_attribs);
79 typedef VAStatus (*VaapiDeriveImage)(VADisplay dpy,
80 VASurfaceID surface,
81 VAImage* image);
79 typedef VAStatus (*VaapiDestroyBuffer)(VADisplay dpy, VABufferID buffer_id); 82 typedef VAStatus (*VaapiDestroyBuffer)(VADisplay dpy, VABufferID buffer_id);
80 typedef VAStatus (*VaapiDestroyConfig)(VADisplay dpy, VAConfigID config_id); 83 typedef VAStatus (*VaapiDestroyConfig)(VADisplay dpy, VAConfigID config_id);
81 typedef VAStatus (*VaapiDestroyContext)(VADisplay dpy, VAContextID context); 84 typedef VAStatus (*VaapiDestroyContext)(VADisplay dpy, VAContextID context);
85 typedef VAStatus (*VaapiDestroyImage)(VADisplay dpy, VAImageID image);
82 typedef VAStatus (*VaapiDestroySurfaces)(VADisplay dpy, 86 typedef VAStatus (*VaapiDestroySurfaces)(VADisplay dpy,
83 VASurfaceID *surfaces, 87 VASurfaceID *surfaces,
84 int num_surfaces); 88 int num_surfaces);
85 typedef int (*VaapiDisplayIsValid)(VADisplay dpy); 89 typedef int (*VaapiDisplayIsValid)(VADisplay dpy);
86 typedef VAStatus (*VaapiEndPicture)(VADisplay dpy, VAContextID context); 90 typedef VAStatus (*VaapiEndPicture)(VADisplay dpy, VAContextID context);
87 typedef const char* (*VaapiErrorStr)(VAStatus error_status); 91 typedef const char* (*VaapiErrorStr)(VAStatus error_status);
88 typedef VAStatus (*VaapiGetConfigAttributes)(VADisplay dpy, 92 typedef VAStatus (*VaapiGetConfigAttributes)(VADisplay dpy,
89 VAProfile profile, 93 VAProfile profile,
90 VAEntrypoint entrypoint, 94 VAEntrypoint entrypoint,
91 VAConfigAttrib *attrib_list, 95 VAConfigAttrib *attrib_list,
92 int num_attribs); 96 int num_attribs);
93 typedef VADisplay (*VaapiGetDisplay)(Display *dpy); 97 typedef VADisplay (*VaapiGetDisplay)(Display *dpy);
94 typedef VAStatus (*VaapiInitialize)(VADisplay dpy, 98 typedef VAStatus (*VaapiInitialize)(VADisplay dpy,
95 int *major_version, 99 int *major_version,
96 int *minor_version); 100 int *minor_version);
101 typedef VAStatus (*VaapiMapBuffer)(VADisplay dpy,
102 VABufferID buf_id,
103 void** pbuf);
97 typedef VAStatus (*VaapiPutSurface)(VADisplay dpy, 104 typedef VAStatus (*VaapiPutSurface)(VADisplay dpy,
98 VASurfaceID surface, 105 VASurfaceID surface,
99 Drawable draw, 106 Drawable draw,
100 short srcx, 107 short srcx,
101 short srcy, 108 short srcy,
102 unsigned short srcw, 109 unsigned short srcw,
103 unsigned short srch, 110 unsigned short srch,
104 short destx, 111 short destx,
105 short desty, 112 short desty,
106 unsigned short destw, 113 unsigned short destw,
107 unsigned short desth, 114 unsigned short desth,
108 VARectangle *cliprects, 115 VARectangle *cliprects,
109 unsigned int number_cliprects, 116 unsigned int number_cliprects,
110 unsigned int flags); 117 unsigned int flags);
111 typedef VAStatus (*VaapiRenderPicture)(VADisplay dpy, 118 typedef VAStatus (*VaapiRenderPicture)(VADisplay dpy,
112 VAContextID context, 119 VAContextID context,
113 VABufferID *buffers, 120 VABufferID *buffers,
114 int num_buffers); 121 int num_buffers);
115 typedef VAStatus (*VaapiSetDisplayAttributes)(VADisplay dpy, 122 typedef VAStatus (*VaapiSetDisplayAttributes)(VADisplay dpy,
116 VADisplayAttribute *type, 123 VADisplayAttribute *type,
117 int num_attributes); 124 int num_attributes);
118 typedef VAStatus (*VaapiSyncSurface)(VADisplay dpy, VASurfaceID render_target); 125 typedef VAStatus (*VaapiSyncSurface)(VADisplay dpy, VASurfaceID render_target);
119 typedef VAStatus (*VaapiTerminate)(VADisplay dpy); 126 typedef VAStatus (*VaapiTerminate)(VADisplay dpy);
127 typedef VAStatus (*VaapiUnmapBuffer)(VADisplay dpy, VABufferID buf_id);
120 128
121 #define VAAPI_SYM(name, handle) Vaapi##name VAAPI_##name = NULL 129 #define VAAPI_SYM(name, handle) Vaapi##name VAAPI_##name = NULL
122 130
123 VAAPI_SYM(BeginPicture, vaapi_handle); 131 VAAPI_SYM(BeginPicture, vaapi_handle);
124 VAAPI_SYM(CreateBuffer, vaapi_handle); 132 VAAPI_SYM(CreateBuffer, vaapi_handle);
125 VAAPI_SYM(CreateConfig, vaapi_handle); 133 VAAPI_SYM(CreateConfig, vaapi_handle);
126 VAAPI_SYM(CreateContext, vaapi_handle); 134 VAAPI_SYM(CreateContext, vaapi_handle);
127 VAAPI_SYM(CreateSurfaces, vaapi_handle); 135 VAAPI_SYM(CreateSurfaces, vaapi_handle);
136 VAAPI_SYM(DeriveImage, vaapi_handle);
128 VAAPI_SYM(DestroyBuffer, vaapi_handle); 137 VAAPI_SYM(DestroyBuffer, vaapi_handle);
129 VAAPI_SYM(DestroyConfig, vaapi_handle); 138 VAAPI_SYM(DestroyConfig, vaapi_handle);
130 VAAPI_SYM(DestroyContext, vaapi_handle); 139 VAAPI_SYM(DestroyContext, vaapi_handle);
140 VAAPI_SYM(DestroyImage, vaapi_handle);
131 VAAPI_SYM(DestroySurfaces, vaapi_handle); 141 VAAPI_SYM(DestroySurfaces, vaapi_handle);
132 VAAPI_SYM(DisplayIsValid, vaapi_handle); 142 VAAPI_SYM(DisplayIsValid, vaapi_handle);
133 VAAPI_SYM(EndPicture, vaapi_handle); 143 VAAPI_SYM(EndPicture, vaapi_handle);
134 VAAPI_SYM(ErrorStr, vaapi_handle); 144 VAAPI_SYM(ErrorStr, vaapi_handle);
135 VAAPI_SYM(GetConfigAttributes, vaapi_handle); 145 VAAPI_SYM(GetConfigAttributes, vaapi_handle);
136 VAAPI_SYM(GetDisplay, vaapi_x11_handle); 146 VAAPI_SYM(GetDisplay, vaapi_x11_handle);
137 VAAPI_SYM(Initialize, vaapi_handle); 147 VAAPI_SYM(Initialize, vaapi_handle);
148 VAAPI_SYM(MapBuffer, vaapi_handle);
138 VAAPI_SYM(PutSurface, vaapi_x11_handle); 149 VAAPI_SYM(PutSurface, vaapi_x11_handle);
139 VAAPI_SYM(RenderPicture, vaapi_handle); 150 VAAPI_SYM(RenderPicture, vaapi_handle);
140 VAAPI_SYM(SetDisplayAttributes, vaapi_handle); 151 VAAPI_SYM(SetDisplayAttributes, vaapi_handle);
141 VAAPI_SYM(SyncSurface, vaapi_x11_handle); 152 VAAPI_SYM(SyncSurface, vaapi_x11_handle);
142 VAAPI_SYM(Terminate, vaapi_handle); 153 VAAPI_SYM(Terminate, vaapi_handle);
154 VAAPI_SYM(UnmapBuffer, vaapi_handle);
143 155
144 #undef VAAPI_SYM 156 #undef VAAPI_SYM
145 157
146 // Maps Profile enum values to VaProfile values. 158 // Maps Profile enum values to VaProfile values.
147 static bool ProfileToVAProfile(media::VideoCodecProfile profile, 159 static bool ProfileToVAProfile(media::VideoCodecProfile profile,
148 VAProfile* va_profile) { 160 VAProfile* va_profile) {
149 switch (profile) { 161 switch (profile) {
150 case media::H264PROFILE_BASELINE: 162 case media::H264PROFILE_BASELINE:
151 *va_profile = VAProfileH264Baseline; 163 *va_profile = VAProfileH264Baseline;
152 break; 164 break;
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 va_surface_id, 456 va_surface_id,
445 x_pixmap, 457 x_pixmap,
446 0, 0, dest_size.width(), dest_size.height(), 458 0, 0, dest_size.width(), dest_size.height(),
447 0, 0, dest_size.width(), dest_size.height(), 459 0, 0, dest_size.width(), dest_size.height(),
448 NULL, 0, 0); 460 NULL, 0, 0);
449 VA_SUCCESS_OR_RETURN(va_res, "Failed putting decode surface to pixmap", 461 VA_SUCCESS_OR_RETURN(va_res, "Failed putting decode surface to pixmap",
450 false); 462 false);
451 return true; 463 return true;
452 } 464 }
453 465
466 bool VaapiWrapper::GetVaImageForTesting(VASurfaceID va_surface_id,
467 VAImage* image,
468 void** mem) {
469 base::AutoLock auto_lock(va_lock_);
470
471 VAStatus va_res = VAAPI_SyncSurface(va_display_, va_surface_id);
472 VA_SUCCESS_OR_RETURN(va_res, "Failed syncing surface", false);
473
474 // Derive a VAImage from the VASurface
475 va_res = VAAPI_DeriveImage(va_display_, va_surface_id, image);
476 VA_LOG_ON_ERROR(va_res, "vaDeriveImage failed");
477 if (va_res != VA_STATUS_SUCCESS)
478 return false;
479
480 // Map the VAImage into memory
481 va_res = VAAPI_MapBuffer(va_display_, image->buf, mem);
482 VA_LOG_ON_ERROR(va_res, "vaMapBuffer failed");
483 if (va_res == VA_STATUS_SUCCESS)
484 return true;
485
486 VAAPI_DestroyImage(va_display_, image->image_id);
487 return false;
488 }
489
490 void VaapiWrapper::ReturnVaImageForTesting(VAImage* image) {
491 base::AutoLock auto_lock(va_lock_);
492
493 VAAPI_UnmapBuffer(va_display_, image->buf);
494 VAAPI_DestroyImage(va_display_, image->image_id);
495 }
496
454 // static 497 // static
455 bool VaapiWrapper::PostSandboxInitialization() { 498 bool VaapiWrapper::PostSandboxInitialization() {
456 vaapi_handle = dlopen("libva.so.1", RTLD_NOW); 499 vaapi_handle = dlopen("libva.so.1", RTLD_NOW);
457 vaapi_x11_handle = dlopen("libva-x11.so.1", RTLD_NOW); 500 vaapi_x11_handle = dlopen("libva-x11.so.1", RTLD_NOW);
458 501
459 if (!vaapi_handle || !vaapi_x11_handle) 502 if (!vaapi_handle || !vaapi_x11_handle)
460 return false; 503 return false;
461 #define VAAPI_DLSYM_OR_RETURN_ON_ERROR(name, handle) \ 504 #define VAAPI_DLSYM_OR_RETURN_ON_ERROR(name, handle) \
462 do { \ 505 do { \
463 VAAPI_##name = reinterpret_cast<Vaapi##name>(dlsym((handle), "va"#name)); \ 506 VAAPI_##name = reinterpret_cast<Vaapi##name>(dlsym((handle), "va"#name)); \
464 if (VAAPI_##name == NULL) { \ 507 if (VAAPI_##name == NULL) { \
465 DVLOG(1) << "Failed to dlsym va"#name; \ 508 DVLOG(1) << "Failed to dlsym va"#name; \
466 return false; \ 509 return false; \
467 } \ 510 } \
468 } while (0) 511 } while (0)
469 512
470 VAAPI_DLSYM_OR_RETURN_ON_ERROR(BeginPicture, vaapi_handle); 513 VAAPI_DLSYM_OR_RETURN_ON_ERROR(BeginPicture, vaapi_handle);
471 VAAPI_DLSYM_OR_RETURN_ON_ERROR(CreateBuffer, vaapi_handle); 514 VAAPI_DLSYM_OR_RETURN_ON_ERROR(CreateBuffer, vaapi_handle);
472 VAAPI_DLSYM_OR_RETURN_ON_ERROR(CreateConfig, vaapi_handle); 515 VAAPI_DLSYM_OR_RETURN_ON_ERROR(CreateConfig, vaapi_handle);
473 VAAPI_DLSYM_OR_RETURN_ON_ERROR(CreateContext, vaapi_handle); 516 VAAPI_DLSYM_OR_RETURN_ON_ERROR(CreateContext, vaapi_handle);
474 VAAPI_DLSYM_OR_RETURN_ON_ERROR(CreateSurfaces, vaapi_handle); 517 VAAPI_DLSYM_OR_RETURN_ON_ERROR(CreateSurfaces, vaapi_handle);
518 VAAPI_DLSYM_OR_RETURN_ON_ERROR(DeriveImage, vaapi_handle);
475 VAAPI_DLSYM_OR_RETURN_ON_ERROR(DestroyBuffer, vaapi_handle); 519 VAAPI_DLSYM_OR_RETURN_ON_ERROR(DestroyBuffer, vaapi_handle);
476 VAAPI_DLSYM_OR_RETURN_ON_ERROR(DestroyConfig, vaapi_handle); 520 VAAPI_DLSYM_OR_RETURN_ON_ERROR(DestroyConfig, vaapi_handle);
477 VAAPI_DLSYM_OR_RETURN_ON_ERROR(DestroyContext, vaapi_handle); 521 VAAPI_DLSYM_OR_RETURN_ON_ERROR(DestroyContext, vaapi_handle);
522 VAAPI_DLSYM_OR_RETURN_ON_ERROR(DestroyImage, vaapi_handle);
478 VAAPI_DLSYM_OR_RETURN_ON_ERROR(DestroySurfaces, vaapi_handle); 523 VAAPI_DLSYM_OR_RETURN_ON_ERROR(DestroySurfaces, vaapi_handle);
479 VAAPI_DLSYM_OR_RETURN_ON_ERROR(DisplayIsValid, vaapi_handle); 524 VAAPI_DLSYM_OR_RETURN_ON_ERROR(DisplayIsValid, vaapi_handle);
480 VAAPI_DLSYM_OR_RETURN_ON_ERROR(EndPicture, vaapi_handle); 525 VAAPI_DLSYM_OR_RETURN_ON_ERROR(EndPicture, vaapi_handle);
481 VAAPI_DLSYM_OR_RETURN_ON_ERROR(ErrorStr, vaapi_handle); 526 VAAPI_DLSYM_OR_RETURN_ON_ERROR(ErrorStr, vaapi_handle);
482 VAAPI_DLSYM_OR_RETURN_ON_ERROR(GetConfigAttributes, vaapi_handle); 527 VAAPI_DLSYM_OR_RETURN_ON_ERROR(GetConfigAttributes, vaapi_handle);
483 VAAPI_DLSYM_OR_RETURN_ON_ERROR(GetDisplay, vaapi_x11_handle); 528 VAAPI_DLSYM_OR_RETURN_ON_ERROR(GetDisplay, vaapi_x11_handle);
484 VAAPI_DLSYM_OR_RETURN_ON_ERROR(Initialize, vaapi_handle); 529 VAAPI_DLSYM_OR_RETURN_ON_ERROR(Initialize, vaapi_handle);
530 VAAPI_DLSYM_OR_RETURN_ON_ERROR(MapBuffer, vaapi_handle);
485 VAAPI_DLSYM_OR_RETURN_ON_ERROR(PutSurface, vaapi_x11_handle); 531 VAAPI_DLSYM_OR_RETURN_ON_ERROR(PutSurface, vaapi_x11_handle);
486 VAAPI_DLSYM_OR_RETURN_ON_ERROR(RenderPicture, vaapi_handle); 532 VAAPI_DLSYM_OR_RETURN_ON_ERROR(RenderPicture, vaapi_handle);
487 VAAPI_DLSYM_OR_RETURN_ON_ERROR(SetDisplayAttributes, vaapi_handle); 533 VAAPI_DLSYM_OR_RETURN_ON_ERROR(SetDisplayAttributes, vaapi_handle);
488 VAAPI_DLSYM_OR_RETURN_ON_ERROR(SyncSurface, vaapi_handle); 534 VAAPI_DLSYM_OR_RETURN_ON_ERROR(SyncSurface, vaapi_handle);
489 VAAPI_DLSYM_OR_RETURN_ON_ERROR(Terminate, vaapi_handle); 535 VAAPI_DLSYM_OR_RETURN_ON_ERROR(Terminate, vaapi_handle);
536 VAAPI_DLSYM_OR_RETURN_ON_ERROR(UnmapBuffer, vaapi_handle);
490 #undef VAAPI_DLSYM 537 #undef VAAPI_DLSYM
491 538
492 return true; 539 return true;
493 } 540 }
494 541
495 } // namespace content 542 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/vaapi_wrapper.h ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698