blob: 92d79b001ec5502fa08a7afd8780f3222384ba8b [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
stefan@webrtc.org439be292012-02-16 14:45:37 +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// This sub-API supports the following functionalities:
12// - Setting send and receive codecs.
13// - Codec specific settings.
14// - Key frame signaling.
15// - Stream management settings.
16
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000017#ifndef WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_
18#define WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000019
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000020#include "webrtc/common_types.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000021
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000022namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000023
24class VideoEngine;
25struct VideoCodec;
26
niklase@google.com470e71d2011-07-07 08:21:25 +000027// This class declares an abstract interface for a user defined observer. It is
28// up to the VideoEngine user to implement a derived class which implements the
29// observer class. The observer is registered using RegisterEncoderObserver()
30// and deregistered using DeregisterEncoderObserver().
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000031class WEBRTC_DLLEXPORT ViEEncoderObserver {
32 public:
33 // This method is called once per second with the current encoded frame rate
34 // and bit rate.
35 virtual void OutgoingRate(const int video_channel,
36 const unsigned int framerate,
37 const unsigned int bitrate) = 0;
henrik.lundin@webrtc.org7ea4f242013-10-02 13:34:26 +000038
39 // This method is called whenever the state of the AutoMuter changes, i.e.,
40 // when |is_muted| toggles.
41 // TODO(hlundin): Remove the default implementation when possible.
henrik.lundin@webrtc.org0d19ed92013-10-21 12:37:13 +000042 virtual void VideoAutoMuted(int video_channel, bool is_muted) {}
henrik.lundin@webrtc.org7ea4f242013-10-02 13:34:26 +000043
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000044 protected:
45 virtual ~ViEEncoderObserver() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000046};
47
niklase@google.com470e71d2011-07-07 08:21:25 +000048// This class declares an abstract interface for a user defined observer. It is
49// up to the VideoEngine user to implement a derived class which implements the
50// observer class. The observer is registered using RegisterDecoderObserver()
51// and deregistered using DeregisterDecoderObserver().
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000052class WEBRTC_DLLEXPORT ViEDecoderObserver {
53 public:
54 // This method is called when a new incoming stream is detected, normally
55 // triggered by a new incoming SSRC or payload type.
56 virtual void IncomingCodecChanged(const int video_channel,
57 const VideoCodec& video_codec) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000058
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000059 // This method is called once per second containing the frame rate and bit
60 // rate for the incoming stream
61 virtual void IncomingRate(const int video_channel,
62 const unsigned int framerate,
63 const unsigned int bitrate) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000064
fischman@webrtc.org37bb4972013-10-23 23:59:45 +000065 // Called periodically with decoder timing information. All values are
66 // "current" snapshots unless decorated with a min_/max_ prefix.
67 // TODO(fischman): drop the do-nothing default impl. when
68 // WebRtcDecoderObserver is updated.
69 virtual void DecoderTiming(int decode_ms,
70 int max_decode_ms,
71 int current_delay_ms,
72 int target_delay_ms,
73 int jitter_buffer_ms,
74 int min_playout_delay_ms,
75 int render_delay_ms) {}
76
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000077 // This method is called when the decoder needs a new key frame from encoder
78 // on the sender.
79 virtual void RequestNewKeyFrame(const int video_channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000080
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000081 protected:
82 virtual ~ViEDecoderObserver() {}
niklase@google.com470e71d2011-07-07 08:21:25 +000083};
84
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000085class WEBRTC_DLLEXPORT ViECodec {
86 public:
87 // Factory for the ViECodec sub‐API and increases an internal reference
88 // counter if successful. Returns NULL if the API is not supported or if
89 // construction fails.
90 static ViECodec* GetInterface(VideoEngine* video_engine);
niklase@google.com470e71d2011-07-07 08:21:25 +000091
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000092 // Releases the ViECodec sub-API and decreases an internal reference
93 // counter.
94 // Returns the new reference count. This value should be zero
95 // for all sub-API:s before the VideoEngine object can be safely deleted.
96 virtual int Release() = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000097
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +000098 // Gets the number of available codecs for the VideoEngine build.
99 virtual int NumberOfCodecs() const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000101 // Gets a VideoCodec struct for a codec containing the default configuration
102 // for that codec type.
103 virtual int GetCodec(const unsigned char list_number,
104 VideoCodec& video_codec) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000105
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000106 // Sets the send codec to use for a specified channel.
107 virtual int SetSendCodec(const int video_channel,
108 const VideoCodec& video_codec) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000109
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000110 // Gets the current send codec settings.
111 virtual int GetSendCodec(const int video_channel,
112 VideoCodec& video_codec) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000113
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000114 // Prepares VideoEngine to receive a certain codec type and setting for a
115 // specified payload type.
116 virtual int SetReceiveCodec(const int video_channel,
117 const VideoCodec& video_codec) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000118
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000119 // Gets the current receive codec.
120 virtual int GetReceiveCodec(const int video_channel,
121 VideoCodec& video_codec) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000123 // This function is used to get codec configuration parameters to be
124 // signaled from the encoder to the decoder in the call setup.
125 virtual int GetCodecConfigParameters(
126 const int video_channel,
127 unsigned char config_parameters[kConfigParameterSize],
128 unsigned char& config_parameters_size) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000130 // Enables advanced scaling of the captured video stream if the stream
131 // differs from the send codec settings.
132 virtual int SetImageScaleStatus(const int video_channel,
133 const bool enable) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000134
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000135 // Gets the number of sent key frames and number of sent delta frames.
136 virtual int GetSendCodecStastistics(const int video_channel,
137 unsigned int& key_frames,
138 unsigned int& delta_frames) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000139
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000140 // Gets the number of decoded key frames and number of decoded delta frames.
141 virtual int GetReceiveCodecStastistics(const int video_channel,
142 unsigned int& key_frames,
143 unsigned int& delta_frames) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000144
mflodman@webrtc.org4aee6b62012-12-14 14:02:10 +0000145 // Estimate of the min required buffer time from the expected arrival time
146 // until rendering to get smooth playback.
147 virtual int GetReceiveSideDelay(const int video_channel,
148 int* delay_ms) const = 0;
149
stefan@webrtc.org439be292012-02-16 14:45:37 +0000150 // Gets the bitrate targeted by the video codec rate control in kbit/s.
151 virtual int GetCodecTargetBitrate(const int video_channel,
152 unsigned int* bitrate) const = 0;
153
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000154 // Gets the number of packets discarded by the jitter buffer because they
155 // arrived too late.
156 virtual unsigned int GetDiscardedPackets(const int video_channel) const = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000157
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000158 // Enables key frame request callback in ViEDecoderObserver.
159 virtual int SetKeyFrameRequestCallbackStatus(const int video_channel,
160 const bool enable) = 0;
stefan@webrtc.org791eec72011-10-11 07:53:43 +0000161
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000162 // Enables key frame requests for detected lost packets.
163 virtual int SetSignalKeyPacketLossStatus(
164 const int video_channel,
165 const bool enable,
166 const bool only_key_frames = false) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000167
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000168 // Registers an instance of a user implementation of the ViEEncoderObserver.
169 virtual int RegisterEncoderObserver(const int video_channel,
170 ViEEncoderObserver& observer) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000171
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000172 // Removes an already registered instance of ViEEncoderObserver.
173 virtual int DeregisterEncoderObserver(const int video_channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000174
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000175 // Registers an instance of a user implementation of the ViEDecoderObserver.
176 virtual int RegisterDecoderObserver(const int video_channel,
177 ViEDecoderObserver& observer) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000178
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000179 // Removes an already registered instance of ViEDecoderObserver.
180 virtual int DeregisterDecoderObserver(const int video_channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000181
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000182 // This function forces the next encoded frame to be a key frame. This is
183 // normally used when the remote endpoint only supports out‐band key frame
184 // request.
185 virtual int SendKeyFrame(const int video_channel) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000186
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000187 // This function makes the decoder wait for a key frame before starting to
188 // decode the incoming video stream.
189 virtual int WaitForFirstKeyFrame(const int video_channel,
190 const bool wait) = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000191
mflodman@webrtc.org1c986e72013-06-26 09:12:49 +0000192 // Enables recording of debugging information.
193 virtual int StartDebugRecording(int video_channel,
194 const char* file_name_utf8) = 0;
195 // Disables recording of debugging information.
196 virtual int StopDebugRecording(int video_channel) = 0;
197
henrik.lundin@webrtc.org7ea4f242013-10-02 13:34:26 +0000198 // Enables AutoMuter to turn off video when the rate drops below
199 // |threshold_bps|, and turns back on when the rate goes back up above
200 // |threshold_bps| + |window_bps|.
201 // This is under development; not tested.
henrik.lundin@webrtc.org70df3052013-10-03 13:38:59 +0000202 // TODO(hlundin): Remove the default implementation when possible.
henrik.lundin@webrtc.org7ea4f242013-10-02 13:34:26 +0000203 virtual void EnableAutoMuting(int video_channel, int threshold_bps,
henrik.lundin@webrtc.org70df3052013-10-03 13:38:59 +0000204 int window_bps) {}
henrik.lundin@webrtc.org7ea4f242013-10-02 13:34:26 +0000205
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000206 protected:
207 ViECodec() {}
208 virtual ~ViECodec() {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000209};
mflodman@webrtc.orgd5a4d9b2012-01-02 13:04:05 +0000210
211} // namespace webrtc
212
213#endif // WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_