Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: content/browser/renderer_host/media/video_capture_provider_switcher.cc

Issue 2867213004: [Mojo Video Capture] Hook up video capture service behind a feature flag (Closed)
Patch Set: Incorporate suggestions from PatchSet 5 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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
5 #include "content/browser/renderer_host/media/video_capture_provider_switcher.h"
6
7 #include "base/callback_helpers.h"
8
9 namespace content {
10
11 namespace {
12
13 class CONTENT_EXPORT VideoCaptureDeviceLauncherSwitcher
14 : public VideoCaptureDeviceLauncher {
15 public:
16 VideoCaptureDeviceLauncherSwitcher(
17 std::unique_ptr<VideoCaptureDeviceLauncher> media_device_launcher,
18 std::unique_ptr<VideoCaptureDeviceLauncher> other_types_launcher)
19 : media_device_launcher_(std::move(media_device_launcher)),
20 other_types_launcher_(std::move(other_types_launcher)) {}
21
22 ~VideoCaptureDeviceLauncherSwitcher() override {}
23
24 void LaunchDeviceAsync(const std::string& device_id,
25 MediaStreamType stream_type,
26 const media::VideoCaptureParams& params,
27 base::WeakPtr<media::VideoFrameReceiver> receiver,
28 Callbacks* callbacks,
29 base::OnceClosure done_cb) override {
30 if (stream_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) {
31 abort_launch_cb_ =
32 base::Bind(&VideoCaptureDeviceLauncher::AbortLaunch,
33 base::Unretained(media_device_launcher_.get()));
piman 2017/05/15 19:34:32 nit: keeping around a callback works, but feels co
chfremer 2017/05/15 22:08:13 I do not disagree. It appears opinions among revie
34 return media_device_launcher_->LaunchDeviceAsync(
35 device_id, stream_type, params, std::move(receiver), callbacks,
36 std::move(done_cb));
37 }
38 abort_launch_cb_ =
39 base::Bind(&VideoCaptureDeviceLauncher::AbortLaunch,
40 base::Unretained(other_types_launcher_.get()));
41 return other_types_launcher_->LaunchDeviceAsync(
42 device_id, stream_type, params, std::move(receiver), callbacks,
43 std::move(done_cb));
44 }
45
46 void AbortLaunch() override {
47 if (abort_launch_cb_.is_null())
48 return;
49 base::ResetAndReturn(&abort_launch_cb_).Run();
50 }
51
52 private:
53 const std::unique_ptr<VideoCaptureDeviceLauncher> media_device_launcher_;
54 const std::unique_ptr<VideoCaptureDeviceLauncher> other_types_launcher_;
55 base::OnceClosure abort_launch_cb_;
56 };
57
58 } // anonymous namespace
59
60 VideoCaptureProviderSwitcher::VideoCaptureProviderSwitcher(
61 std::unique_ptr<VideoCaptureProvider> media_device_capture_provider,
62 std::unique_ptr<VideoCaptureProvider> other_types_capture_provider)
63 : media_device_capture_provider_(std::move(media_device_capture_provider)),
64 other_types_capture_provider_(std::move(other_types_capture_provider)) {}
65
66 VideoCaptureProviderSwitcher::~VideoCaptureProviderSwitcher() = default;
67
68 void VideoCaptureProviderSwitcher::Uninitialize() {
69 media_device_capture_provider_->Uninitialize();
70 other_types_capture_provider_->Uninitialize();
71 }
72
73 void VideoCaptureProviderSwitcher::GetDeviceInfosAsync(
74 const base::Callback<void(
75 const std::vector<media::VideoCaptureDeviceInfo>&)>& result_callback) {
76 media_device_capture_provider_->GetDeviceInfosAsync(result_callback);
77 }
78
79 std::unique_ptr<VideoCaptureDeviceLauncher>
80 VideoCaptureProviderSwitcher::CreateDeviceLauncher() {
81 return base::MakeUnique<VideoCaptureDeviceLauncherSwitcher>(
82 media_device_capture_provider_->CreateDeviceLauncher(),
83 other_types_capture_provider_->CreateDeviceLauncher());
84 }
85
86 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698