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_ENCODED_h_
35 #define GMP_VIDEO_FRAME_ENCODED_h_
36 
37 #include <stdint.h>
38 #include "gmp-video-frame.h"
39 #include "gmp-video-codec.h"
40 
41 enum GMPVideoFrameType {
42   kGMPKeyFrame = 0,
43   kGMPDeltaFrame = 1,
44   kGMPGoldenFrame = 2,
45   kGMPAltRefFrame = 3,
46   kGMPSkipFrame = 4,
47   kGMPVideoFrameInvalid = 5  // Must always be last.
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 GMPVideoEncodedFrame : public GMPVideoFrame {
60  public:
61   // MAIN THREAD ONLY
62   virtual GMPErr CreateEmptyFrame(uint32_t aSize) = 0;
63   // MAIN THREAD ONLY
64   virtual GMPErr CopyFrame(const GMPVideoEncodedFrame& aVideoFrame) = 0;
65   virtual void SetEncodedWidth(uint32_t aEncodedWidth) = 0;
66   virtual uint32_t EncodedWidth() = 0;
67   virtual void SetEncodedHeight(uint32_t aEncodedHeight) = 0;
68   virtual uint32_t EncodedHeight() = 0;
69   // Microseconds
70   virtual void SetTimeStamp(uint64_t aTimeStamp) = 0;
71   virtual uint64_t TimeStamp() = 0;
72   // Set frame duration (microseconds)
73   // NOTE: next-frame's Timestamp() != this-frame's TimeStamp()+Duration()
74   // depending on rounding to avoid having to track roundoff errors
75   // and dropped/missing frames(!) (which may leave a large gap)
76   virtual void SetDuration(uint64_t aDuration) = 0;
77   virtual uint64_t Duration() const = 0;
78   virtual void SetFrameType(GMPVideoFrameType aFrameType) = 0;
79   virtual GMPVideoFrameType FrameType() = 0;
80   virtual void SetAllocatedSize(uint32_t aNewSize) = 0;
81   virtual uint32_t AllocatedSize() = 0;
82   virtual void SetSize(uint32_t aSize) = 0;
83   virtual uint32_t Size() = 0;
84   virtual void SetCompleteFrame(bool aCompleteFrame) = 0;
85   virtual bool CompleteFrame() = 0;
86   virtual const uint8_t* Buffer() const = 0;
87   virtual uint8_t* Buffer() = 0;
88   virtual GMPBufferType BufferType() const = 0;
89   virtual void SetBufferType(GMPBufferType aBufferType) = 0;
90 };
91 
92 #endif  // GMP_VIDEO_FRAME_ENCODED_h_
93