blob: d6fba488e72bb71106a81ccbd09f124393e9cabd [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.org52fd98d2012-02-13 09:03:53 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
philipel9d3ab612015-12-21 04:12:39 -080014#include <stdio.h>
15#include <vector>
16
Henrik Kjellander2557b862015-11-18 22:00:21 +010017#include "webrtc/modules/video_coding/include/video_codec_interface.h"
18#include "webrtc/modules/video_coding/include/video_coding_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000019
tommi@webrtc.org558dc402015-03-07 20:55:56 +000020#include "webrtc/base/criticalsection.h"
sprang@webrtc.org40709352013-11-26 11:41:59 +000021
andresp@webrtc.org1df9dc32014-01-09 08:01:57 +000022namespace webrtc {
sprang@webrtc.org40709352013-11-26 11:41:59 +000023class CriticalSectionWrapper;
24
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000025namespace media_optimization {
henrik.lundin@webrtc.orgbec11ef2013-09-23 19:54:25 +000026class MediaOptimization;
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000027} // namespace media_optimization
niklase@google.com470e71d2011-07-07 08:21:25 +000028
Peter Boström69ccb332015-10-29 16:30:23 +010029struct EncoderParameters {
30 uint32_t target_bitrate;
31 uint8_t loss_rate;
32 int64_t rtt;
33 uint32_t input_frame_rate;
34};
35
philipel9d3ab612015-12-21 04:12:39 -080036class VCMEncodedFrameCallback : public EncodedImageCallback {
37 public:
sprang3911c262016-04-15 01:24:14 -070038 explicit VCMEncodedFrameCallback(EncodedImageCallback* post_encode_callback);
39 virtual ~VCMEncodedFrameCallback();
niklase@google.com470e71d2011-07-07 08:21:25 +000040
sprang3911c262016-04-15 01:24:14 -070041 // 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);
47 void SetPayloadType(uint8_t payload_type) { payload_type_ = payload_type; }
48 void SetInternalSource(bool internal_source) {
49 internal_source_ = internal_source;
50 }
51 void SetRotation(VideoRotation rotation) { rotation_ = rotation; }
52 void SignalLastEncoderImplementationUsed(
53 const char* encoder_implementation_name);
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +000054
philipel9d3ab612015-12-21 04:12:39 -080055 private:
sprang3911c262016-04-15 01:24:14 -070056 VCMPacketizationCallback* send_callback_;
57 media_optimization::MediaOptimization* media_opt_;
58 uint8_t payload_type_;
59 bool internal_source_;
60 VideoRotation rotation_;
sprang@webrtc.org40709352013-11-26 11:41:59 +000061
sprang3911c262016-04-15 01:24:14 -070062 EncodedImageCallback* post_encode_callback_;
63};
sprang@webrtc.org40709352013-11-26 11:41:59 +000064
philipel9d3ab612015-12-21 04:12:39 -080065class VCMGenericEncoder {
66 friend class VCMCodecDataBase;
Peter Boström69ccb332015-10-29 16:30:23 +010067
philipel9d3ab612015-12-21 04:12:39 -080068 public:
69 VCMGenericEncoder(VideoEncoder* encoder,
70 VideoEncoderRateObserver* rate_observer,
71 VCMEncodedFrameCallback* encoded_frame_callback,
sprang3911c262016-04-15 01:24:14 -070072 bool internal_source);
philipel9d3ab612015-12-21 04:12:39 -080073 ~VCMGenericEncoder();
philipel9d3ab612015-12-21 04:12:39 -080074 int32_t Release();
philipel9d3ab612015-12-21 04:12:39 -080075 int32_t InitEncode(const VideoCodec* settings,
sprang3911c262016-04-15 01:24:14 -070076 int32_t number_of_cores,
77 size_t max_payload_size);
78 int32_t Encode(const VideoFrame& frame,
79 const CodecSpecificInfo* codec_specific,
80 const std::vector<FrameType>& frame_types);
niklase@google.com470e71d2011-07-07 08:21:25 +000081
philipel9d3ab612015-12-21 04:12:39 -080082 void SetEncoderParameters(const EncoderParameters& params);
83 EncoderParameters GetEncoderParameters() const;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
philipel9d3ab612015-12-21 04:12:39 -080085 int32_t SetPeriodicKeyFrames(bool enable);
philipel9d3ab612015-12-21 04:12:39 -080086 int32_t RequestFrame(const std::vector<FrameType>& frame_types);
philipel9d3ab612015-12-21 04:12:39 -080087 bool InternalSource() const;
philipel9d3ab612015-12-21 04:12:39 -080088 void OnDroppedFrame();
philipel9d3ab612015-12-21 04:12:39 -080089 bool SupportsNativeHandle() const;
philipel9d3ab612015-12-21 04:12:39 -080090 int GetTargetFramerate();
91
92 private:
93 VideoEncoder* const encoder_;
94 VideoEncoderRateObserver* const rate_observer_;
95 VCMEncodedFrameCallback* const vcm_encoded_frame_callback_;
96 const bool internal_source_;
pbos5ad935c2016-01-25 03:52:44 -080097 rtc::CriticalSection params_lock_;
philipel9d3ab612015-12-21 04:12:39 -080098 EncoderParameters encoder_params_ GUARDED_BY(params_lock_);
99 VideoRotation rotation_;
100 bool is_screenshare_;
sprang3911c262016-04-15 01:24:14 -0700101};
niklase@google.com470e71d2011-07-07 08:21:25 +0000102
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000103} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000104
philipel9d3ab612015-12-21 04:12:39 -0800105#endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_