Chromium Code Reviews| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 | 39 |
| 40 if (state_ != kIdle) { | 40 if (state_ != kIdle) { |
| 41 DVLOG(1) << "Allocate() invoked when not in state Idle."; | 41 DVLOG(1) << "Allocate() invoked when not in state Idle."; |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 | 44 |
| 45 if (!(params.requested_format.pixel_format == PIXEL_FORMAT_I420 && | 45 if (!(params.requested_format.pixel_format == PIXEL_FORMAT_I420 && |
| 46 params.requested_format.pixel_storage == PIXEL_STORAGE_CPU) && | 46 params.requested_format.pixel_storage == PIXEL_STORAGE_CPU) && |
| 47 !(params.requested_format.pixel_format == PIXEL_FORMAT_ARGB && | 47 !(params.requested_format.pixel_format == PIXEL_FORMAT_ARGB && |
| 48 params.requested_format.pixel_storage == PIXEL_STORAGE_TEXTURE)) { | 48 params.requested_format.pixel_storage == PIXEL_STORAGE_TEXTURE)) { |
| 49 const std::string error_msg = base::StringPrintf( | 49 client->OnError( |
| 50 "unsupported format: %s", | 50 FROM_HERE, |
| 51 VideoCaptureFormat::ToString(params.requested_format).c_str()); | 51 base::StringPrintf( |
| 52 DVLOG(1) << error_msg; | 52 "unsupported format: %s", |
| 53 client->OnError(error_msg); | 53 VideoCaptureFormat::ToString(params.requested_format).c_str())); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 | 56 |
| 57 oracle_proxy_ = new ThreadSafeCaptureOracle( | 57 oracle_proxy_ = new ThreadSafeCaptureOracle( |
| 58 client.Pass(), params, capture_machine_->IsAutoThrottlingEnabled()); | 58 client.Pass(), params, capture_machine_->IsAutoThrottlingEnabled()); |
| 59 | 59 |
| 60 capture_machine_->Start( | 60 capture_machine_->Start( |
| 61 oracle_proxy_, params, | 61 oracle_proxy_, params, |
| 62 base::Bind(&ScreenCaptureDeviceCore::CaptureStarted, AsWeakPtr())); | 62 base::Bind(&ScreenCaptureDeviceCore::CaptureStarted, AsWeakPtr())); |
| 63 | 63 |
| 64 TransitionStateTo(kCapturing); | 64 TransitionStateTo(kCapturing); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void ScreenCaptureDeviceCore::StopAndDeAllocate() { | 67 void ScreenCaptureDeviceCore::StopAndDeAllocate() { |
| 68 DCHECK(thread_checker_.CalledOnValidThread()); | 68 DCHECK(thread_checker_.CalledOnValidThread()); |
| 69 | 69 |
| 70 if (state_ != kCapturing) | 70 if (state_ != kCapturing) |
| 71 return; | 71 return; |
| 72 | 72 |
| 73 oracle_proxy_->Stop(); | 73 oracle_proxy_->Stop(); |
| 74 oracle_proxy_ = NULL; | 74 oracle_proxy_ = NULL; |
| 75 | 75 |
| 76 TransitionStateTo(kIdle); | 76 TransitionStateTo(kIdle); |
| 77 | 77 |
| 78 capture_machine_->Stop(base::Bind(&base::DoNothing)); | 78 capture_machine_->Stop(base::Bind(&base::DoNothing)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void ScreenCaptureDeviceCore::CaptureStarted(bool success) { | 81 void ScreenCaptureDeviceCore::CaptureStarted(bool success) { |
| 82 DCHECK(thread_checker_.CalledOnValidThread()); | 82 DCHECK(thread_checker_.CalledOnValidThread()); |
| 83 if (!success) { | 83 if (!success) |
| 84 std::string reason("Failed to start capture machine."); | 84 Error(FROM_HERE, "Failed to start capture machine."); |
| 85 DVLOG(1) << reason; | |
| 86 Error(reason); | |
| 87 } | |
| 88 } | 85 } |
| 89 | 86 |
| 90 ScreenCaptureDeviceCore::ScreenCaptureDeviceCore( | 87 ScreenCaptureDeviceCore::ScreenCaptureDeviceCore( |
| 91 scoped_ptr<VideoCaptureMachine> capture_machine) | 88 scoped_ptr<VideoCaptureMachine> capture_machine) |
| 92 : state_(kIdle), capture_machine_(capture_machine.Pass()) { | 89 : state_(kIdle), capture_machine_(capture_machine.Pass()) { |
| 93 DCHECK(capture_machine_.get()); | 90 DCHECK(capture_machine_.get()); |
| 94 } | 91 } |
| 95 | 92 |
| 96 ScreenCaptureDeviceCore::~ScreenCaptureDeviceCore() { | 93 ScreenCaptureDeviceCore::~ScreenCaptureDeviceCore() { |
| 97 DCHECK(thread_checker_.CalledOnValidThread()); | 94 DCHECK(thread_checker_.CalledOnValidThread()); |
| 98 DCHECK_NE(state_, kCapturing); | 95 DCHECK_NE(state_, kCapturing); |
| 99 if (capture_machine_) { | 96 if (capture_machine_) { |
| 100 capture_machine_->Stop( | 97 capture_machine_->Stop( |
| 101 base::Bind(&DeleteCaptureMachine, base::Passed(&capture_machine_))); | 98 base::Bind(&DeleteCaptureMachine, base::Passed(&capture_machine_))); |
| 102 } | 99 } |
| 103 DVLOG(1) << "ScreenCaptureDeviceCore@" << this << " destroying."; | 100 DVLOG(1) << "ScreenCaptureDeviceCore@" << this << " destroying."; |
| 104 } | 101 } |
| 105 | 102 |
| 106 void ScreenCaptureDeviceCore::TransitionStateTo(State next_state) { | 103 void ScreenCaptureDeviceCore::TransitionStateTo(State next_state) { |
| 107 DCHECK(thread_checker_.CalledOnValidThread()); | 104 DCHECK(thread_checker_.CalledOnValidThread()); |
| 108 | 105 |
| 109 #ifndef NDEBUG | 106 #ifndef NDEBUG |
| 110 static const char* kStateNames[] = { | 107 static const char* kStateNames[] = {"Idle", "Capturing", "Error"}; |
|
mcasas
2015/10/29 23:06:08
|State| had only 3 entries, so I guess l.111 was s
| |
| 111 "Idle", "Allocated", "Capturing", "Error"}; | 108 static_assert(arraysize(kStateNames) == kLastCaptureState, |
| 109 "Different number of states and textual descriptions"); | |
| 112 DVLOG(1) << "State change: " << kStateNames[state_] << " --> " | 110 DVLOG(1) << "State change: " << kStateNames[state_] << " --> " |
| 113 << kStateNames[next_state]; | 111 << kStateNames[next_state]; |
| 114 #endif | 112 #endif |
| 115 | 113 |
| 116 state_ = next_state; | 114 state_ = next_state; |
| 117 } | 115 } |
| 118 | 116 |
| 119 void ScreenCaptureDeviceCore::Error(const std::string& reason) { | 117 void ScreenCaptureDeviceCore::Error(const tracked_objects::Location& from_here, |
| 118 const std::string& reason) { | |
| 120 DCHECK(thread_checker_.CalledOnValidThread()); | 119 DCHECK(thread_checker_.CalledOnValidThread()); |
| 121 | 120 |
| 122 if (state_ == kIdle) | 121 if (state_ == kIdle) |
| 123 return; | 122 return; |
| 124 | 123 |
| 125 if (oracle_proxy_.get()) | 124 if (oracle_proxy_.get()) |
| 126 oracle_proxy_->ReportError(reason); | 125 oracle_proxy_->ReportError(from_here, reason); |
| 127 | 126 |
| 128 StopAndDeAllocate(); | 127 StopAndDeAllocate(); |
| 129 TransitionStateTo(kError); | 128 TransitionStateTo(kError); |
| 130 } | 129 } |
| 131 | 130 |
| 132 } // namespace media | 131 } // namespace media |
| OLD | NEW |