Index: media/capture/service/video_capture_device_client_impl.h |
diff --git a/media/capture/service/video_capture_device_client_impl.h b/media/capture/service/video_capture_device_client_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..68c41e606ab47e8e2f1a3937610bf3b8d2cce5a5 |
--- /dev/null |
+++ b/media/capture/service/video_capture_device_client_impl.h |
@@ -0,0 +1,104 @@ |
+// 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 CONTENT_BROWSER_VIDEO_CAPTURE_VIDEO_CAPTURE_ADAPTER_H_ |
+#define CONTENT_BROWSER_VIDEO_CAPTURE_VIDEO_CAPTURE_ADAPTER_H_ |
+ |
+#include <string> |
+ |
+#include "base/callback_forward.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" |
+ |
+namespace base { |
+class TimeTicks; |
+} |
+ |
+namespace gfx { |
+class Size; |
+} |
+ |
+namespace media { |
+class VideoFrame; |
+} |
+ |
+namespace media { |
+ |
+class MojoVideoFrame; |
+ |
+// 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 allocated |
+// VideoFrames have a SharedMemory inside. The interface-defined Buffer is a |
+// thin wrapper around those. |
+// This class lives inside whichever thread the VideoCaptureDevice lives. It |
+// sends data back to its unique Delegate in that very thread. |
+class VideoCaptureDeviceClientImpl : public media::VideoCaptureDevice::Client { |
+ public: |
+ class Delegate { |
+ public: |
+ virtual ~Delegate() {} |
+ |
+ // Called when a new |frame| is available, on Device Thread. |
+ virtual void OnFrame(const scoped_refptr<MojoVideoFrame>& frame, |
+ const base::TimeTicks& timestamp) = 0; |
+ |
+ // Called when there has been a fatal error which invalidates capture. |
+ 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 VideoCaptureDeviceClientImpl(Delegate* delegate); |
+ |
+ ~VideoCaptureDeviceClientImpl() override; |
+ |
+ private: |
+ friend class VideoCaptureDeviceClientImplTest; |
+ 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; |
+ 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* const delegate_; |
+ |
+ // The underlying multithreaded MojoVideoFrame pool. |
+ const scoped_refptr<VideoFramePool> video_frame_pool_; |
+ |
+ // This class is single threaded except construction. |
+ base::ThreadChecker thread_checker_; |
+ |
+ base::WeakPtrFactory<VideoCaptureDeviceClientImpl> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClientImpl); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // CONTENT_BROWSER_VIDEO_CAPTURE_VIDEO_CAPTURE_ADAPTER_H_ |