[go: nahoru, domu]

VideoDecodeAccelerator: make Accelerator owned by Decoder

{V4L2,Vaapi}VideoDecodeAccelerator classes own both a *Decoder
and a number of *Accelerators; the *Decoder in turn gets a
naked pointer to the appropriate *Accelerator. This creates an
unnecessary complication in the ownership diagram. This CL
cleans that up by giving the ownership of the *Accelerator to
the appropriate *Decoder, reducing the footprint of the
*VideoDecodeAccelerator and with it its internal state. As a
side bonus, *Decoder can turn the *Accelerator into a pseudo
invariant.

After PS9, the naked ptr to VaapiWrapper inside Vaapi*Accelerator
is changed to a const scoped_refptr<VaapiWrapper>.

* in the former paragraphs is either {H264,VP8,VP9}

To simplify the review, I made a diagram of how it looks
before this CL: https://goo.gl/EorgA3
  (parts changing in red)
after this CL: https://goo.gl/UUvXcS

Test: simplechrome on soraka and scarlet, playback: h264, vp8, vp9
from crosvideo, then video_decode_accelerator_unittests.

Bug: 717265
Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Ic8f1f200a38c2d04b22e1c11e9fcaad61fea575f
Reviewed-on: https://chromium-review.googlesource.com/928826
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Reviewed-by: Pawel Osciak <posciak@chromium.org>
Cr-Commit-Position: refs/heads/master@{#538507}
diff --git a/media/gpu/vp9_decoder.cc b/media/gpu/vp9_decoder.cc
index be7fd85..4c99f25 100644
--- a/media/gpu/vp9_decoder.cc
+++ b/media/gpu/vp9_decoder.cc
@@ -17,14 +17,14 @@
 
 VP9Decoder::VP9Accelerator::~VP9Accelerator() {}
 
-VP9Decoder::VP9Decoder(VP9Accelerator* accelerator)
+VP9Decoder::VP9Decoder(std::unique_ptr<VP9Accelerator> accelerator)
     : state_(kNeedStreamMetadata),
-      accelerator_(accelerator),
-      parser_(accelerator->IsFrameContextRequired()) {
+      accelerator_(std::move(accelerator)),
+      parser_(accelerator_->IsFrameContextRequired()) {
   ref_frames_.resize(kVp9NumRefFrames);
 }
 
-VP9Decoder::~VP9Decoder() {}
+VP9Decoder::~VP9Decoder() = default;
 
 void VP9Decoder::SetStream(const uint8_t* ptr, size_t size) {
   DCHECK(ptr);