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 | |
Henrik Kjellander | 2557b86 | 2015-11-18 22:00:21 +0100 | [diff] [blame^] | 14 | #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 15 | #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
| 17 | #include <stdio.h> |
| 18 | |
tommi@webrtc.org | 558dc40 | 2015-03-07 20:55:56 +0000 | [diff] [blame] | 19 | #include "webrtc/base/criticalsection.h" |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 20 | #include "webrtc/base/scoped_ptr.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 | /***********************************/ |
| 39 | class VCMEncodedFrameCallback : public EncodedImageCallback |
| 40 | { |
| 41 | public: |
andresp@webrtc.org | 1df9dc3 | 2014-01-09 08:01:57 +0000 | [diff] [blame] | 42 | VCMEncodedFrameCallback(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 | */ |
henrik.lundin@webrtc.org | bec11ef | 2013-09-23 19:54:25 +0000 | [diff] [blame] | 59 | void SetMediaOpt (media_optimization::MediaOptimization* mediaOpt); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 61 | void SetPayloadType(uint8_t payloadType) { _payloadType = payloadType; }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | void SetInternalSource(bool internalSource) { _internalSource = internalSource; }; |
| 63 | |
guoweis@webrtc.org | 54d072e | 2015-03-17 21:54:50 +0000 | [diff] [blame] | 64 | void SetRotation(VideoRotation rotation) { _rotation = rotation; } |
| 65 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | private: |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | VCMPacketizationCallback* _sendCallback; |
henrik.lundin@webrtc.org | bec11ef | 2013-09-23 19:54:25 +0000 | [diff] [blame] | 68 | media_optimization::MediaOptimization* _mediaOpt; |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 69 | uint8_t _payloadType; |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 70 | bool _internalSource; |
guoweis@webrtc.org | 54d072e | 2015-03-17 21:54:50 +0000 | [diff] [blame] | 71 | VideoRotation _rotation; |
sprang@webrtc.org | 4070935 | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 72 | |
sprang@webrtc.org | 4070935 | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 73 | EncodedImageCallback* post_encode_callback_; |
| 74 | |
tommi@webrtc.org | a9da4c5 | 2012-07-20 11:17:23 +0000 | [diff] [blame] | 75 | #ifdef DEBUG_ENCODER_BIT_STREAM |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 76 | FILE* _bitStreamAfterEncoder; |
tommi@webrtc.org | a9da4c5 | 2012-07-20 11:17:23 +0000 | [diff] [blame] | 77 | #endif |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | };// end of VCMEncodeFrameCallback class |
| 79 | |
| 80 | |
| 81 | /******************************/ |
| 82 | /* VCMGenericEncoder class */ |
| 83 | /******************************/ |
| 84 | class VCMGenericEncoder |
| 85 | { |
| 86 | friend class VCMCodecDataBase; |
| 87 | public: |
tommi@webrtc.org | 558dc40 | 2015-03-07 20:55:56 +0000 | [diff] [blame] | 88 | VCMGenericEncoder(VideoEncoder* encoder, |
| 89 | VideoEncoderRateObserver* rate_observer, |
Peter Boström | 4f5db11 | 2015-10-29 16:53:59 +0100 | [diff] [blame] | 90 | VCMEncodedFrameCallback* encoded_frame_callback, |
tommi@webrtc.org | 558dc40 | 2015-03-07 20:55:56 +0000 | [diff] [blame] | 91 | bool internalSource); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 92 | ~VCMGenericEncoder(); |
| 93 | /** |
pbos@webrtc.org | b9bb3d1 | 2013-05-16 18:40:48 +0000 | [diff] [blame] | 94 | * Free encoder memory |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | */ |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 96 | int32_t Release(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 97 | /** |
pbos@webrtc.org | b9bb3d1 | 2013-05-16 18:40:48 +0000 | [diff] [blame] | 98 | * Initialize the encoder with the information from the VideoCodec |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 99 | */ |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 100 | int32_t InitEncode(const VideoCodec* settings, |
pbos@webrtc.org | b9bb3d1 | 2013-05-16 18:40:48 +0000 | [diff] [blame] | 101 | int32_t numberOfCores, |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 102 | size_t maxPayloadSize); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 103 | /** |
pbos@webrtc.org | b9bb3d1 | 2013-05-16 18:40:48 +0000 | [diff] [blame] | 104 | * Encode raw image |
| 105 | * inputFrame : Frame containing raw image |
| 106 | * codecSpecificInfo : Specific codec data |
| 107 | * cameraFrameRate : Request or information from the remote side |
| 108 | * frameType : The requested frame type to encode |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | */ |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 110 | int32_t Encode(const VideoFrame& inputFrame, |
pbos@webrtc.org | b9bb3d1 | 2013-05-16 18:40:48 +0000 | [diff] [blame] | 111 | const CodecSpecificInfo* codecSpecificInfo, |
| 112 | const std::vector<FrameType>& frameTypes); |
Peter Boström | 69ccb33 | 2015-10-29 16:30:23 +0100 | [diff] [blame] | 113 | |
| 114 | void SetEncoderParameters(const EncoderParameters& params); |
Peter Boström | 69ccb33 | 2015-10-29 16:30:23 +0100 | [diff] [blame] | 115 | EncoderParameters GetEncoderParameters() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 117 | int32_t SetPeriodicKeyFrames(bool enable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 118 | |
pbos@webrtc.org | 7b859cc | 2013-04-02 15:54:38 +0000 | [diff] [blame] | 119 | int32_t RequestFrame(const std::vector<FrameType>& frame_types); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 120 | |
| 121 | bool InternalSource() const; |
| 122 | |
jackychen | 61b4d51 | 2015-04-21 15:30:11 -0700 | [diff] [blame] | 123 | void OnDroppedFrame(); |
| 124 | |
Peter Boström | eb66e80 | 2015-06-05 11:08:03 +0200 | [diff] [blame] | 125 | bool SupportsNativeHandle() const; |
| 126 | |
jackychen | 6e2ce6e | 2015-07-13 16:26:33 -0700 | [diff] [blame] | 127 | int GetTargetFramerate(); |
| 128 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | private: |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 130 | VideoEncoder* const encoder_; |
| 131 | VideoEncoderRateObserver* const rate_observer_; |
Peter Boström | 4f5db11 | 2015-10-29 16:53:59 +0100 | [diff] [blame] | 132 | VCMEncodedFrameCallback* const vcm_encoded_frame_callback_; |
tommi@webrtc.org | 558dc40 | 2015-03-07 20:55:56 +0000 | [diff] [blame] | 133 | const bool internal_source_; |
Peter Boström | 69ccb33 | 2015-10-29 16:30:23 +0100 | [diff] [blame] | 134 | mutable rtc::CriticalSection params_lock_; |
Peter Boström | 4f5db11 | 2015-10-29 16:53:59 +0100 | [diff] [blame] | 135 | EncoderParameters encoder_params_ GUARDED_BY(params_lock_); |
guoweis@webrtc.org | 54d072e | 2015-03-17 21:54:50 +0000 | [diff] [blame] | 136 | VideoRotation rotation_; |
Erik Språng | 2c4c914 | 2015-06-24 11:24:44 +0200 | [diff] [blame] | 137 | bool is_screenshare_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 138 | }; // end of VCMGenericEncoder class |
| 139 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 140 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 141 | |
| 142 | #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ |