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 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 36 | class VCMEncodedFrameCallback : public EncodedImageCallback { |
| 37 | public: |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 38 | explicit VCMEncodedFrameCallback(EncodedImageCallback* post_encode_callback); |
| 39 | virtual ~VCMEncodedFrameCallback(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 41 | // Implements EncodedImageCallback. |
| 42 | int32_t Encoded(const EncodedImage& encoded_image, |
| 43 | const CodecSpecificInfo* codec_specific, |
| 44 | const RTPFragmentationHeader* fragmentation_header) override; |
| 45 | int32_t SetTransportCallback(VCMPacketizationCallback* transport); |
| 46 | void SetMediaOpt(media_optimization::MediaOptimization* media_opt); |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 47 | void SetInternalSource(bool internal_source) { |
| 48 | internal_source_ = internal_source; |
| 49 | } |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 50 | void SignalLastEncoderImplementationUsed( |
| 51 | const char* encoder_implementation_name); |
guoweis@webrtc.org | 54d072e | 2015-03-17 21:54:50 +0000 | [diff] [blame] | 52 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 53 | private: |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 54 | VCMPacketizationCallback* send_callback_; |
| 55 | media_optimization::MediaOptimization* media_opt_; |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 56 | bool internal_source_; |
sprang@webrtc.org | 4070935 | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 57 | |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 58 | EncodedImageCallback* post_encode_callback_; |
| 59 | }; |
sprang@webrtc.org | 4070935 | 2013-11-26 11:41:59 +0000 | [diff] [blame] | 60 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 61 | class VCMGenericEncoder { |
| 62 | friend class VCMCodecDataBase; |
Peter Boström | 69ccb33 | 2015-10-29 16:30:23 +0100 | [diff] [blame] | 63 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 64 | public: |
| 65 | VCMGenericEncoder(VideoEncoder* encoder, |
| 66 | VideoEncoderRateObserver* rate_observer, |
| 67 | VCMEncodedFrameCallback* encoded_frame_callback, |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 68 | bool internal_source); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 69 | ~VCMGenericEncoder(); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 70 | int32_t Release(); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 71 | int32_t InitEncode(const VideoCodec* settings, |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 72 | int32_t number_of_cores, |
| 73 | size_t max_payload_size); |
| 74 | int32_t Encode(const VideoFrame& frame, |
| 75 | const CodecSpecificInfo* codec_specific, |
| 76 | const std::vector<FrameType>& frame_types); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 78 | void SetEncoderParameters(const EncoderParameters& params); |
| 79 | EncoderParameters GetEncoderParameters() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 81 | int32_t SetPeriodicKeyFrames(bool enable); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 82 | int32_t RequestFrame(const std::vector<FrameType>& frame_types); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 83 | bool InternalSource() const; |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 84 | void OnDroppedFrame(); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 85 | bool SupportsNativeHandle() const; |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 86 | |
| 87 | private: |
| 88 | VideoEncoder* const encoder_; |
| 89 | VideoEncoderRateObserver* const rate_observer_; |
| 90 | VCMEncodedFrameCallback* const vcm_encoded_frame_callback_; |
| 91 | const bool internal_source_; |
pbos | 5ad935c | 2016-01-25 03:52:44 -0800 | [diff] [blame] | 92 | rtc::CriticalSection params_lock_; |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 93 | EncoderParameters encoder_params_ GUARDED_BY(params_lock_); |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 94 | bool is_screenshare_; |
sprang | 3911c26 | 2016-04-15 01:24:14 -0700 | [diff] [blame] | 95 | }; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 97 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 99 | #endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_ |