| OLD | NEW |
| (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 #ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_ARC_CAMERA3_SERVICE_H_ |
| 6 #define MEDIA_CAPTURE_VIDEO_CHROMEOS_ARC_CAMERA3_SERVICE_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/memory/singleton.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread.h" |
| 14 #include "media/capture/capture_export.h" |
| 15 #include "media/capture/video/chromeos/mojo/arc_camera3_service.mojom.h" |
| 16 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 17 #include "mojo/public/cpp/bindings/binding_set.h" |
| 18 #include "mojo/public/cpp/bindings/interface_ptr_set.h" |
| 19 |
| 20 namespace media { |
| 21 |
| 22 class CAPTURE_EXPORT ArcCamera3Service final |
| 23 : public arc::mojom::ArcCamera3Service { |
| 24 public: |
| 25 class CameraClientObserver |
| 26 : public base::SupportsWeakPtr<CameraClientObserver> { |
| 27 public: |
| 28 virtual void NotifyCameraHalRegistered( |
| 29 arc::mojom::CameraModulePtr camera_module) = 0; |
| 30 }; |
| 31 |
| 32 static ArcCamera3Service* GetInstance(); |
| 33 |
| 34 bool Start(); |
| 35 |
| 36 void AddClientObserver(std::unique_ptr<CameraClientObserver> observer); |
| 37 |
| 38 bool is_started() { |
| 39 return proxy_thread_.IsRunning() && blocking_io_thread_.IsRunning(); |
| 40 } |
| 41 |
| 42 private: |
| 43 // A WeakPtr wrapper class around arc::mojom::ArcCamera3HalPtr. |
| 44 class CameraHal : public base::SupportsWeakPtr<CameraHal> { |
| 45 public: |
| 46 explicit CameraHal(arc::mojom::ArcCamera3HalPtr camera_hal); |
| 47 |
| 48 void OpenCameraHal(arc::mojom::CameraModuleRequest camera_module_request); |
| 49 |
| 50 private: |
| 51 arc::mojom::ArcCamera3HalPtr camera_hal_; |
| 52 DISALLOW_IMPLICIT_CONSTRUCTORS(CameraHal); |
| 53 }; |
| 54 |
| 55 friend base::DefaultSingletonTraits<ArcCamera3Service>; |
| 56 |
| 57 ArcCamera3Service(); |
| 58 ~ArcCamera3Service(); |
| 59 |
| 60 // Creates the unix domain socket for the camera client processes and the |
| 61 // camera HALv3 adapter process to connect. |
| 62 void CreateSocket(); |
| 63 |
| 64 void CreateServiceLoop(mojo::edk::ScopedPlatformHandle socket_fd); |
| 65 |
| 66 // Waits for incoming connections (from HAL process or from client processes). |
| 67 // Runs on |blocking_io_thread_|. |
| 68 void WaitForIncomingConnection(base::ScopedFD cancel_fd); |
| 69 |
| 70 // ArcCamera3Service implementations. |
| 71 void RegisterCameraHal(arc::mojom::ArcCamera3HalPtr camera_hal) final; |
| 72 void RegisterClient(arc::mojom::ArcCamera3ClientPtr client) final; |
| 73 |
| 74 void AddClientObserverOnProxyThread( |
| 75 std::unique_ptr<CameraClientObserver> observer); |
| 76 |
| 77 // Handler for incoming Mojo connection on the unix domain socket. |
| 78 void OnPeerConnected(mojo::ScopedMessagePipeHandle message_pipe); |
| 79 |
| 80 // Mojo connection error handlers. |
| 81 void OnCameraHalConnectionError(); |
| 82 void OnMojoClientConnectionError(CameraClientObserver* client); |
| 83 |
| 84 void StopOnProxyThread(); |
| 85 |
| 86 mojo::edk::ScopedPlatformHandle proxy_fd_; |
| 87 base::ScopedFD cancel_pipe_; |
| 88 |
| 89 base::Thread proxy_thread_; |
| 90 base::Thread blocking_io_thread_; |
| 91 scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner_; |
| 92 scoped_refptr<base::SingleThreadTaskRunner> blocking_io_task_runner_; |
| 93 |
| 94 std::vector<std::unique_ptr<mojo::Binding<arc::mojom::ArcCamera3Service>>> |
| 95 bindings_; |
| 96 |
| 97 std::unique_ptr<CameraHal> camera_hal_; |
| 98 |
| 99 std::set<std::unique_ptr<CameraClientObserver>> client_observers_; |
| 100 |
| 101 DISALLOW_COPY_AND_ASSIGN(ArcCamera3Service); |
| 102 }; |
| 103 |
| 104 } // namespace media |
| 105 |
| 106 #endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_ARC_CAMERA3_SERVICE_H_ |
| OLD | NEW |