128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org/*
228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * libjingle
328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * Copyright 2004 Google Inc.
428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org *
528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * Redistribution and use in source and binary forms, with or without
628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * modification, are permitted provided that the following conditions are met:
728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org *
828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org *  1. Redistributions of source code must retain the above copyright notice,
928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org *     this list of conditions and the following disclaimer.
1028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org *  2. Redistributions in binary form must reproduce the above copyright notice,
1128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org *     this list of conditions and the following disclaimer in the documentation
1228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org *     and/or other materials provided with the distribution.
1328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org *  3. The name of the author may not be used to endorse or promote products
1428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org *     derived from this software without specific prior written permission.
1528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org *
1628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
1728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
1928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org */
2728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
2828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#ifndef TALK_MEDIA_BASE_VIDEOFRAME_H_
2928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#define TALK_MEDIA_BASE_VIDEOFRAME_H_
3028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
31d4e598d57aed714a599444a7eab5e8fdde52a950buildbot@webrtc.org#include "webrtc/base/basictypes.h"
32d4e598d57aed714a599444a7eab5e8fdde52a950buildbot@webrtc.org#include "webrtc/base/stream.h"
336f8ce060a21fcdc1c951fbf06768eb0cc0083b2fkjellander#include "webrtc/common_video/include/video_frame_buffer.h"
346c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org#include "webrtc/common_video/rotation.h"
3528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
3628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgnamespace cricket {
3728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
3828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org// Represents a YUV420 (a.k.a. I420) video frame.
3928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.orgclass VideoFrame {
4028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org public:
4128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  VideoFrame() {}
4228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual ~VideoFrame() {}
4328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
44268493a96b93d6a11a595b3272c5a4cd7a1fdc47nisse  virtual bool InitToBlack(int w, int h, size_t pixel_width,
45268493a96b93d6a11a595b3272c5a4cd7a1fdc47nisse                           size_t pixel_height, int64_t time_stamp) = 0;
4628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|.
4728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // |h| can be negative indicating a vertically flipped image.
4828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // |dw| is destination width; can be less than |w| if cropping is desired.
4928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // |dh| is destination height, like |dw|, but must be a positive number.
5028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Returns whether the function succeeded or failed.
516c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org
520c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual bool Reset(uint32_t fourcc,
536c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org                     int w,
546c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org                     int h,
556c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org                     int dw,
566c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org                     int dh,
570c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                     uint8_t* sample,
586c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org                     size_t sample_size,
59268493a96b93d6a11a595b3272c5a4cd7a1fdc47nisse                     size_t pixel_width,
60268493a96b93d6a11a595b3272c5a4cd7a1fdc47nisse                     size_t pixel_height,
616c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org                     int64_t time_stamp,
621d82813961d49e1a433024221b6f7164856635ecperkj@webrtc.org                     webrtc::VideoRotation rotation,
633954e1dfe126815053c2f908214f89f9d5035a0fMagnus Jedvert                     bool apply_rotation) = 0;
646c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org
6528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Basic accessors.
6664c1e8cda5cb4db85c5c296bf2f6a8181af7de9dGuo-wei Shieh  // Note this is the width and height without rotation applied.
6728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual size_t GetWidth() const = 0;
6828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual size_t GetHeight() const = 0;
6964c1e8cda5cb4db85c5c296bf2f6a8181af7de9dGuo-wei Shieh
7028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  size_t GetChromaWidth() const { return (GetWidth() + 1) / 2; }
7128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  size_t GetChromaHeight() const { return (GetHeight() + 1) / 2; }
7228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  size_t GetChromaSize() const { return GetUPitch() * GetChromaHeight(); }
739dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org  // These can return NULL if the object is not backed by a buffer.
740c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual const uint8_t* GetYPlane() const = 0;
750c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual const uint8_t* GetUPlane() const = 0;
760c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual const uint8_t* GetVPlane() const = 0;
770c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual uint8_t* GetYPlane() = 0;
780c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual uint8_t* GetUPlane() = 0;
790c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual uint8_t* GetVPlane() = 0;
809dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org
810c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual int32_t GetYPitch() const = 0;
820c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual int32_t GetUPitch() const = 0;
830c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual int32_t GetVPitch() const = 0;
8428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
859dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org  // Returns the handle of the underlying video frame. This is used when the
869dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org  // frame is backed by a texture. The object should be destroyed when it is no
879dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org  // longer in use, so the underlying resource can be freed.
889dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org  virtual void* GetNativeHandle() const = 0;
899dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org
903954e1dfe126815053c2f908214f89f9d5035a0fMagnus Jedvert  // Returns the underlying video frame buffer. This function is ok to call
913954e1dfe126815053c2f908214f89f9d5035a0fMagnus Jedvert  // multiple times, but the returned object will refer to the same memory.
92afdd5dd372d69be7244a3d90d70de9d5ecd60eb9magjed@webrtc.org  virtual rtc::scoped_refptr<webrtc::VideoFrameBuffer> GetVideoFrameBuffer()
933954e1dfe126815053c2f908214f89f9d5035a0fMagnus Jedvert      const = 0;
94afdd5dd372d69be7244a3d90d70de9d5ecd60eb9magjed@webrtc.org
95268493a96b93d6a11a595b3272c5a4cd7a1fdc47nisse  // For retrieving the aspect ratio of each pixel. Usually this is 1x1, but
96268493a96b93d6a11a595b3272c5a4cd7a1fdc47nisse  // the aspect_ratio_idc parameter of H.264 can specify non-square pixels.
97268493a96b93d6a11a595b3272c5a4cd7a1fdc47nisse  virtual size_t GetPixelWidth() const = 0;
98268493a96b93d6a11a595b3272c5a4cd7a1fdc47nisse  virtual size_t GetPixelHeight() const = 0;
99268493a96b93d6a11a595b3272c5a4cd7a1fdc47nisse
100599e299b9dc3dc07fc78cfeaba629566a201b4f1kjellander@webrtc.org  virtual int64_t GetTimeStamp() const = 0;
101599e299b9dc3dc07fc78cfeaba629566a201b4f1kjellander@webrtc.org  virtual void SetTimeStamp(int64_t time_stamp) = 0;
10228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
10328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Indicates the rotation angle in degrees.
1046c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org  // TODO(guoweis): Remove this function, rename GetVideoRotation and remove the
1051226e926e6104322d9b99026b98f515cb4d40fd4guoweis@webrtc.org  // skeleton implementation of GetRotation once chrome is updated.
1066c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org  virtual int GetRotation() const { return GetVideoRotation(); }
1076c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org  virtual webrtc::VideoRotation GetVideoRotation() const {
1086c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org    return webrtc::kVideoRotation_0;
1096c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org  }
11028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
11128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Make a shallow copy of the frame. The frame buffer itself is not copied.
11228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Both the current and new VideoFrame will share a single reference-counted
11328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // frame buffer.
11428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual VideoFrame *Copy() const = 0;
11528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
11628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Since VideoFrame supports shallow copy and the internal frame buffer might
1173954e1dfe126815053c2f908214f89f9d5035a0fMagnus Jedvert  // be shared, this function can be used to check exclusive ownership.
1183954e1dfe126815053c2f908214f89f9d5035a0fMagnus Jedvert  virtual bool IsExclusive() const = 0;
11950b229509187cf63b5c80ff5ae55694f0e84ee23magjed@webrtc.org
12050b229509187cf63b5c80ff5ae55694f0e84ee23magjed@webrtc.org  // In case VideoFrame needs exclusive access of the frame buffer, user can
12150b229509187cf63b5c80ff5ae55694f0e84ee23magjed@webrtc.org  // call MakeExclusive() to make sure the frame buffer is exclusively
12250b229509187cf63b5c80ff5ae55694f0e84ee23magjed@webrtc.org  // accessible to the current object.  This might mean a deep copy of the frame
12328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // buffer if it is currently shared by other objects.
12428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual bool MakeExclusive() = 0;
12528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
12628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Writes the frame into the given frame buffer, provided that it is of
12728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // sufficient size. Returns the frame's actual size, regardless of whether
12828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // it was written or not (like snprintf). If there is insufficient space,
12928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // nothing is written.
1300c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual size_t CopyToBuffer(uint8_t* buffer, size_t size) const;
13128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
13228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Writes the frame into the given planes, stretched to the given width and
13328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // height. The parameter "interpolate" controls whether to interpolate or just
13428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // take the nearest-point. The parameter "crop" controls whether to crop this
13528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // frame to the aspect ratio of the given dimensions before stretching.
1360c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual bool CopyToPlanes(uint8_t* dst_y,
1370c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                            uint8_t* dst_u,
1380c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                            uint8_t* dst_v,
1390c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                            int32_t dst_pitch_y,
1400c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                            int32_t dst_pitch_u,
1410c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                            int32_t dst_pitch_v) const;
14228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
14328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Writes the frame into the target VideoFrame.
14428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual void CopyToFrame(VideoFrame* target) const;
14528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
14600c509ad1c94805b3332f2ce876c04705abf8ef5guoweis@webrtc.org  // Return a copy of frame which has its pending rotation applied. The
14700c509ad1c94805b3332f2ce876c04705abf8ef5guoweis@webrtc.org  // ownership of the returned frame is held by this frame.
1483954e1dfe126815053c2f908214f89f9d5035a0fMagnus Jedvert  virtual const VideoFrame* GetCopyWithRotationApplied() const = 0;
14900c509ad1c94805b3332f2ce876c04705abf8ef5guoweis@webrtc.org
15028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Writes the frame into the given stream and returns the StreamResult.
151d4e598d57aed714a599444a7eab5e8fdde52a950buildbot@webrtc.org  // See webrtc/base/stream.h for a description of StreamResult and error.
15228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Error may be NULL. If a non-success value is returned from
15328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // StreamInterface::Write(), we immediately return with that value.
154f09e7b8a4f521447ea56e3e8c5ff2f6826feacf2magjed@webrtc.org  virtual rtc::StreamResult Write(rtc::StreamInterface* stream,
155f09e7b8a4f521447ea56e3e8c5ff2f6826feacf2magjed@webrtc.org                                  int* error) const;
15628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
15728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Converts the I420 data to RGB of a certain type such as ARGB and ABGR.
15828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Returns the frame's actual size, regardless of whether it was written or
15928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // not (like snprintf). Parameters size and stride_rgb are in units of bytes.
16028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // If there is insufficient space, nothing is written.
1610c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual size_t ConvertToRgbBuffer(uint32_t to_fourcc,
1620c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                                    uint8_t* buffer,
1630c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                                    size_t size,
1640c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                                    int stride_rgb) const;
16528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
16628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Writes the frame into the given planes, stretched to the given width and
16728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // height. The parameter "interpolate" controls whether to interpolate or just
16828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // take the nearest-point. The parameter "crop" controls whether to crop this
16928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // frame to the aspect ratio of the given dimensions before stretching.
1700c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  virtual void StretchToPlanes(uint8_t* y,
1710c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                               uint8_t* u,
1720c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                               uint8_t* v,
1730c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                               int32_t pitchY,
1740c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                               int32_t pitchU,
1750c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                               int32_t pitchV,
1760c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                               size_t width,
1770c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                               size_t height,
1780c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                               bool interpolate,
1790c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                               bool crop) const;
18028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
18128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Writes the frame into the target VideoFrame, stretched to the size of that
18228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // frame. The parameter "interpolate" controls whether to interpolate or just
18328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // take the nearest-point. The parameter "crop" controls whether to crop this
18428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // frame to the aspect ratio of the target frame before stretching.
18528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual void StretchToFrame(VideoFrame *target, bool interpolate,
18628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                              bool crop) const;
18728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
18828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Stretches the frame to the given size, creating a new VideoFrame object to
18928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // hold it. The parameter "interpolate" controls whether to interpolate or
19028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // just take the nearest-point. The parameter "crop" controls whether to crop
19128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // this frame to the aspect ratio of the given dimensions before stretching.
19228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  virtual VideoFrame *Stretch(size_t w, size_t h, bool interpolate,
19328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                              bool crop) const;
19428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
19528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Sets the video frame to black.
1969dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org  virtual bool SetToBlack();
19728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
19828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Tests if sample is valid.  Returns true if valid.
1990c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström  static bool Validate(uint32_t fourcc,
2000c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                       int w,
2010c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                       int h,
2020c4e06b4c6107a1b94f764e279e4fb4161e905b0Peter Boström                       const uint8_t* sample,
20328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org                       size_t sample_size);
20428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
20528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Size of an I420 image of given dimensions when stored as a frame buffer.
20628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  static size_t SizeOf(size_t w, size_t h) {
20728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org    return w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2;
20828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  }
20928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
21028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org protected:
21128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org  // Creates an empty frame.
212268493a96b93d6a11a595b3272c5a4cd7a1fdc47nisse  virtual VideoFrame *CreateEmptyFrame(int w, int h, size_t pixel_width,
213268493a96b93d6a11a595b3272c5a4cd7a1fdc47nisse                                       size_t pixel_height,
214599e299b9dc3dc07fc78cfeaba629566a201b4f1kjellander@webrtc.org                                       int64_t time_stamp) const = 0;
21517b889b899c3eeaa96dc26a6e61cd2e6296b0fecGuo-wei Shieh  virtual void SetRotation(webrtc::VideoRotation rotation) = 0;
21628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org};
21728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
21828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}  // namespace cricket
21928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org
22028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#endif  // TALK_MEDIA_BASE_VIDEOFRAME_H_
221