blob: 0d8ad50b5f9613cbeafd0557acd8db72d779bc7e [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
Henrik Kjellander2557b862015-11-18 22:00:21 +010014#include "webrtc/modules/video_coding/include/video_codec_interface.h"
15#include "webrtc/modules/video_coding/include/video_coding_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016
17#include <stdio.h>
18
tommi@webrtc.org558dc402015-03-07 20:55:56 +000019#include "webrtc/base/criticalsection.h"
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000020#include "webrtc/base/scoped_ptr.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/***********************************/
39class VCMEncodedFrameCallback : public EncodedImageCallback
40{
41public:
andresp@webrtc.org1df9dc32014-01-09 08:01:57 +000042 VCMEncodedFrameCallback(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 */
henrik.lundin@webrtc.orgbec11ef2013-09-23 19:54:25 +000059 void SetMediaOpt (media_optimization::MediaOptimization* mediaOpt);
niklase@google.com470e71d2011-07-07 08:21:25 +000060
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000061 void SetPayloadType(uint8_t payloadType) { _payloadType = payloadType; };
niklase@google.com470e71d2011-07-07 08:21:25 +000062 void SetInternalSource(bool internalSource) { _internalSource = internalSource; };
63
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +000064 void SetRotation(VideoRotation rotation) { _rotation = rotation; }
65
niklase@google.com470e71d2011-07-07 08:21:25 +000066private:
niklase@google.com470e71d2011-07-07 08:21:25 +000067 VCMPacketizationCallback* _sendCallback;
henrik.lundin@webrtc.orgbec11ef2013-09-23 19:54:25 +000068 media_optimization::MediaOptimization* _mediaOpt;
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000069 uint8_t _payloadType;
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000070 bool _internalSource;
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +000071 VideoRotation _rotation;
sprang@webrtc.org40709352013-11-26 11:41:59 +000072
sprang@webrtc.org40709352013-11-26 11:41:59 +000073 EncodedImageCallback* post_encode_callback_;
74
tommi@webrtc.orga9da4c52012-07-20 11:17:23 +000075#ifdef DEBUG_ENCODER_BIT_STREAM
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000076 FILE* _bitStreamAfterEncoder;
tommi@webrtc.orga9da4c52012-07-20 11:17:23 +000077#endif
niklase@google.com470e71d2011-07-07 08:21:25 +000078};// end of VCMEncodeFrameCallback class
79
80
81/******************************/
82/* VCMGenericEncoder class */
83/******************************/
84class VCMGenericEncoder
85{
86 friend class VCMCodecDataBase;
87public:
tommi@webrtc.org558dc402015-03-07 20:55:56 +000088 VCMGenericEncoder(VideoEncoder* encoder,
89 VideoEncoderRateObserver* rate_observer,
Peter Boström4f5db112015-10-29 16:53:59 +010090 VCMEncodedFrameCallback* encoded_frame_callback,
tommi@webrtc.org558dc402015-03-07 20:55:56 +000091 bool internalSource);
niklase@google.com470e71d2011-07-07 08:21:25 +000092 ~VCMGenericEncoder();
93 /**
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +000094 * Free encoder memory
niklase@google.com470e71d2011-07-07 08:21:25 +000095 */
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000096 int32_t Release();
niklase@google.com470e71d2011-07-07 08:21:25 +000097 /**
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +000098 * Initialize the encoder with the information from the VideoCodec
niklase@google.com470e71d2011-07-07 08:21:25 +000099 */
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +0000100 int32_t InitEncode(const VideoCodec* settings,
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +0000101 int32_t numberOfCores,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000102 size_t maxPayloadSize);
niklase@google.com470e71d2011-07-07 08:21:25 +0000103 /**
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +0000104 * Encode raw image
105 * inputFrame : Frame containing raw image
106 * codecSpecificInfo : Specific codec data
107 * cameraFrameRate : Request or information from the remote side
108 * frameType : The requested frame type to encode
niklase@google.com470e71d2011-07-07 08:21:25 +0000109 */
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -0700110 int32_t Encode(const VideoFrame& inputFrame,
pbos@webrtc.orgb9bb3d12013-05-16 18:40:48 +0000111 const CodecSpecificInfo* codecSpecificInfo,
112 const std::vector<FrameType>& frameTypes);
Peter Boström69ccb332015-10-29 16:30:23 +0100113
114 void SetEncoderParameters(const EncoderParameters& params);
Peter Boström69ccb332015-10-29 16:30:23 +0100115 EncoderParameters GetEncoderParameters() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000116
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +0000117 int32_t SetPeriodicKeyFrames(bool enable);
niklase@google.com470e71d2011-07-07 08:21:25 +0000118
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +0000119 int32_t RequestFrame(const std::vector<FrameType>& frame_types);
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
121 bool InternalSource() const;
122
jackychen61b4d512015-04-21 15:30:11 -0700123 void OnDroppedFrame();
124
Peter Boströmeb66e802015-06-05 11:08:03 +0200125 bool SupportsNativeHandle() const;
126
jackychen6e2ce6e2015-07-13 16:26:33 -0700127 int GetTargetFramerate();
128
niklase@google.com470e71d2011-07-07 08:21:25 +0000129private:
pbos@webrtc.org891d4832015-02-26 13:15:22 +0000130 VideoEncoder* const encoder_;
131 VideoEncoderRateObserver* const rate_observer_;
Peter Boström4f5db112015-10-29 16:53:59 +0100132 VCMEncodedFrameCallback* const vcm_encoded_frame_callback_;
tommi@webrtc.org558dc402015-03-07 20:55:56 +0000133 const bool internal_source_;
Peter Boström69ccb332015-10-29 16:30:23 +0100134 mutable rtc::CriticalSection params_lock_;
Peter Boström4f5db112015-10-29 16:53:59 +0100135 EncoderParameters encoder_params_ GUARDED_BY(params_lock_);
guoweis@webrtc.org54d072e2015-03-17 21:54:50 +0000136 VideoRotation rotation_;
Erik Språng2c4c9142015-06-24 11:24:44 +0200137 bool is_screenshare_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000138}; // end of VCMGenericEncoder class
139
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000140} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000141
142#endif // WEBRTC_MODULES_VIDEO_CODING_GENERIC_ENCODER_H_