blob: c717668d5839ec24de5941e40d36f27d46add32d [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:
27 VideoEncoderSoftwareFallbackWrapper(VideoCodecType codec_type,
28 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;
42
43 int32_t SetRates(uint32_t bitrate, uint32_t framerate) override;
44 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_;
58 uint32_t bitrate_;
59 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
66 const EncoderType encoder_type_;
67 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_