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 PlanarYuvBuffer; |
22 // not contain any frame metadata such as rotation, timestamp, pixel_width, etc. | 22 |
23 // Base class for frame buffers of different kinds of pixel format. The tag | |
24 // in Format() indicates what pixel format the buffer contains, and each pixel | |
25 // format is implemented as a subclass. To access the pixel data, call the | |
26 // appropriate GetXXX() function, where XXX represents the pixel format | |
27 // specified by Format(). There is also a function ToI420() that can always be | |
28 // 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
| |
29 // internal WebRTC software encoders that can only handle I420. A special enum | |
30 // value 'kNative' is provided for external clients to implement their own frame | |
31 // buffer representations, e.g. as textures. The external client is then | |
32 // responsible for casting the native buffer into the correct subclass. Frame | |
33 // metadata such as rotation and timestamp are stored in webrtc::VideoFrame, and | |
34 // not here. | |
23 class VideoFrameBuffer : public rtc::RefCountInterface { | 35 class VideoFrameBuffer : public rtc::RefCountInterface { |
24 public: | 36 public: |
37 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
| |
38 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
| |
39 kI420, | |
40 kI444, | |
41 }; | |
42 | |
43 // This function specifies in what pixel format the data is stored in. | |
44 virtual PixelFormat Format() const; | |
45 | |
25 // The resolution of the frame in pixels. For formats where some planes are | 46 // The resolution of the frame in pixels. For formats where some planes are |
26 // subsampled, this is the highest-resolution plane. | 47 // subsampled, this is the highest-resolution plane. |
27 virtual int width() const = 0; | 48 virtual int width() const = 0; |
28 virtual int height() const = 0; | 49 virtual int height() const = 0; |
29 | 50 |
51 // Returns a memory-backed frame buffer in I420 format. If the pixel data is | |
52 // in another format, a conversion will take place. All implementations must | |
53 // provide a fallback to I420 for compatibility with e.g the internal WebRTC | |
54 // software encoders. | |
55 virtual rtc::scoped_refptr<PlanarYuvBuffer> ToI420(); | |
56 | |
57 // 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
| |
58 virtual rtc::scoped_refptr<PlanarYuvBuffer> GetI420(); | |
59 virtual rtc::scoped_refptr<PlanarYuvBuffer> GetI444(); | |
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 and kI444. | |
86 class PlanarYuvBuffer : public VideoFrameBuffer { | |
87 public: | |
88 int ChromaWidth() const; | |
89 int ChromaHeight() const; | |
90 | |
91 // Returns pointer to the pixel data for a given plane. The memory is owned by | |
92 // the VideoFrameBuffer object and must not be freed by the caller. | |
93 const uint8_t* DataY() const override = 0; | |
94 const uint8_t* DataU() const override = 0; | |
95 const uint8_t* DataV() const override = 0; | |
96 | |
97 // Returns the number of bytes between successive rows for a given plane. | |
98 int StrideY() const override = 0; | |
99 int StrideU() const override = 0; | |
100 int StrideV() const override = 0; | |
101 | |
102 rtc::scoped_refptr<PlanarYuvBuffer> ToI420() override; | |
103 | |
104 rtc::scoped_refptr<PlanarYuvBuffer> GetI420() override; | |
105 rtc::scoped_refptr<PlanarYuvBuffer> GetI444() override; | |
106 | |
107 protected: | |
108 ~PlanarYuvBuffer() override {} | |
109 }; | |
110 | |
53 } // namespace webrtc | 111 } // namespace webrtc |
54 | 112 |
55 #endif // WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ | 113 #endif // WEBRTC_API_VIDEO_VIDEO_FRAME_BUFFER_H_ |
OLD | NEW |