• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * libjingle
3  * Copyright 2013 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_WEBRTC_WEBRTCTEXTUREVIDEOFRAME_H_
29 #define TALK_MEDIA_WEBRTC_WEBRTCTEXTUREVIDEOFRAME_H_
30 
31 #include "talk/media/base/videoframe.h"
32 #include "webrtc/base/refcount.h"
33 #include "webrtc/base/scoped_ref_ptr.h"
34 #include "webrtc/common_video/interface/native_handle.h"
35 
36 namespace cricket {
37 
38 // A video frame backed by the texture via a native handle.
39 class WebRtcTextureVideoFrame : public VideoFrame {
40  public:
41   WebRtcTextureVideoFrame(webrtc::NativeHandle* handle, int width, int height,
42                           int64 elapsed_time, int64 time_stamp);
43   virtual ~WebRtcTextureVideoFrame();
44 
45   // From base class VideoFrame.
46   virtual bool InitToBlack(int w, int h, size_t pixel_width,
47                            size_t pixel_height, int64 elapsed_time,
48                            int64 time_stamp);
49   virtual bool Reset(uint32 fourcc, int w, int h, int dw, int dh, uint8* sample,
50                      size_t sample_size, size_t pixel_width,
51                      size_t pixel_height, int64 elapsed_time, int64 time_stamp,
52                      int rotation);
GetWidth()53   virtual size_t GetWidth() const { return width_; }
GetHeight()54   virtual size_t GetHeight() const { return height_; }
55   virtual const uint8* GetYPlane() const;
56   virtual const uint8* GetUPlane() const;
57   virtual const uint8* GetVPlane() const;
58   virtual uint8* GetYPlane();
59   virtual uint8* GetUPlane();
60   virtual uint8* GetVPlane();
61   virtual int32 GetYPitch() const;
62   virtual int32 GetUPitch() const;
63   virtual int32 GetVPitch() const;
GetPixelWidth()64   virtual size_t GetPixelWidth() const { return 1; }
GetPixelHeight()65   virtual size_t GetPixelHeight() const { return 1; }
GetElapsedTime()66   virtual int64 GetElapsedTime() const { return elapsed_time_; }
GetTimeStamp()67   virtual int64 GetTimeStamp() const { return time_stamp_; }
SetElapsedTime(int64 elapsed_time)68   virtual void SetElapsedTime(int64 elapsed_time) {
69     elapsed_time_ = elapsed_time;
70   }
SetTimeStamp(int64 time_stamp)71   virtual void SetTimeStamp(int64 time_stamp) { time_stamp_ = time_stamp; }
GetRotation()72   virtual int GetRotation() const { return 0; }
73   virtual VideoFrame* Copy() const;
74   virtual bool MakeExclusive();
75   virtual size_t CopyToBuffer(uint8* buffer, size_t size) const;
76   virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8* buffer,
77                                     size_t size, int stride_rgb) const;
GetNativeHandle()78   virtual void* GetNativeHandle() const { return handle_.get(); }
79 
80   virtual bool CopyToPlanes(
81       uint8* dst_y, uint8* dst_u, uint8* dst_v,
82       int32 dst_pitch_y, int32 dst_pitch_u, int32 dst_pitch_v) const;
83   virtual void CopyToFrame(VideoFrame* target) const;
84   virtual rtc::StreamResult Write(rtc::StreamInterface* stream,
85                                         int* error);
86   virtual void StretchToPlanes(
87       uint8* y, uint8* u, uint8* v, int32 pitchY, int32 pitchU, int32 pitchV,
88       size_t width, size_t height, bool interpolate, bool crop) const;
89   virtual size_t StretchToBuffer(size_t w, size_t h, uint8* buffer, size_t size,
90                                  bool interpolate, bool crop) const;
91   virtual void StretchToFrame(VideoFrame* target, bool interpolate,
92                               bool crop) const;
93   virtual VideoFrame* Stretch(size_t w, size_t h, bool interpolate,
94                               bool crop) const;
95   virtual bool SetToBlack();
96 
97  protected:
98   virtual VideoFrame* CreateEmptyFrame(int w, int h, size_t pixel_width,
99                                        size_t pixel_height, int64 elapsed_time,
100                                        int64 time_stamp) const;
101 
102  private:
103   // The handle of the underlying video frame.
104   rtc::scoped_refptr<webrtc::NativeHandle> handle_;
105   int width_;
106   int height_;
107   int64 elapsed_time_;
108   int64 time_stamp_;
109 };
110 
111 }  // namespace cricket
112 
113 #endif  // TALK_MEDIA_WEBRTC_WEBRTCTEXTUREVIDEOFRAME_H_
114