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

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: Rebase to May 19th 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 VideoCaptureDeviceLauncherSwitcher : public VideoCaptureDeviceLauncher {
14 public:
15 VideoCaptureDeviceLauncherSwitcher(
16 std::unique_ptr<VideoCaptureDeviceLauncher> media_device_launcher,
17 std::unique_ptr<VideoCaptureDeviceLauncher> other_types_launcher)
18 : media_device_launcher_(std::move(media_device_launcher)),
19 other_types_launcher_(std::move(other_types_launcher)) {}
20
21 ~VideoCaptureDeviceLauncherSwitcher() override {}
22
23 void LaunchDeviceAsync(const std::string& device_id,
24 MediaStreamType stream_type,
25 const media::VideoCaptureParams& params,
26 base::WeakPtr<media::VideoFrameReceiver> receiver,
27 Callbacks* callbacks,
28 base::OnceClosure done_cb) override {
29 if (stream_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) {
30 // Use of Unretained() is safe, because |media_device_launcher_| is owned
31 // by |this|.
32 abort_launch_cb_ =
33 base::Bind(&VideoCaptureDeviceLauncher::AbortLaunch,
34 base::Unretained(media_device_launcher_.get()));
35 return media_device_launcher_->LaunchDeviceAsync(
36 device_id, stream_type, params, std::move(receiver), callbacks,
37 std::move(done_cb));
38 }
39 // Use of Unretained() is safe, because |other_types_launcher_| is owned by
40 // |this|.
41 abort_launch_cb_ =
42 base::Bind(&VideoCaptureDeviceLauncher::AbortLaunch,
43 base::Unretained(other_types_launcher_.get()));
44 return other_types_launcher_->LaunchDeviceAsync(
45 device_id, stream_type, params, std::move(receiver), callbacks,
46 std::move(done_cb));
47 }
48
49 void AbortLaunch() override {
50 if (abort_launch_cb_.is_null())
51 return;
52 base::ResetAndReturn(&abort_launch_cb_).Run();
53 }
54
55 private:
56 const std::unique_ptr<VideoCaptureDeviceLauncher> media_device_launcher_;
57 const std::unique_ptr<VideoCaptureDeviceLauncher> other_types_launcher_;
58 base::OnceClosure abort_launch_cb_;
59 };
60
61 } // anonymous namespace
62
63 VideoCaptureProviderSwitcher::VideoCaptureProviderSwitcher(
64 std::unique_ptr<VideoCaptureProvider> media_device_capture_provider,
65 std::unique_ptr<VideoCaptureProvider> other_types_capture_provider)
66 : media_device_capture_provider_(std::move(media_device_capture_provider)),
67 other_types_capture_provider_(std::move(other_types_capture_provider)) {}
68
69 VideoCaptureProviderSwitcher::~VideoCaptureProviderSwitcher() = default;
70
71 void VideoCaptureProviderSwitcher::Uninitialize() {
72 media_device_capture_provider_->Uninitialize();
73 other_types_capture_provider_->Uninitialize();
74 }
75
76 void VideoCaptureProviderSwitcher::GetDeviceInfosAsync(
77 const GetDeviceInfosCallback& result_callback) {
78 media_device_capture_provider_->GetDeviceInfosAsync(result_callback);
79 }
80
81 std::unique_ptr<VideoCaptureDeviceLauncher>
82 VideoCaptureProviderSwitcher::CreateDeviceLauncher() {
83 return base::MakeUnique<VideoCaptureDeviceLauncherSwitcher>(
84 media_device_capture_provider_->CreateDeviceLauncher(),
85 other_types_capture_provider_->CreateDeviceLauncher());
86 }
87
88 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698