blob: 5d81f4ac1e0322a6e8d55cbda7cfc27e2527007d [file] [log] [blame]
magjed614d5b72016-11-15 06:30:54 -08001/*
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
18#include "webrtc/video_encoder.h"
19
20namespace webrtc {
21
22// Class used to wrap external VideoEncoders to provide a fallback option on
23// software encoding when a hardware encoder fails to encode a stream due to
24// hardware restrictions, such as max resolution.
25class VideoEncoderSoftwareFallbackWrapper : public VideoEncoder {
26 public:
magjedeacbaea2016-11-17 08:51:59 -080027 VideoEncoderSoftwareFallbackWrapper(VideoCodecType codec_type,
magjed614d5b72016-11-15 06:30:54 -080028 webrtc::VideoEncoder* encoder);
29
30 int32_t InitEncode(const VideoCodec* codec_settings,
31 int32_t number_of_cores,
32 size_t max_payload_size) override;
33
34 int32_t RegisterEncodeCompleteCallback(
35 EncodedImageCallback* callback) override;
36
37 int32_t Release() override;
38 int32_t Encode(const VideoFrame& frame,
39 const CodecSpecificInfo* codec_specific_info,
40 const std::vector<FrameType>* frame_types) override;
41 int32_t SetChannelParameters(uint32_t packet_loss, int64_t rtt) override;
Erik Språng08127a92016-11-16 16:41:30 +010042 int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation,
43 uint32_t framerate) override;
magjed614d5b72016-11-15 06:30:54 -080044 void OnDroppedFrame() override;
45 bool SupportsNativeHandle() const override;
46
47 private:
48 bool InitFallbackEncoder();
49
50 // Settings used in the last InitEncode call and used if a dynamic fallback to
51 // software is required.
52 VideoCodec codec_settings_;
53 int32_t number_of_cores_;
54 size_t max_payload_size_;
55
56 // The last bitrate/framerate set, and a flag for noting they are set.
57 bool rates_set_;
Erik Språng08127a92016-11-16 16:41:30 +010058 BitrateAllocation bitrate_allocation_;
magjed614d5b72016-11-15 06:30:54 -080059 uint32_t framerate_;
60
61 // The last channel parameters set, and a flag for noting they are set.
62 bool channel_parameters_set_;
63 uint32_t packet_loss_;
64 int64_t rtt_;
65
magjedeacbaea2016-11-17 08:51:59 -080066 const EncoderType encoder_type_;
magjed614d5b72016-11-15 06:30:54 -080067 webrtc::VideoEncoder* const encoder_;
68
69 std::unique_ptr<webrtc::VideoEncoder> fallback_encoder_;
70 std::string fallback_implementation_name_;
71 EncodedImageCallback* callback_;
72};
73
74} // namespace webrtc
75
76#endif // WEBRTC_MEDIA_ENGINE_VIDEOENCODERSOFTWAREFALLBACKWRAPPER_H_