media/webrtc/signaling/src/media-conduit/VideoConduit.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef VIDEO_SESSION_H_
michael@0 6 #define VIDEO_SESSION_H_
michael@0 7
michael@0 8 #include "mozilla/Attributes.h"
michael@0 9
michael@0 10 #include "MediaConduitInterface.h"
michael@0 11 #include "MediaEngineWrapper.h"
michael@0 12
michael@0 13 // Video Engine Includes
michael@0 14 #include "webrtc/common_types.h"
michael@0 15 #ifdef FF
michael@0 16 #undef FF // Avoid name collision between scoped_ptr.h and nsCRTGlue.h.
michael@0 17 #endif
michael@0 18 #include "webrtc/modules/video_coding/codecs/interface/video_codec_interface.h"
michael@0 19 #include "webrtc/video_engine/include/vie_base.h"
michael@0 20 #include "webrtc/video_engine/include/vie_capture.h"
michael@0 21 #include "webrtc/video_engine/include/vie_codec.h"
michael@0 22 #include "webrtc/video_engine/include/vie_external_codec.h"
michael@0 23 #include "webrtc/video_engine/include/vie_render.h"
michael@0 24 #include "webrtc/video_engine/include/vie_network.h"
michael@0 25 #include "webrtc/video_engine/include/vie_rtp_rtcp.h"
michael@0 26
michael@0 27 /** This file hosts several structures identifying different aspects
michael@0 28 * of a RTP Session.
michael@0 29 */
michael@0 30
michael@0 31 using webrtc::ViEBase;
michael@0 32 using webrtc::ViENetwork;
michael@0 33 using webrtc::ViECodec;
michael@0 34 using webrtc::ViECapture;
michael@0 35 using webrtc::ViERender;
michael@0 36 using webrtc::ViEExternalCapture;
michael@0 37 using webrtc::ViEExternalCodec;
michael@0 38
michael@0 39 namespace mozilla {
michael@0 40
michael@0 41 class WebrtcAudioConduit;
michael@0 42
michael@0 43 // Interface of external video encoder for WebRTC.
michael@0 44 class WebrtcVideoEncoder:public VideoEncoder
michael@0 45 ,public webrtc::VideoEncoder
michael@0 46 {};
michael@0 47
michael@0 48 // Interface of external video decoder for WebRTC.
michael@0 49 class WebrtcVideoDecoder:public VideoDecoder
michael@0 50 ,public webrtc::VideoDecoder
michael@0 51 {};
michael@0 52
michael@0 53 /**
michael@0 54 * Concrete class for Video session. Hooks up
michael@0 55 * - media-source and target to external transport
michael@0 56 */
michael@0 57 class WebrtcVideoConduit:public VideoSessionConduit
michael@0 58 ,public webrtc::Transport
michael@0 59 ,public webrtc::ExternalRenderer
michael@0 60 {
michael@0 61 public:
michael@0 62 //VoiceEngine defined constant for Payload Name Size.
michael@0 63 static const unsigned int CODEC_PLNAME_SIZE;
michael@0 64
michael@0 65 /**
michael@0 66 * Set up A/V sync between this (incoming) VideoConduit and an audio conduit.
michael@0 67 */
michael@0 68 void SyncTo(WebrtcAudioConduit *aConduit);
michael@0 69
michael@0 70 /**
michael@0 71 * Function to attach Renderer end-point for the Media-Video conduit.
michael@0 72 * @param aRenderer : Reference to the concrete Video renderer implementation
michael@0 73 * Note: Multiple invocations of this API shall remove an existing renderer
michael@0 74 * and attaches the new to the Conduit.
michael@0 75 */
michael@0 76 virtual MediaConduitErrorCode AttachRenderer(mozilla::RefPtr<VideoRenderer> aVideoRenderer);
michael@0 77 virtual void DetachRenderer();
michael@0 78
michael@0 79 /**
michael@0 80 * APIs used by the registered external transport to this Conduit to
michael@0 81 * feed in received RTP Frames to the VideoEngine for decoding
michael@0 82 */
michael@0 83 virtual MediaConduitErrorCode ReceivedRTPPacket(const void *data, int len);
michael@0 84
michael@0 85 /**
michael@0 86 * APIs used by the registered external transport to this Conduit to
michael@0 87 * feed in received RTP Frames to the VideoEngine for decoding
michael@0 88 */
michael@0 89 virtual MediaConduitErrorCode ReceivedRTCPPacket(const void *data, int len);
michael@0 90
michael@0 91 /**
michael@0 92 * Function to configure send codec for the video session
michael@0 93 * @param sendSessionConfig: CodecConfiguration
michael@0 94 * @result: On Success, the video engine is configured with passed in codec for send
michael@0 95 * On failure, video engine transmit functionality is disabled.
michael@0 96 * NOTE: This API can be invoked multiple time. Invoking this API may involve restarting
michael@0 97 * transmission sub-system on the engine.
michael@0 98 */
michael@0 99 virtual MediaConduitErrorCode ConfigureSendMediaCodec(const VideoCodecConfig* codecInfo);
michael@0 100
michael@0 101 /**
michael@0 102 * Function to configure list of receive codecs for the video session
michael@0 103 * @param sendSessionConfig: CodecConfiguration
michael@0 104 * @result: On Success, the video engine is configured with passed in codec for send
michael@0 105 * Also the playout is enabled.
michael@0 106 * On failure, video engine transmit functionality is disabled.
michael@0 107 * NOTE: This API can be invoked multiple time. Invoking this API may involve restarting
michael@0 108 * transmission sub-system on the engine.
michael@0 109 */
michael@0 110 virtual MediaConduitErrorCode ConfigureRecvMediaCodecs(
michael@0 111 const std::vector<VideoCodecConfig* >& codecConfigList);
michael@0 112
michael@0 113 /**
michael@0 114 * Register Transport for this Conduit. RTP and RTCP frames from the VideoEngine
michael@0 115 * shall be passed to the registered transport for transporting externally.
michael@0 116 */
michael@0 117 virtual MediaConduitErrorCode AttachTransport(mozilla::RefPtr<TransportInterface> aTransport);
michael@0 118
michael@0 119 /**
michael@0 120 * Function to select and change the encoding resolution based on incoming frame size
michael@0 121 * and current available bandwidth.
michael@0 122 * @param width, height: dimensions of the frame
michael@0 123 */
michael@0 124 virtual bool SelectSendResolution(unsigned short width,
michael@0 125 unsigned short height);
michael@0 126
michael@0 127 /**
michael@0 128 * Function to deliver a capture video frame for encoding and transport
michael@0 129 * @param video_frame: pointer to captured video-frame.
michael@0 130 * @param video_frame_length: size of the frame
michael@0 131 * @param width, height: dimensions of the frame
michael@0 132 * @param video_type: Type of the video frame - I420, RAW
michael@0 133 * @param captured_time: timestamp when the frame was captured.
michael@0 134 * if 0 timestamp is automatcally generated by the engine.
michael@0 135 *NOTE: ConfigureSendMediaCodec() SHOULD be called before this function can be invoked
michael@0 136 * This ensures the inserted video-frames can be transmitted by the conduit
michael@0 137 */
michael@0 138 virtual MediaConduitErrorCode SendVideoFrame(unsigned char* video_frame,
michael@0 139 unsigned int video_frame_length,
michael@0 140 unsigned short width,
michael@0 141 unsigned short height,
michael@0 142 VideoType video_type,
michael@0 143 uint64_t capture_time);
michael@0 144
michael@0 145 /**
michael@0 146 * Set an external encoder object |encoder| to the payload type |pltype|
michael@0 147 * for sender side codec.
michael@0 148 */
michael@0 149 virtual MediaConduitErrorCode SetExternalSendCodec(int pltype,
michael@0 150 VideoEncoder* encoder);
michael@0 151
michael@0 152 /**
michael@0 153 * Set an external decoder object |decoder| to the payload type |pltype|
michael@0 154 * for receiver side codec.
michael@0 155 */
michael@0 156 virtual MediaConduitErrorCode SetExternalRecvCodec(int pltype,
michael@0 157 VideoDecoder* decoder);
michael@0 158
michael@0 159
michael@0 160 /**
michael@0 161 * Webrtc transport implementation to send and receive RTP packet.
michael@0 162 * VideoConduit registers itself as ExternalTransport to the VideoEngine
michael@0 163 */
michael@0 164 virtual int SendPacket(int channel, const void *data, int len) ;
michael@0 165
michael@0 166 /**
michael@0 167 * Webrtc transport implementation to send and receive RTCP packet.
michael@0 168 * VideoConduit registers itself as ExternalTransport to the VideoEngine
michael@0 169 */
michael@0 170 virtual int SendRTCPPacket(int channel, const void *data, int len) ;
michael@0 171
michael@0 172
michael@0 173 /**
michael@0 174 * Webrtc External Renderer Implementation APIs.
michael@0 175 * Raw I420 Frames are delivred to the VideoConduit by the VideoEngine
michael@0 176 */
michael@0 177 virtual int FrameSizeChange(unsigned int, unsigned int, unsigned int);
michael@0 178
michael@0 179 virtual int DeliverFrame(unsigned char*,int, uint32_t , int64_t,
michael@0 180 void *handle);
michael@0 181
michael@0 182 /**
michael@0 183 * Does DeliverFrame() support a null buffer and non-null handle
michael@0 184 * (video texture)?
michael@0 185 * B2G support it (when using HW video decoder with graphic buffer output).
michael@0 186 * XXX Investigate! Especially for Android
michael@0 187 */
michael@0 188 virtual bool IsTextureSupported() {
michael@0 189 #ifdef WEBRTC_GONK
michael@0 190 return true;
michael@0 191 #else
michael@0 192 return false;
michael@0 193 #endif
michael@0 194 }
michael@0 195
michael@0 196 unsigned short SendingWidth() {
michael@0 197 return mSendingWidth;
michael@0 198 }
michael@0 199
michael@0 200 unsigned short SendingHeight() {
michael@0 201 return mSendingHeight;
michael@0 202 }
michael@0 203
michael@0 204 unsigned int SendingMaxFs() {
michael@0 205 if(mCurSendCodecConfig) {
michael@0 206 return mCurSendCodecConfig->mMaxFrameSize;
michael@0 207 }
michael@0 208 return 0;
michael@0 209 }
michael@0 210
michael@0 211 unsigned int SendingMaxFr() {
michael@0 212 if(mCurSendCodecConfig) {
michael@0 213 return mCurSendCodecConfig->mMaxFrameRate;
michael@0 214 }
michael@0 215 return 0;
michael@0 216 }
michael@0 217
michael@0 218 WebrtcVideoConduit():
michael@0 219 mOtherDirection(nullptr),
michael@0 220 mShutDown(false),
michael@0 221 mVideoEngine(nullptr),
michael@0 222 mTransport(nullptr),
michael@0 223 mRenderer(nullptr),
michael@0 224 mPtrExtCapture(nullptr),
michael@0 225 mEngineTransmitting(false),
michael@0 226 mEngineReceiving(false),
michael@0 227 mChannel(-1),
michael@0 228 mCapId(-1),
michael@0 229 mCurSendCodecConfig(nullptr),
michael@0 230 mSendingWidth(0),
michael@0 231 mSendingHeight(0),
michael@0 232 mReceivingWidth(640),
michael@0 233 mReceivingHeight(480),
michael@0 234 mVideoLatencyTestEnable(false),
michael@0 235 mVideoLatencyAvg(0)
michael@0 236 {
michael@0 237 }
michael@0 238
michael@0 239 virtual ~WebrtcVideoConduit() ;
michael@0 240
michael@0 241 MediaConduitErrorCode Init(WebrtcVideoConduit *other);
michael@0 242
michael@0 243 int GetChannel() { return mChannel; }
michael@0 244 webrtc::VideoEngine* GetVideoEngine() { return mVideoEngine; }
michael@0 245 bool GetLocalSSRC(unsigned int* ssrc);
michael@0 246 bool GetRemoteSSRC(unsigned int* ssrc);
michael@0 247 bool GetAVStats(int32_t* jitterBufferDelayMs,
michael@0 248 int32_t* playoutBufferDelayMs,
michael@0 249 int32_t* avSyncOffsetMs);
michael@0 250 bool GetRTPStats(unsigned int* jitterMs, unsigned int* cumulativeLost);
michael@0 251 bool GetRTCPReceiverReport(DOMHighResTimeStamp* timestamp,
michael@0 252 uint32_t* jitterMs,
michael@0 253 uint32_t* packetsReceived,
michael@0 254 uint64_t* bytesReceived,
michael@0 255 uint32_t* cumulativeLost,
michael@0 256 int32_t* rttMs);
michael@0 257 bool GetRTCPSenderReport(DOMHighResTimeStamp* timestamp,
michael@0 258 unsigned int* packetsSent,
michael@0 259 uint64_t* bytesSent);
michael@0 260 uint64_t MozVideoLatencyAvg();
michael@0 261
michael@0 262 private:
michael@0 263
michael@0 264 WebrtcVideoConduit(const WebrtcVideoConduit& other) MOZ_DELETE;
michael@0 265 void operator=(const WebrtcVideoConduit& other) MOZ_DELETE;
michael@0 266
michael@0 267 //Local database of currently applied receive codecs
michael@0 268 typedef std::vector<VideoCodecConfig* > RecvCodecList;
michael@0 269
michael@0 270 //Function to convert between WebRTC and Conduit codec structures
michael@0 271 void CodecConfigToWebRTCCodec(const VideoCodecConfig* codecInfo,
michael@0 272 webrtc::VideoCodec& cinst);
michael@0 273
michael@0 274 // Function to copy a codec structure to Conduit's database
michael@0 275 bool CopyCodecToDB(const VideoCodecConfig* codecInfo);
michael@0 276
michael@0 277 // Functions to verify if the codec passed is already in
michael@0 278 // conduits database
michael@0 279 bool CheckCodecForMatch(const VideoCodecConfig* codecInfo) const;
michael@0 280 bool CheckCodecsForMatch(const VideoCodecConfig* curCodecConfig,
michael@0 281 const VideoCodecConfig* codecInfo) const;
michael@0 282
michael@0 283 //Checks the codec to be applied
michael@0 284 MediaConduitErrorCode ValidateCodecConfig(const VideoCodecConfig* codecInfo, bool send) const;
michael@0 285
michael@0 286 //Utility function to dump recv codec database
michael@0 287 void DumpCodecDB() const;
michael@0 288
michael@0 289 // Video Latency Test averaging filter
michael@0 290 void VideoLatencyUpdate(uint64_t new_sample);
michael@0 291
michael@0 292 // The two sides of a send/receive pair of conduits each keep a pointer to the other.
michael@0 293 // They also share a single VideoEngine and mChannel. Shutdown must be coordinated
michael@0 294 // carefully to avoid double-freeing or accessing after one frees.
michael@0 295 WebrtcVideoConduit* mOtherDirection;
michael@0 296 // The other side has shut down our mChannel and related items already
michael@0 297 bool mShutDown;
michael@0 298
michael@0 299 // A few of these are shared by both directions. They're released by the last
michael@0 300 // conduit to die.
michael@0 301 webrtc::VideoEngine* mVideoEngine; // shared
michael@0 302 mozilla::RefPtr<TransportInterface> mTransport;
michael@0 303 mozilla::RefPtr<VideoRenderer> mRenderer;
michael@0 304
michael@0 305 ScopedCustomReleasePtr<webrtc::ViEBase> mPtrViEBase;
michael@0 306 ScopedCustomReleasePtr<webrtc::ViECapture> mPtrViECapture;
michael@0 307 ScopedCustomReleasePtr<webrtc::ViECodec> mPtrViECodec;
michael@0 308 ScopedCustomReleasePtr<webrtc::ViENetwork> mPtrViENetwork;
michael@0 309 ScopedCustomReleasePtr<webrtc::ViERender> mPtrViERender;
michael@0 310 ScopedCustomReleasePtr<webrtc::ViERTP_RTCP> mPtrRTP;
michael@0 311 ScopedCustomReleasePtr<webrtc::ViEExternalCodec> mPtrExtCodec;
michael@0 312
michael@0 313 webrtc::ViEExternalCapture* mPtrExtCapture; // shared
michael@0 314
michael@0 315 // Engine state we are concerned with.
michael@0 316 bool mEngineTransmitting; //If true ==> Transmit Sub-system is up and running
michael@0 317 bool mEngineReceiving; // if true ==> Receive Sus-sysmtem up and running
michael@0 318
michael@0 319 int mChannel; // Video Channel for this conduit
michael@0 320 int mCapId; // Capturer for this conduit
michael@0 321 RecvCodecList mRecvCodecList;
michael@0 322 VideoCodecConfig* mCurSendCodecConfig;
michael@0 323 unsigned short mSendingWidth;
michael@0 324 unsigned short mSendingHeight;
michael@0 325 unsigned short mReceivingWidth;
michael@0 326 unsigned short mReceivingHeight;
michael@0 327 bool mVideoLatencyTestEnable;
michael@0 328 uint64_t mVideoLatencyAvg;
michael@0 329
michael@0 330 static const unsigned int sAlphaNum = 7;
michael@0 331 static const unsigned int sAlphaDen = 8;
michael@0 332 static const unsigned int sRoundingPadding = 1024;
michael@0 333
michael@0 334 mozilla::RefPtr<WebrtcAudioConduit> mSyncedTo;
michael@0 335 };
michael@0 336
michael@0 337 } // end namespace
michael@0 338
michael@0 339 #endif

mercurial