Chromium Code Reviews| 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? | |
|
perkj_webrtc
2016/04/08 14:52:18
I hope not...
Can't you just create a new ctor wh
nisse-webrtc
2016/04/11 06:58:56
That should work. Sounds a little hackish, but may
| |
| 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 |
| 50 bool Init(const CapturedFrame* frame, int dw, int dh, bool apply_rotation); | 55 bool Init(const CapturedFrame* frame, int dw, int dh, bool apply_rotation); |
| 51 | 56 |
| 57 void InitToEmptyBuffer(int w, int h); | |
| 52 void InitToEmptyBuffer(int w, int h, int64_t time_stamp_ns); | 58 void InitToEmptyBuffer(int w, int h, int64_t time_stamp_ns); |
| 53 | 59 |
| 54 bool InitToBlack(int w, int h, int64_t time_stamp_ns); | 60 bool InitToBlack(int w, int h, int64_t time_stamp_ns); |
| 55 | 61 |
| 56 int width() const override; | 62 int width() const override; |
| 57 int height() const override; | 63 int height() const override; |
| 58 | 64 |
| 59 const uint8_t* GetYPlane() const override; | 65 const uint8_t* GetYPlane() const override; |
| 60 const uint8_t* GetUPlane() const override; | 66 const uint8_t* GetUPlane() const override; |
| 61 const uint8_t* GetVPlane() const override; | 67 const uint8_t* GetVPlane() const override; |
| 62 uint8_t* GetYPlane() override; | 68 uint8_t* GetYPlane() override; |
| 63 uint8_t* GetUPlane() override; | 69 uint8_t* GetUPlane() override; |
| 64 uint8_t* GetVPlane() override; | 70 uint8_t* GetVPlane() override; |
| 65 int32_t GetYPitch() const override; | 71 int32_t GetYPitch() const override; |
| 66 int32_t GetUPitch() const override; | 72 int32_t GetUPitch() const override; |
| 67 int32_t GetVPitch() const override; | 73 int32_t GetVPitch() const override; |
| 68 void* GetNativeHandle() const override; | 74 void* GetNativeHandle() const override; |
| 69 rtc::scoped_refptr<webrtc::VideoFrameBuffer> GetVideoFrameBuffer() | 75 rtc::scoped_refptr<webrtc::VideoFrameBuffer> GetVideoFrameBuffer() |
| 70 const override; | 76 const override; |
| 71 | 77 |
| 72 int64_t GetTimeStamp() const override { return time_stamp_ns_; } | 78 /* System monotonic clock */ |
| 73 void SetTimeStamp(int64_t time_stamp_ns) override { | 79 int64_t timestamp_us() const override { return timestamp_us_; } |
| 74 time_stamp_ns_ = time_stamp_ns; | 80 void set_timestamp_us(int64_t time_us) { timestamp_us_ = time_us; }; |
| 75 } | |
| 76 | 81 |
| 77 webrtc::VideoRotation GetVideoRotation() const override { | 82 webrtc::VideoRotation GetVideoRotation() const override { |
| 78 return rotation_; | 83 return rotation_; |
| 79 } | 84 } |
| 80 | 85 |
| 81 VideoFrame* Copy() const override; | 86 VideoFrame* Copy() const override; |
| 82 bool IsExclusive() const override; | 87 bool IsExclusive() const override; |
| 83 size_t ConvertToRgbBuffer(uint32_t to_fourcc, | 88 size_t ConvertToRgbBuffer(uint32_t to_fourcc, |
| 84 uint8_t* buffer, | 89 uint8_t* buffer, |
| 85 size_t size, | 90 size_t size, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 96 // |dw| is destination width; can be less than |w| if cropping is desired. | 101 // |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. | 102 // |dh| is destination height, like |dw|, but must be a positive number. |
| 98 // Returns whether the function succeeded or failed. | 103 // Returns whether the function succeeded or failed. |
| 99 bool Reset(uint32_t format, | 104 bool Reset(uint32_t format, |
| 100 int w, | 105 int w, |
| 101 int h, | 106 int h, |
| 102 int dw, | 107 int dw, |
| 103 int dh, | 108 int dh, |
| 104 uint8_t* sample, | 109 uint8_t* sample, |
| 105 size_t sample_size, | 110 size_t sample_size, |
| 106 int64_t time_stamp_ns, | |
| 107 webrtc::VideoRotation rotation, | 111 webrtc::VideoRotation rotation, |
| 108 bool apply_rotation); | 112 bool apply_rotation); |
| 109 | 113 |
| 110 private: | 114 private: |
| 111 VideoFrame* CreateEmptyFrame(int w, int h, | 115 VideoFrame* CreateEmptyFrame(int w, int h, |
| 112 int64_t time_stamp_ns) const override; | 116 int64_t time_stamp_ns) const override; |
| 113 | 117 |
| 114 // An opaque reference counted handle that stores the pixel data. | 118 // An opaque reference counted handle that stores the pixel data. |
| 115 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; | 119 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; |
| 116 int64_t time_stamp_ns_; | 120 int64_t timestamp_us_; |
| 117 webrtc::VideoRotation rotation_; | 121 webrtc::VideoRotation rotation_; |
| 118 | 122 |
| 119 // This is mutable as the calculation is expensive but once calculated, it | 123 // This is mutable as the calculation is expensive but once calculated, it |
| 120 // remains const. | 124 // remains const. |
| 121 mutable std::unique_ptr<VideoFrame> rotated_frame_; | 125 mutable std::unique_ptr<VideoFrame> rotated_frame_; |
| 122 }; | 126 }; |
| 123 | 127 |
| 124 } // namespace cricket | 128 } // namespace cricket |
| 125 | 129 |
| 126 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ | 130 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ |
| OLD | NEW |