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

Unified Diff: content/common/gpu/media/vaapi_h264_decoder.cc

Issue 10843058: VAVDA: Destroy vaapi buffers after we're done drawing. (Closed) Base URL: https://git.chromium.org/git/chromium/src@master
Patch Set: Did the locking in a separate CL. Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/gpu/media/vaapi_h264_decoder.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/gpu/media/vaapi_h264_decoder.cc
diff --git a/content/common/gpu/media/vaapi_h264_decoder.cc b/content/common/gpu/media/vaapi_h264_decoder.cc
index cb716b29fb75c32969b160cbd644919ceb60394d..73429d1f3d5a3830f750d460ae590cabeaa7b105 100644
--- a/content/common/gpu/media/vaapi_h264_decoder.cc
+++ b/content/common/gpu/media/vaapi_h264_decoder.cc
@@ -20,7 +20,7 @@
DVLOG(1) << err_msg \
<< " VA error: " << VAAPI_ErrorStr(va_res); \
} \
- } while(0)
+ } while (0)
#define VA_SUCCESS_OR_RETURN(va_res, err_msg, ret) \
do { \
@@ -31,6 +31,12 @@
} \
} while (0)
+#define VA_LOG_ERROR(va_res, err_msg) \
+ do { \
+ DVLOG(1) << err_msg \
+ << " VA error: " << VAAPI_ErrorStr(va_res); \
+ } while (0)
+
namespace content {
void *vaapi_handle = dlopen("libva.so", RTLD_NOW);
@@ -371,6 +377,10 @@ void VaapiH264Decoder::Reset() {
prev_ref_pic_order_cnt_lsb_ = -1;
prev_ref_field_ = H264Picture::FIELD_NONE;
+ // When called from the constructor, although va_display_ is invalid,
+ // |pending_slice_bufs_| and |pending_va_bufs_| are empty.
+ DestroyPendingBuffers();
+
pending_slice_bufs_ = std::queue<VABufferID>();
pending_va_bufs_ = std::queue<VABufferID>();
@@ -416,10 +426,11 @@ void VaapiH264Decoder::Destroy() {
break;
if (destroy_surfaces)
DestroyVASurfaces();
+ DestroyPendingBuffers();
Pawel Osciak 2012/08/03 20:57:14 This should only be required in one of the three a
va_res = VAAPI_DestroyConfig(va_display_, va_config_id_);
VA_LOG_ON_ERROR(va_res, "vaDestroyConfig failed");
- va_res = VAAPI_Terminate(va_display_);
- VA_LOG_ON_ERROR(va_res, "vaTerminate failed");
+ va_res = VAAPI_Terminate(va_display_);
+ VA_LOG_ON_ERROR(va_res, "vaTerminate failed");
// fallthrough
case kUninitialized:
break;
@@ -600,7 +611,14 @@ bool VaapiH264Decoder::CreateVASurfaces() {
pic_width_, pic_height_, VA_PROGRESSIVE,
va_surface_ids_, GetRequiredNumOfPictures(),
&va_context_id_);
- VA_SUCCESS_OR_RETURN(va_res, "vaCreateContext failed", false);
+
+ if (va_res != VA_STATUS_SUCCESS) {
+ VAAPI_DestroySurfaces(va_display_, va_surface_ids_,
+ GetRequiredNumOfPictures());
+ DVLOG(1) << "vaCreateContext failed"
+ << " VA error: " << VAAPI_ErrorStr(va_res);
+ return false;
+ }
return true;
}
@@ -617,6 +635,21 @@ void VaapiH264Decoder::DestroyVASurfaces() {
VA_LOG_ON_ERROR(va_res, "vaDestroySurfaces failed");
}
+void VaapiH264Decoder::DestroyPendingBuffers() {
+ while (!pending_slice_bufs_.empty()) {
+ VABufferID buffer = pending_slice_bufs_.front();
+ VAStatus va_res = VAAPI_DestroyBuffer(va_display_, buffer);
+ VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed");
+ pending_slice_bufs_.pop();
+ }
+ while (!pending_va_bufs_.empty()) {
+ VABufferID buffer = pending_va_bufs_.front();
+ VAStatus va_res = VAAPI_DestroyBuffer(va_display_, buffer);
+ VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed");
+ pending_va_bufs_.pop();
+ }
+}
+
// Fill |va_pic| with default/neutral values.
static void InitVAPicture(VAPictureH264* va_pic) {
memset(va_pic, 0, sizeof(*va_pic));
@@ -995,6 +1028,14 @@ bool VaapiH264Decoder::QueueSlice(H264SliceHeader* slice_hdr) {
return true;
}
+void VaapiH264Decoder::DestroyBuffers(VABufferID* va_buffers,
+ size_t num_va_buffers) {
+ for (size_t i = 0; i < num_va_buffers; ++i) {
+ VAStatus va_res = VAAPI_DestroyBuffer(va_display_, va_buffers[i]);
+ VA_LOG_ON_ERROR(va_res, "vaDestroyBuffer failed");
+ }
+}
+
// TODO(posciak) start using vaMapBuffer instead of vaCreateBuffer wherever
// possible.
@@ -1021,49 +1062,53 @@ bool VaapiH264Decoder::DecodePicture() {
dec_surface->va_surface_id());
VA_SUCCESS_OR_RETURN(va_res, "vaBeginPicture failed", false);
- // Put buffer IDs for pending parameter buffers into buffers[].
- VABufferID buffers[kMaxVABuffers];
- size_t num_buffers = pending_va_bufs_.size();
- for (size_t i = 0; i < num_buffers && i < kMaxVABuffers; ++i) {
- buffers[i] = pending_va_bufs_.front();
+ // Put buffer IDs for pending parameter buffers into va_buffers[].
+ VABufferID va_buffers[kMaxVABuffers];
+ size_t num_va_buffers = pending_va_bufs_.size();
+ for (size_t i = 0; i < num_va_buffers && i < kMaxVABuffers; ++i) {
+ va_buffers[i] = pending_va_bufs_.front();
pending_va_bufs_.pop();
}
// And send them to the HW decoder.
- va_res = VAAPI_RenderPicture(va_display_, va_context_id_, buffers,
- num_buffers);
- VA_SUCCESS_OR_RETURN(va_res, "vaRenderPicture for va_bufs failed", false);
-
- DVLOG(4) << "Committed " << num_buffers << "VA buffers";
-
- for (size_t i = 0; i < num_buffers; ++i) {
- va_res = VAAPI_DestroyBuffer(va_display_, buffers[i]);
- VA_SUCCESS_OR_RETURN(va_res, "vaDestroyBuffer for va_bufs failed", false);
+ va_res = VAAPI_RenderPicture(va_display_, va_context_id_, va_buffers,
+ num_va_buffers);
+ if (va_res != VA_STATUS_SUCCESS) {
+ DestroyBuffers(va_buffers, num_va_buffers);
+ VA_LOG_ERROR(va_res, "vaRenderPicture for va_bufs failed");
+ return false;
}
- // Put buffer IDs for pending slice data buffers into buffers[].
- num_buffers = pending_slice_bufs_.size();
- for (size_t i = 0; i < num_buffers && i < kMaxVABuffers; ++i) {
- buffers[i] = pending_slice_bufs_.front();
+ DVLOG(4) << "Committed " << num_va_buffers << "VA buffers";
+
+ // Put buffer IDs for pending slice data buffers into slice_buffers[].
+ VABufferID slice_buffers[kMaxVABuffers];
+ size_t num_slice_buffers = pending_slice_bufs_.size();
+ for (size_t i = 0; i < num_slice_buffers && i < kMaxVABuffers; ++i) {
+ slice_buffers[i] = pending_slice_bufs_.front();
pending_slice_bufs_.pop();
}
// And send them to the Hw decoder.
- va_res = VAAPI_RenderPicture(va_display_, va_context_id_, buffers,
- num_buffers);
- VA_SUCCESS_OR_RETURN(va_res, "vaRenderPicture for slices failed", false);
-
- DVLOG(4) << "Committed " << num_buffers << "slice buffers";
-
- for (size_t i = 0; i < num_buffers; ++i) {
- va_res = VAAPI_DestroyBuffer(va_display_, buffers[i]);
- VA_SUCCESS_OR_RETURN(va_res, "vaDestroyBuffer for slices failed", false);
+ va_res = VAAPI_RenderPicture(va_display_, va_context_id_, slice_buffers,
+ num_slice_buffers);
+ if (va_res != VA_STATUS_SUCCESS) {
+ DestroyBuffers(va_buffers, num_va_buffers);
+ DestroyBuffers(slice_buffers, num_slice_buffers);
+ VA_LOG_ERROR(va_res, "vaRenderPicture for slices failed");
+ return false;
}
+ DVLOG(4) << "Committed " << num_slice_buffers << "slice buffers";
+
// Instruct HW decoder to start processing committed buffers (decode this
// picture). This does not block until the end of decode.
va_res = VAAPI_EndPicture(va_display_, va_context_id_);
- VA_SUCCESS_OR_RETURN(va_res, "vaEndPicture failed", false);
+ VA_LOG_ON_ERROR(va_res, "vaEndPicture failed");
+
+ // Now that EndPicture has passed we can destroy our buffers.
+ DestroyBuffers(va_buffers, num_va_buffers);
+ DestroyBuffers(slice_buffers, num_slice_buffers);
// Used to notify clients that we had sufficient data to start decoding
// a new frame.
« no previous file with comments | « content/common/gpu/media/vaapi_h264_decoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698