| 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 bool InitToBlack(int w, int h, int64_t time_stamp_ns) override; | |
| 70 | |
| 71 // From base class VideoFrame. | |
| 72 bool Reset(uint32_t format, | |
| 73 int w, | |
| 74 int h, | |
| 75 int dw, | |
| 76 int dh, | |
| 77 uint8_t* sample, | |
| 78 size_t sample_size, | |
| 79 int64_t time_stamp_ns, | |
| 80 webrtc::VideoRotation rotation, | |
| 81 bool apply_rotation) override; | |
| 82 | |
| 83 size_t GetWidth() const override; | |
| 84 size_t GetHeight() const override; | |
| 85 const uint8_t* GetYPlane() const override; | |
| 86 const uint8_t* GetUPlane() const override; | |
| 87 const uint8_t* GetVPlane() const override; | |
| 88 uint8_t* GetYPlane() override; | |
| 89 uint8_t* GetUPlane() override; | |
| 90 uint8_t* GetVPlane() override; | |
| 91 int32_t GetYPitch() const override; | |
| 92 int32_t GetUPitch() const override; | |
| 93 int32_t GetVPitch() const override; | |
| 94 void* GetNativeHandle() const override; | |
| 95 rtc::scoped_refptr<webrtc::VideoFrameBuffer> GetVideoFrameBuffer() | |
| 96 const override; | |
| 97 | |
| 98 int64_t GetTimeStamp() const override { return time_stamp_ns_; } | |
| 99 void SetTimeStamp(int64_t time_stamp_ns) override { | |
| 100 time_stamp_ns_ = time_stamp_ns; | |
| 101 } | |
| 102 | |
| 103 webrtc::VideoRotation GetVideoRotation() const override { | |
| 104 return rotation_; | |
| 105 } | |
| 106 | |
| 107 VideoFrame* Copy() const override; | |
| 108 bool IsExclusive() const override; | |
| 109 bool MakeExclusive() override; | |
| 110 size_t ConvertToRgbBuffer(uint32_t to_fourcc, | |
| 111 uint8_t* buffer, | |
| 112 size_t size, | |
| 113 int stride_rgb) const override; | |
| 114 | |
| 115 const VideoFrame* GetCopyWithRotationApplied() const override; | |
| 116 | |
| 117 protected: | |
| 118 void SetRotation(webrtc::VideoRotation rotation) override { | |
| 119 rotation_ = rotation; | |
| 120 } | |
| 121 | |
| 122 private: | |
| 123 VideoFrame* CreateEmptyFrame(int w, int h, | |
| 124 int64_t time_stamp_ns) const override; | |
| 125 | |
| 126 // An opaque reference counted handle that stores the pixel data. | |
| 127 rtc::scoped_refptr<webrtc::VideoFrameBuffer> video_frame_buffer_; | |
| 128 int64_t time_stamp_ns_; | |
| 129 webrtc::VideoRotation rotation_; | |
| 130 | |
| 131 // This is mutable as the calculation is expensive but once calculated, it | |
| 132 // remains const. | |
| 133 mutable rtc::scoped_ptr<VideoFrame> rotated_frame_; | |
| 134 }; | |
| 135 | |
| 136 } // namespace cricket | |
| 137 | |
| 138 #endif // TALK_MEDIA_WEBRTCVIDEOFRAME_H_ | |
| OLD | NEW |