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 // Interface of a simple frame buffer containing pixel data. This interface does | 21 class I420BufferInterface; |
22 // not contain any frame metadata such as rotation, timestamp, pixel_width, etc. | 22 class I444BufferInterface; |
23 | |
24 // Base class for frame buffers of different kinds of pixel format. The tag | |
25 // in Format() indicates what pixel format the buffer contains, and each | |
26 // pixel format is implemented as a subclass. To access the pixel data, call the | |
27 // appropriate ToXXX() function, where XXX represents the pixel format specified | |
28 // by Format(). The function ToI420() can always be called, and serves as a | |
29 // fallback for e.g. the internal WebRTC software encoders that can only handle | |
30 // I420. Calling ToI420() requires a pixel format conversion for formats other | |
31 // than I420. A special enum value 'kNative' is provided for external clients to | |
32 // implement their own frame buffer representations, e.g. as textures. The | |
33 // external client is then responsible for casting the native buffer into the | |
34 // correct subclass. Frame metadata such as rotation and timestamp are stored in | |
35 // webrtc::VideoFrame, and not here. | |
23 class VideoFrameBuffer : public rtc::RefCountInterface { | 36 class VideoFrameBuffer : public rtc::RefCountInterface { |
24 public: | 37 public: |
38 enum class PixelFormat { | |
39 kNative, | |
40 kI420, | |
41 kI444, | |
42 }; | |
43 | |
44 // This function specifies in what pixel format the data is stored in. | |
45 virtual PixelFormat Format() const; | |
46 | |
25 // The resolution of the frame in pixels. For formats where some planes are | 47 // The resolution of the frame in pixels. For formats where some planes are |
26 // subsampled, this is the highest-resolution plane. | 48 // subsampled, this is the highest-resolution plane. |
27 virtual int width() const = 0; | 49 virtual int width() const = 0; |
28 virtual int height() const = 0; | 50 virtual int height() const = 0; |
29 | 51 |
52 // Returns a memory-backed frame buffer in I420 format. If the pixel data is | |
53 // in another format, a conversion will take place. All implementations must | |
54 // provide a fallback to I420 for compatibility with e.g the internal WebRTC | |
55 // software encoders. | |
56 virtual rtc::scoped_refptr<I420BufferInterface> ToI420(); | |
57 | |
58 // This function should only be called if Format() == kI444. | |
59 virtual rtc::scoped_refptr<I444BufferInterface> ToI444(); | |
60 | |
61 // Deprecated - use ToI420() first instead. | |
30 // Returns pointer to the pixel data for a given plane. The memory is owned by | 62 // Returns pointer to the pixel data for a given plane. The memory is owned by |
31 // the VideoFrameBuffer object and must not be freed by the caller. | 63 // the VideoFrameBuffer object and must not be freed by the caller. |
32 virtual const uint8_t* DataY() const = 0; | 64 virtual const uint8_t* DataY() const; |
33 virtual const uint8_t* DataU() const = 0; | 65 virtual const uint8_t* DataU() const; |
34 virtual const uint8_t* DataV() const = 0; | 66 virtual const uint8_t* DataV() const; |
67 // Returns the number of bytes between successive rows for a given plane. | |
68 virtual int StrideY() const; | |
69 virtual int StrideU() const; | |
70 virtual int StrideV() const; | |
35 | 71 |
36 // Returns the number of bytes between successive rows for a given plane. | 72 // Deprecated - use BufferType() to determine if the stored data is kNative, |
37 virtual int StrideY() const = 0; | 73 // and then cast into the appropriate type. |
38 virtual int StrideU() const = 0; | |
39 virtual int StrideV() const = 0; | |
40 | |
41 // Return the handle of the underlying video frame. This is used when the | 74 // Return the handle of the underlying video frame. This is used when the |
42 // frame is backed by a texture. | 75 // frame is backed by a texture. |
43 virtual void* native_handle() const = 0; | 76 virtual void* native_handle() const; |
44 | 77 |
45 // Returns a new memory-backed frame buffer converted from this buffer's | 78 // Deprecated - use ToI420() instead. |
46 // native handle. | 79 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer(); |
47 virtual rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() = 0; | |
48 | 80 |
49 protected: | 81 protected: |
50 ~VideoFrameBuffer() override {} | 82 ~VideoFrameBuffer() override {} |
51 }; | 83 }; |
52 | 84 |
85 // This interface represents PixelFormat::kI420. | |
86 class I420BufferInterface : public VideoFrameBuffer { | |
87 public: | |
88 PixelFormat Format() const override; | |
89 | |
90 int ChromaWidth() const { return (width() + 1) / 2; } | |
nisse-webrtc
2017/05/02 09:52:37
Implementing these separately in the two interface
magjed_webrtc
2017/05/03 13:36:55
I added a PlanarYuvBuffer interface that is common
| |
91 int ChromaHeight() const { return (height() + 1) / 2; } | |
92 | |
93 // Returns pointer to the pixel data for a given plane. The memory is owned by | |
94 // the VideoFrameBuffer object and must not be freed by the caller. | |
95 const uint8_t* DataY() const override = 0; | |
96 const uint8_t* DataU() const override = 0; | |
97 const uint8_t* DataV() const override = 0; | |
98 | |
99 // Returns the number of bytes between successive rows for a given plane. | |
100 int StrideY() const override = 0; | |
101 int StrideU() const override = 0; | |
102 int StrideV() const override = 0; | |
103 | |
104 rtc::scoped_refptr<I420BufferInterface> ToI420() override; | |
105 | |
106 protected: | |
107 ~I420BufferInterface() override {} | |
108 }; | |
109 | |
110 // This interface represents PixelFormat::kI444. | |
111 class I444BufferInterface : public VideoFrameBuffer { | |
112 public: | |
113 PixelFormat Format() const override; | |
114 | |
115 int ChromaWidth() const { return width(); } | |
116 int ChromaHeight() const { return height(); } | |
117 | |
118 // Returns pointer to the pixel data for a given plane. The memory is owned by | |
119 // the VideoFrameBuffer object and must not be freed by the caller. | |
120 const uint8_t* DataY() const override = 0; | |
121 const uint8_t* DataU() const override = 0; | |
122 const uint8_t* DataV() const override = 0; | |
123 | |
124 // Returns the number of bytes between successive rows for a given plane. | |
125 int StrideY() const override = 0; | |
126 int StrideU() const override = 0; | |
127 int StrideV() const override = 0; | |
128 | |
129 rtc::scoped_refptr<I420BufferInterface> ToI420() override; | |
130 rtc::scoped_refptr<I444BufferInterface> ToI444() override; | |
131 | |
132 protected: | |
133 ~I444BufferInterface() override {} | |
134 }; | |
135 | |
53 } // namespace webrtc | 136 } // namespace webrtc |
54 | 137 |
55 #endif // WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ | 138 #endif // WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ |
OLD | NEW |