Index: webrtc/api/video/video_frame_buffer.h |
diff --git a/webrtc/api/video/video_frame_buffer.h b/webrtc/api/video/video_frame_buffer.h |
index c8c2e5d5d4087c5bcf6bb1ec4d24ea9df30da88e..e6998c647aa391f907a976d2778a1d6250e87d14 100644 |
--- a/webrtc/api/video/video_frame_buffer.h |
+++ b/webrtc/api/video/video_frame_buffer.h |
@@ -18,38 +18,96 @@ |
namespace webrtc { |
-// Interface of a simple frame buffer containing pixel data. This interface does |
-// not contain any frame metadata such as rotation, timestamp, pixel_width, etc. |
+class PlanarYuvBuffer; |
+ |
+// Base class for frame buffers of different kinds of pixel format. The tag |
+// in Format() indicates what pixel format the buffer contains, and each pixel |
+// format is implemented as a subclass. To access the pixel data, call the |
+// appropriate GetXXX() function, where XXX represents the pixel format |
+// specified by Format(). There is also a function ToI420() that can always be |
+// called that will convert to I420. This serves as a fallback for e.g. the |
nisse-webrtc
2017/05/04 08:15:29
Maybe add some guidelines on when it makes sense t
magjed_webrtc
2017/05/04 12:25:13
Done. It's a bit more tricky to describe when it's
|
+// internal WebRTC software encoders that can only handle I420. A special enum |
+// value 'kNative' is provided for external clients to implement their own frame |
+// buffer representations, e.g. as textures. The external client is then |
+// responsible for casting the native buffer into the correct subclass. Frame |
+// metadata such as rotation and timestamp are stored in webrtc::VideoFrame, and |
+// not here. |
class VideoFrameBuffer : public rtc::RefCountInterface { |
public: |
+ enum class PixelFormat { |
nisse-webrtc
2017/05/04 08:15:29
Is "PixelFormat" the right name for this? Maybe ju
magjed_webrtc
2017/05/04 12:25:13
Done, I also prefer just Type. I changed the Forma
|
+ kNative, |
nisse-webrtc
2017/05/04 08:15:29
For kNative, if casting of the void* returned by n
magjed_webrtc
2017/05/04 12:25:13
Yes, we will be able to simplify the code after th
|
+ kI420, |
+ kI444, |
+ }; |
+ |
+ // This function specifies in what pixel format the data is stored in. |
+ virtual PixelFormat Format() const; |
+ |
// The resolution of the frame in pixels. For formats where some planes are |
// subsampled, this is the highest-resolution plane. |
virtual int width() const = 0; |
virtual int height() const = 0; |
+ // Returns a memory-backed frame buffer in I420 format. If the pixel data is |
+ // in another format, a conversion will take place. All implementations must |
+ // provide a fallback to I420 for compatibility with e.g the internal WebRTC |
+ // software encoders. |
+ virtual rtc::scoped_refptr<PlanarYuvBuffer> ToI420(); |
+ |
+ // These functions should only be called if Format() is of the correct type. |
nisse-webrtc
2017/05/04 08:15:29
With "should", what's the failure behavior? Are th
magjed_webrtc
2017/05/04 12:25:13
Right now I'm enforcing it with RTC_NOTREACHED and
nisse-webrtc
2017/05/05 11:33:04
And then likely crash in release builds too, since
|
+ virtual rtc::scoped_refptr<PlanarYuvBuffer> GetI420(); |
+ virtual rtc::scoped_refptr<PlanarYuvBuffer> GetI444(); |
+ |
+ // Deprecated - use ToI420() first instead. |
// Returns pointer to the pixel data for a given plane. The memory is owned by |
// the VideoFrameBuffer object and must not be freed by the caller. |
- virtual const uint8_t* DataY() const = 0; |
- virtual const uint8_t* DataU() const = 0; |
- virtual const uint8_t* DataV() const = 0; |
- |
+ virtual const uint8_t* DataY() const; |
+ virtual const uint8_t* DataU() const; |
+ virtual const uint8_t* DataV() const; |
// Returns the number of bytes between successive rows for a given plane. |
- virtual int StrideY() const = 0; |
- virtual int StrideU() const = 0; |
- virtual int StrideV() const = 0; |
+ virtual int StrideY() const; |
+ virtual int StrideU() const; |
+ virtual int StrideV() const; |
+ // Deprecated - use BufferType() to determine if the stored data is kNative, |
+ // and then cast into the appropriate type. |
// Return the handle of the underlying video frame. This is used when the |
// frame is backed by a texture. |
- virtual void* native_handle() const = 0; |
+ virtual void* native_handle() const; |
- // Returns a new memory-backed frame buffer converted from this buffer's |
- // native handle. |
- virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() = 0; |
+ // Deprecated - use ToI420() instead. |
+ virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer(); |
protected: |
~VideoFrameBuffer() override {} |
}; |
+// This interface represents PixelFormat::kI420 and kI444. |
+class PlanarYuvBuffer : public VideoFrameBuffer { |
+ public: |
+ int ChromaWidth() const; |
+ int ChromaHeight() const; |
+ |
+ // Returns pointer to the pixel data for a given plane. The memory is owned by |
+ // the VideoFrameBuffer object and must not be freed by the caller. |
+ const uint8_t* DataY() const override = 0; |
+ const uint8_t* DataU() const override = 0; |
+ const uint8_t* DataV() const override = 0; |
+ |
+ // Returns the number of bytes between successive rows for a given plane. |
+ int StrideY() const override = 0; |
+ int StrideU() const override = 0; |
+ int StrideV() const override = 0; |
+ |
+ rtc::scoped_refptr<PlanarYuvBuffer> ToI420() override; |
+ |
+ rtc::scoped_refptr<PlanarYuvBuffer> GetI420() override; |
+ rtc::scoped_refptr<PlanarYuvBuffer> GetI444() override; |
+ |
+ protected: |
+ ~PlanarYuvBuffer() override {} |
+}; |
+ |
} // namespace webrtc |
#endif // WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ |