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