niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | // 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.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 17 | #ifndef WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_ |
| 18 | #define WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
| 20 | #include "common_types.h" |
| 21 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 22 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
| 24 | class VideoEngine; |
| 25 | struct VideoCodec; |
| 26 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | // 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.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 31 | class 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; |
| 38 | protected: |
| 39 | virtual ~ViEEncoderObserver() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | // This class declares an abstract interface for a user defined observer. It is |
| 43 | // up to the VideoEngine user to implement a derived class which implements the |
| 44 | // observer class. The observer is registered using RegisterDecoderObserver() |
| 45 | // and deregistered using DeregisterDecoderObserver(). |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 46 | class WEBRTC_DLLEXPORT ViEDecoderObserver { |
| 47 | public: |
| 48 | // This method is called when a new incoming stream is detected, normally |
| 49 | // triggered by a new incoming SSRC or payload type. |
| 50 | virtual void IncomingCodecChanged(const int video_channel, |
| 51 | const VideoCodec& video_codec) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 53 | // This method is called once per second containing the frame rate and bit |
| 54 | // rate for the incoming stream |
| 55 | virtual void IncomingRate(const int video_channel, |
| 56 | const unsigned int framerate, |
| 57 | const unsigned int bitrate) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 59 | // This method is called when the decoder needs a new key frame from encoder |
| 60 | // on the sender. |
| 61 | virtual void RequestNewKeyFrame(const int video_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 63 | protected: |
| 64 | virtual ~ViEDecoderObserver() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 67 | class WEBRTC_DLLEXPORT ViECodec { |
| 68 | public: |
| 69 | // Factory for the ViECodec sub‐API and increases an internal reference |
| 70 | // counter if successful. Returns NULL if the API is not supported or if |
| 71 | // construction fails. |
| 72 | static ViECodec* GetInterface(VideoEngine* video_engine); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 74 | // Releases the ViECodec sub-API and decreases an internal reference |
| 75 | // counter. |
| 76 | // Returns the new reference count. This value should be zero |
| 77 | // for all sub-API:s before the VideoEngine object can be safely deleted. |
| 78 | virtual int Release() = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 79 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 80 | // Gets the number of available codecs for the VideoEngine build. |
| 81 | virtual int NumberOfCodecs() const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 82 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 83 | // Gets a VideoCodec struct for a codec containing the default configuration |
| 84 | // for that codec type. |
| 85 | virtual int GetCodec(const unsigned char list_number, |
| 86 | VideoCodec& video_codec) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 88 | // Sets the send codec to use for a specified channel. |
| 89 | virtual int SetSendCodec(const int video_channel, |
| 90 | const VideoCodec& video_codec) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 92 | // Gets the current send codec settings. |
| 93 | virtual int GetSendCodec(const int video_channel, |
| 94 | VideoCodec& video_codec) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 95 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 96 | // Prepares VideoEngine to receive a certain codec type and setting for a |
| 97 | // specified payload type. |
| 98 | virtual int SetReceiveCodec(const int video_channel, |
| 99 | const VideoCodec& video_codec) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 101 | // Gets the current receive codec. |
| 102 | virtual int GetReceiveCodec(const int video_channel, |
| 103 | VideoCodec& video_codec) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 105 | // This function is used to get codec configuration parameters to be |
| 106 | // signaled from the encoder to the decoder in the call setup. |
| 107 | virtual int GetCodecConfigParameters( |
| 108 | const int video_channel, |
| 109 | unsigned char config_parameters[kConfigParameterSize], |
| 110 | unsigned char& config_parameters_size) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 111 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 112 | // Enables advanced scaling of the captured video stream if the stream |
| 113 | // differs from the send codec settings. |
| 114 | virtual int SetImageScaleStatus(const int video_channel, |
| 115 | const bool enable) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 116 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 117 | // Gets the number of sent key frames and number of sent delta frames. |
| 118 | virtual int GetSendCodecStastistics(const int video_channel, |
| 119 | unsigned int& key_frames, |
| 120 | unsigned int& delta_frames) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 122 | // Gets the number of decoded key frames and number of decoded delta frames. |
| 123 | virtual int GetReceiveCodecStastistics(const int video_channel, |
| 124 | unsigned int& key_frames, |
| 125 | unsigned int& delta_frames) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 126 | |
mflodman@webrtc.org | 4aee6b6 | 2012-12-14 14:02:10 +0000 | [diff] [blame] | 127 | // Estimate of the min required buffer time from the expected arrival time |
| 128 | // until rendering to get smooth playback. |
| 129 | virtual int GetReceiveSideDelay(const int video_channel, |
| 130 | int* delay_ms) const = 0; |
| 131 | |
stefan@webrtc.org | 439be29 | 2012-02-16 14:45:37 +0000 | [diff] [blame] | 132 | // Gets the bitrate targeted by the video codec rate control in kbit/s. |
| 133 | virtual int GetCodecTargetBitrate(const int video_channel, |
| 134 | unsigned int* bitrate) const = 0; |
| 135 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 136 | // Gets the number of packets discarded by the jitter buffer because they |
| 137 | // arrived too late. |
| 138 | virtual unsigned int GetDiscardedPackets(const int video_channel) const = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 139 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 140 | // Enables key frame request callback in ViEDecoderObserver. |
| 141 | virtual int SetKeyFrameRequestCallbackStatus(const int video_channel, |
| 142 | const bool enable) = 0; |
stefan@webrtc.org | 791eec7 | 2011-10-11 07:53:43 +0000 | [diff] [blame] | 143 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 144 | // Enables key frame requests for detected lost packets. |
| 145 | virtual int SetSignalKeyPacketLossStatus( |
| 146 | const int video_channel, |
| 147 | const bool enable, |
| 148 | const bool only_key_frames = false) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 149 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 150 | // Registers an instance of a user implementation of the ViEEncoderObserver. |
| 151 | virtual int RegisterEncoderObserver(const int video_channel, |
| 152 | ViEEncoderObserver& observer) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 154 | // Removes an already registered instance of ViEEncoderObserver. |
| 155 | virtual int DeregisterEncoderObserver(const int video_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 156 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 157 | // Registers an instance of a user implementation of the ViEDecoderObserver. |
| 158 | virtual int RegisterDecoderObserver(const int video_channel, |
| 159 | ViEDecoderObserver& observer) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 160 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 161 | // Removes an already registered instance of ViEDecoderObserver. |
| 162 | virtual int DeregisterDecoderObserver(const int video_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 163 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 164 | // This function forces the next encoded frame to be a key frame. This is |
| 165 | // normally used when the remote endpoint only supports out‐band key frame |
| 166 | // request. |
| 167 | virtual int SendKeyFrame(const int video_channel) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 168 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 169 | // This function makes the decoder wait for a key frame before starting to |
| 170 | // decode the incoming video stream. |
| 171 | virtual int WaitForFirstKeyFrame(const int video_channel, |
| 172 | const bool wait) = 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 173 | |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 174 | protected: |
| 175 | ViECodec() {} |
| 176 | virtual ~ViECodec() {} |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 177 | }; |
mflodman@webrtc.org | d5a4d9b | 2012-01-02 13:04:05 +0000 | [diff] [blame] | 178 | |
| 179 | } // namespace webrtc |
| 180 | |
| 181 | #endif // WEBRTC_VIDEO_ENGINE_INCLUDE_VIE_CODEC_H_ |