123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #pragma once
- #include "api/video/video_frame.h"
- #include "api/video/video_sink_interface.h"
- #include "callback.h"
- using I420FrameReadyCallback = Callback<const void*,
- const void*,
- const void*,
- const void*,
- int,
- int,
- int,
- int,
- int,
- int>;
- using ARGBFrameReadyCallback = Callback<
- const uint8_t*,int,
- const uint8_t*,int,
- const uint8_t*, int,
- const int,const int,
- const int>;
- constexpr inline size_t ArgbDataSize(int height, int stride) {
- return static_cast<size_t>(height) * stride * 4;
- }
- class ArgbBuffer : public webrtc::VideoFrameBuffer {
- public:
-
- static inline rtc::scoped_refptr<ArgbBuffer> Create(int width, int height) {
- return new rtc::RefCountedObject<ArgbBuffer>(width, height, width * 4);
- }
-
-
-
-
-
-
-
-
-
-
-
- inline Type type() const override { return VideoFrameBuffer::Type::kNative; }
- inline int width() const override { return width_; }
- inline int height() const override { return height_; }
- rtc::scoped_refptr<webrtc::I420BufferInterface> ToI420() override;
- inline uint8_t* Data() { return data_.get(); }
- inline const uint8_t* Data() const { return data_.get(); }
- inline int Stride() const { return stride_; }
- inline constexpr size_t Size() const {
- return ArgbDataSize(height_, stride_);
- }
- protected:
- ArgbBuffer(int width, int height, int stride) ;
- ~ArgbBuffer() override = default;
- private:
- const int width_;
- const int height_;
- const int stride_;
- const std::unique_ptr<uint8_t, webrtc::AlignedFreeDeleter> data_;
- };
- class VideoFrameObserver : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
- public:
-
-
-
- void SetCallback(I420FrameReadyCallback callback) ;
-
-
-
- void SetCallback(ARGBFrameReadyCallback callback) ;
- protected:
- ArgbBuffer* GetArgbScratchBuffer(int width, int height);
-
- void OnFrame(const webrtc::VideoFrame& frame) override;
- private:
-
- I420FrameReadyCallback i420_callback_;
-
- ARGBFrameReadyCallback argb_callback_;
-
- std::mutex mutex_;
-
- rtc::scoped_refptr<ArgbBuffer> argb_scratch_buffer_;
- };
|