blob: 8191a58d875ba53e44928057ff1320affed80f50 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
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/base/buffer.h"
32#include "talk/base/refcount.h"
33#include "talk/base/scoped_ref_ptr.h"
34#include "talk/media/base/videoframe.h"
35#include "webrtc/common_types.h"
36#include "webrtc/modules/interface/module_common_types.h"
37
38namespace cricket {
39
40struct CapturedFrame;
41
henrike@webrtc.org28e20752013-07-10 00:45:36 +000042class WebRtcVideoFrame : public VideoFrame {
43 public:
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044 WebRtcVideoFrame();
45 ~WebRtcVideoFrame();
46
47 // Creates a frame from a raw sample with FourCC "format" and size "w" x "h".
48 // "h" can be negative indicating a vertically flipped image.
49 // "dh" is destination height if cropping is desired and is always positive.
50 // Returns "true" if successful.
51 bool Init(uint32 format, int w, int h, int dw, int dh, uint8* sample,
52 size_t sample_size, size_t pixel_width, size_t pixel_height,
53 int64 elapsed_time, int64 time_stamp, int rotation);
54
55 bool Init(const CapturedFrame* frame, int dw, int dh);
56
wu@webrtc.org16d62542013-11-05 23:45:14 +000057 // Aliases this WebRtcVideoFrame to a CapturedFrame. |frame| must outlive
58 // this WebRtcVideoFrame.
59 bool Alias(const CapturedFrame* frame, int dw, int dh);
60
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061 bool InitToBlack(int w, int h, size_t pixel_width, size_t pixel_height,
62 int64 elapsed_time, int64 time_stamp);
63
wu@webrtc.org16d62542013-11-05 23:45:14 +000064 // Aliases this WebRtcVideoFrame to a memory buffer. |buffer| must outlive
65 // this WebRtcVideoFrame.
66 void Alias(uint8* buffer, size_t buffer_size, int w, int h,
67 size_t pixel_width, size_t pixel_height, int64 elapsed_time,
68 int64 time_stamp, int rotation);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070 bool AddWatermark();
wu@webrtc.org16d62542013-11-05 23:45:14 +000071 webrtc::VideoFrame* frame();
72 const webrtc::VideoFrame* frame() const;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073
74 // From base class VideoFrame.
75 virtual bool Reset(uint32 format, int w, int h, int dw, int dh, uint8* sample,
76 size_t sample_size, size_t pixel_width,
77 size_t pixel_height, int64 elapsed_time, int64 time_stamp,
78 int rotation);
79
80 virtual size_t GetWidth() const;
81 virtual size_t GetHeight() const;
82 virtual const uint8* GetYPlane() const;
83 virtual const uint8* GetUPlane() const;
84 virtual const uint8* GetVPlane() const;
85 virtual uint8* GetYPlane();
86 virtual uint8* GetUPlane();
87 virtual uint8* GetVPlane();
88 virtual int32 GetYPitch() const { return frame()->Width(); }
89 virtual int32 GetUPitch() const { return (frame()->Width() + 1) / 2; }
90 virtual int32 GetVPitch() const { return (frame()->Width() + 1) / 2; }
wu@webrtc.org9dba5252013-08-05 20:36:57 +000091 virtual void* GetNativeHandle() const { return NULL; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092
93 virtual size_t GetPixelWidth() const { return pixel_width_; }
94 virtual size_t GetPixelHeight() const { return pixel_height_; }
95 virtual int64 GetElapsedTime() const { return elapsed_time_; }
96 virtual int64 GetTimeStamp() const { return time_stamp_; }
97 virtual void SetElapsedTime(int64 elapsed_time) {
98 elapsed_time_ = elapsed_time;
99 }
100 virtual void SetTimeStamp(int64 time_stamp) { time_stamp_ = time_stamp; }
101
102 virtual int GetRotation() const { return rotation_; }
103
104 virtual VideoFrame* Copy() const;
105 virtual bool MakeExclusive();
106 virtual size_t CopyToBuffer(uint8* buffer, size_t size) const;
107 virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8* buffer,
108 size_t size, int stride_rgb) const;
109
110 private:
wu@webrtc.org16d62542013-11-05 23:45:14 +0000111 class FrameBuffer;
112 typedef talk_base::RefCountedObject<FrameBuffer> RefCountedBuffer;
113
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114 void Attach(RefCountedBuffer* video_buffer, size_t buffer_size, int w, int h,
115 size_t pixel_width, size_t pixel_height, int64 elapsed_time,
116 int64 time_stamp, int rotation);
117
118 virtual VideoFrame* CreateEmptyFrame(int w, int h, size_t pixel_width,
119 size_t pixel_height, int64 elapsed_time,
120 int64 time_stamp) const;
121 void InitToEmptyBuffer(int w, int h, size_t pixel_width, size_t pixel_height,
122 int64 elapsed_time, int64 time_stamp);
123
124 talk_base::scoped_refptr<RefCountedBuffer> video_buffer_;
125 bool is_black_;
126 size_t pixel_width_;
127 size_t pixel_height_;
128 int64 elapsed_time_;
129 int64 time_stamp_;
130 int rotation_;
131};
132
133} // namespace cricket
134
135#endif // TALK_MEDIA_WEBRTCVIDEOFRAME_H_