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

Side by Side Diff: services/video_capture/device_factory_media_to_mojo_adapter.h

Issue 2824883005: [Mojo Video Capture] Stop service when last client disconnects. (Closed)
Patch Set: Incorporate suggestions from PatchSet #4 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
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 #ifndef SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_ 5 #ifndef SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_
6 #define SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_ 6 #define SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "media/capture/video/video_capture_device_client.h" 10 #include "media/capture/video/video_capture_device_client.h"
11 #include "media/capture/video/video_capture_system.h" 11 #include "media/capture/video/video_capture_system.h"
12 #include "mojo/public/cpp/bindings/binding.h" 12 #include "mojo/public/cpp/bindings/binding.h"
13 #include "services/service_manager/public/cpp/service_context_ref.h"
13 #include "services/video_capture/public/interfaces/device_factory.mojom.h" 14 #include "services/video_capture/public/interfaces/device_factory.mojom.h"
14 15
15 namespace video_capture { 16 namespace video_capture {
16 17
17 class DeviceMediaToMojoAdapter; 18 class DeviceMediaToMojoAdapter;
18 19
19 // Wraps a media::VideoCaptureSystem and exposes its functionality through the 20 // Wraps a media::VideoCaptureSystem and exposes its functionality through the
20 // mojom::DeviceFactory interface. Keeps track of device instances that have 21 // mojom::DeviceFactory interface. Keeps track of device instances that have
21 // been created to ensure that it does not create more than one instance of the 22 // been created to ensure that it does not create more than one instance of the
22 // same media::VideoCaptureDevice at the same time. 23 // same media::VideoCaptureDevice at the same time.
23 class DeviceFactoryMediaToMojoAdapter : public mojom::DeviceFactory { 24 class DeviceFactoryMediaToMojoAdapter : public mojom::DeviceFactory {
24 public: 25 public:
25 DeviceFactoryMediaToMojoAdapter( 26 DeviceFactoryMediaToMojoAdapter(
27 std::unique_ptr<service_manager::ServiceContextRef> service_ref,
26 std::unique_ptr<media::VideoCaptureSystem> capture_system, 28 std::unique_ptr<media::VideoCaptureSystem> capture_system,
27 const media::VideoCaptureJpegDecoderFactoryCB& 29 const media::VideoCaptureJpegDecoderFactoryCB&
28 jpeg_decoder_factory_callback); 30 jpeg_decoder_factory_callback);
29 ~DeviceFactoryMediaToMojoAdapter() override; 31 ~DeviceFactoryMediaToMojoAdapter() override;
30 32
31 // mojom::DeviceFactory: 33 // mojom::DeviceFactory implementation.
32 void GetDeviceInfos(const GetDeviceInfosCallback& callback) override; 34 void GetDeviceInfos(const GetDeviceInfosCallback& callback) override;
33 void CreateDevice(const std::string& device_id, 35 void CreateDevice(const std::string& device_id,
34 mojom::DeviceRequest device_request, 36 mojom::DeviceRequest device_request,
35 const CreateDeviceCallback& callback) override; 37 const CreateDeviceCallback& callback) override;
36 38
37 private: 39 private:
38 struct ActiveDeviceEntry { 40 struct ActiveDeviceEntry {
39 ActiveDeviceEntry(); 41 ActiveDeviceEntry();
40 ~ActiveDeviceEntry(); 42 ~ActiveDeviceEntry();
41 ActiveDeviceEntry(ActiveDeviceEntry&& other); 43 ActiveDeviceEntry(ActiveDeviceEntry&& other);
42 ActiveDeviceEntry& operator=(ActiveDeviceEntry&& other); 44 ActiveDeviceEntry& operator=(ActiveDeviceEntry&& other);
43 45
44 std::unique_ptr<DeviceMediaToMojoAdapter> device; 46 std::unique_ptr<DeviceMediaToMojoAdapter> device;
45 // TODO(chfremer) Use mojo::Binding<> directly instead of unique_ptr<> when 47 // TODO(chfremer) Use mojo::Binding<> directly instead of unique_ptr<> when
46 // mojo::Binding<> supports move operators. 48 // mojo::Binding<> supports move operators.
47 // https://crbug.com/644314 49 // https://crbug.com/644314
48 std::unique_ptr<mojo::Binding<mojom::Device>> binding; 50 std::unique_ptr<mojo::Binding<mojom::Device>> binding;
49 }; 51 };
50 52
53 void CreateAndAddNewDevice(const std::string& device_id,
54 mojom::DeviceRequest device_request,
55 const CreateDeviceCallback& callback);
51 void OnClientConnectionErrorOrClose(const std::string& device_id); 56 void OnClientConnectionErrorOrClose(const std::string& device_id);
52 57
58 const std::unique_ptr<service_manager::ServiceContextRef> service_ref_;
53 const std::unique_ptr<media::VideoCaptureSystem> capture_system_; 59 const std::unique_ptr<media::VideoCaptureSystem> capture_system_;
54 const media::VideoCaptureJpegDecoderFactoryCB jpeg_decoder_factory_callback_; 60 const media::VideoCaptureJpegDecoderFactoryCB jpeg_decoder_factory_callback_;
55 std::map<std::string, ActiveDeviceEntry> active_devices_by_id_; 61 std::map<std::string, ActiveDeviceEntry> active_devices_by_id_;
62 bool has_called_get_device_infos_;
63
64 base::WeakPtrFactory<DeviceFactoryMediaToMojoAdapter> weak_factory_;
65
66 DISALLOW_COPY_AND_ASSIGN(DeviceFactoryMediaToMojoAdapter);
56 }; 67 };
57 68
58 } // namespace video_capture 69 } // namespace video_capture
59 70
60 #endif // SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_ 71 #endif // SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_
OLDNEW
« no previous file with comments | « services/video_capture/BUILD.gn ('k') | services/video_capture/device_factory_media_to_mojo_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698