OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ | 11 #ifndef WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ |
12 #define WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ | 12 #define WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 | 15 |
16 #include "webrtc/base/buffer.h" | 16 #include "webrtc/base/buffer.h" |
17 #include "webrtc/base/refcount.h" | 17 #include "webrtc/base/refcount.h" |
18 #include "webrtc/base/scoped_ref_ptr.h" | 18 #include "webrtc/base/scoped_ref_ptr.h" |
19 #include "webrtc/common_types.h" | 19 #include "webrtc/common_types.h" |
20 #include "webrtc/common_video/include/video_frame_buffer.h" | 20 #include "webrtc/common_video/include/video_frame_buffer.h" |
21 #include "webrtc/media/base/videoframe.h" | 21 #include "webrtc/media/base/videoframe.h" |
22 | 22 |
23 namespace cricket { | 23 namespace cricket { |
24 | 24 |
25 struct CapturedFrame; | 25 struct CapturedFrame; |
26 | 26 |
27 class WebRtcVideoFrame : public VideoFrame { | 27 class WebRtcVideoFrame : public VideoFrame { |
28 public: | 28 public: |
29 WebRtcVideoFrame(); | 29 WebRtcVideoFrame(); |
30 // TODO(nisse): Find a way to transition to using us units for the | |
31 // constructor and init methods. Maybe it's easiest to drop the | |
32 // timestamp argument, and require a separate method call for | |
33 // setting the timestamp? | |
34 | |
30 WebRtcVideoFrame(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, | 35 WebRtcVideoFrame(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, |
31 int64_t time_stamp_ns, | 36 int64_t time_stamp_ns, |
32 webrtc::VideoRotation rotation); | 37 webrtc::VideoRotation rotation); |
33 | 38 |
34 ~WebRtcVideoFrame(); | 39 ~WebRtcVideoFrame(); |
35 | 40 |
36 // Creates a frame from a raw sample with FourCC "format" and size "w" x "h". | 41 // Creates a frame from a raw sample with FourCC "format" and size "w" x "h". |
37 // "h" can be negative indicating a vertically flipped image. | 42 // "h" can be negative indicating a vertically flipped image. |
38 // "dh" is destination height if cropping is desired and is always positive. | 43 // "dh" is destination height if cropping is desired and is always positive. |
39 // Returns "true" if successful. | 44 // Returns "true" if successful. |
40 bool Init(uint32_t format, | 45 bool Init(uint32_t format, |
41 int w, | 46 int w, |
42 int h, | 47 int h, |
43 int dw, | 48 int dw, |
44 int dh, | 49 int dh, |
45 uint8_t* sample, | 50 uint8_t* sample, |
46 size_t sample_size, | 51 size_t sample_size, |
47 int64_t time_stamp_ns, | 52 int64_t time_stamp_ns, |
48 webrtc::VideoRotation rotation); | 53 webrtc::VideoRotation rotation); |
49 | 54 |
55 // The timestamp of the captured frame is expected to use the same | |
56 // timescale and epoch as rtc::Time. Consider adding a warning | |
pbos-webrtc
2016/04/13 12:04:04
Put your ldap in a TODO here for the Consider
nisse-webrtc
2016/04/13 13:02:12
Done.
| |
57 // message, or even an RTC_DCHECK, if the time is too far off. | |
50 bool Init(const CapturedFrame* frame, int dw, int dh, bool apply_rotation); | 58 bool Init(const CapturedFrame* frame, int dw, int dh, bool apply_rotation); |
51 | 59 |
60 void InitToEmptyBuffer(int w, int h); | |
52 void InitToEmptyBuffer(int w, int h, int64_t time_stamp_ns); | 61 void InitToEmptyBuffer(int w, int h, int64_t time_stamp_ns); |
53 | 62 |
54 bool InitToBlack(int w, int h, int64_t time_stamp_ns); | 63 bool InitToBlack(int w, int h, int64_t time_stamp_ns); |
55 | 64 |
56 int width() const override; | 65 int width() const override; |
57 int height() const override; | 66 int height() const override; |
58 | 67 |
59 const uint8_t* GetYPlane() const override; | 68 const uint8_t* GetYPlane() const override; |
60 const uint8_t* GetUPlane() const override; | 69 const uint8_t* GetUPlane() const override; |
61 const uint8_t* GetVPlane() const override; | 70 const uint8_t* GetVPlane() const override; |
62 uint8_t* GetYPlane() override; | 71 uint8_t* GetYPlane() override; |
63 uint8_t* GetUPlane() override; | 72 uint8_t* GetUPlane() override; |
64 uint8_t* GetVPlane() override; | 73 uint8_t* GetVPlane() override; |
65 int32_t GetYPitch() const override; | 74 int32_t GetYPitch() const override; |
66 int32_t GetUPitch() const override; | 75 int32_t GetUPitch() const override; |
67 int32_t GetVPitch() const override; | 76 int32_t GetVPitch() const override; |
68 void* GetNativeHandle() const override; | 77 void* GetNativeHandle() const override; |
69 rtc::scoped_refptr<webrtc::VideoFrameBuffer> GetVideoFrameBuffer() | 78 rtc::scoped_refptr<webrtc::VideoFrameBuffer> GetVideoFrameBuffer() |
70 const override; | 79 const override; |
71 | 80 |
72 int64_t GetTimeStamp() const override { return time_stamp_ns_; } | 81 /* System monotonic clock */ |
73 void SetTimeStamp(int64_t time_stamp_ns) override { | 82 int64_t timestamp_us() const override { return timestamp_us_; } |
74 time_stamp_ns_ = time_stamp_ns; | 83 void set_timestamp_us(int64_t time_us) { timestamp_us_ = time_us; }; |
75 } | |
76 | 84 |
77 webrtc::VideoRotation GetVideoRotation() const override { | 85 webrtc::VideoRotation GetVideoRotation() const override { |
78 return rotation_; | 86 return rotation_; |
79 } | 87 } |
80 | 88 |
81 VideoFrame* Copy() const override; | 89 VideoFrame* Copy() const override; |
82 bool IsExclusive() const override; | 90 bool IsExclusive() const override; |
83 size_t ConvertToRgbBuffer(uint32_t to_fourcc, | 91 size_t ConvertToRgbBuffer(uint32_t to_fourcc, |
84 uint8_t* buffer, | 92 uint8_t* buffer, |
85 size_t size, | 93 size_t size, |
86 int stride_rgb) const override; | 94 int stride_rgb) const override; |
87 | 95 |
88 const VideoFrame* GetCopyWithRotationApplied() const override; | 96 const VideoFrame* GetCopyWithRotationApplied() const override; |
89 | 97 |
90 protected: | 98 protected: |
91 void SetRotation(webrtc::VideoRotation rotation) override { | 99 void SetRotation(webrtc::VideoRotation rotation) override { |
92 rotation_ = rotation; | 100 rotation_ = rotation; |
93 } | 101 } |
94 // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|. | 102 // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|. |
95 // |h| can be negative indicating a vertically flipped image. | 103 // |h| can be negative indicating a vertically flipped image. |
96 // |dw| is destination width; can be less than |w| if cropping is desired. | 104 // |dw| is destination width; can be less than |w| if cropping is desired. |
97 // |dh| is destination height, like |dw|, but must be a positive number. | 105 // |dh| is destination height, like |dw|, but must be a positive number. |
98 // Returns whether the function succeeded or failed. | 106 // Returns whether the function succeeded or failed. |
99 bool Reset(uint32_t format, | 107 bool Reset(uint32_t format, |
pbos-webrtc
2016/04/13 12:04:04
Shouldn't this take the timestamp as argument?
nisse-webrtc
2016/04/13 13:02:12
Done.
| |
100 int w, | 108 int w, |
101 int h, | 109 int h, |
102 int dw, | 110 int dw, |
103 int dh, | 111 int dh, |
104 uint8_t* sample, | 112 uint8_t* sample, |
105 size_t sample_size, | 113 size_t sample_size, |
106 int64_t time_stamp_ns, | |
107 webrtc::VideoRotation rotation, | 114 webrtc::VideoRotation rotation, |
108 bool apply_rotation); | 115 bool apply_rotation); |
109 | 116 |
110 private: | 117 private: |
111 VideoFrame* CreateEmptyFrame(int w, int h, | 118 VideoFrame* CreateEmptyFrame(int w, int h, |
112 int64_t time_stamp_ns) const override; | 119 int64_t time_stamp_ns) const override; |
113 | 120 |
114 // An opaque reference counted handle that stores the pixel data. | 121 // An opaque reference counted handle that stores the pixel data. |
115 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; | 122 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; |
116 int64_t time_stamp_ns_; | 123 int64_t timestamp_us_; |
117 webrtc::VideoRotation rotation_; | 124 webrtc::VideoRotation rotation_; |
118 | 125 |
119 // This is mutable as the calculation is expensive but once calculated, it | 126 // This is mutable as the calculation is expensive but once calculated, it |
120 // remains const. | 127 // remains const. |
121 mutable std::unique_ptr<VideoFrame> rotated_frame_; | 128 mutable std::unique_ptr<VideoFrame> rotated_frame_; |
122 }; | 129 }; |
123 | 130 |
124 } // namespace cricket | 131 } // namespace cricket |
125 | 132 |
126 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ | 133 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ |
OLD | NEW |