Home | History | Annotate | Download | only in interface
      1 /*
      2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_VIDEO_CODEC_INTERFACE_H
     12 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_VIDEO_CODEC_INTERFACE_H
     13 
     14 #include <vector>
     15 
     16 #include "webrtc/common_types.h"
     17 #include "webrtc/common_video/interface/i420_video_frame.h"
     18 #include "webrtc/modules/interface/module_common_types.h"
     19 #include "webrtc/modules/video_coding/codecs/interface/video_error_codes.h"
     20 #include "webrtc/typedefs.h"
     21 #include "webrtc/video_encoder.h"
     22 
     23 namespace webrtc
     24 {
     25 
     26 class RTPFragmentationHeader; // forward declaration
     27 
     28 // Note: if any pointers are added to this struct, it must be fitted
     29 // with a copy-constructor. See below.
     30 struct CodecSpecificInfoVP8 {
     31   bool hasReceivedSLI;
     32   uint8_t pictureIdSLI;
     33   bool hasReceivedRPSI;
     34   uint64_t pictureIdRPSI;
     35   int16_t pictureId;  // Negative value to skip pictureId.
     36   bool nonReference;
     37   uint8_t simulcastIdx;
     38   uint8_t temporalIdx;
     39   bool layerSync;
     40   int tl0PicIdx;  // Negative value to skip tl0PicIdx.
     41   int8_t keyIdx;  // Negative value to skip keyIdx.
     42 };
     43 
     44 struct CodecSpecificInfoGeneric {
     45   uint8_t simulcast_idx;
     46 };
     47 
     48 struct CodecSpecificInfoH264 {};
     49 
     50 union CodecSpecificInfoUnion {
     51   CodecSpecificInfoGeneric generic;
     52   CodecSpecificInfoVP8 VP8;
     53   CodecSpecificInfoH264 H264;
     54 };
     55 
     56 // Note: if any pointers are added to this struct or its sub-structs, it
     57 // must be fitted with a copy-constructor. This is because it is copied
     58 // in the copy-constructor of VCMEncodedFrame.
     59 struct CodecSpecificInfo
     60 {
     61     VideoCodecType   codecType;
     62     CodecSpecificInfoUnion codecSpecific;
     63 };
     64 
     65 class DecodedImageCallback
     66 {
     67 public:
     68     virtual ~DecodedImageCallback() {};
     69 
     70     // Callback function which is called when an image has been decoded.
     71     //
     72     // Input:
     73     //          - decodedImage         : The decoded image.
     74     //
     75     // Return value                    : 0 if OK, < 0 otherwise.
     76     virtual int32_t Decoded(I420VideoFrame& decodedImage) = 0;
     77 
     78     virtual int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) {return -1;}
     79 
     80     virtual int32_t ReceivedDecodedFrame(const uint64_t pictureId) {return -1;}
     81 };
     82 
     83 class VideoDecoder
     84 {
     85 public:
     86     virtual ~VideoDecoder() {};
     87 
     88     // Initialize the decoder with the information from the VideoCodec.
     89     //
     90     // Input:
     91     //          - inst              : Codec settings
     92     //          - numberOfCores     : Number of cores available for the decoder
     93     //
     94     // Return value                 : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
     95     virtual int32_t InitDecode(const VideoCodec* codecSettings, int32_t numberOfCores) = 0;
     96 
     97     // Decode encoded image (as a part of a video stream). The decoded image
     98     // will be returned to the user through the decode complete callback.
     99     //
    100     // Input:
    101     //          - inputImage        : Encoded image to be decoded
    102     //          - missingFrames     : True if one or more frames have been lost
    103     //                                since the previous decode call.
    104     //          - fragmentation     : Specifies where the encoded frame can be
    105     //                                split into separate fragments. The meaning
    106     //                                of fragment is codec specific, but often
    107     //                                means that each fragment is decodable by
    108     //                                itself.
    109     //          - codecSpecificInfo : Pointer to codec specific data
    110     //          - renderTimeMs      : System time to render in milliseconds. Only
    111     //                                used by decoders with internal rendering.
    112     //
    113     // Return value                 : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
    114     virtual int32_t
    115     Decode(const EncodedImage& inputImage,
    116            bool missingFrames,
    117            const RTPFragmentationHeader* fragmentation,
    118            const CodecSpecificInfo* codecSpecificInfo = NULL,
    119            int64_t renderTimeMs = -1) = 0;
    120 
    121     // Register an decode complete callback object.
    122     //
    123     // Input:
    124     //          - callback         : Callback object which handles decoded images.
    125     //
    126     // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
    127     virtual int32_t RegisterDecodeCompleteCallback(DecodedImageCallback* callback) = 0;
    128 
    129     // Free decoder memory.
    130     //
    131     // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
    132     virtual int32_t Release() = 0;
    133 
    134     // Reset decoder state and prepare for a new call.
    135     //
    136     // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
    137     virtual int32_t Reset() = 0;
    138 
    139     // Codec configuration data sent out-of-band, i.e. in SIP call setup
    140     //
    141     // Input/Output:
    142     //          - buffer           : Buffer pointer to the configuration data
    143     //          - size             : The size of the configuration data in
    144     //                               bytes
    145     //
    146     // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
    147     virtual int32_t SetCodecConfigParameters(const uint8_t* /*buffer*/, int32_t /*size*/) { return WEBRTC_VIDEO_CODEC_ERROR; }
    148 
    149     // Create a copy of the codec and its internal state.
    150     //
    151     // Return value                : A copy of the instance if OK, NULL otherwise.
    152     virtual VideoDecoder* Copy() { return NULL; }
    153 };
    154 
    155 }  // namespace webrtc
    156 
    157 #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_INTERFACE_VIDEO_CODEC_INTERFACE_H
    158