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
3 // found in the LICENSE file.
5 #include "cc/layers/video_frame_provider_client_impl.h"
7 #include "base/trace_event/trace_event.h"
8 #include "cc/base/math_util.h"
9 #include "cc/layers/video_layer_impl.h"
10 #include "media/base/video_frame.h"
15 scoped_refptr
<VideoFrameProviderClientImpl
>
16 VideoFrameProviderClientImpl::Create(
17 VideoFrameProvider
* provider
) {
18 return make_scoped_refptr(
19 new VideoFrameProviderClientImpl(provider
));
22 VideoFrameProviderClientImpl::~VideoFrameProviderClientImpl() {}
24 VideoFrameProviderClientImpl::VideoFrameProviderClientImpl(
25 VideoFrameProvider
* provider
)
26 : active_video_layer_(nullptr), provider_(provider
) {
27 // 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);
33 // This matrix is the default transformation for stream textures, and flips
35 stream_texture_matrix_
= gfx::Transform(
42 void VideoFrameProviderClientImpl::SetActiveVideoLayer(
43 VideoLayerImpl
* video_layer
) {
44 DCHECK(thread_checker_
.CalledOnValidThread());
46 active_video_layer_
= video_layer
;
49 void VideoFrameProviderClientImpl::Stop() {
50 // It's called when the main thread is blocked, so lock isn't needed.
53 DCHECK(thread_checker_
.CalledOnValidThread());
54 provider_
->SetVideoFrameProviderClient(nullptr);
58 bool VideoFrameProviderClientImpl::Stopped() {
59 DCHECK(thread_checker_
.CalledOnValidThread());
60 // |provider_| is changed while the main thread is blocked, and not changed
61 // thereafter, so lock isn't needed.
65 scoped_refptr
<media::VideoFrame
>
66 VideoFrameProviderClientImpl::AcquireLockAndCurrentFrame() {
67 DCHECK(thread_checker_
.CalledOnValidThread());
68 provider_lock_
.Acquire(); // Balanced by call to ReleaseLock().
72 return provider_
->GetCurrentFrame();
75 void VideoFrameProviderClientImpl::PutCurrentFrame(
76 const scoped_refptr
<media::VideoFrame
>& frame
) {
77 DCHECK(thread_checker_
.CalledOnValidThread());
78 provider_lock_
.AssertAcquired();
79 provider_
->PutCurrentFrame(frame
);
82 void VideoFrameProviderClientImpl::ReleaseLock() {
83 DCHECK(thread_checker_
.CalledOnValidThread());
84 provider_lock_
.AssertAcquired();
85 provider_lock_
.Release();
88 void VideoFrameProviderClientImpl::StopUsingProvider() {
89 // Block the provider from shutting down until this client is done
91 base::AutoLock
locker(provider_lock_
);
95 void VideoFrameProviderClientImpl::DidReceiveFrame() {
97 "VideoFrameProviderClientImpl::DidReceiveFrame",
99 !!active_video_layer_
);
100 DCHECK(thread_checker_
.CalledOnValidThread());
101 if (active_video_layer_
)
102 active_video_layer_
->SetNeedsRedraw();
105 void VideoFrameProviderClientImpl::DidUpdateMatrix(const float* matrix
) {
106 DCHECK(thread_checker_
.CalledOnValidThread());
107 stream_texture_matrix_
= gfx::Transform(
108 matrix
[0], matrix
[4], matrix
[8], matrix
[12],
109 matrix
[1], matrix
[5], matrix
[9], matrix
[13],
110 matrix
[2], matrix
[6], matrix
[10], matrix
[14],
111 matrix
[3], matrix
[7], matrix
[11], matrix
[15]);
112 if (active_video_layer_
)
113 active_video_layer_
->SetNeedsRedraw();