blob: d821f3d3e530cc2238058cacc6ae94c123a935a8 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 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/*
12 * vie_encoder.h
13 */
14
15#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_ENCODER_H_
16#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_ENCODER_H_
17
18#include "vie_defines.h"
19#include "typedefs.h"
20#include "vie_frame_provider_base.h"
21#include "vie_file_recorder.h"
22#include "rtp_rtcp_defines.h"
23#include "video_coding_defines.h"
24#include "video_processing.h"
25#include "common_types.h"
26
27namespace webrtc {
28class CriticalSectionWrapper;
29class ProcessThread;
30class RtpRtcp;
31class ViEEffectFilter;
32class VideoCodingModule;
33class ViEEncoderObserver;
34
35class ViEEncoder: public ViEFrameCallback, // New frame delivery
36 public RtpVideoFeedback, // Feedback from RTP module
37 public RtcpFeedback, // RTP/RTCP Module
38 public VCMPacketizationCallback, // Callback from VCM
39 public VCMProtectionCallback, // Callback from VCM
40 public VCMSendStatisticsCallback // Callback from VCM
41{
42public:
43 ViEEncoder(WebRtc_Word32 engineId, WebRtc_Word32 channelId,
44 WebRtc_UWord32 numberOfCores,
45 ProcessThread& moduleProcessThread);
46 ~ViEEncoder();
47
48 // Drops incoming packets
49 void Pause();
50 void Restart();
51
52 WebRtc_Word32 DropDeltaAfterKey(bool enable);
53
54 // Codec settings
55 WebRtc_UWord8 NumberOfCodecs();
56 WebRtc_Word32 GetCodec(WebRtc_UWord8 listIndex, VideoCodec& videoCodec);
57 WebRtc_Word32 RegisterExternalEncoder(VideoEncoder* encoder,
58 WebRtc_UWord8 plType);
59 WebRtc_Word32 DeRegisterExternalEncoder(WebRtc_UWord8 plType);
60 WebRtc_Word32 SetEncoder(const VideoCodec& videoCodec);
61 WebRtc_Word32 GetEncoder(VideoCodec& videoCodec);
62
63 WebRtc_Word32 GetCodecConfigParameters(
64 unsigned char configParameters[kConfigParameterSize],
65 unsigned char& configParametersSize);
66
67 // Scale or crop/pad image
68 WebRtc_Word32 ScaleInputImage(bool enable);
69
70 // RTP settings
71 RtpRtcp* SendRtpRtcpModule();
72
73 // Implementing ViEFrameCallback
74 virtual void DeliverFrame(int id, VideoFrame& videoFrame, int numCSRCs = 0,
75 const WebRtc_UWord32 CSRC[kRtpCsrcSize] = NULL);
76 virtual void DelayChanged(int id, int frameDelay);
77 virtual int GetPreferedFrameSettings(int &width, int &height,
78 int &frameRate);
79
80 virtual void ProviderDestroyed(int id) { return; }
81
82 WebRtc_Word32 EncodeFrame(VideoFrame& videoFrame);
83 WebRtc_Word32 SendKeyFrame();
84 WebRtc_Word32 SendCodecStatistics(WebRtc_UWord32& numKeyFrames,
85 WebRtc_UWord32& numDeltaFrames);
86 // Loss protection
87 WebRtc_Word32 UpdateProtectionMethod();
88 // Implements VCMPacketizationCallback
89 virtual WebRtc_Word32
90 SendData(const FrameType frameType,
91 const WebRtc_UWord8 payloadType,
92 const WebRtc_UWord32 timeStamp,
93 const WebRtc_UWord8* payloadData,
94 const WebRtc_UWord32 payloadSize,
95 const RTPFragmentationHeader& fragmentationHeader,
96 const RTPVideoTypeHeader* rtpTypeHdr);
97 // Implements VideoProtectionCallback
98 virtual WebRtc_Word32 ProtectionRequest(const WebRtc_UWord8 deltaFECRate,
99 const WebRtc_UWord8 keyFECRate,
100 const bool nack);
101 // Implements VideoSendStatisticsCallback
102 virtual WebRtc_Word32 SendStatistics(const WebRtc_UWord32 bitRate,
103 const WebRtc_UWord32 frameRate);
104 WebRtc_Word32 RegisterCodecObserver(ViEEncoderObserver* observer);
105 // Implements RtcpFeedback
106 virtual void OnSLIReceived(const WebRtc_Word32 id,
107 const WebRtc_UWord8 pictureId);
108 virtual void OnRPSIReceived(const WebRtc_Word32 id,
109 const WebRtc_UWord64 pictureId);
110
111 // Implements RtpVideoFeedback
112 virtual void OnReceivedIntraFrameRequest(const WebRtc_Word32 id,
113 const WebRtc_UWord8 message = 0);
114 virtual void OnNetworkChanged(const WebRtc_Word32 id,
115 const WebRtc_UWord32 minBitrateBps,
116 const WebRtc_UWord32 maxBitrateBps,
117 const WebRtc_UWord8 fractionLost,
118 const WebRtc_UWord16 roundTripTimeMs,
119 const WebRtc_UWord16 bwEstimateKbitMin,
120 const WebRtc_UWord16 bwEstimateKbitMax);
121 // Effect filter
122 WebRtc_Word32 RegisterEffectFilter(ViEEffectFilter* effectFilter);
123 //Recording
124 ViEFileRecorder& GetOutgoingFileRecorder();
125
126private:
127 WebRtc_Word32 _engineId;
128
129 class QMTestVideoSettingsCallback : public VCMQMSettingsCallback
130 {
131 public:
132 QMTestVideoSettingsCallback();
133 // update VPM with QM (quality modes: frame size & frame rate) settings
134 WebRtc_Word32 SetVideoQMSettings(const WebRtc_UWord32 frameRate,
135 const WebRtc_UWord32 width,
136 const WebRtc_UWord32 height);
137 // register VPM and VCM
138 void RegisterVPM(VideoProcessingModule* vpm);
139 void RegisterVCM(VideoCodingModule* vcm);
140 void SetNumOfCores(WebRtc_Word32 numOfCores)
141 {_numOfCores = numOfCores;};
142 void SetMaxPayloadLength(WebRtc_Word32 maxPayloadLength)
143 {_maxPayloadLength = maxPayloadLength;};
144 private:
145 VideoProcessingModule* _vpm;
146 VideoCodingModule* _vcm;
147 WebRtc_Word32 _numOfCores;
148 WebRtc_Word32 _maxPayloadLength;
149 };
150
151 WebRtc_Word32 _channelId;
152 const WebRtc_UWord32 _numberOfCores;
153
154 VideoCodingModule& _vcm;
155 VideoProcessingModule& _vpm;
156 RtpRtcp& _rtpRtcp;
157 CriticalSectionWrapper& _callbackCritsect;
158 CriticalSectionWrapper& _dataCritsect;
159 VideoCodec _sendCodec;
160
161 bool _paused;
162 WebRtc_Word64 _timeLastIntraRequestMs;
163 WebRtc_Word32 _channelsDroppingDeltaFrames;
164 bool _dropNextFrame;
165 //Loss protection
166 bool _fecEnabled;
167 bool _nackEnabled;
168 // Uses
169 ViEEncoderObserver* _codecObserver;
170 ViEEffectFilter* _effectFilter;
171 ProcessThread& _moduleProcessThread;
172
173 bool _hasReceivedSLI;
174 WebRtc_UWord8 _pictureIdSLI;
175 bool _hasReceivedRPSI;
176 WebRtc_UWord64 _pictureIdRPSI;
177
178 //Recording
179 ViEFileRecorder _fileRecorder;
180
181 // Quality modes callback
182 QMTestVideoSettingsCallback* _qmCallback;
183
184};
185} // namespace webrtc
186#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_ENCODER_H_