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