| 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 void RegisterCameraHal(arc::mojom::ArcCamera3HalPtr camera_hal) final; |
| 39 |
| 40 void RegisterClient(arc::mojom::ArcCamera3ClientPtr client) final; |
| 41 |
| 42 bool is_started() { |
| 43 return proxy_thread_.IsRunning() && blocking_io_thread_.IsRunning(); |
| 44 } |
| 45 |
| 46 private: |
| 47 friend base::DefaultSingletonTraits<ArcCamera3Service>; |
| 48 |
| 49 ArcCamera3Service(); |
| 50 |
| 51 ~ArcCamera3Service(); |
| 52 |
| 53 void StopOnProxyThread(); |
| 54 |
| 55 void CreateSocket(); |
| 56 |
| 57 void CreateServiceLoop(mojo::edk::ScopedPlatformHandle socket_fd); |
| 58 |
| 59 void WaitForIncomingConnection(base::ScopedFD cancel_fd); |
| 60 |
| 61 void OnPeerConnected(mojo::ScopedMessagePipeHandle message_pipe); |
| 62 |
| 63 void OnCameraHalConnectionError(); |
| 64 void OnMojoClientConnectionError(CameraClientObserver* client); |
| 65 |
| 66 mojo::edk::ScopedPlatformHandle proxy_fd_; |
| 67 base::ScopedFD cancel_pipe_; |
| 68 |
| 69 base::Thread proxy_thread_; |
| 70 base::Thread blocking_io_thread_; |
| 71 scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner_; |
| 72 scoped_refptr<base::SingleThreadTaskRunner> blocking_io_task_runner_; |
| 73 |
| 74 std::vector<std::unique_ptr<mojo::Binding<arc::mojom::ArcCamera3Service>>> |
| 75 bindings_; |
| 76 |
| 77 class CameraHal : public base::SupportsWeakPtr<CameraHal> { |
| 78 public: |
| 79 explicit CameraHal(arc::mojom::ArcCamera3HalPtr camera_hal); |
| 80 |
| 81 void OpenCameraHal( |
| 82 const base::Callback<void(arc::mojom::CameraModulePtr camera_module)> |
| 83 callback); |
| 84 |
| 85 private: |
| 86 arc::mojom::ArcCamera3HalPtr camera_hal_; |
| 87 DISALLOW_IMPLICIT_CONSTRUCTORS(CameraHal); |
| 88 }; |
| 89 std::unique_ptr<CameraHal> camera_hal_; |
| 90 |
| 91 std::set<std::unique_ptr<CameraClientObserver>> client_observers_; |
| 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(ArcCamera3Service); |
| 94 }; |
| 95 |
| 96 } // namespace media |
| 97 |
| 98 #endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_ARC_CAMERA3_SERVICE_H_ |
| OLD | NEW |