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