gmp-video-frame-i420.h (5591B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* Copyright (c) 2011, The WebRTC project authors. All rights reserved. 3 * Copyright (c) 2014, Mozilla 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 ** Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 ** Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided with the 15 * distribution. 16 * 17 ** Neither the name of Google nor the names of its contributors may 18 * be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #ifndef GMP_VIDEO_FRAME_I420_h_ 35 #define GMP_VIDEO_FRAME_I420_h_ 36 37 #include <stdint.h> 38 39 #include "gmp-errors.h" 40 #include "gmp-video-frame.h" 41 #include "gmp-video-plane.h" 42 43 enum GMPPlaneType { 44 kGMPYPlane = 0, 45 kGMPUPlane = 1, 46 kGMPVPlane = 2, 47 kGMPNumOfPlanes = 3 48 }; 49 50 // The implementation backing this interface uses shared memory for the 51 // buffer(s). This means it can only be used by the "owning" process. 52 // At first the process which created the object owns it. When the object 53 // is passed to an interface the creator loses ownership and must Destroy() 54 // the object. Further attempts to use it may fail due to not being able to 55 // access the underlying buffer(s). 56 // 57 // Methods that create or destroy shared memory must be called on the main 58 // thread. They are marked below. 59 class GMPVideoi420Frame : public GMPVideoFrame { 60 public: 61 // MAIN THREAD ONLY 62 // CreateEmptyFrame: Sets frame dimensions and allocates buffers based 63 // on set dimensions - height and plane stride. 64 // If required size is bigger than the allocated one, new buffers of adequate 65 // size will be allocated. 66 virtual GMPErr CreateEmptyFrame(int32_t aWidth, int32_t aHeight, 67 int32_t aStride_y, int32_t aStride_u, 68 int32_t aStride_v) = 0; 69 70 // MAIN THREAD ONLY 71 // CreateFrame: Sets the frame's members and buffers. If required size is 72 // bigger than allocated one, new buffers of adequate size will be allocated. 73 virtual GMPErr CreateFrame(int32_t aSize_y, const uint8_t* aBuffer_y, 74 int32_t aSize_u, const uint8_t* aBuffer_u, 75 int32_t aSize_v, const uint8_t* aBuffer_v, 76 int32_t aWidth, int32_t aHeight, int32_t aStride_y, 77 int32_t aStride_u, int32_t aStride_v) = 0; 78 79 // MAIN THREAD ONLY 80 // Copy frame: If required size is bigger than allocated one, new buffers of 81 // adequate size will be allocated. 82 virtual GMPErr CopyFrame(const GMPVideoi420Frame& aVideoFrame) = 0; 83 84 // Swap Frame. 85 virtual void SwapFrame(GMPVideoi420Frame* aVideoFrame) = 0; 86 87 // Get pointer to buffer per plane. 88 virtual uint8_t* Buffer(GMPPlaneType aType) = 0; 89 90 // Overloading with const. 91 virtual const uint8_t* Buffer(GMPPlaneType aType) const = 0; 92 93 // Get allocated size per plane. 94 virtual int32_t AllocatedSize(GMPPlaneType aType) const = 0; 95 96 // Get allocated stride per plane. 97 virtual int32_t Stride(GMPPlaneType aType) const = 0; 98 99 // Set frame width. 100 virtual GMPErr SetWidth(int32_t aWidth) = 0; 101 102 // Set frame height. 103 virtual GMPErr SetHeight(int32_t aHeight) = 0; 104 105 // Get frame width. 106 virtual int32_t Width() const = 0; 107 108 // Get frame height. 109 virtual int32_t Height() const = 0; 110 111 // Set frame timestamp (microseconds) 112 virtual void SetTimestamp(uint64_t aTimestamp) = 0; 113 114 // Get frame timestamp (microseconds) 115 virtual uint64_t Timestamp() const = 0; 116 117 // Set frame duration (microseconds) 118 // NOTE: next-frame's Timestamp() != this-frame's TimeStamp()+Duration() 119 // depending on rounding to avoid having to track roundoff errors 120 // and dropped/missing frames(!) (which may leave a large gap) 121 virtual void SetDuration(uint64_t aDuration) = 0; 122 123 // Get frame duration (microseconds) 124 virtual uint64_t Duration() const = 0; 125 126 // Return true if underlying plane buffers are of zero size, false if not. 127 virtual bool IsZeroSize() const = 0; 128 129 // Reset underlying plane buffers sizes to 0. This function doesn't clear 130 // memory. 131 virtual void ResetSize() = 0; 132 133 // -- These methods have been added in kGMPVersion34 -- 134 135 // Set an updated frame timestamp (microseconds) from decoder 136 virtual void SetUpdatedTimestamp(uint64_t aTimestamp) = 0; 137 138 // Get an updated frame timestamp (microseconds) from decoder 139 virtual uint64_t UpdatedTimestamp() const = 0; 140 }; 141 142 #endif // GMP_VIDEO_FRAME_I420_h_