OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/gpu/avda_surface_tracker.h" | 5 #include "media/remoting/remoting_cdm_controller.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/logging.h" |
9 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
10 | 11 |
11 namespace media { | 12 namespace media { |
12 | 13 |
13 namespace { | 14 RemotingCdmController::RemotingCdmController( |
14 static base::LazyInstance<AVDASurfaceTracker> g_lazy_instance = | 15 scoped_refptr<RemotingSourceImpl> remoting_source) |
15 LAZY_INSTANCE_INITIALIZER; | 16 : remoting_source_(std::move(remoting_source)) { |
| 17 remoting_source_->AddClient(this); |
16 } | 18 } |
17 | 19 |
18 AVDASurfaceTracker::AVDASurfaceTracker() {} | 20 RemotingCdmController::~RemotingCdmController() { |
| 21 DCHECK(thread_checker_.CalledOnValidThread()); |
19 | 22 |
20 AVDASurfaceTracker::~AVDASurfaceTracker() {} | 23 remoting_source_->RemoveClient(this); |
21 | |
22 void AVDASurfaceTracker::RegisterOnDestroyingSurfaceCallback( | |
23 const OnDestroyingSurfaceCallback& cb) { | |
24 DCHECK(thread_checker_.CalledOnValidThread()); | |
25 callbacks_.push_back(cb); | |
26 } | 24 } |
27 | 25 |
28 void AVDASurfaceTracker::UnregisterOnDestroyingSurfaceCallback( | 26 void RemotingCdmController::OnStarted(bool success) { |
29 const OnDestroyingSurfaceCallback& cb) { | |
30 DCHECK(thread_checker_.CalledOnValidThread()); | 27 DCHECK(thread_checker_.CalledOnValidThread()); |
31 for (auto it = callbacks_.begin(); it != callbacks_.end(); ++it) { | 28 |
32 if (it->Equals(cb)) { | 29 DCHECK(!cdm_check_cb_.is_null()); |
33 callbacks_.erase(it); | 30 base::ResetAndReturn(&cdm_check_cb_).Run(success); |
34 return; | 31 is_remoting_ = success; |
35 } | 32 } |
| 33 |
| 34 void RemotingCdmController::OnSessionStateChanged() { |
| 35 DCHECK(thread_checker_.CalledOnValidThread()); |
| 36 |
| 37 if (is_remoting_ && |
| 38 remoting_source_->state() == RemotingSessionState::SESSION_STOPPING) { |
| 39 remoting_source_->ShutDown(); |
| 40 is_remoting_ = false; |
36 } | 41 } |
37 } | 42 } |
38 | 43 |
39 void AVDASurfaceTracker::NotifyDestroyingSurface(int surface_id) { | 44 void RemotingCdmController::ShouldCreateRemotingCdm( |
| 45 const CdmCheckCallback& cb) { |
40 DCHECK(thread_checker_.CalledOnValidThread()); | 46 DCHECK(thread_checker_.CalledOnValidThread()); |
41 for (const auto& cb : callbacks_) | 47 DCHECK(!cb.is_null()); |
42 cb.Run(surface_id); | |
43 } | |
44 | 48 |
45 AVDASurfaceTracker* AVDASurfaceTracker::GetInstance() { | 49 if (is_remoting_) { |
46 return g_lazy_instance.Pointer(); | 50 cb.Run(true); |
| 51 return; |
| 52 } |
| 53 |
| 54 DCHECK(cdm_check_cb_.is_null()); |
| 55 cdm_check_cb_ = cb; |
| 56 remoting_source_->StartRemoting(this); |
47 } | 57 } |
48 | 58 |
49 } // namespace media | 59 } // namespace media |
OLD | NEW |