| 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 #include "webrtc/base/gtest_prod_util.h" | |
| 23 | 22 |
| 24 namespace cricket { | 23 namespace cricket { |
| 25 | 24 |
| 26 struct CapturedFrame; | 25 struct CapturedFrame; |
| 27 | 26 |
| 28 class WebRtcVideoFrame : public VideoFrame { | 27 class WebRtcVideoFrame : public VideoFrame { |
| 29 public: | 28 public: |
| 30 WebRtcVideoFrame(); | 29 WebRtcVideoFrame(); |
| 31 | 30 |
| 32 // Preferred construction, with microsecond timestamp. | 31 // Preferred construction, with microsecond timestamp. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 55 int64_t time_stamp_ns, | 54 int64_t time_stamp_ns, |
| 56 webrtc::VideoRotation rotation); | 55 webrtc::VideoRotation rotation); |
| 57 | 56 |
| 58 // The timestamp of the captured frame is expected to use the same | 57 // The timestamp of the captured frame is expected to use the same |
| 59 // timescale and epoch as rtc::Time. | 58 // timescale and epoch as rtc::Time. |
| 60 // TODO(nisse): Consider adding a warning message, or even an RTC_DCHECK, if | 59 // TODO(nisse): Consider adding a warning message, or even an RTC_DCHECK, if |
| 61 // the time is too far off. | 60 // the time is too far off. |
| 62 bool Init(const CapturedFrame* frame, int dw, int dh, bool apply_rotation); | 61 bool Init(const CapturedFrame* frame, int dw, int dh, bool apply_rotation); |
| 63 | 62 |
| 64 void InitToEmptyBuffer(int w, int h); | 63 void InitToEmptyBuffer(int w, int h); |
| 64 void InitToEmptyBuffer(int w, int h, int64_t time_stamp_ns); |
| 65 | 65 |
| 66 int width() const override; | 66 int width() const override; |
| 67 int height() const override; | 67 int height() const override; |
| 68 | 68 |
| 69 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& video_frame_buffer() | 69 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& video_frame_buffer() |
| 70 const override; | 70 const override; |
| 71 | 71 |
| 72 /* System monotonic clock */ | 72 /* System monotonic clock */ |
| 73 int64_t timestamp_us() const override { return timestamp_us_; } | 73 int64_t timestamp_us() const override { return timestamp_us_; } |
| 74 void set_timestamp_us(int64_t time_us) override { timestamp_us_ = time_us; }; | 74 void set_timestamp_us(int64_t time_us) override { timestamp_us_ = time_us; }; |
| 75 | 75 |
| 76 webrtc::VideoRotation rotation() const override { return rotation_; } | 76 webrtc::VideoRotation rotation() const override { return rotation_; } |
| 77 | 77 |
| 78 VideoFrame* Copy() const override; | 78 VideoFrame* Copy() const override; |
| 79 | 79 |
| 80 size_t ConvertToRgbBuffer(uint32_t to_fourcc, | 80 size_t ConvertToRgbBuffer(uint32_t to_fourcc, |
| 81 uint8_t* buffer, | 81 uint8_t* buffer, |
| 82 size_t size, | 82 size_t size, |
| 83 int stride_rgb) const override; | 83 int stride_rgb) const override; |
| 84 | 84 |
| 85 const VideoFrame* GetCopyWithRotationApplied() const override; | 85 const VideoFrame* GetCopyWithRotationApplied() const override; |
| 86 | 86 |
| 87 protected: | 87 protected: |
| 88 void set_rotation(webrtc::VideoRotation rotation) override { |
| 89 rotation_ = rotation; |
| 90 } |
| 88 // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|. | 91 // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|. |
| 89 // |h| can be negative indicating a vertically flipped image. | 92 // |h| can be negative indicating a vertically flipped image. |
| 90 // |dw| is destination width; can be less than |w| if cropping is desired. | 93 // |dw| is destination width; can be less than |w| if cropping is desired. |
| 91 // |dh| is destination height, like |dw|, but must be a positive number. | 94 // |dh| is destination height, like |dw|, but must be a positive number. |
| 92 // Returns whether the function succeeded or failed. | 95 // Returns whether the function succeeded or failed. |
| 93 bool Reset(uint32_t format, | 96 bool Reset(uint32_t format, |
| 94 int w, | 97 int w, |
| 95 int h, | 98 int h, |
| 96 int dw, | 99 int dw, |
| 97 int dh, | 100 int dh, |
| 98 uint8_t* sample, | 101 uint8_t* sample, |
| 99 size_t sample_size, | 102 size_t sample_size, |
| 100 int64_t timestamp_us, | 103 int64_t timestamp_us, |
| 101 webrtc::VideoRotation rotation, | 104 webrtc::VideoRotation rotation, |
| 102 bool apply_rotation); | 105 bool apply_rotation); |
| 103 | 106 |
| 104 private: | 107 private: |
| 105 // The test mutates |rotation_|, so it needs to be a friend. | 108 VideoFrame* CreateEmptyFrame(int w, int h, |
| 106 FRIEND_TEST_ALL_PREFIXES(WebRtcVideoFrameTest, ApplyRotationToFrame); | 109 int64_t time_stamp_ns) const override; |
| 107 | 110 |
| 108 // An opaque reference counted handle that stores the pixel data. | 111 // An opaque reference counted handle that stores the pixel data. |
| 109 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; | 112 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; |
| 110 int64_t timestamp_us_; | 113 int64_t timestamp_us_; |
| 111 webrtc::VideoRotation rotation_; | 114 webrtc::VideoRotation rotation_; |
| 112 | 115 |
| 113 // This is mutable as the calculation is expensive but once calculated, it | 116 // This is mutable as the calculation is expensive but once calculated, it |
| 114 // remains const. | 117 // remains const. |
| 115 mutable std::unique_ptr<VideoFrame> rotated_frame_; | 118 mutable std::unique_ptr<VideoFrame> rotated_frame_; |
| 116 }; | 119 }; |
| 117 | 120 |
| 118 } // namespace cricket | 121 } // namespace cricket |
| 119 | 122 |
| 120 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ | 123 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ |
| OLD | NEW |