OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/capture/content/screen_capture_device_core.h" | 5 #include "media/capture/content/screen_capture_device_core.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 capture_machine_->Start( | 62 capture_machine_->Start( |
63 oracle_proxy_, params, | 63 oracle_proxy_, params, |
64 base::Bind(&ScreenCaptureDeviceCore::CaptureStarted, AsWeakPtr())); | 64 base::Bind(&ScreenCaptureDeviceCore::CaptureStarted, AsWeakPtr())); |
65 | 65 |
66 TransitionStateTo(kCapturing); | 66 TransitionStateTo(kCapturing); |
67 } | 67 } |
68 | 68 |
69 void ScreenCaptureDeviceCore::RequestRefreshFrame() { | 69 void ScreenCaptureDeviceCore::RequestRefreshFrame() { |
70 DCHECK(thread_checker_.CalledOnValidThread()); | 70 DCHECK(thread_checker_.CalledOnValidThread()); |
71 | 71 |
72 if (state_ != kCapturing) | 72 if (state_ != kCapturing && state_ != kSuspended) |
73 return; | 73 return; |
74 | 74 |
75 if (oracle_proxy_->AttemptPassiveRefresh()) | 75 if (oracle_proxy_->AttemptPassiveRefresh()) |
76 return; | 76 return; |
77 capture_machine_->MaybeCaptureForRefresh(); | 77 capture_machine_->MaybeCaptureForRefresh(); |
78 } | 78 } |
79 | 79 |
80 void ScreenCaptureDeviceCore::Suspend() { | |
81 DCHECK(thread_checker_.CalledOnValidThread()); | |
82 | |
83 if (state_ != kCapturing) | |
84 return; | |
85 | |
86 TransitionStateTo(kSuspended); | |
87 | |
88 capture_machine_->Suspend(); | |
89 } | |
90 | |
91 void ScreenCaptureDeviceCore::Resume() { | |
92 DCHECK(thread_checker_.CalledOnValidThread()); | |
93 | |
94 if (state_ != kSuspended) | |
95 return; | |
96 | |
97 TransitionStateTo(kCapturing); | |
98 | |
99 capture_machine_->Resume(); | |
100 } | |
101 | |
80 void ScreenCaptureDeviceCore::StopAndDeAllocate() { | 102 void ScreenCaptureDeviceCore::StopAndDeAllocate() { |
81 DCHECK(thread_checker_.CalledOnValidThread()); | 103 DCHECK(thread_checker_.CalledOnValidThread()); |
82 | 104 |
83 if (state_ != kCapturing) | 105 if (state_ != kCapturing && state_ != kSuspended) |
84 return; | 106 return; |
85 | 107 |
86 oracle_proxy_->Stop(); | 108 oracle_proxy_->Stop(); |
87 oracle_proxy_ = NULL; | 109 oracle_proxy_ = NULL; |
88 | 110 |
89 TransitionStateTo(kIdle); | 111 TransitionStateTo(kIdle); |
90 | 112 |
91 capture_machine_->Stop(base::Bind(&base::DoNothing)); | 113 capture_machine_->Stop(base::Bind(&base::DoNothing)); |
92 } | 114 } |
93 | 115 |
94 void ScreenCaptureDeviceCore::CaptureStarted(bool success) { | 116 void ScreenCaptureDeviceCore::CaptureStarted(bool success) { |
95 DCHECK(thread_checker_.CalledOnValidThread()); | 117 DCHECK(thread_checker_.CalledOnValidThread()); |
96 if (!success) | 118 if (!success) |
97 Error(FROM_HERE, "Failed to start capture machine."); | 119 Error(FROM_HERE, "Failed to start capture machine."); |
98 } | 120 } |
99 | 121 |
100 ScreenCaptureDeviceCore::ScreenCaptureDeviceCore( | 122 ScreenCaptureDeviceCore::ScreenCaptureDeviceCore( |
101 std::unique_ptr<VideoCaptureMachine> capture_machine) | 123 std::unique_ptr<VideoCaptureMachine> capture_machine) |
102 : state_(kIdle), capture_machine_(std::move(capture_machine)) { | 124 : state_(kIdle), capture_machine_(std::move(capture_machine)) { |
103 DCHECK(capture_machine_.get()); | 125 DCHECK(capture_machine_.get()); |
104 } | 126 } |
105 | 127 |
106 ScreenCaptureDeviceCore::~ScreenCaptureDeviceCore() { | 128 ScreenCaptureDeviceCore::~ScreenCaptureDeviceCore() { |
107 DCHECK(thread_checker_.CalledOnValidThread()); | 129 DCHECK(thread_checker_.CalledOnValidThread()); |
108 DCHECK_NE(state_, kCapturing); | 130 DCHECK(state_ != kCapturing && state_ != kSuspended); |
109 if (capture_machine_) { | 131 if (capture_machine_) { |
110 capture_machine_->Stop( | 132 capture_machine_->Stop( |
111 base::Bind(&DeleteCaptureMachine, base::Passed(&capture_machine_))); | 133 base::Bind(&DeleteCaptureMachine, base::Passed(&capture_machine_))); |
112 } | 134 } |
113 DVLOG(1) << "ScreenCaptureDeviceCore@" << this << " destroying."; | 135 DVLOG(1) << "ScreenCaptureDeviceCore@" << this << " destroying."; |
114 } | 136 } |
115 | 137 |
116 void ScreenCaptureDeviceCore::TransitionStateTo(State next_state) { | 138 void ScreenCaptureDeviceCore::TransitionStateTo(State next_state) { |
117 DCHECK(thread_checker_.CalledOnValidThread()); | 139 DCHECK(thread_checker_.CalledOnValidThread()); |
118 | 140 |
119 #ifndef NDEBUG | 141 #ifndef NDEBUG |
120 static const char* kStateNames[] = {"Idle", "Capturing", "Error"}; | 142 static constexpr char* kStateNames[] = {"Idle", "Capturing", "Suspended", |
braveyao
2016/09/26 17:14:47
Compiling failure for Android:
ISO C++11 does not
miu
2016/09/27 20:46:50
Fixed.
| |
143 "Error"}; | |
121 static_assert(arraysize(kStateNames) == kLastCaptureState, | 144 static_assert(arraysize(kStateNames) == kLastCaptureState, |
122 "Different number of states and textual descriptions"); | 145 "Different number of states and textual descriptions"); |
123 DVLOG(1) << "State change: " << kStateNames[state_] << " --> " | 146 DVLOG(1) << "State change: " << kStateNames[state_] << " --> " |
124 << kStateNames[next_state]; | 147 << kStateNames[next_state]; |
125 #endif | 148 #endif |
126 | 149 |
127 state_ = next_state; | 150 state_ = next_state; |
128 } | 151 } |
129 | 152 |
130 void ScreenCaptureDeviceCore::Error(const tracked_objects::Location& from_here, | 153 void ScreenCaptureDeviceCore::Error(const tracked_objects::Location& from_here, |
131 const std::string& reason) { | 154 const std::string& reason) { |
132 DCHECK(thread_checker_.CalledOnValidThread()); | 155 DCHECK(thread_checker_.CalledOnValidThread()); |
133 | 156 |
134 if (state_ == kIdle) | 157 if (state_ == kIdle) |
135 return; | 158 return; |
136 | 159 |
137 if (oracle_proxy_.get()) | 160 if (oracle_proxy_.get()) |
138 oracle_proxy_->ReportError(from_here, reason); | 161 oracle_proxy_->ReportError(from_here, reason); |
139 | 162 |
140 StopAndDeAllocate(); | 163 StopAndDeAllocate(); |
141 TransitionStateTo(kError); | 164 TransitionStateTo(kError); |
142 } | 165 } |
143 | 166 |
144 } // namespace media | 167 } // namespace media |
OLD | NEW |