magjed | 614d5b7 | 2016-11-15 06:30:54 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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_MEDIA_ENGINE_VIDEOENCODERSOFTWAREFALLBACKWRAPPER_H_ |
| 12 | #define WEBRTC_MEDIA_ENGINE_VIDEOENCODERSOFTWAREFALLBACKWRAPPER_H_ |
| 13 | |
| 14 | #include <memory> |
| 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
ilnik | d60d06a | 2017-04-05 03:02:20 -0700 | [diff] [blame^] | 18 | #include "webrtc/api/video_codecs/video_encoder.h" |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 19 | #include "webrtc/media/base/codec.h" |
magjed | 614d5b7 | 2016-11-15 06:30:54 -0800 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
| 23 | // Class used to wrap external VideoEncoders to provide a fallback option on |
| 24 | // software encoding when a hardware encoder fails to encode a stream due to |
| 25 | // hardware restrictions, such as max resolution. |
| 26 | class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder { |
| 27 | public: |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 28 | VideoEncoderSoftwareFallbackWrapper(const cricket::VideoCodec& codec, |
magjed | 614d5b7 | 2016-11-15 06:30:54 -0800 | [diff] [blame] | 29 | webrtc::VideoEncoder* encoder); |
| 30 | |
| 31 | int32_t InitEncode(const VideoCodec* codec_settings, |
| 32 | int32_t number_of_cores, |
| 33 | size_t max_payload_size) override; |
| 34 | |
| 35 | int32_t RegisterEncodeCompleteCallback( |
| 36 | EncodedImageCallback* callback) override; |
| 37 | |
| 38 | int32_t Release() override; |
| 39 | int32_t Encode(const VideoFrame& frame, |
| 40 | const CodecSpecificInfo* codec_specific_info, |
| 41 | const std::vector<FrameType>* frame_types) override; |
| 42 | int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 43 | int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, |
| 44 | uint32_t framerate) override; |
magjed | 614d5b7 | 2016-11-15 06:30:54 -0800 | [diff] [blame] | 45 | bool SupportsNativeHandle() const override; |
kthelgason | 876222f | 2016-11-29 01:44:11 -0800 | [diff] [blame] | 46 | ScalingSettings GetScalingSettings() const override; |
kthelgason | 535dbd3 | 2017-01-26 00:36:31 -0800 | [diff] [blame] | 47 | const char *ImplementationName() const override; |
magjed | 614d5b7 | 2016-11-15 06:30:54 -0800 | [diff] [blame] | 48 | |
| 49 | private: |
| 50 | bool InitFallbackEncoder(); |
| 51 | |
| 52 | // Settings used in the last InitEncode call and used if a dynamic fallback to |
| 53 | // software is required. |
| 54 | VideoCodec codec_settings_; |
| 55 | int32_t number_of_cores_; |
| 56 | size_t max_payload_size_; |
| 57 | |
| 58 | // The last bitrate/framerate set, and a flag for noting they are set. |
| 59 | bool rates_set_; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 60 | BitrateAllocation bitrate_allocation_; |
magjed | 614d5b7 | 2016-11-15 06:30:54 -0800 | [diff] [blame] | 61 | uint32_t framerate_; |
| 62 | |
| 63 | // The last channel parameters set, and a flag for noting they are set. |
| 64 | bool channel_parameters_set_; |
| 65 | uint32_t packet_loss_; |
| 66 | int64_t rtt_; |
| 67 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 68 | const cricket::VideoCodec codec_; |
magjed | 614d5b7 | 2016-11-15 06:30:54 -0800 | [diff] [blame] | 69 | webrtc::VideoEncoder* const encoder_; |
| 70 | |
| 71 | std::unique_ptr<webrtc::VideoEncoder> fallback_encoder_; |
| 72 | std::string fallback_implementation_name_; |
| 73 | EncodedImageCallback* callback_; |
| 74 | }; |
| 75 | |
| 76 | } // namespace webrtc |
| 77 | |
| 78 | #endif // WEBRTC_MEDIA_ENGINE_VIDEOENCODERSOFTWAREFALLBACKWRAPPER_H_ |