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_I420_MAIN_INTERFACE_I420_H_
     12 #define WEBRTC_MODULES_VIDEO_CODING_CODECS_I420_MAIN_INTERFACE_I420_H_
     13 
     14 #include <vector>
     15 
     16 #include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h"
     17 #include "webrtc/typedefs.h"
     18 
     19 namespace webrtc {
     20 
     21 enum { kI420HeaderSize = 4 };
     22 
     23 class I420Encoder : public VideoEncoder {
     24  public:
     25   I420Encoder();
     26 
     27   virtual ~I420Encoder();
     28 
     29 // Initialize the encoder with the information from the VideoCodec.
     30 //
     31 // Input:
     32 //          - codecSettings     : Codec settings.
     33 //          - numberOfCores     : Number of cores available for the encoder.
     34 //          - maxPayloadSize    : The maximum size each payload is allowed
     35 //                                to have. Usually MTU - overhead.
     36 //
     37 // Return value                 : WEBRTC_VIDEO_CODEC_OK if OK.
     38 //                                <0 - Error
     39   virtual int InitEncode(const VideoCodec* codecSettings,
     40                          int /*numberOfCores*/,
     41                          uint32_t /*maxPayloadSize*/) OVERRIDE;
     42 
     43 // "Encode" an I420 image (as a part of a video stream). The encoded image
     44 // will be returned to the user via the encode complete callback.
     45 //
     46 // Input:
     47 //          - inputImage        : Image to be encoded.
     48 //          - codecSpecificInfo : Pointer to codec specific data.
     49 //          - frameType         : Frame type to be sent (Key /Delta).
     50 //
     51 // Return value                 : WEBRTC_VIDEO_CODEC_OK if OK.
     52 //                                <0 - Error
     53   virtual int Encode(
     54       const I420VideoFrame& inputImage,
     55       const CodecSpecificInfo* /*codecSpecificInfo*/,
     56       const std::vector<VideoFrameType>* /*frame_types*/) OVERRIDE;
     57 
     58 // Register an encode complete callback object.
     59 //
     60 // Input:
     61 //          - callback         : Callback object which handles encoded images.
     62 //
     63 // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
     64   virtual int RegisterEncodeCompleteCallback(
     65       EncodedImageCallback* callback) OVERRIDE;
     66 
     67 // Free encoder memory.
     68 //
     69 // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
     70   virtual int Release() OVERRIDE;
     71 
     72   virtual int SetRates(uint32_t /*newBitRate*/,
     73                        uint32_t /*frameRate*/) OVERRIDE {
     74     return WEBRTC_VIDEO_CODEC_OK;
     75   }
     76 
     77   virtual int SetChannelParameters(uint32_t /*packetLoss*/,
     78                                    int /*rtt*/) OVERRIDE {
     79     return WEBRTC_VIDEO_CODEC_OK;
     80   }
     81 
     82   virtual int CodecConfigParameters(uint8_t* /*buffer*/,
     83                                     int /*size*/) OVERRIDE {
     84     return WEBRTC_VIDEO_CODEC_OK;
     85   }
     86 
     87  private:
     88   static uint8_t* InsertHeader(uint8_t* buffer, uint16_t width,
     89                                uint16_t height);
     90 
     91   bool                     _inited;
     92   EncodedImage             _encodedImage;
     93   EncodedImageCallback*    _encodedCompleteCallback;
     94 };  // class I420Encoder
     95 
     96 class I420Decoder : public VideoDecoder {
     97  public:
     98   I420Decoder();
     99 
    100   virtual ~I420Decoder();
    101 
    102 // Initialize the decoder.
    103 // The user must notify the codec of width and height values.
    104 //
    105 // Return value         :  WEBRTC_VIDEO_CODEC_OK.
    106 //                        <0 - Errors
    107   virtual int InitDecode(const VideoCodec* codecSettings,
    108                          int /*numberOfCores*/) OVERRIDE;
    109 
    110   virtual int SetCodecConfigParameters(const uint8_t* /*buffer*/,
    111                                        int /*size*/) OVERRIDE {
    112     return WEBRTC_VIDEO_CODEC_OK;
    113   }
    114 
    115 // Decode encoded image (as a part of a video stream). The decoded image
    116 // will be returned to the user through the decode complete callback.
    117 //
    118 // Input:
    119 //          - inputImage        : Encoded image to be decoded
    120 //          - missingFrames     : True if one or more frames have been lost
    121 //                                since the previous decode call.
    122 //          - codecSpecificInfo : pointer to specific codec data
    123 //          - renderTimeMs      : Render time in Ms
    124 //
    125 // Return value                 : WEBRTC_VIDEO_CODEC_OK if OK
    126 //                                 <0 - Error
    127   virtual int Decode(const EncodedImage& inputImage,
    128                      bool missingFrames,
    129                      const RTPFragmentationHeader* /*fragmentation*/,
    130                      const CodecSpecificInfo* /*codecSpecificInfo*/,
    131                      int64_t /*renderTimeMs*/) OVERRIDE;
    132 
    133 // Register a decode complete callback object.
    134 //
    135 // Input:
    136 //          - callback         : Callback object which handles decoded images.
    137 //
    138 // Return value                : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise.
    139   virtual int RegisterDecodeCompleteCallback(
    140       DecodedImageCallback* callback) OVERRIDE;
    141 
    142 // Free decoder memory.
    143 //
    144 // Return value                : WEBRTC_VIDEO_CODEC_OK if OK.
    145 //                                  <0 - Error
    146   virtual int Release() OVERRIDE;
    147 
    148 // Reset decoder state and prepare for a new call.
    149 //
    150 // Return value         :  WEBRTC_VIDEO_CODEC_OK.
    151 //                          <0 - Error
    152   virtual int Reset() OVERRIDE;
    153 
    154  private:
    155   static const uint8_t* ExtractHeader(const uint8_t* buffer,
    156                                       uint16_t* width,
    157                                       uint16_t* height);
    158 
    159   I420VideoFrame              _decodedImage;
    160   int                         _width;
    161   int                         _height;
    162   bool                        _inited;
    163   DecodedImageCallback*       _decodeCompleteCallback;
    164 };  // class I420Decoder
    165 
    166 }  // namespace webrtc
    167 
    168 #endif  // WEBRTC_MODULES_VIDEO_CODING_CODECS_I420_MAIN_INTERFACE_I420_H_
    169