niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
pwestin@webrtc.org | 52fd98d | 2012-02-13 09:03:53 +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 | |
| 11 | #ifndef WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ |
| 12 | #define WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ |
| 13 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 14 | #include <stdio.h> |
| 15 | #include <vector> |
| 16 | |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame] | 17 | #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 18 | #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
tommi@webrtc.org | 558dc40 | 2015-03-07 20:55:56 +0000 | [diff] [blame] | 20 | #include "webrtc/base/criticalsection.h" |
sprang@webrtc.org | 4070935 | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 21 | |
andresp@webrtc.org | 1df9dc3 | 2014-01-09 08:01:57 +0000 | [diff] [blame] | 22 | namespace webrtc { |
sprang@webrtc.org | 4070935 | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 23 | class CriticalSectionWrapper; |
| 24 | |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 25 | namespace media_optimization { |
henrik.lundin@webrtc.org | bec11ef | 2013-09-23 19:54:25 +0000 | [diff] [blame] | 26 | class MediaOptimization; |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 27 | } // namespace media_optimization |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | |
Peter Boström | 69ccb33 | 2015-10-29 16:30:23 +0100 | [diff] [blame] | 29 | struct EncoderParameters { |
| 30 | uint32_t target_bitrate; |
| 31 | uint8_t loss_rate; |
| 32 | int64_t rtt; |
| 33 | uint32_t input_frame_rate; |
| 34 | }; |
| 35 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | /*************************************/ |
| 37 | /* VCMEncodeFrameCallback class */ |
| 38 | /***********************************/ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 39 | class VCMEncodedFrameCallback : public EncodedImageCallback { |
| 40 | public: |
| 41 | explicit VCMEncodedFrameCallback( |
| 42 | EncodedImageCallback* post_encode_callback); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | virtual ~VCMEncodedFrameCallback(); |
| 44 | |
| 45 | /* |
| 46 | * Callback implementation - codec encode complete |
| 47 | */ |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 48 | int32_t Encoded( |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 49 | const EncodedImage& encodedImage, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | const CodecSpecificInfo* codecSpecificInfo = NULL, |
| 51 | const RTPFragmentationHeader* fragmentationHeader = NULL); |
| 52 | /* |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | * Callback implementation - generic encoder encode complete |
| 54 | */ |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 55 | int32_t SetTransportCallback(VCMPacketizationCallback* transport); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | /** |
| 57 | * Set media Optimization |
| 58 | */ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 59 | void SetMediaOpt(media_optimization::MediaOptimization* mediaOpt); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 61 | void SetPayloadType(uint8_t payloadType) { |
| 62 | _payloadType = payloadType; |
| 63 | } |
| 64 | |
| 65 | void SetInternalSource(bool internalSource) { |
| 66 | _internalSource = internalSource; |
| 67 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 68 | |
guoweis@webrtc.org | 54d072e | 2015-03-17 21:54:50 +0000 | [diff] [blame] | 69 | void SetRotation(VideoRotation rotation) { _rotation = rotation; } |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 70 | void SignalLastEncoderImplementationUsed( |
| 71 | const char* encoder_implementation_name); |
guoweis@webrtc.org | 54d072e | 2015-03-17 21:54:50 +0000 | [diff] [blame] | 72 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 73 | private: |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 74 | VCMPacketizationCallback* send_callback_; |
henrik.lundin@webrtc.org | bec11ef | 2013-09-23 19:54:25 +0000 | [diff] [blame] | 75 | media_optimization::MediaOptimization* _mediaOpt; |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 76 | uint8_t _payloadType; |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 77 | bool _internalSource; |
guoweis@webrtc.org | 54d072e | 2015-03-17 21:54:50 +0000 | [diff] [blame] | 78 | VideoRotation _rotation; |
sprang@webrtc.org | 4070935 | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 79 | |
sprang@webrtc.org | 4070935 | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 80 | EncodedImageCallback* post_encode_callback_; |
| 81 | |
tommi@webrtc.org | a9da4c5 | 2012-07-20 11:17:23 +0000 | [diff] [blame] | 82 | #ifdef DEBUG_ENCODER_BIT_STREAM |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 83 | FILE* _bitStreamAfterEncoder; |
tommi@webrtc.org | a9da4c5 | 2012-07-20 11:17:23 +0000 | [diff] [blame] | 84 | #endif |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 85 | }; // end of VCMEncodeFrameCallback class |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
| 87 | /******************************/ |
| 88 | /* VCMGenericEncoder class */ |
| 89 | /******************************/ |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 90 | class VCMGenericEncoder { |
| 91 | friend class VCMCodecDataBase; |
Peter Boström | 69ccb33 | 2015-10-29 16:30:23 +0100 | [diff] [blame] | 92 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 93 | public: |
| 94 | VCMGenericEncoder(VideoEncoder* encoder, |
| 95 | VideoEncoderRateObserver* rate_observer, |
| 96 | VCMEncodedFrameCallback* encoded_frame_callback, |
| 97 | bool internalSource); |
| 98 | ~VCMGenericEncoder(); |
| 99 | /** |
| 100 | * Free encoder memory |
| 101 | */ |
| 102 | int32_t Release(); |
| 103 | /** |
| 104 | * Initialize the encoder with the information from the VideoCodec |
| 105 | */ |
| 106 | int32_t InitEncode(const VideoCodec* settings, |
| 107 | int32_t numberOfCores, |
| 108 | size_t maxPayloadSize); |
| 109 | /** |
| 110 | * Encode raw image |
| 111 | * inputFrame : Frame containing raw image |
| 112 | * codecSpecificInfo : Specific codec data |
| 113 | * cameraFrameRate : Request or information from the remote side |
| 114 | * frameType : The requested frame type to encode |
| 115 | */ |
| 116 | int32_t Encode(const VideoFrame& inputFrame, |
| 117 | const CodecSpecificInfo* codecSpecificInfo, |
| 118 | const std::vector<FrameType>& frameTypes); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 120 | void SetEncoderParameters(const EncoderParameters& params); |
| 121 | EncoderParameters GetEncoderParameters() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 123 | int32_t SetPeriodicKeyFrames(bool enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 124 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 125 | int32_t RequestFrame(const std::vector<FrameType>& frame_types); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 126 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 127 | bool InternalSource() const; |
jackychen | 61b4d51 | 2015-04-21 15:30:11 -0700 | [diff] [blame] | 128 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 129 | void OnDroppedFrame(); |
Peter Boström | eb66e80 | 2015-06-05 11:08:03 +0200 | [diff] [blame] | 130 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 131 | bool SupportsNativeHandle() const; |
jackychen | 6e2ce6e | 2015-07-13 16:26:33 -0700 | [diff] [blame] | 132 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 133 | int GetTargetFramerate(); |
| 134 | |
| 135 | private: |
| 136 | VideoEncoder* const encoder_; |
| 137 | VideoEncoderRateObserver* const rate_observer_; |
| 138 | VCMEncodedFrameCallback* const vcm_encoded_frame_callback_; |
| 139 | const bool internal_source_; |
pbos | 5ad935c | 2016-01-25 03:52:44 -0800 | [diff] [blame] | 140 | rtc::CriticalSection params_lock_; |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 141 | EncoderParameters encoder_params_ GUARDED_BY(params_lock_); |
| 142 | VideoRotation rotation_; |
| 143 | bool is_screenshare_; |
| 144 | }; // end of VCMGenericEncoder class |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 145 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 146 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 147 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 148 | #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ |