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

Unified Diff: media/capture/video/chromeos/arc_camera3_service.h

Issue 2878233002: media: add ArcCamera3Service Mojo service (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: media/capture/video/chromeos/arc_camera3_service.h
diff --git a/media/capture/video/chromeos/arc_camera3_service.h b/media/capture/video/chromeos/arc_camera3_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..cb16da3cdc2f28e849c3d56421e24c741dd1ec46
--- /dev/null
+++ b/media/capture/video/chromeos/arc_camera3_service.h
@@ -0,0 +1,98 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_ARC_CAMERA3_SERVICE_H_
+#define MEDIA_CAPTURE_VIDEO_CHROMEOS_ARC_CAMERA3_SERVICE_H_
+
+#include <vector>
+
+#include "base/memory/singleton.h"
+#include "base/memory/weak_ptr.h"
+#include "base/single_thread_task_runner.h"
+#include "base/threading/thread.h"
+#include "media/capture/capture_export.h"
+#include "media/capture/video/chromeos/mojo/arc_camera3_service.mojom.h"
+#include "mojo/edk/embedder/scoped_platform_handle.h"
+#include "mojo/public/cpp/bindings/binding_set.h"
+#include "mojo/public/cpp/bindings/interface_ptr_set.h"
+
+namespace media {
+
+class CAPTURE_EXPORT ArcCamera3Service final
+ : public arc::mojom::ArcCamera3Service {
+ public:
+ class CameraClientObserver
+ : public base::SupportsWeakPtr<CameraClientObserver> {
+ public:
+ virtual void NotifyCameraHalRegistered(
+ arc::mojom::CameraModulePtr camera_module) = 0;
+ };
+
+ static ArcCamera3Service* GetInstance();
+
+ bool Start();
+
+ void AddClientObserver(std::unique_ptr<CameraClientObserver> observer);
+
+ void RegisterCameraHal(arc::mojom::ArcCamera3HalPtr camera_hal) final;
+
+ void RegisterClient(arc::mojom::ArcCamera3ClientPtr client) final;
+
+ bool is_started() {
+ return proxy_thread_.IsRunning() && blocking_io_thread_.IsRunning();
+ }
+
+ private:
+ friend base::DefaultSingletonTraits<ArcCamera3Service>;
+
+ ArcCamera3Service();
+
+ ~ArcCamera3Service();
+
+ void StopOnProxyThread();
+
+ void CreateSocket();
+
+ void CreateServiceLoop(mojo::edk::ScopedPlatformHandle socket_fd);
+
+ void WaitForIncomingConnection(base::ScopedFD cancel_fd);
+
+ void OnPeerConnected(mojo::ScopedMessagePipeHandle message_pipe);
+
+ void OnCameraHalConnectionError();
+ void OnMojoClientConnectionError(CameraClientObserver* client);
+
+ mojo::edk::ScopedPlatformHandle proxy_fd_;
+ base::ScopedFD cancel_pipe_;
+
+ base::Thread proxy_thread_;
+ base::Thread blocking_io_thread_;
+ scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner_;
+ scoped_refptr<base::SingleThreadTaskRunner> blocking_io_task_runner_;
+
+ std::vector<std::unique_ptr<mojo::Binding<arc::mojom::ArcCamera3Service>>>
+ bindings_;
+
+ class CameraHal : public base::SupportsWeakPtr<CameraHal> {
+ public:
+ explicit CameraHal(arc::mojom::ArcCamera3HalPtr camera_hal);
+
+ void OpenCameraHal(
+ const base::Callback<void(arc::mojom::CameraModulePtr camera_module)>
+ callback);
+
+ private:
+ arc::mojom::ArcCamera3HalPtr camera_hal_;
+ DISALLOW_IMPLICIT_CONSTRUCTORS(CameraHal);
+ };
+ std::unique_ptr<CameraHal> camera_hal_;
+
+ std::set<std::unique_ptr<CameraClientObserver>> client_observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(ArcCamera3Service);
+};
+
+} // namespace media
+
+#endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_ARC_CAMERA3_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698