niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | fdf21c8 | 2012-02-02 12:46:58 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_VIDEO_CODING_CODECS_I420_INCLUDE_I420_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_CODECS_I420_INCLUDE_I420_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
pbos@webrtc.org | 8911ce4 | 2013-03-18 16:39:03 +0000 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 16 | #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 17 | #include "webrtc/rtc_base/checks.h" |
pbos@webrtc.org | 8911ce4 | 2013-03-18 16:39:03 +0000 | [diff] [blame] | 18 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
mikhal@webrtc.org | b95e9ca | 2012-07-10 20:58:08 +0000 | [diff] [blame] | 20 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | |
mikhal@webrtc.org | b95e9ca | 2012-07-10 20:58:08 +0000 | [diff] [blame] | 22 | class I420Encoder : public VideoEncoder { |
pbos@webrtc.org | 8911ce4 | 2013-03-18 16:39:03 +0000 | [diff] [blame] | 23 | public: |
mikhal@webrtc.org | b95e9ca | 2012-07-10 20:58:08 +0000 | [diff] [blame] | 24 | I420Encoder(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
mikhal@webrtc.org | b95e9ca | 2012-07-10 20:58:08 +0000 | [diff] [blame] | 26 | virtual ~I420Encoder(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 28 | // Initialize the encoder with the information from the VideoCodec. |
| 29 | // |
| 30 | // Input: |
| 31 | // - codecSettings : Codec settings. |
| 32 | // - numberOfCores : Number of cores available for the encoder. |
| 33 | // - maxPayloadSize : The maximum size each payload is allowed |
| 34 | // to have. Usually MTU - overhead. |
| 35 | // |
| 36 | // Return value : WEBRTC_VIDEO_CODEC_OK if OK. |
| 37 | // <0 - Error |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 38 | int InitEncode(const VideoCodec* codecSettings, |
| 39 | int /*numberOfCores*/, |
| 40 | size_t /*maxPayloadSize*/) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 41 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 42 | // "Encode" an I420 image (as a part of a video stream). The encoded image |
| 43 | // will be returned to the user via the encode complete callback. |
| 44 | // |
| 45 | // Input: |
| 46 | // - inputImage : Image to be encoded. |
| 47 | // - codecSpecificInfo : Pointer to codec specific data. |
| 48 | // - frameType : Frame type to be sent (Key /Delta). |
| 49 | // |
| 50 | // Return value : WEBRTC_VIDEO_CODEC_OK if OK. |
| 51 | // <0 - Error |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 52 | int Encode(const VideoFrame& inputImage, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 53 | const CodecSpecificInfo* /*codecSpecificInfo*/, |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 54 | const std::vector<FrameType>* /*frame_types*/) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 56 | // Register an encode complete callback object. |
| 57 | // |
| 58 | // Input: |
| 59 | // - callback : Callback object which handles encoded images. |
| 60 | // |
| 61 | // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 62 | int RegisterEncodeCompleteCallback(EncodedImageCallback* callback) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 64 | // Free encoder memory. |
| 65 | // |
| 66 | // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 67 | int Release() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 69 | int SetChannelParameters(uint32_t /*packetLoss*/, int64_t /*rtt*/) override { |
pbos@webrtc.org | 8911ce4 | 2013-03-18 16:39:03 +0000 | [diff] [blame] | 70 | return WEBRTC_VIDEO_CODEC_OK; |
| 71 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 72 | |
pbos@webrtc.org | 8911ce4 | 2013-03-18 16:39:03 +0000 | [diff] [blame] | 73 | private: |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 74 | static uint8_t* InsertHeader(uint8_t* buffer, |
| 75 | uint16_t width, |
pbos@webrtc.org | 8911ce4 | 2013-03-18 16:39:03 +0000 | [diff] [blame] | 76 | uint16_t height); |
| 77 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 78 | bool _inited; |
| 79 | EncodedImage _encodedImage; |
| 80 | EncodedImageCallback* _encodedCompleteCallback; |
pbos@webrtc.org | 8911ce4 | 2013-03-18 16:39:03 +0000 | [diff] [blame] | 81 | }; // class I420Encoder |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
mikhal@webrtc.org | b95e9ca | 2012-07-10 20:58:08 +0000 | [diff] [blame] | 83 | class I420Decoder : public VideoDecoder { |
pbos@webrtc.org | 8911ce4 | 2013-03-18 16:39:03 +0000 | [diff] [blame] | 84 | public: |
mikhal@webrtc.org | b95e9ca | 2012-07-10 20:58:08 +0000 | [diff] [blame] | 85 | I420Decoder(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
mikhal@webrtc.org | b95e9ca | 2012-07-10 20:58:08 +0000 | [diff] [blame] | 87 | virtual ~I420Decoder(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 88 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 89 | // Initialize the decoder. |
| 90 | // The user must notify the codec of width and height values. |
| 91 | // |
| 92 | // Return value : WEBRTC_VIDEO_CODEC_OK. |
| 93 | // <0 - Errors |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 94 | int InitDecode(const VideoCodec* codecSettings, |
| 95 | int /*numberOfCores*/) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 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 | // - codecSpecificInfo : pointer to specific codec data |
| 105 | // - renderTimeMs : Render time in Ms |
| 106 | // |
| 107 | // Return value : WEBRTC_VIDEO_CODEC_OK if OK |
| 108 | // <0 - Error |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 109 | int Decode(const EncodedImage& inputImage, |
| 110 | bool missingFrames, |
| 111 | const RTPFragmentationHeader* /*fragmentation*/, |
| 112 | const CodecSpecificInfo* /*codecSpecificInfo*/, |
| 113 | int64_t /*renderTimeMs*/) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 115 | // Register a decode complete callback object. |
| 116 | // |
| 117 | // Input: |
| 118 | // - callback : Callback object which handles decoded images. |
| 119 | // |
| 120 | // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 121 | int RegisterDecodeCompleteCallback(DecodedImageCallback* callback) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 123 | // Free decoder memory. |
| 124 | // |
| 125 | // Return value : WEBRTC_VIDEO_CODEC_OK if OK. |
| 126 | // <0 - Error |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 127 | int Release() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | |
pbos@webrtc.org | 8911ce4 | 2013-03-18 16:39:03 +0000 | [diff] [blame] | 129 | private: |
pbos@webrtc.org | 7f7162a | 2013-07-30 15:18:31 +0000 | [diff] [blame] | 130 | static const uint8_t* ExtractHeader(const uint8_t* buffer, |
| 131 | uint16_t* width, |
| 132 | uint16_t* height); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 133 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 134 | int _width; |
| 135 | int _height; |
| 136 | bool _inited; |
| 137 | DecodedImageCallback* _decodeCompleteCallback; |
pbos@webrtc.org | 8911ce4 | 2013-03-18 16:39:03 +0000 | [diff] [blame] | 138 | }; // class I420Decoder |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 139 | |
pbos@webrtc.org | 8911ce4 | 2013-03-18 16:39:03 +0000 | [diff] [blame] | 140 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 141 | |
philipel | cce46fc | 2015-12-21 03:04:49 -0800 | [diff] [blame] | 142 | #endif // WEBRTC_MODULES_VIDEO_CODING_CODECS_I420_INCLUDE_I420_H_ |