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 #include "nsAutoPtr.h" 39 40 namespace mozilla { 41 class CryptoSample; 42 43 namespace gmp { 44 45 class GMPVideoHostImpl; 46 class GMPVideoEncodedFrameData; 47 48 class GMPVideoEncodedFrameImpl : public GMPVideoEncodedFrame { 49 friend struct IPC::ParamTraits<mozilla::gmp::GMPVideoEncodedFrameImpl>; 50 51 public: 52 explicit GMPVideoEncodedFrameImpl(GMPVideoHostImpl* aHost); 53 GMPVideoEncodedFrameImpl(const GMPVideoEncodedFrameData& aFrameData, 54 GMPVideoHostImpl* aHost); 55 virtual ~GMPVideoEncodedFrameImpl(); 56 57 // This is called during a normal destroy sequence, which is 58 // when a consumer is finished or during XPCOM shutdown. 59 void DoneWithAPI(); 60 // Does not attempt to release Shmem, as the Shmem has already been released. 61 void ActorDestroyed(); 62 63 bool RelinquishFrameData(GMPVideoEncodedFrameData& aFrameData); 64 65 // GMPVideoFrame 66 GMPVideoFrameFormat GetFrameFormat() override; 67 void Destroy() override; 68 69 // GMPVideoEncodedFrame 70 GMPErr CreateEmptyFrame(uint32_t aSize) override; 71 GMPErr CopyFrame(const GMPVideoEncodedFrame& aFrame) override; 72 void SetEncodedWidth(uint32_t aEncodedWidth) override; 73 uint32_t EncodedWidth() override; 74 void SetEncodedHeight(uint32_t aEncodedHeight) override; 75 uint32_t EncodedHeight() override; 76 // Microseconds 77 void SetTimeStamp(uint64_t aTimeStamp) override; 78 uint64_t TimeStamp() override; 79 // Set frame duration (microseconds) 80 // NOTE: next-frame's Timestamp() != this-frame's TimeStamp()+Duration() 81 // depending on rounding to avoid having to track roundoff errors 82 // and dropped/missing frames(!) (which may leave a large gap) 83 void SetDuration(uint64_t aDuration) override; 84 uint64_t Duration() const override; 85 void SetFrameType(GMPVideoFrameType aFrameType) override; 86 GMPVideoFrameType FrameType() override; 87 void SetAllocatedSize(uint32_t aNewSize) override; 88 uint32_t AllocatedSize() override; 89 void SetSize(uint32_t aSize) override; 90 uint32_t Size() override; 91 void SetCompleteFrame(bool aCompleteFrame) override; 92 bool CompleteFrame() override; 93 const uint8_t* Buffer() const override; 94 uint8_t* Buffer() override; 95 GMPBufferType BufferType() const override; 96 void SetBufferType(GMPBufferType aBufferType) override; 97 98 private: 99 void DestroyBuffer(); 100 101 uint32_t mEncodedWidth; 102 uint32_t mEncodedHeight; 103 uint64_t mTimeStamp; 104 uint64_t mDuration; 105 GMPVideoFrameType mFrameType; 106 uint32_t mSize; 107 bool mCompleteFrame; 108 GMPVideoHostImpl* mHost; 109 ipc::Shmem mBuffer; 110 GMPBufferType mBufferType; 111 }; 112 113 } // namespace gmp 114 115 } // namespace mozilla 116 117 #endif // GMPVideoEncodedFrameImpl_h_ 118