pbos@webrtc.org | 1c65545 | 2014-09-17 09:02:25 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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_VIDEO_ENCODER_H_ |
| 12 | #define WEBRTC_VIDEO_ENCODER_H_ |
| 13 | |
| 14 | #include <vector> |
| 15 | |
pbos@webrtc.org | 6b97015 | 2014-09-18 12:42:28 | [diff] [blame] | 16 | #include "webrtc/common_types.h" |
pbos@webrtc.org | 1c65545 | 2014-09-17 09:02:25 | [diff] [blame] | 17 | #include "webrtc/typedefs.h" |
| 18 | #include "webrtc/video_frame.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | class RTPFragmentationHeader; |
| 23 | // TODO(pbos): Expose these through a public (root) header or change these APIs. |
| 24 | struct CodecSpecificInfo; |
| 25 | struct VideoCodec; |
| 26 | |
| 27 | class EncodedImageCallback { |
| 28 | public: |
| 29 | virtual ~EncodedImageCallback() {} |
| 30 | |
| 31 | // Callback function which is called when an image has been encoded. |
changbin.shao@webrtc.org | 972ccb8 | 2015-02-09 09:14:03 | [diff] [blame] | 32 | virtual int32_t Encoded(const EncodedImage& encoded_image, |
| 33 | const CodecSpecificInfo* codec_specific_info, |
| 34 | const RTPFragmentationHeader* fragmentation) = 0; |
pbos@webrtc.org | 1c65545 | 2014-09-17 09:02:25 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | class VideoEncoder { |
| 38 | public: |
| 39 | enum EncoderType { |
| 40 | kVp8, |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 41 | kVp9, |
pbos@webrtc.org | 1c65545 | 2014-09-17 09:02:25 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | static VideoEncoder* Create(EncoderType codec_type); |
| 45 | |
pbos@webrtc.org | 6b97015 | 2014-09-18 12:42:28 | [diff] [blame] | 46 | static VideoCodecVP8 GetDefaultVp8Settings(); |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 47 | static VideoCodecVP9 GetDefaultVp9Settings(); |
pbos@webrtc.org | 6b97015 | 2014-09-18 12:42:28 | [diff] [blame] | 48 | static VideoCodecH264 GetDefaultH264Settings(); |
| 49 | |
pbos@webrtc.org | 1c65545 | 2014-09-17 09:02:25 | [diff] [blame] | 50 | virtual ~VideoEncoder() {} |
| 51 | |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 52 | // Initialize the encoder with the information from the codecSettings |
| 53 | // |
| 54 | // Input: |
| 55 | // - codec_settings : Codec settings |
| 56 | // - number_of_cores : Number of cores available for the encoder |
| 57 | // - max_payload_size : The maximum size each payload is allowed |
| 58 | // to have. Usually MTU - overhead. |
| 59 | // |
| 60 | // Return value : Set bit rate if OK |
| 61 | // <0 - Errors: |
| 62 | // WEBRTC_VIDEO_CODEC_ERR_PARAMETER |
| 63 | // WEBRTC_VIDEO_CODEC_ERR_SIZE |
| 64 | // WEBRTC_VIDEO_CODEC_LEVEL_EXCEEDED |
| 65 | // WEBRTC_VIDEO_CODEC_MEMORY |
| 66 | // WEBRTC_VIDEO_CODEC_ERROR |
pbos@webrtc.org | 1c65545 | 2014-09-17 09:02:25 | [diff] [blame] | 67 | virtual int32_t InitEncode(const VideoCodec* codec_settings, |
| 68 | int32_t number_of_cores, |
pkasting@chromium.org | 0ab923a | 2014-11-20 22:28:14 | [diff] [blame] | 69 | size_t max_payload_size) = 0; |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 70 | |
| 71 | // Register an encode complete callback object. |
| 72 | // |
| 73 | // Input: |
| 74 | // - callback : Callback object which handles encoded images. |
| 75 | // |
| 76 | // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. |
pbos@webrtc.org | 1c65545 | 2014-09-17 09:02:25 | [diff] [blame] | 77 | virtual int32_t RegisterEncodeCompleteCallback( |
| 78 | EncodedImageCallback* callback) = 0; |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 79 | |
| 80 | // Free encoder memory. |
| 81 | // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. |
pbos@webrtc.org | 1c65545 | 2014-09-17 09:02:25 | [diff] [blame] | 82 | virtual int32_t Release() = 0; |
| 83 | |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 84 | // Encode an I420 image (as a part of a video stream). The encoded image |
| 85 | // will be returned to the user through the encode complete callback. |
| 86 | // |
| 87 | // Input: |
| 88 | // - frame : Image to be encoded |
| 89 | // - frame_types : Frame type to be generated by the encoder. |
| 90 | // |
| 91 | // Return value : WEBRTC_VIDEO_CODEC_OK if OK |
| 92 | // <0 - Errors: |
| 93 | // WEBRTC_VIDEO_CODEC_ERR_PARAMETER |
| 94 | // WEBRTC_VIDEO_CODEC_MEMORY |
| 95 | // WEBRTC_VIDEO_CODEC_ERROR |
| 96 | // WEBRTC_VIDEO_CODEC_TIMEOUT |
pbos@webrtc.org | 1c65545 | 2014-09-17 09:02:25 | [diff] [blame] | 97 | virtual int32_t Encode(const I420VideoFrame& frame, |
| 98 | const CodecSpecificInfo* codec_specific_info, |
| 99 | const std::vector<VideoFrameType>* frame_types) = 0; |
| 100 | |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 101 | // Inform the encoder of the new packet loss rate and the round-trip time of |
| 102 | // the network. |
| 103 | // |
| 104 | // Input: |
| 105 | // - packet_loss : Fraction lost |
| 106 | // (loss rate in percent = 100 * packetLoss / 255) |
| 107 | // - rtt : Round-trip time in milliseconds |
| 108 | // Return value : WEBRTC_VIDEO_CODEC_OK if OK |
| 109 | // <0 - Errors: WEBRTC_VIDEO_CODEC_ERROR |
pkasting@chromium.org | a3166c4 | 2015-01-12 21:51:21 | [diff] [blame] | 110 | virtual int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) = 0; |
marpan@webrtc.org | 6637388 | 2014-11-01 06:10:48 | [diff] [blame] | 111 | |
| 112 | // Inform the encoder about the new target bit rate. |
| 113 | // |
| 114 | // Input: |
| 115 | // - bitrate : New target bit rate |
| 116 | // - framerate : The target frame rate |
| 117 | // |
| 118 | // Return value : WEBRTC_VIDEO_CODEC_OK if OK, < 0 otherwise. |
pbos@webrtc.org | 1c65545 | 2014-09-17 09:02:25 | [diff] [blame] | 119 | virtual int32_t SetRates(uint32_t bitrate, uint32_t framerate) = 0; |
| 120 | |
| 121 | virtual int32_t SetPeriodicKeyFrames(bool enable) { return -1; } |
| 122 | virtual int32_t CodecConfigParameters(uint8_t* /*buffer*/, int32_t /*size*/) { |
| 123 | return -1; |
| 124 | } |
| 125 | }; |
| 126 | |
| 127 | } // namespace webrtc |
| 128 | #endif // WEBRTC_VIDEO_ENCODER_H_ |