EncodeImageBuffer.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. #include "rtc_base/ref_counted_object.h"
  3. #include "absl/strings/match.h"
  4. class EncodedVideoI420Buffer : public webrtc::I420BufferInterface {
  5. public:
  6. EncodedVideoI420Buffer(int width, int height, const rtc::scoped_refptr<webrtc::EncodedImageBufferInterface>& encoded_data) : width_(width), height_(height), encoded_data_(encoded_data) {
  7. }
  8. virtual int width() const { return width_; }
  9. virtual int height() const { return height_; }
  10. virtual const uint8_t* DataY() const { return encoded_data_->data(); }
  11. virtual const uint8_t* DataU() const { return encoded_data_->data(); }
  12. virtual const uint8_t* DataV() const { return encoded_data_->data(); }
  13. virtual int StrideY() const { return encoded_data_->size(); }
  14. virtual int StrideU() const { return (encoded_data_->size() + 1) / 2; }
  15. virtual int StrideV() const { return (encoded_data_->size() + 1) / 2; }
  16. private:
  17. const int width_;
  18. const int height_;
  19. rtc::scoped_refptr<webrtc::EncodedImageBufferInterface> encoded_data_;
  20. };
  21. class EncodedVideoFrameBuffer : public webrtc::VideoFrameBuffer {
  22. public:
  23. EncodedVideoFrameBuffer(int width, int height, const rtc::scoped_refptr<webrtc::EncodedImageBufferInterface>& encoded_data) : width_(width), height_(height) {
  24. buffer_ = new rtc::RefCountedObject<EncodedVideoI420Buffer>(width_, height_, encoded_data);
  25. }
  26. virtual Type type() const { return webrtc::VideoFrameBuffer::Type::kNative; }
  27. virtual rtc::scoped_refptr<webrtc::I420BufferInterface> ToI420() { return webrtc::I420Buffer::Create(width(), height()); }
  28. virtual int width() const { return width_; }
  29. virtual int height() const { return height_; }
  30. const webrtc::I420BufferInterface* GetI420() const { return buffer_.get(); }
  31. private:
  32. const int width_;
  33. const int height_;
  34. rtc::scoped_refptr<EncodedVideoI420Buffer> buffer_;
  35. };