gmp-video-encode.h (5549B)
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_ENCODE_h_ 35 #define GMP_VIDEO_ENCODE_h_ 36 37 #include <stdint.h> 38 39 #include "gmp-errors.h" 40 #include "gmp-video-codec.h" 41 #include "gmp-video-frame-encoded.h" 42 #include "gmp-video-frame-i420.h" 43 44 // ALL METHODS MUST BE CALLED ON THE MAIN THREAD 45 class GMPVideoEncoderCallback { 46 public: 47 virtual ~GMPVideoEncoderCallback() {} 48 49 virtual void Encoded(GMPVideoEncodedFrame* aEncodedFrame, 50 const uint8_t* aCodecSpecificInfo, 51 uint32_t aCodecSpecificInfoLength) = 0; 52 53 // Called when the encoder encounters a catestrophic error and cannot 54 // continue. Gecko will not send any more input for encoding. 55 virtual void Error(GMPErr aError) = 0; 56 }; 57 58 #define GMP_API_VIDEO_ENCODER "encode-video" 59 60 // Video encoding for a single stream. A GMP may be asked to create multiple 61 // encoders concurrently. 62 // 63 // API name macro: GMP_API_VIDEO_ENCODER 64 // Host API: GMPVideoHost 65 // 66 // ALL METHODS MUST BE CALLED ON THE MAIN THREAD 67 class GMPVideoEncoder { 68 public: 69 virtual ~GMPVideoEncoder() {} 70 71 // Initialize the encoder with the information from the VideoCodec. 72 // 73 // Input: 74 // - codecSettings : Codec settings 75 // - aCodecSpecific : codec specific data, pointer to a 76 // GMPCodecSpecific structure appropriate for 77 // this codec type. 78 // - aCodecSpecificLength : number of bytes in aCodecSpecific 79 // - aCallback: Subclass should retain reference to it until EncodingComplete 80 // is called. Do not attempt to delete it, host retains 81 // ownership. 82 // - aNnumberOfCores : Number of cores available for the encoder 83 // - aMaxPayloadSize : The maximum size each payload is allowed 84 // to have. Usually MTU - overhead. 85 virtual void InitEncode(const GMPVideoCodec& aCodecSettings, 86 const uint8_t* aCodecSpecific, 87 uint32_t aCodecSpecificLength, 88 GMPVideoEncoderCallback* aCallback, 89 int32_t aNumberOfCores, uint32_t aMaxPayloadSize) = 0; 90 91 // Encode an I420 frame (as a part of a video stream). The encoded frame 92 // will be returned to the user through the encode complete callback. 93 // 94 // Input: 95 // - aInputFrame : Frame to be encoded 96 // - aCodecSpecificInfo : codec specific data, pointer to a 97 // GMPCodecSpecificInfo structure appropriate for 98 // this codec type. 99 // - aCodecSpecificInfoLength : number of bytes in aCodecSpecific 100 // - aFrameTypes : The frame type to encode 101 // - aFrameTypesLength : The number of elements in aFrameTypes array. 102 virtual void Encode(GMPVideoi420Frame* aInputFrame, 103 const uint8_t* aCodecSpecificInfo, 104 uint32_t aCodecSpecificInfoLength, 105 const GMPVideoFrameType* aFrameTypes, 106 uint32_t aFrameTypesLength) = 0; 107 108 // Inform the encoder about the packet loss and round trip time on the 109 // network used to decide the best pattern and signaling. 110 // 111 // - packetLoss : Fraction lost (loss rate in percent = 112 // 100 * packetLoss / 255) 113 // - rtt : Round-trip time in milliseconds 114 virtual void SetChannelParameters(uint32_t aPacketLoss, uint32_t aRTT) = 0; 115 116 // Inform the encoder about the new target bit rate. 117 // 118 // - newBitRate : New target bit rate 119 // - frameRate : The target frame rate 120 virtual void SetRates(uint32_t aNewBitRate, uint32_t aFrameRate) = 0; 121 122 // Use this function to enable or disable periodic key frames. Can be useful 123 // for codecs which have other ways of stopping error propagation. 124 // 125 // - enable : Enable or disable periodic key frames 126 virtual void SetPeriodicKeyFrames(bool aEnable) = 0; 127 128 // May free Encoder memory. 129 virtual void EncodingComplete() = 0; 130 }; 131 132 #endif // GMP_VIDEO_ENCODE_h_