| 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 COMPONENTS_VIDEO_CAPTURE_DEVICE_CLIENT_IMPL_H_ |
| 6 #define COMPONENTS_VIDEO_CAPTURE_DEVICE_CLIENT_IMPL_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/threading/thread_checker.h" |
| 15 #include "media/base/video_capture_types.h" |
| 16 #include "media/base/video_types.h" |
| 17 #include "media/capture/video/video_capture_device.h" |
| 18 #include "mojo/public/cpp/system/buffer.h" |
| 19 |
| 20 namespace base { |
| 21 class TimeTicks; |
| 22 } |
| 23 |
| 24 namespace gfx { |
| 25 class Size; |
| 26 } |
| 27 |
| 28 namespace media { |
| 29 class VideoFrame; |
| 30 } |
| 31 |
| 32 namespace video_capture { |
| 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 theallocated |
| 38 // VideoFrames have a SharedMemory inside. The interface-defined Buffer is a |
| 39 // thin wrapper around those. |
| 40 class DeviceClientImpl : public media::VideoCaptureDevice::Client { |
| 41 public: |
| 42 class Delegate { |
| 43 public: |
| 44 virtual ~Delegate() {} |
| 45 |
| 46 // Called when a frame buffer is populated with new frame data. The delegate |
| 47 // should run |release_callback| when done with the frame. |
| 48 virtual void OnFrame(const scoped_refptr<media::VideoFrame>& frame, |
| 49 const base::TimeTicks& timestamp, |
| 50 const base::Closure& release_callback) = 0; |
| 51 |
| 52 // Called when there has been a fatal error which invalidates the capture |
| 53 // device. |
| 54 virtual void OnError(const std::string& reason) = 0; |
| 55 }; |
| 56 |
| 57 // The Delegate implementation needs to be thread-safe. More specifically, |
| 58 // each Delegate method should be safe to call on the same arbitrary thread. |
| 59 // |delegate| is not owned and must outlive |this|. |
| 60 explicit DeviceClientImpl(Delegate* delegate); |
| 61 |
| 62 ~DeviceClientImpl() override; |
| 63 |
| 64 private: |
| 65 friend class DeviceClientImplTest; |
| 66 class VideoFramePool; |
| 67 |
| 68 // media::VideoCaptureDevice::Client: |
| 69 void OnIncomingCapturedData(const uint8_t* data, |
| 70 int length, |
| 71 const media::VideoCaptureFormat& frame_format, |
| 72 int clockwise_rotation, |
| 73 const base::TimeTicks& timestamp) override; |
| 74 void OnIncomingCapturedYuvData(const uint8_t* y_data, |
| 75 const uint8_t* u_data, |
| 76 const uint8_t* v_data, |
| 77 size_t y_stride, |
| 78 size_t u_stride, |
| 79 size_t v_stride, |
| 80 const media::VideoCaptureFormat& frame_format, |
| 81 int clockwise_rotation, |
| 82 const base::TimeTicks& timestamp) override; |
| 83 scoped_ptr<Buffer> ReserveOutputBuffer( |
| 84 const gfx::Size& dimensions, |
| 85 media::VideoPixelFormat pixel_format, |
| 86 media::VideoPixelStorage pixel_storage) override; |
| 87 void OnIncomingCapturedBuffer(scoped_ptr<Buffer> buffer, |
| 88 const media::VideoCaptureFormat& frame_format, |
| 89 const base::TimeTicks& timestamp) override; |
| 90 void OnIncomingCapturedVideoFrame( |
| 91 scoped_ptr<Buffer> buffer, |
| 92 const scoped_refptr<media::VideoFrame>& frame, |
| 93 const base::TimeTicks& timestamp) override; |
| 94 void OnError(const tracked_objects::Location& from_here, |
| 95 const std::string& reason) override; |
| 96 double GetBufferPoolUtilization() const override; |
| 97 |
| 98 // The |delegate_| to where we send the capture-converted VideoFrames. |
| 99 Delegate* delegate_; |
| 100 |
| 101 scoped_refptr<VideoFramePool> video_frame_pool_; |
| 102 |
| 103 base::ThreadChecker thread_checker_; |
| 104 |
| 105 base::WeakPtrFactory<DeviceClientImpl> weak_factory_; |
| 106 |
| 107 DISALLOW_COPY_AND_ASSIGN(DeviceClientImpl); |
| 108 }; |
| 109 |
| 110 } // namespace video_capture |
| 111 |
| 112 #endif // COMPONENTS_VIDEO_CAPTURE_DEVICE_CLIENT_IMPL_H_ |
| OLD | NEW |