1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* Copyright (c) 2014, Mozilla Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above 13 * copyright notice, this list of conditions and the following 14 * disclaimer in the documentation and/or other materials provided 15 * with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 28 * OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef GMPVideoEncodedFrameImpl_h_ 32 #define GMPVideoEncodedFrameImpl_h_ 33 34 #include "gmp-errors.h" 35 #include "gmp-video-frame.h" 36 #include "gmp-video-frame-encoded.h" 37 #include "mozilla/ipc/Shmem.h" 38 39 namespace mozilla { 40 class CryptoSample; 41 42 namespace gmp { 43 44 class GMPVideoHostImpl; 45 class GMPVideoEncodedFrameData; 46 47 class GMPVideoEncodedFrameImpl : public GMPVideoEncodedFrame { 48 friend struct IPC::ParamTraits<mozilla::gmp::GMPVideoEncodedFrameImpl>; 49 50 public: 51 explicit GMPVideoEncodedFrameImpl(GMPVideoHostImpl* aHost); 52 GMPVideoEncodedFrameImpl(const GMPVideoEncodedFrameData& aFrameData, 53 GMPVideoHostImpl* aHost); 54 virtual ~GMPVideoEncodedFrameImpl(); 55 56 // This is called during a normal destroy sequence, which is 57 // when a consumer is finished or during XPCOM shutdown. 58 void DoneWithAPI(); 59 // Does not attempt to release Shmem, as the Shmem has already been released. 60 void ActorDestroyed(); 61 62 bool RelinquishFrameData(GMPVideoEncodedFrameData& aFrameData); 63 64 // GMPVideoFrame 65 GMPVideoFrameFormat GetFrameFormat() override; 66 void Destroy() override; 67 68 // GMPVideoEncodedFrame 69 GMPErr CreateEmptyFrame(uint32_t aSize) override; 70 GMPErr CopyFrame(const GMPVideoEncodedFrame& aFrame) override; 71 void SetEncodedWidth(uint32_t aEncodedWidth) override; 72 uint32_t EncodedWidth() override; 73 void SetEncodedHeight(uint32_t aEncodedHeight) override; 74 uint32_t EncodedHeight() override; 75 // Microseconds 76 void SetTimeStamp(uint64_t aTimeStamp) override; 77 uint64_t TimeStamp() override; 78 // Set frame duration (microseconds) 79 // NOTE: next-frame's Timestamp() != this-frame's TimeStamp()+Duration() 80 // depending on rounding to avoid having to track roundoff errors 81 // and dropped/missing frames(!) (which may leave a large gap) 82 void SetDuration(uint64_t aDuration) override; 83 uint64_t Duration() const override; 84 void SetFrameType(GMPVideoFrameType aFrameType) override; 85 GMPVideoFrameType FrameType() override; 86 void SetAllocatedSize(uint32_t aNewSize) override; 87 uint32_t AllocatedSize() override; 88 void SetSize(uint32_t aSize) override; 89 uint32_t Size() override; 90 void SetCompleteFrame(bool aCompleteFrame) override; 91 bool CompleteFrame() override; 92 const uint8_t* Buffer() const override; 93 uint8_t* Buffer() override; 94 GMPBufferType BufferType() const override; 95 void SetBufferType(GMPBufferType aBufferType) override; 96 97 private: 98 void DestroyBuffer(); 99 100 uint32_t mEncodedWidth; 101 uint32_t mEncodedHeight; 102 uint64_t mTimeStamp; 103 uint64_t mDuration; 104 GMPVideoFrameType mFrameType; 105 uint32_t mSize; 106 bool mCompleteFrame; 107 GMPVideoHostImpl* mHost; 108 ipc::Shmem mBuffer; 109 GMPBufferType mBufferType; 110 }; 111 112 } // namespace gmp 113 114 } // namespace mozilla 115 116 #endif // GMPVideoEncodedFrameImpl_h_ 117