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 // TODO(nisse): Deprecated, replace cricket::WebRtcVideoFrame with | |
12 // webrtc::VideoFrame everywhere, then delete this file. See | |
13 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5682. | |
14 | |
11 #ifndef WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ | 15 #ifndef WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ |
12 #define WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ | 16 #define WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ |
13 | 17 |
14 #include <memory> | 18 #include <memory> |
15 | 19 |
16 #include "webrtc/base/buffer.h" | 20 #include "webrtc/base/buffer.h" |
17 #include "webrtc/base/refcount.h" | 21 #include "webrtc/base/refcount.h" |
18 #include "webrtc/base/scoped_ref_ptr.h" | 22 #include "webrtc/base/scoped_ref_ptr.h" |
19 #include "webrtc/common_types.h" | 23 #include "webrtc/common_types.h" |
20 #include "webrtc/common_video/include/video_frame_buffer.h" | 24 #include "webrtc/common_video/include/video_frame_buffer.h" |
21 #include "webrtc/media/base/videoframe.h" | 25 #include "webrtc/media/base/videoframe.h" |
22 | 26 |
23 namespace cricket { | 27 namespace cricket { |
24 | 28 |
25 // TODO(nisse): This class will be deleted when the cricket::VideoFrame and | |
26 // webrtc::VideoFrame classes are merged. See | |
27 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5682. Try to use only the | |
28 // preferred constructor, and the non-deprecated methods of the VideoFrame base | |
29 // class. | |
30 class WebRtcVideoFrame : public VideoFrame { | 29 class WebRtcVideoFrame : public VideoFrame { |
31 public: | 30 public: |
32 // TODO(nisse): Deprecated. Using the default constructor violates the | 31 WebRtcVideoFrame() : VideoFrame() {} |
33 // reasonable assumption that video_frame_buffer() returns a valid buffer. | 32 WebRtcVideoFrame(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, |
34 WebRtcVideoFrame(); | 33 webrtc::VideoRotation rotation, |
35 | 34 int64_t timestamp_us) |
36 // Preferred constructor. | 35 : VideoFrame(buffer, rotation, timestamp_us) {} |
37 WebRtcVideoFrame(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, | 36 WebRtcVideoFrame(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, |
38 webrtc::VideoRotation rotation, | 37 webrtc::VideoRotation rotation, |
39 int64_t timestamp_us, | 38 int64_t timestamp_us, |
40 uint32_t transport_frame_id); | 39 uint32_t transport_frame_id) |
41 | 40 : VideoFrame(buffer, rotation, timestamp_us) { |
42 // Alternative constructor, when not knowing or caring about the | 41 // For now, transport_frame_id and rtp timestamp are the same. |
perkj_webrtc
2016/10/07 07:06:59
TODO... - reconsider for quick?
nisse-webrtc
2016/10/07 12:47:30
Done.
| |
43 // transport_frame_id. Which is set to zero. | 42 set_timestamp(transport_frame_id); |
44 WebRtcVideoFrame(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, | 43 } |
45 webrtc::VideoRotation rotation, | |
46 int64_t timestamp_us); | |
47 | |
48 // TODO(nisse): Deprecated, delete as soon as all callers have switched to the | |
49 // above constructor with microsecond timestamp. | |
50 WebRtcVideoFrame(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, | |
51 int64_t timestamp_ns, | |
52 webrtc::VideoRotation rotation); | |
53 | |
54 ~WebRtcVideoFrame(); | |
55 | |
56 // TODO(nisse): Init (and its helpers Reset and Validate) are used | |
57 // only by the LoadFrame function used in the VideoFrame unittests. | |
58 // Rewrite tests, and delete this function. | |
59 | |
60 // Creates a frame from a raw sample with FourCC "format" and size "w" x "h". | |
61 // "h" can be negative indicating a vertically flipped image. | |
62 // "dh" is destination height if cropping is desired and is always positive. | |
63 // Returns "true" if successful. | |
64 bool Init(uint32_t format, | |
65 int w, | |
66 int h, | |
67 int dw, | |
68 int dh, | |
69 uint8_t* sample, | |
70 size_t sample_size, | |
71 int64_t timestamp_ns, | |
72 webrtc::VideoRotation rotation); | |
73 | |
74 void InitToEmptyBuffer(int w, int h); | |
75 | |
76 int width() const override; | |
77 int height() const override; | |
78 | |
79 const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& video_frame_buffer() | |
80 const override; | |
81 | |
82 uint32_t transport_frame_id() const override; | |
83 | |
84 int64_t timestamp_us() const override; | |
85 void set_timestamp_us(int64_t time_us) override; | |
86 | |
87 webrtc::VideoRotation rotation() const override; | |
88 | |
89 protected: | |
90 // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|. | |
91 // |h| can be negative indicating a vertically flipped image. | |
92 // |dw| is destination width; can be less than |w| if cropping is desired. | |
93 // |dh| is destination height, like |dw|, but must be a positive number. | |
94 // Returns whether the function succeeded or failed. | |
95 bool Reset(uint32_t format, | |
96 int w, | |
97 int h, | |
98 int dw, | |
99 int dh, | |
100 uint8_t* sample, | |
101 size_t sample_size, | |
102 int64_t timestamp_us, | |
103 webrtc::VideoRotation rotation, | |
104 bool apply_rotation); | |
105 | |
106 private: | |
107 // Tests mutate |rotation_|, so the base test class is a friend. | |
108 friend class WebRtcVideoFrameTest; | |
109 | |
110 // An opaque reference counted handle that stores the pixel data. | |
111 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; | |
112 int64_t timestamp_us_; | |
113 uint32_t transport_frame_id_; | |
114 webrtc::VideoRotation rotation_; | |
115 | |
116 // This is mutable as the calculation is expensive but once calculated, it | |
117 // remains const. | |
118 mutable std::unique_ptr<VideoFrame> rotated_frame_; | |
119 }; | 44 }; |
120 | 45 |
121 } // namespace cricket | 46 } // namespace cricket |
122 | 47 |
123 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ | 48 #endif // WEBRTC_MEDIA_ENGINE_WEBRTCVIDEOFRAME_H_ |
OLD | NEW |