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

Unified Diff: components/video_capture/device_client_impl.h

Issue 1637793004: [WIP] Mojo Video Capture thingy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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: components/video_capture/device_client_impl.h
diff --git a/components/video_capture/device_client_impl.h b/components/video_capture/device_client_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..01ddee2e98ead6e7df558240d2c4b7a92bfd65a5
--- /dev/null
+++ b/components/video_capture/device_client_impl.h
@@ -0,0 +1,112 @@
+// Copyright 2016 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 COMPONENTS_VIDEO_CAPTURE_DEVICE_CLIENT_IMPL_H_
+#define COMPONENTS_VIDEO_CAPTURE_DEVICE_CLIENT_IMPL_H_
+
+#include <string>
+
+#include "base/callback_forward.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/thread_checker.h"
+#include "media/base/video_capture_types.h"
+#include "media/base/video_types.h"
+#include "media/capture/video/video_capture_device.h"
+#include "mojo/public/cpp/system/buffer.h"
+
+namespace base {
+class TimeTicks;
+}
+
+namespace gfx {
+class Size;
+}
+
+namespace media {
+class VideoFrame;
+}
+
+namespace video_capture {
+
+// Device client implementation. We are owned by a VideoCaptureDevice that calls
+// with captured data (usually via OnIncomingCapturedData()) that gets converted
+// into a VideoFrame and sent to our Delegate.
+// This class uses an internal VideoFramePool, a simple pool where theallocated
+// VideoFrames have a SharedMemory inside. The interface-defined Buffer is a
+// thin wrapper around those.
+class DeviceClientImpl : public media::VideoCaptureDevice::Client {
+ public:
+ class Delegate {
+ public:
+ virtual ~Delegate() {}
+
+ // Called when a frame buffer is populated with new frame data. The delegate
+ // should run |release_callback| when done with the frame.
+ virtual void OnFrame(const scoped_refptr<media::VideoFrame>& frame,
+ const base::TimeTicks& timestamp,
+ const base::Closure& release_callback) = 0;
+
+ // Called when there has been a fatal error which invalidates the capture
+ // device.
+ virtual void OnError(const std::string& reason) = 0;
+ };
+
+ // The Delegate implementation needs to be thread-safe. More specifically,
+ // each Delegate method should be safe to call on the same arbitrary thread.
+ // |delegate| is not owned and must outlive |this|.
+ explicit DeviceClientImpl(Delegate* delegate);
+
+ ~DeviceClientImpl() override;
+
+ private:
+ friend class DeviceClientImplTest;
+ class VideoFramePool;
+
+ // media::VideoCaptureDevice::Client:
+ void OnIncomingCapturedData(const uint8_t* data,
+ int length,
+ const media::VideoCaptureFormat& frame_format,
+ int clockwise_rotation,
+ const base::TimeTicks& timestamp) override;
+ void OnIncomingCapturedYuvData(const uint8_t* y_data,
+ const uint8_t* u_data,
+ const uint8_t* v_data,
+ size_t y_stride,
+ size_t u_stride,
+ size_t v_stride,
+ const media::VideoCaptureFormat& frame_format,
+ int clockwise_rotation,
+ const base::TimeTicks& timestamp) override;
+ scoped_ptr<Buffer> ReserveOutputBuffer(
+ const gfx::Size& dimensions,
+ media::VideoPixelFormat pixel_format,
+ media::VideoPixelStorage pixel_storage) override;
+ void OnIncomingCapturedBuffer(scoped_ptr<Buffer> buffer,
+ const media::VideoCaptureFormat& frame_format,
+ const base::TimeTicks& timestamp) override;
+ void OnIncomingCapturedVideoFrame(
+ scoped_ptr<Buffer> buffer,
+ const scoped_refptr<media::VideoFrame>& frame,
+ const base::TimeTicks& timestamp) override;
+ void OnError(const tracked_objects::Location& from_here,
+ const std::string& reason) override;
+ double GetBufferPoolUtilization() const override;
+
+ // The |delegate_| to where we send the capture-converted VideoFrames.
+ Delegate* delegate_;
+
+ scoped_refptr<VideoFramePool> video_frame_pool_;
+
+ base::ThreadChecker thread_checker_;
+
+ base::WeakPtrFactory<DeviceClientImpl> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeviceClientImpl);
+};
+
+} // namespace video_capture
+
+#endif // COMPONENTS_VIDEO_CAPTURE_DEVICE_CLIENT_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698