OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 CONTENT_BROWSER_VIDEO_CAPTURE_VIDEO_CAPTURE_ADAPTER_H_ |
| 6 #define CONTENT_BROWSER_VIDEO_CAPTURE_VIDEO_CAPTURE_ADAPTER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/thread_checker.h" |
| 14 #include "media/base/video_capture_types.h" |
| 15 #include "media/base/video_types.h" |
| 16 #include "media/capture/video/video_capture_device.h" |
| 17 |
| 18 namespace base { |
| 19 class TimeTicks; |
| 20 } |
| 21 |
| 22 namespace gfx { |
| 23 class Size; |
| 24 } |
| 25 |
| 26 namespace media { |
| 27 class VideoFrame; |
| 28 } |
| 29 |
| 30 namespace media { |
| 31 |
| 32 class MojoVideoFrame; |
| 33 |
| 34 // Device Client implementation. We are owned by a VideoCaptureDevice that calls |
| 35 // with captured data (usually via OnIncomingCapturedData()) that gets converted |
| 36 // into a VideoFrame and sent to our Delegate. |
| 37 // This class uses an internal VideoFramePool, a simple pool where allocated |
| 38 // VideoFrames have a SharedMemory inside. The interface-defined Buffer is a |
| 39 // thin wrapper around those. |
| 40 // This class lives inside whichever thread the VideoCaptureDevice lives. It |
| 41 // sends data back to its unique Delegate in that very thread. |
| 42 class VideoCaptureDeviceClientImpl : public media::VideoCaptureDevice::Client { |
| 43 public: |
| 44 class Delegate { |
| 45 public: |
| 46 virtual ~Delegate() {} |
| 47 |
| 48 // Called when a new |frame| is available, on Device Thread. |
| 49 virtual void OnFrame(const scoped_refptr<MojoVideoFrame>& frame, |
| 50 const base::TimeTicks& timestamp) = 0; |
| 51 |
| 52 // Called when there has been a fatal error which invalidates capture. |
| 53 virtual void OnError(const std::string& reason) = 0; |
| 54 }; |
| 55 |
| 56 // The Delegate implementation needs to be thread-safe. More specifically, |
| 57 // each Delegate method should be safe to call on the same arbitrary thread. |
| 58 // |delegate| is not owned and must outlive |this|. |
| 59 explicit VideoCaptureDeviceClientImpl(Delegate* delegate); |
| 60 |
| 61 ~VideoCaptureDeviceClientImpl() override; |
| 62 |
| 63 private: |
| 64 friend class VideoCaptureDeviceClientImplTest; |
| 65 class VideoFramePool; |
| 66 |
| 67 // media::VideoCaptureDevice::Client: |
| 68 void OnIncomingCapturedData(const uint8_t* data, |
| 69 int length, |
| 70 const media::VideoCaptureFormat& frame_format, |
| 71 int clockwise_rotation, |
| 72 const base::TimeTicks& timestamp) override; |
| 73 scoped_ptr<Buffer> ReserveOutputBuffer( |
| 74 const gfx::Size& dimensions, |
| 75 media::VideoPixelFormat pixel_format, |
| 76 media::VideoPixelStorage pixel_storage) override; |
| 77 void OnIncomingCapturedBuffer(scoped_ptr<Buffer> buffer, |
| 78 const media::VideoCaptureFormat& frame_format, |
| 79 const base::TimeTicks& timestamp) override; |
| 80 void OnIncomingCapturedVideoFrame( |
| 81 scoped_ptr<Buffer> buffer, |
| 82 const scoped_refptr<media::VideoFrame>& frame, |
| 83 const base::TimeTicks& timestamp) override; |
| 84 void OnError(const tracked_objects::Location& from_here, |
| 85 const std::string& reason) override; |
| 86 double GetBufferPoolUtilization() const override; |
| 87 |
| 88 // The |delegate_| to where we send the capture-converted VideoFrames. |
| 89 Delegate* const delegate_; |
| 90 |
| 91 // The underlying multithreaded MojoVideoFrame pool. |
| 92 const scoped_refptr<VideoFramePool> video_frame_pool_; |
| 93 |
| 94 // This class is single threaded except construction. |
| 95 base::ThreadChecker thread_checker_; |
| 96 |
| 97 base::WeakPtrFactory<VideoCaptureDeviceClientImpl> weak_factory_; |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClientImpl); |
| 100 }; |
| 101 |
| 102 } // namespace media |
| 103 |
| 104 #endif // CONTENT_BROWSER_VIDEO_CAPTURE_VIDEO_CAPTURE_ADAPTER_H_ |
OLD | NEW |