gmp-video-decode.h (5261B)
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_DECODE_h_ 35 #define GMP_VIDEO_DECODE_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 GMPVideoDecoderCallback { 46 public: 47 virtual ~GMPVideoDecoderCallback() {} 48 49 virtual void Decoded(GMPVideoi420Frame* aDecodedFrame) = 0; 50 51 virtual void ReceivedDecodedReferenceFrame(const uint64_t aPictureId) = 0; 52 53 virtual void ReceivedDecodedFrame(const uint64_t aPictureId) = 0; 54 55 virtual void InputDataExhausted() = 0; 56 57 virtual void DrainComplete() = 0; 58 59 virtual void ResetComplete() = 0; 60 61 // Called when the decoder encounters a catestrophic error and cannot 62 // continue. Gecko will not send any more input for decoding. 63 virtual void Error(GMPErr aError) = 0; 64 }; 65 66 #define GMP_API_VIDEO_DECODER "decode-video" 67 68 // Video decoding for a single stream. A GMP may be asked to create multiple 69 // decoders concurrently. 70 // 71 // API name macro: GMP_API_VIDEO_DECODER 72 // Host API: GMPVideoHost 73 // 74 // ALL METHODS MUST BE CALLED ON THE MAIN THREAD 75 class GMPVideoDecoder { 76 public: 77 virtual ~GMPVideoDecoder() {} 78 79 // - aCodecSettings: Details of decoder to create. 80 // - aCodecSpecific: codec specific data, cast to a GMPVideoCodecXXX struct 81 // to get codec specific config data. 82 // - aCodecSpecificLength: number of bytes in aCodecSpecific. 83 // - aCallback: Subclass should retain reference to it until DecodingComplete 84 // is called. Do not attempt to delete it, host retains 85 // ownership. 86 // aCoreCount: number of CPU cores. 87 virtual void InitDecode(const GMPVideoCodec& aCodecSettings, 88 const uint8_t* aCodecSpecific, 89 uint32_t aCodecSpecificLength, 90 GMPVideoDecoderCallback* aCallback, 91 int32_t aCoreCount) = 0; 92 93 // Decode encoded frame (as a part of a video stream). The decoded frame 94 // will be returned to the user through the decode complete callback. 95 // 96 // - aInputFrame: Frame to decode. Call Destroy() on frame when it's decoded. 97 // - aMissingFrames: True if one or more frames have been lost since the 98 // previous decode call. 99 // - aCodecSpecificInfo : codec specific data, pointer to a 100 // GMPCodecSpecificInfo structure appropriate for 101 // this codec type. 102 // - aCodecSpecificInfoLength : number of bytes in aCodecSpecificInfo 103 // - renderTimeMs : System time to render in milliseconds. Only used by 104 // decoders with internal rendering. 105 virtual void Decode(GMPVideoEncodedFrame* aInputFrame, bool aMissingFrames, 106 const uint8_t* aCodecSpecificInfo, 107 uint32_t aCodecSpecificInfoLength, 108 int64_t aRenderTimeMs = -1) = 0; 109 110 // Reset decoder state and prepare for a new call to Decode(...). 111 // Flushes the decoder pipeline. 112 // The decoder should enqueue a task to run ResetComplete() on the main 113 // thread once the reset has finished. 114 virtual void Reset() = 0; 115 116 // Output decoded frames for any data in the pipeline, regardless of ordering. 117 // All remaining decoded frames should be immediately returned via callback. 118 // The decoder should enqueue a task to run DrainComplete() on the main 119 // thread once the reset has finished. 120 virtual void Drain() = 0; 121 122 // May free decoder memory. 123 virtual void DecodingComplete() = 0; 124 }; 125 126 #endif // GMP_VIDEO_DECODE_h_