[go: nahoru, domu]

vaapi: VP9 accelerator/decoder fixes for protected content

This doesn't fully fix VP9 decrypted decoding, but it makes the
VP9Decoder changes cleaner than they were. It also adds a call that was
missed in the accelerator for setting the crypto params if we seek back
to clear content.

This still has corruption on screen, especially if there's UI activity
over the video. But still not sure how that matters.

BUG=b:153111783,b:155509231
TEST=VP9 decrypt+decode works mostly

Change-Id: Ib2ee90e6ce8fb6f2087c595e1a765e0481cc6249
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2567150
Commit-Queue: Jeffrey Kardatzke <jkardatzke@google.com>
Reviewed-by: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833944}
diff --git a/media/gpu/vp9_decoder.cc b/media/gpu/vp9_decoder.cc
index fda81b91..d10b5a1a 100644
--- a/media/gpu/vp9_decoder.cc
+++ b/media/gpu/vp9_decoder.cc
@@ -135,16 +135,14 @@
   while (true) {
     // If we have a pending picture to decode, try that first.
     if (pending_pic_) {
-      VP9Accelerator::Status status = DecodeAndOutputPicture(pending_pic_);
+      VP9Accelerator::Status status =
+          DecodeAndOutputPicture(std::move(pending_pic_));
       if (status == VP9Accelerator::Status::kFail) {
-        pending_pic_.reset();
         SetError();
         return kDecodeError;
       }
       if (status == VP9Accelerator::Status::kTryAgain)
         return kTryAgain;
-
-      pending_pic_.reset();
     }
 
     // Read a new frame header if one is not awaiting decoding already.
@@ -286,35 +284,32 @@
       return kConfigChange;
     }
 
-    pending_pic_ = accelerator_->CreateVP9Picture();
-    if (!pending_pic_) {
+    scoped_refptr<VP9Picture> pic = accelerator_->CreateVP9Picture();
+    if (!pic) {
       return kRanOutOfSurfaces;
     }
     DVLOG(2) << "Render resolution: " << new_render_rect.ToString();
 
-    pending_pic_->set_visible_rect(new_render_rect);
-    pending_pic_->set_bitstream_id(stream_id_);
+    pic->set_visible_rect(new_render_rect);
+    pic->set_bitstream_id(stream_id_);
 
-    pending_pic_->set_decrypt_config(std::move(decrypt_config));
+    pic->set_decrypt_config(std::move(decrypt_config));
 
     // For VP9, container color spaces override video stream color spaces.
     if (container_color_space_.IsSpecified())
-      pending_pic_->set_colorspace(container_color_space_);
+      pic->set_colorspace(container_color_space_);
     else if (curr_frame_hdr_)
-      pending_pic_->set_colorspace(curr_frame_hdr_->GetColorSpace());
+      pic->set_colorspace(curr_frame_hdr_->GetColorSpace());
 
-    pending_pic_->frame_hdr = std::move(curr_frame_hdr_);
+    pic->frame_hdr = std::move(curr_frame_hdr_);
 
-    VP9Accelerator::Status status = DecodeAndOutputPicture(pending_pic_);
+    VP9Accelerator::Status status = DecodeAndOutputPicture(std::move(pic));
     if (status == VP9Accelerator::Status::kFail) {
-      pending_pic_.reset();
       SetError();
       return kDecodeError;
     }
     if (status == VP9Accelerator::Status::kTryAgain)
       return kTryAgain;
-
-    pending_pic_.reset();
   }
 }
 
@@ -351,8 +346,11 @@
   VP9Accelerator::Status status = accelerator_->SubmitDecode(
       pic, context.segmentation(), context.loop_filter(), ref_frames_,
       std::move(done_cb));
-  if (status != VP9Accelerator::Status::kOk)
+  if (status != VP9Accelerator::Status::kOk) {
+    if (status == VP9Accelerator::Status::kTryAgain)
+      pending_pic_ = std::move(pic);
     return status;
+  }
 
   if (pic->frame_hdr->show_frame) {
     if (!accelerator_->OutputPicture(pic))