Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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: | 
| 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 DiscardDeviceInfosAndCallContinuation( | |
| 54 base::Closure continuation, | |
| 55 const std::vector<media::VideoCaptureDeviceInfo>&); | |
| 56 void CreateAndAddNewDevice(const std::string& device_id, | |
| 57 mojom::DeviceRequest device_request, | |
| 58 const CreateDeviceCallback& callback); | |
| 51 void OnClientConnectionErrorOrClose(const std::string& device_id); | 59 void OnClientConnectionErrorOrClose(const std::string& device_id); | 
| 52 | 60 | 
| 61 const std::unique_ptr<service_manager::ServiceContextRef> service_ref_; | |
| 53 const std::unique_ptr<media::VideoCaptureSystem> capture_system_; | 62 const std::unique_ptr<media::VideoCaptureSystem> capture_system_; | 
| 54 const media::VideoCaptureJpegDecoderFactoryCB jpeg_decoder_factory_callback_; | 63 const media::VideoCaptureJpegDecoderFactoryCB jpeg_decoder_factory_callback_; | 
| 55 std::map<std::string, ActiveDeviceEntry> active_devices_by_id_; | 64 std::map<std::string, ActiveDeviceEntry> active_devices_by_id_; | 
| 65 bool has_called_get_device_infos_ = false; | |
| 
 
mcasas
2017/04/26 22:12:31
nit: initialize this to false in the ctor initiali
 
chfremer
2017/04/26 23:33:35
Done.
 
 | |
| 66 | |
| 67 base::WeakPtrFactory<DeviceFactoryMediaToMojoAdapter> weak_factory_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(DeviceFactoryMediaToMojoAdapter); | |
| 56 }; | 70 }; | 
| 57 | 71 | 
| 58 } // namespace video_capture | 72 } // namespace video_capture | 
| 59 | 73 | 
| 60 #endif // SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_ | 74 #endif // SERVICES_VIDEO_CAPTURE_DEVICE_FACTORY_MEDIA_TO_MOJO_ADAPTER_H_ | 
| OLD | NEW |