Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ | 11 #ifndef WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ |
| 12 #define WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ | 12 #define WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ |
| 13 | 13 |
| 14 #include <stdint.h> | 14 #include <stdint.h> |
| 15 | 15 |
| 16 #include "webrtc/base/refcount.h" | 16 #include "webrtc/base/refcount.h" |
| 17 #include "webrtc/base/scoped_ref_ptr.h" | 17 #include "webrtc/base/scoped_ref_ptr.h" |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 | 20 |
| 21 class PlanarYuvBuffer; | 21 class I420BufferInterface; |
| 22 class I444BufferInterface; | |
| 22 | 23 |
| 23 // Base class for frame buffers of different types of pixel format and storage. | 24 // Base class for frame buffers of different types of pixel format and storage. |
| 24 // The tag in type() indicates how the data is represented, and each type is | 25 // The tag in type() indicates how the data is represented, and each type is |
| 25 // implemented as a subclass. To access the pixel data, call the appropriate | 26 // implemented as a subclass. To access the pixel data, call the appropriate |
| 26 // GetXXX() function, where XXX represents the type. There is also a function | 27 // GetXXX() function, where XXX represents the type. There is also a function |
| 27 // ToI420() that returns a frame buffer in I420 format, converting from the | 28 // ToI420() that returns a frame buffer in I420 format, converting from the |
| 28 // underlying representation if necessary. I420 is the most widely accepted | 29 // underlying representation if necessary. I420 is the most widely accepted |
| 29 // format and serves as a fallback for video sinks that can only handle I420, | 30 // format and serves as a fallback for video sinks that can only handle I420, |
| 30 // e.g. the internal WebRTC software encoders. A special enum value 'kNative' is | 31 // e.g. the internal WebRTC software encoders. A special enum value 'kNative' is |
| 31 // provided for external clients to implement their own frame buffer | 32 // provided for external clients to implement their own frame buffer |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 51 | 52 |
| 52 // The resolution of the frame in pixels. For formats where some planes are | 53 // The resolution of the frame in pixels. For formats where some planes are |
| 53 // subsampled, this is the highest-resolution plane. | 54 // subsampled, this is the highest-resolution plane. |
| 54 virtual int width() const = 0; | 55 virtual int width() const = 0; |
| 55 virtual int height() const = 0; | 56 virtual int height() const = 0; |
| 56 | 57 |
| 57 // Returns a memory-backed frame buffer in I420 format. If the pixel data is | 58 // Returns a memory-backed frame buffer in I420 format. If the pixel data is |
| 58 // in another format, a conversion will take place. All implementations must | 59 // in another format, a conversion will take place. All implementations must |
| 59 // provide a fallback to I420 for compatibility with e.g. the internal WebRTC | 60 // provide a fallback to I420 for compatibility with e.g. the internal WebRTC |
| 60 // software encoders. | 61 // software encoders. |
| 61 virtual rtc::scoped_refptr<PlanarYuvBuffer> ToI420(); | 62 virtual rtc::scoped_refptr<I420BufferInterface> ToI420(); |
| 62 | 63 |
| 63 // These functions should only be called if type() is of the correct type. | 64 // These functions should only be called if type() is of the correct type. |
| 64 // Calling with a different type will result in a crash. | 65 // Calling with a different type will result in a crash. |
| 65 rtc::scoped_refptr<PlanarYuvBuffer> GetI420(); | 66 rtc::scoped_refptr<I420BufferInterface> GetI420(); |
|
nisse-webrtc
2017/05/29 14:20:05
I think it's nicer if we make these functions virt
magjed_webrtc
2017/05/29 17:40:07
What benefit do you see from making these function
nisse-webrtc
2017/05/30 07:05:32
I see two (weak) benefits: Consistency with the ot
kwiberg-webrtc
2017/05/30 07:32:07
Drive-by opinion: Don't be afraid of raw pointers
| |
| 66 rtc::scoped_refptr<PlanarYuvBuffer> GetI444(); | 67 rtc::scoped_refptr<I444BufferInterface> GetI444(); |
| 67 | 68 |
| 68 // Deprecated - use ToI420() first instead. | 69 // Deprecated - use ToI420() first instead. |
| 69 // Returns pointer to the pixel data for a given plane. The memory is owned by | 70 // Returns pointer to the pixel data for a given plane. The memory is owned by |
| 70 // the VideoFrameBuffer object and must not be freed by the caller. | 71 // the VideoFrameBuffer object and must not be freed by the caller. |
| 71 virtual const uint8_t* DataY() const; | 72 virtual const uint8_t* DataY() const; |
| 72 virtual const uint8_t* DataU() const; | 73 virtual const uint8_t* DataU() const; |
| 73 virtual const uint8_t* DataV() const; | 74 virtual const uint8_t* DataV() const; |
| 74 // Returns the number of bytes between successive rows for a given plane. | 75 // Returns the number of bytes between successive rows for a given plane. |
| 75 virtual int StrideY() const; | 76 virtual int StrideY() const; |
| 76 virtual int StrideU() const; | 77 virtual int StrideU() const; |
| 77 virtual int StrideV() const; | 78 virtual int StrideV() const; |
| 78 | 79 |
| 79 // Deprecated - use type() to determine if the stored data is kNative, and | 80 // Deprecated - use type() to determine if the stored data is kNative, and |
| 80 // then cast into the appropriate type. | 81 // then cast into the appropriate type. |
| 81 // Return the handle of the underlying video frame. This is used when the | 82 // Return the handle of the underlying video frame. This is used when the |
| 82 // frame is backed by a texture. | 83 // frame is backed by a texture. |
| 83 virtual void* native_handle() const; | 84 virtual void* native_handle() const; |
| 84 | 85 |
| 85 // Deprecated - use ToI420() instead. | 86 // Deprecated - use ToI420() instead. |
| 86 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer(); | 87 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer(); |
| 87 | 88 |
| 88 protected: | 89 protected: |
| 89 ~VideoFrameBuffer() override {} | 90 ~VideoFrameBuffer() override {} |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 // This interface represents Type::kI420 and Type::kI444. | 93 // This interface represents Type::kI420 and Type::kI444. |
| 93 class PlanarYuvBuffer : public VideoFrameBuffer { | 94 class PlanarYuvBuffer : public VideoFrameBuffer { |
| 94 public: | 95 public: |
| 95 int ChromaWidth() const; | 96 virtual int ChromaWidth() const = 0; |
| 96 int ChromaHeight() const; | 97 virtual int ChromaHeight() const = 0; |
| 97 | 98 |
| 98 // Returns pointer to the pixel data for a given plane. The memory is owned by | 99 // Returns pointer to the pixel data for a given plane. The memory is owned by |
| 99 // the VideoFrameBuffer object and must not be freed by the caller. | 100 // the VideoFrameBuffer object and must not be freed by the caller. |
| 100 const uint8_t* DataY() const override = 0; | 101 const uint8_t* DataY() const override = 0; |
| 101 const uint8_t* DataU() const override = 0; | 102 const uint8_t* DataU() const override = 0; |
| 102 const uint8_t* DataV() const override = 0; | 103 const uint8_t* DataV() const override = 0; |
| 103 | 104 |
| 104 // Returns the number of bytes between successive rows for a given plane. | 105 // Returns the number of bytes between successive rows for a given plane. |
| 105 int StrideY() const override = 0; | 106 int StrideY() const override = 0; |
| 106 int StrideU() const override = 0; | 107 int StrideU() const override = 0; |
| 107 int StrideV() const override = 0; | 108 int StrideV() const override = 0; |
| 108 | 109 |
| 109 rtc::scoped_refptr<PlanarYuvBuffer> ToI420() override; | |
| 110 | |
| 111 protected: | 110 protected: |
| 112 ~PlanarYuvBuffer() override {} | 111 ~PlanarYuvBuffer() override {} |
| 113 }; | 112 }; |
| 114 | 113 |
| 114 class I420BufferInterface : public PlanarYuvBuffer { | |
| 115 public: | |
| 116 Type type() const final; | |
| 117 | |
| 118 int ChromaWidth() const final; | |
| 119 int ChromaHeight() const final; | |
| 120 | |
| 121 rtc::scoped_refptr<I420BufferInterface> ToI420() final; | |
|
nisse-webrtc
2017/05/29 14:20:05
Here we could also put the GetI420() final {return
| |
| 122 | |
| 123 protected: | |
| 124 ~I420BufferInterface() override {} | |
| 125 }; | |
| 126 | |
| 127 class I444BufferInterface : public PlanarYuvBuffer { | |
| 128 public: | |
| 129 Type type() const final; | |
| 130 | |
| 131 int ChromaWidth() const final; | |
| 132 int ChromaHeight() const final; | |
| 133 | |
| 134 rtc::scoped_refptr<I420BufferInterface> ToI420() final; | |
| 135 | |
| 136 protected: | |
| 137 ~I444BufferInterface() override {} | |
| 138 }; | |
| 139 | |
| 115 } // namespace webrtc | 140 } // namespace webrtc |
| 116 | 141 |
| 117 #endif // WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ | 142 #endif // WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ |
| OLD | NEW |