blob: e96d99578150f7b531445e14cb35f46995070801 [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
niklase@google.com470e71d2011-07-07 08:21:25 +000036/*************************************/
37/* VCMEncodeFrameCallback class */
38/***********************************/
philipel9d3ab612015-12-21 04:12:39 -080039class VCMEncodedFrameCallback : public EncodedImageCallback {
40 public:
41 explicit VCMEncodedFrameCallback(
42 EncodedImageCallback* post_encode_callback);
niklase@google.com470e71d2011-07-07 08:21:25 +000043 virtual ~VCMEncodedFrameCallback();
44
45 /*
46 * Callback implementation - codec encode complete
47 */
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000048 int32_t Encoded(
pbos@webrtc.org273a4142014-12-01 15:23:21 +000049 const EncodedImage& encodedImage,
niklase@google.com470e71d2011-07-07 08:21:25 +000050 const CodecSpecificInfo* codecSpecificInfo = NULL,
51 const RTPFragmentationHeader* fragmentationHeader = NULL);
52 /*
niklase@google.com470e71d2011-07-07 08:21:25 +000053 * Callback implementation - generic encoder encode complete
54 */
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000055 int32_t SetTransportCallback(VCMPacketizationCallback* transport);
niklase@google.com470e71d2011-07-07 08:21:25 +000056 /**
57 * Set media Optimization
58 */
philipel9d3ab612015-12-21 04:12:39 -080059 void SetMediaOpt(media_optimization::MediaOptimization* mediaOpt);
niklase@google.com470e71d2011-07-07 08:21:25 +000060
philipel9d3ab612015-12-21 04:12:39 -080061 void SetPayloadType(uint8_t payloadType) {
62 _payloadType = payloadType;
63 }
64
65 void SetInternalSource(bool internalSource) {
66 _internalSource = internalSource;
67 }
niklase@google.com470e71d2011-07-07 08:21:25 +000068
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +000069 void SetRotation(VideoRotation rotation) { _rotation = rotation; }
Peter Boströmb7d9a972015-12-18 16:01:11 +010070 void SignalLastEncoderImplementationUsed(
71 const char* encoder_implementation_name);
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +000072
philipel9d3ab612015-12-21 04:12:39 -080073 private:
Peter Boströmb7d9a972015-12-18 16:01:11 +010074 VCMPacketizationCallback* send_callback_;
henrik.lundin@webrtc.orgbec11ef2013-09-23 19:54:25 +000075 media_optimization::MediaOptimization* _mediaOpt;
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000076 uint8_t _payloadType;
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000077 bool _internalSource;
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +000078 VideoRotation _rotation;
sprang@webrtc.org40709352013-11-26 11:41:59 +000079
sprang@webrtc.org40709352013-11-26 11:41:59 +000080 EncodedImageCallback* post_encode_callback_;
81
tommi@webrtc.orga9da4c52012-07-20 11:17:23 +000082#ifdef DEBUG_ENCODER_BIT_STREAM
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000083 FILE* _bitStreamAfterEncoder;
tommi@webrtc.orga9da4c52012-07-20 11:17:23 +000084#endif
philipel9d3ab612015-12-21 04:12:39 -080085}; // end of VCMEncodeFrameCallback class
niklase@google.com470e71d2011-07-07 08:21:25 +000086
87/******************************/
88/* VCMGenericEncoder class */
89/******************************/
philipel9d3ab612015-12-21 04:12:39 -080090class VCMGenericEncoder {
91 friend class VCMCodecDataBase;
Peter Boström69ccb332015-10-29 16:30:23 +010092
philipel9d3ab612015-12-21 04:12:39 -080093 public:
94 VCMGenericEncoder(VideoEncoder* encoder,
95 VideoEncoderRateObserver* rate_observer,
96 VCMEncodedFrameCallback* encoded_frame_callback,
97 bool internalSource);
98 ~VCMGenericEncoder();
99 /**
100 * Free encoder memory
101 */
102 int32_t Release();
103 /**
104 * Initialize the encoder with the information from the VideoCodec
105 */
106 int32_t InitEncode(const VideoCodec* settings,
107 int32_t numberOfCores,
108 size_t maxPayloadSize);
109 /**
110 * Encode raw image
111 * inputFrame : Frame containing raw image
112 * codecSpecificInfo : Specific codec data
113 * cameraFrameRate : Request or information from the remote side
114 * frameType : The requested frame type to encode
115 */
116 int32_t Encode(const VideoFrame& inputFrame,
117 const CodecSpecificInfo* codecSpecificInfo,
118 const std::vector<FrameType>& frameTypes);
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
philipel9d3ab612015-12-21 04:12:39 -0800120 void SetEncoderParameters(const EncoderParameters& params);
121 EncoderParameters GetEncoderParameters() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
philipel9d3ab612015-12-21 04:12:39 -0800123 int32_t SetPeriodicKeyFrames(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000124
philipel9d3ab612015-12-21 04:12:39 -0800125 int32_t RequestFrame(const std::vector<FrameType>& frame_types);
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
philipel9d3ab612015-12-21 04:12:39 -0800127 bool InternalSource() const;
jackychen61b4d512015-04-21 15:30:11 -0700128
philipel9d3ab612015-12-21 04:12:39 -0800129 void OnDroppedFrame();
Peter Boströmeb66e802015-06-05 11:08:03 +0200130
philipel9d3ab612015-12-21 04:12:39 -0800131 bool SupportsNativeHandle() const;
jackychen6e2ce6e2015-07-13 16:26:33 -0700132
philipel9d3ab612015-12-21 04:12:39 -0800133 int GetTargetFramerate();
134
135 private:
136 VideoEncoder* const encoder_;
137 VideoEncoderRateObserver* const rate_observer_;
138 VCMEncodedFrameCallback* const vcm_encoded_frame_callback_;
139 const bool internal_source_;
pbos5ad935c2016-01-25 03:52:44 -0800140 rtc::CriticalSection params_lock_;
philipel9d3ab612015-12-21 04:12:39 -0800141 EncoderParameters encoder_params_ GUARDED_BY(params_lock_);
142 VideoRotation rotation_;
143 bool is_screenshare_;
144}; // end of VCMGenericEncoder class
niklase@google.com470e71d2011-07-07 08:21:25 +0000145
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000146} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000147
philipel9d3ab612015-12-21 04:12:39 -0800148#endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_