blob: 2b1256798f226b8037e6f99d08ab0f32d3cf2c7b [file] [log] [blame]
[email protected]48871fc2013-01-23 07:36:511// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]cc3cfaa2013-03-18 09:05:525#include "cc/layers/video_frame_provider_client_impl.h"
[email protected]48871fc2013-01-23 07:36:516
primianoc06e2382015-01-28 04:21:497#include "base/trace_event/trace_event.h"
[email protected]681ccff2013-03-18 06:13:528#include "cc/base/math_util.h"
[email protected]cc3cfaa2013-03-18 09:05:529#include "cc/layers/video_layer_impl.h"
[email protected]b7cfc632013-04-10 04:44:4910#include "media/base/video_frame.h"
[email protected]48871fc2013-01-23 07:36:5111
12namespace cc {
13
14// static
15scoped_refptr<VideoFrameProviderClientImpl>
16 VideoFrameProviderClientImpl::Create(
17 VideoFrameProvider* provider) {
18 return make_scoped_refptr(
19 new VideoFrameProviderClientImpl(provider));
20}
21
22VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() {}
23
24VideoFrameProviderClientImpl::VideoFrameProviderClientImpl(
25 VideoFrameProvider* provider)
kulkarni.a4015690f12014-10-10 13:50:0626 : active_video_layer_(nullptr), provider_(provider) {
[email protected]48871fc2013-01-23 07:36:5127 // This only happens during a commit on the compositor thread while the main
28 // thread is blocked. That makes this a thread-safe call to set the video
29 // frame provider client that does not require a lock. The same is true of
30 // the call to Stop().
31 provider_->SetVideoFrameProviderClient(this);
32
33 // This matrix is the default transformation for stream textures, and flips
34 // on the Y axis.
35 stream_texture_matrix_ = gfx::Transform(
36 1.0, 0.0, 0.0, 0.0,
37 0.0, -1.0, 0.0, 1.0,
38 0.0, 0.0, 1.0, 0.0,
39 0.0, 0.0, 0.0, 1.0);
40}
41
42void VideoFrameProviderClientImpl::Stop() {
43 if (!provider_)
44 return;
kulkarni.a4015690f12014-10-10 13:50:0645 provider_->SetVideoFrameProviderClient(nullptr);
46 provider_ = nullptr;
[email protected]48871fc2013-01-23 07:36:5147}
48
[email protected]af2cd322013-03-22 16:56:1849scoped_refptr<media::VideoFrame>
50VideoFrameProviderClientImpl::AcquireLockAndCurrentFrame() {
[email protected]48871fc2013-01-23 07:36:5151 provider_lock_.Acquire(); // Balanced by call to ReleaseLock().
52 if (!provider_)
kulkarni.a4015690f12014-10-10 13:50:0653 return nullptr;
[email protected]48871fc2013-01-23 07:36:5154
55 return provider_->GetCurrentFrame();
56}
57
[email protected]af2cd322013-03-22 16:56:1858void VideoFrameProviderClientImpl::PutCurrentFrame(
59 const scoped_refptr<media::VideoFrame>& frame) {
[email protected]48871fc2013-01-23 07:36:5160 provider_lock_.AssertAcquired();
61 provider_->PutCurrentFrame(frame);
62}
63
64void VideoFrameProviderClientImpl::ReleaseLock() {
65 provider_lock_.AssertAcquired();
66 provider_lock_.Release();
67}
68
69void VideoFrameProviderClientImpl::StopUsingProvider() {
70 // Block the provider from shutting down until this client is done
71 // using the frame.
72 base::AutoLock locker(provider_lock_);
kulkarni.a4015690f12014-10-10 13:50:0673 provider_ = nullptr;
[email protected]48871fc2013-01-23 07:36:5174}
75
76void VideoFrameProviderClientImpl::DidReceiveFrame() {
[email protected]9469d782014-04-18 01:23:5677 TRACE_EVENT1("cc",
78 "VideoFrameProviderClientImpl::DidReceiveFrame",
79 "active_video_layer",
80 !!active_video_layer_);
[email protected]48871fc2013-01-23 07:36:5181 if (active_video_layer_)
[email protected]4af49d542013-03-15 22:18:4782 active_video_layer_->SetNeedsRedraw();
[email protected]48871fc2013-01-23 07:36:5183}
84
85void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix) {
86 stream_texture_matrix_ = gfx::Transform(
87 matrix[0], matrix[4], matrix[8], matrix[12],
88 matrix[1], matrix[5], matrix[9], matrix[13],
89 matrix[2], matrix[6], matrix[10], matrix[14],
90 matrix[3], matrix[7], matrix[11], matrix[15]);
91 if (active_video_layer_)
[email protected]4af49d542013-03-15 22:18:4792 active_video_layer_->SetNeedsRedraw();
[email protected]48871fc2013-01-23 07:36:5193}
94
95} // namespace cc