videoframe.h revision 00c509ad1c94805b3332f2ce876c04705abf8ef5
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" 33afdd5dd372d69be7244a3d90d70de9d5ecd60eb9magjed@webrtc.org#include "webrtc/common_video/interface/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 4428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual bool InitToBlack(int w, int h, size_t pixel_width, 45599e299b9dc3dc07fc78cfeaba629566a201b4f1kjellander@webrtc.org size_t pixel_height, int64_t elapsed_time, 46599e299b9dc3dc07fc78cfeaba629566a201b4f1kjellander@webrtc.org int64_t time_stamp) = 0; 4728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Creates a frame from a raw sample with FourCC |format| and size |w| x |h|. 4828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // |h| can be negative indicating a vertically flipped image. 4928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // |dw| is destination width; can be less than |w| if cropping is desired. 5028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // |dh| is destination height, like |dw|, but must be a positive number. 5128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Returns whether the function succeeded or failed. 526c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org 536c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org // TODO(guoweis): remove the implementation and the next Reset once chrome 546c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org // gets the code. 556c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org virtual bool Reset(uint32 fourcc, 566c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int w, 576c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int h, 586c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int dw, 596c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int dh, 606c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org uint8* sample, 616c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org size_t sample_size, 626c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org size_t pixel_width, 636c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org size_t pixel_height, 646c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int64_t elapsed_time, 656c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int64_t time_stamp, 661d82813961d49e1a433024221b6f7164856635ecperkj@webrtc.org webrtc::VideoRotation rotation, 671d82813961d49e1a433024221b6f7164856635ecperkj@webrtc.org bool apply_rotation) { 686c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org return false; 696c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org } 706c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org 716c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org virtual bool Reset(uint32 fourcc, 726c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int w, 736c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int h, 746c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int dw, 756c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int dh, 766c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org uint8* sample, 776c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org size_t sample_size, 786c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org size_t pixel_width, 796c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org size_t pixel_height, 806c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int64_t elapsed_time, 816c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int64_t time_stamp, 826c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org int rotation) { 836c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org return Reset(fourcc, w, h, dw, dh, sample, sample_size, pixel_width, 846c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org pixel_height, elapsed_time, time_stamp, 851d82813961d49e1a433024221b6f7164856635ecperkj@webrtc.org static_cast<webrtc::VideoRotation>(rotation), true); 866c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org } 8728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 8828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Basic accessors. 8928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual size_t GetWidth() const = 0; 9028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual size_t GetHeight() const = 0; 9128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org size_t GetChromaWidth() const { return (GetWidth() + 1) / 2; } 9228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org size_t GetChromaHeight() const { return (GetHeight() + 1) / 2; } 9328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org size_t GetChromaSize() const { return GetUPitch() * GetChromaHeight(); } 949dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org // These can return NULL if the object is not backed by a buffer. 9528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual const uint8 *GetYPlane() const = 0; 9628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual const uint8 *GetUPlane() const = 0; 9728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual const uint8 *GetVPlane() const = 0; 9828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual uint8 *GetYPlane() = 0; 9928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual uint8 *GetUPlane() = 0; 10028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual uint8 *GetVPlane() = 0; 1019dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org 10228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual int32 GetYPitch() const = 0; 10328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual int32 GetUPitch() const = 0; 10428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual int32 GetVPitch() const = 0; 10528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 1069dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org // Returns the handle of the underlying video frame. This is used when the 1079dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org // frame is backed by a texture. The object should be destroyed when it is no 1089dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org // longer in use, so the underlying resource can be freed. 1099dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org virtual void* GetNativeHandle() const = 0; 1109dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org 111afdd5dd372d69be7244a3d90d70de9d5ecd60eb9magjed@webrtc.org // Returns the underlying video frame buffer. The default implementation 112afdd5dd372d69be7244a3d90d70de9d5ecd60eb9magjed@webrtc.org // returns a shallow wrapper, converting itself into a 113afdd5dd372d69be7244a3d90d70de9d5ecd60eb9magjed@webrtc.org // webrtc::VideoFrameBuffer. This function is ok to call multiple times, but 114afdd5dd372d69be7244a3d90d70de9d5ecd60eb9magjed@webrtc.org // the returned object will refer to the same memory. 115afdd5dd372d69be7244a3d90d70de9d5ecd60eb9magjed@webrtc.org // TODO(magjed): Make pure virtual when all subclasses implement this. 116afdd5dd372d69be7244a3d90d70de9d5ecd60eb9magjed@webrtc.org virtual rtc::scoped_refptr<webrtc::VideoFrameBuffer> GetVideoFrameBuffer() 117afdd5dd372d69be7244a3d90d70de9d5ecd60eb9magjed@webrtc.org const; 118afdd5dd372d69be7244a3d90d70de9d5ecd60eb9magjed@webrtc.org 11928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // For retrieving the aspect ratio of each pixel. Usually this is 1x1, but 12028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // the aspect_ratio_idc parameter of H.264 can specify non-square pixels. 12128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual size_t GetPixelWidth() const = 0; 12228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual size_t GetPixelHeight() const = 0; 12328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 124599e299b9dc3dc07fc78cfeaba629566a201b4f1kjellander@webrtc.org virtual int64_t GetElapsedTime() const = 0; 125599e299b9dc3dc07fc78cfeaba629566a201b4f1kjellander@webrtc.org virtual int64_t GetTimeStamp() const = 0; 126599e299b9dc3dc07fc78cfeaba629566a201b4f1kjellander@webrtc.org virtual void SetElapsedTime(int64_t elapsed_time) = 0; 127599e299b9dc3dc07fc78cfeaba629566a201b4f1kjellander@webrtc.org virtual void SetTimeStamp(int64_t time_stamp) = 0; 12828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 12928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Indicates the rotation angle in degrees. 1306c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org // TODO(guoweis): Remove this function, rename GetVideoRotation and remove the 1311226e926e6104322d9b99026b98f515cb4d40fd4guoweis@webrtc.org // skeleton implementation of GetRotation once chrome is updated. 1326c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org virtual int GetRotation() const { return GetVideoRotation(); } 1336c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org virtual webrtc::VideoRotation GetVideoRotation() const { 1346c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org return webrtc::kVideoRotation_0; 1356c930c71831b6eda6e85903c505459569a02ad9aguoweis@webrtc.org } 13628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 13728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Make a shallow copy of the frame. The frame buffer itself is not copied. 13828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Both the current and new VideoFrame will share a single reference-counted 13928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // frame buffer. 14028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual VideoFrame *Copy() const = 0; 14128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 14228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Since VideoFrame supports shallow copy and the internal frame buffer might 14350b229509187cf63b5c80ff5ae55694f0e84ee23magjed@webrtc.org // be shared, this function can be used to check exclusive ownership. The 14450b229509187cf63b5c80ff5ae55694f0e84ee23magjed@webrtc.org // default implementation is conservative and returns false. Subclasses with 14550b229509187cf63b5c80ff5ae55694f0e84ee23magjed@webrtc.org // knowledge of implementation specific details can override this. 14650b229509187cf63b5c80ff5ae55694f0e84ee23magjed@webrtc.org virtual bool IsExclusive() const { return false; } 14750b229509187cf63b5c80ff5ae55694f0e84ee23magjed@webrtc.org 14850b229509187cf63b5c80ff5ae55694f0e84ee23magjed@webrtc.org // In case VideoFrame needs exclusive access of the frame buffer, user can 14950b229509187cf63b5c80ff5ae55694f0e84ee23magjed@webrtc.org // call MakeExclusive() to make sure the frame buffer is exclusively 15050b229509187cf63b5c80ff5ae55694f0e84ee23magjed@webrtc.org // accessible to the current object. This might mean a deep copy of the frame 15128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // buffer if it is currently shared by other objects. 15228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual bool MakeExclusive() = 0; 15328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 15428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Writes the frame into the given frame buffer, provided that it is of 15528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // sufficient size. Returns the frame's actual size, regardless of whether 15628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // it was written or not (like snprintf). If there is insufficient space, 15728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // nothing is written. 1583864363e2c3043bd23081abe32ad13dcb6d718edmagjed@webrtc.org virtual size_t CopyToBuffer(uint8 *buffer, size_t size) const; 15928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 16028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Writes the frame into the given planes, stretched to the given width and 16128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // height. The parameter "interpolate" controls whether to interpolate or just 16228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // take the nearest-point. The parameter "crop" controls whether to crop this 16328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // frame to the aspect ratio of the given dimensions before stretching. 16428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual bool CopyToPlanes( 16528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org uint8* dst_y, uint8* dst_u, uint8* dst_v, 16628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org int32 dst_pitch_y, int32 dst_pitch_u, int32 dst_pitch_v) const; 16728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 16828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Writes the frame into the target VideoFrame. 16928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual void CopyToFrame(VideoFrame* target) const; 17028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 17100c509ad1c94805b3332f2ce876c04705abf8ef5guoweis@webrtc.org // Return a copy of frame which has its pending rotation applied. The 17200c509ad1c94805b3332f2ce876c04705abf8ef5guoweis@webrtc.org // ownership of the returned frame is held by this frame. 17300c509ad1c94805b3332f2ce876c04705abf8ef5guoweis@webrtc.org virtual const VideoFrame* GetCopyWithRotationApplied() const { 17400c509ad1c94805b3332f2ce876c04705abf8ef5guoweis@webrtc.org return nullptr; 17500c509ad1c94805b3332f2ce876c04705abf8ef5guoweis@webrtc.org } 17600c509ad1c94805b3332f2ce876c04705abf8ef5guoweis@webrtc.org 17728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Writes the frame into the given stream and returns the StreamResult. 178d4e598d57aed714a599444a7eab5e8fdde52a950buildbot@webrtc.org // See webrtc/base/stream.h for a description of StreamResult and error. 17928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Error may be NULL. If a non-success value is returned from 18028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // StreamInterface::Write(), we immediately return with that value. 181f09e7b8a4f521447ea56e3e8c5ff2f6826feacf2magjed@webrtc.org virtual rtc::StreamResult Write(rtc::StreamInterface* stream, 182f09e7b8a4f521447ea56e3e8c5ff2f6826feacf2magjed@webrtc.org int* error) const; 18328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 18428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Converts the I420 data to RGB of a certain type such as ARGB and ABGR. 18528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Returns the frame's actual size, regardless of whether it was written or 18628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // not (like snprintf). Parameters size and stride_rgb are in units of bytes. 18728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // If there is insufficient space, nothing is written. 18828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual size_t ConvertToRgbBuffer(uint32 to_fourcc, uint8 *buffer, 189bdcf38c89446b1b464a646414f6cd7573a190bd1magjed@webrtc.org size_t size, int stride_rgb) const; 19028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 19128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Writes the frame into the given planes, stretched to the given width and 19228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // height. The parameter "interpolate" controls whether to interpolate or just 19328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // take the nearest-point. The parameter "crop" controls whether to crop this 19428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // frame to the aspect ratio of the given dimensions before stretching. 19528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual void StretchToPlanes( 19628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org uint8 *y, uint8 *u, uint8 *v, int32 pitchY, int32 pitchU, int32 pitchV, 19728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org size_t width, size_t height, bool interpolate, bool crop) const; 19828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 19928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Writes the frame into the given frame buffer, stretched to the given width 20028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // and height, provided that it is of sufficient size. Returns the frame's 20128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // actual size, regardless of whether it was written or not (like snprintf). 20228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // If there is insufficient space, nothing is written. The parameter 20328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // "interpolate" controls whether to interpolate or just take the 20428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // nearest-point. The parameter "crop" controls whether to crop this frame to 20528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // the aspect ratio of the given dimensions before stretching. 20628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual size_t StretchToBuffer(size_t w, size_t h, uint8 *buffer, size_t size, 20728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org bool interpolate, bool crop) const; 20828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 20928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Writes the frame into the target VideoFrame, stretched to the size of that 21028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // frame. The parameter "interpolate" controls whether to interpolate or just 21128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // take the nearest-point. The parameter "crop" controls whether to crop this 21228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // frame to the aspect ratio of the target frame before stretching. 21328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual void StretchToFrame(VideoFrame *target, bool interpolate, 21428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org bool crop) const; 21528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 21628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Stretches the frame to the given size, creating a new VideoFrame object to 21728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // hold it. The parameter "interpolate" controls whether to interpolate or 21828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // just take the nearest-point. The parameter "crop" controls whether to crop 21928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // this frame to the aspect ratio of the given dimensions before stretching. 22028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual VideoFrame *Stretch(size_t w, size_t h, bool interpolate, 22128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org bool crop) const; 22228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 22328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Sets the video frame to black. 2249dba52562725dbaced0d671982201ede753d72e8wu@webrtc.org virtual bool SetToBlack(); 22528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 22628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Tests if sample is valid. Returns true if valid. 22728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org static bool Validate(uint32 fourcc, int w, int h, const uint8 *sample, 22828e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org size_t sample_size); 22928e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 23028e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Size of an I420 image of given dimensions when stored as a frame buffer. 23128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org static size_t SizeOf(size_t w, size_t h) { 23228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org return w * h + ((w + 1) / 2) * ((h + 1) / 2) * 2; 23328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org } 23428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 23528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org protected: 23628e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org // Creates an empty frame. 23728e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org virtual VideoFrame *CreateEmptyFrame(int w, int h, size_t pixel_width, 238599e299b9dc3dc07fc78cfeaba629566a201b4f1kjellander@webrtc.org size_t pixel_height, 239599e299b9dc3dc07fc78cfeaba629566a201b4f1kjellander@webrtc.org int64_t elapsed_time, 240599e299b9dc3dc07fc78cfeaba629566a201b4f1kjellander@webrtc.org int64_t time_stamp) const = 0; 24128e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org}; 24228e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 24328e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org} // namespace cricket 24428e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org 24528e20752806a492f5a6a5d343c02f9556f39b1cdhenrike@webrtc.org#endif // TALK_MEDIA_BASE_VIDEOFRAME_H_ 246