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