OLD | NEW |
| (Empty) |
1 /* | |
2 * libjingle | |
3 * Copyright 2011 Google Inc. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions are met: | |
7 * | |
8 * 1. Redistributions of source code must retain the above copyright notice, | |
9 * this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
11 * this list of conditions and the following disclaimer in the documentation | |
12 * and/or other materials provided with the distribution. | |
13 * 3. The name of the author may not be used to endorse or promote products | |
14 * derived from this software without specific prior written permission. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 */ | |
27 | |
28 #ifndef TALK_MEDIA_WEBRTCVIDEOFRAME_H_ | |
29 #define TALK_MEDIA_WEBRTCVIDEOFRAME_H_ | |
30 | |
31 #include "talk/media/base/videoframe.h" | |
32 #include "webrtc/base/buffer.h" | |
33 #include "webrtc/base/refcount.h" | |
34 #include "webrtc/base/scoped_ref_ptr.h" | |
35 #include "webrtc/common_types.h" | |
36 #include "webrtc/common_video/include/video_frame_buffer.h" | |
37 | |
38 namespace cricket { | |
39 | |
40 struct CapturedFrame; | |
41 | |
42 class WebRtcVideoFrame : public VideoFrame { | |
43 public: | |
44 WebRtcVideoFrame(); | |
45 WebRtcVideoFrame(const rtc::scoped_refptr<webrtc::VideoFrameBuffer>& buffer, | |
46 int64_t time_stamp_ns, | |
47 webrtc::VideoRotation rotation); | |
48 | |
49 ~WebRtcVideoFrame(); | |
50 | |
51 // Creates a frame from a raw sample with FourCC "format" and size "w" x "h". | |
52 // "h" can be negative indicating a vertically flipped image. | |
53 // "dh" is destination height if cropping is desired and is always positive. | |
54 // Returns "true" if successful. | |
55 bool Init(uint32_t format, | |
56 int w, | |
57 int h, | |
58 int dw, | |
59 int dh, | |
60 uint8_t* sample, | |
61 size_t sample_size, | |
62 int64_t time_stamp_ns, | |
63 webrtc::VideoRotation rotation); | |
64 | |
65 bool Init(const CapturedFrame* frame, int dw, int dh, bool apply_rotation); | |
66 | |
67 void InitToEmptyBuffer(int w, int h, int64_t time_stamp_ns); | |
68 | |
69 // TODO(nisse): Old signature. Delete after chrome is updated. | |
70 void InitToEmptyBuffer(int w, int h, size_t pixel_width, size_t pixel_height, | |
71 int64_t time_stamp_ns) { | |
72 InitToEmptyBuffer(w, h, time_stamp_ns); | |
73 } | |
74 | |
75 bool InitToBlack(int w, int h, int64_t time_stamp_ns) override; | |
76 // Needed to inherit the InitToBlack wrapper method with 5 | |
77 // arguments. | |
78 using VideoFrame::InitToBlack; | |
79 | |
80 // From base class VideoFrame. | |
81 bool Reset(uint32_t format, | |
82 int w, | |
83 int h, | |
84 int dw, | |
85 int dh, | |
86 uint8_t* sample, | |
87 size_t sample_size, | |
88 int64_t time_stamp_ns, | |
89 webrtc::VideoRotation rotation, | |
90 bool apply_rotation) override; | |
91 | |
92 size_t GetWidth() const override; | |
93 size_t GetHeight() const override; | |
94 const uint8_t* GetYPlane() const override; | |
95 const uint8_t* GetUPlane() const override; | |
96 const uint8_t* GetVPlane() const override; | |
97 uint8_t* GetYPlane() override; | |
98 uint8_t* GetUPlane() override; | |
99 uint8_t* GetVPlane() override; | |
100 int32_t GetYPitch() const override; | |
101 int32_t GetUPitch() const override; | |
102 int32_t GetVPitch() const override; | |
103 void* GetNativeHandle() const override; | |
104 rtc::scoped_refptr<webrtc::VideoFrameBuffer> GetVideoFrameBuffer() | |
105 const override; | |
106 | |
107 int64_t GetTimeStamp() const override { return time_stamp_ns_; } | |
108 void SetTimeStamp(int64_t time_stamp_ns) override { | |
109 time_stamp_ns_ = time_stamp_ns; | |
110 } | |
111 | |
112 webrtc::VideoRotation GetVideoRotation() const override { | |
113 return rotation_; | |
114 } | |
115 | |
116 VideoFrame* Copy() const override; | |
117 bool IsExclusive() const override; | |
118 bool MakeExclusive() override; | |
119 size_t ConvertToRgbBuffer(uint32_t to_fourcc, | |
120 uint8_t* buffer, | |
121 size_t size, | |
122 int stride_rgb) const override; | |
123 | |
124 const VideoFrame* GetCopyWithRotationApplied() const override; | |
125 | |
126 protected: | |
127 void SetRotation(webrtc::VideoRotation rotation) override { | |
128 rotation_ = rotation; | |
129 } | |
130 | |
131 private: | |
132 VideoFrame* CreateEmptyFrame(int w, int h, | |
133 int64_t time_stamp_ns) const override; | |
134 | |
135 // An opaque reference counted handle that stores the pixel data. | |
136 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; | |
137 int64_t time_stamp_ns_; | |
138 webrtc::VideoRotation rotation_; | |
139 | |
140 // This is mutable as the calculation is expensive but once calculated, it | |
141 // remains const. | |
142 mutable rtc::scoped_ptr<VideoFrame> rotated_frame_; | |
143 }; | |
144 | |
145 } // namespace cricket | |
146 | |
147 #endif // TALK_MEDIA_WEBRTCVIDEOFRAME_H_ | |
OLD | NEW |