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

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rwxr-xr-x

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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 MEDIA_CONDUIT_ABSTRACTION_
michael@0 6 #define MEDIA_CONDUIT_ABSTRACTION_
michael@0 7
michael@0 8 #include "nsISupportsImpl.h"
michael@0 9 #include "nsXPCOM.h"
michael@0 10 #include "nsDOMNavigationTiming.h"
michael@0 11 #include "mozilla/RefPtr.h"
michael@0 12 #include "CodecConfig.h"
michael@0 13 #include "VideoTypes.h"
michael@0 14 #include "MediaConduitErrors.h"
michael@0 15
michael@0 16 #include "ImageContainer.h"
michael@0 17
michael@0 18 #include <vector>
michael@0 19
michael@0 20 namespace mozilla {
michael@0 21 /**
michael@0 22 * Abstract Interface for transporting RTP packets - audio/vidoeo
michael@0 23 * The consumers of this interface are responsible for passing in
michael@0 24 * the RTPfied media packets
michael@0 25 */
michael@0 26 class TransportInterface
michael@0 27 {
michael@0 28 public:
michael@0 29 virtual ~TransportInterface() {}
michael@0 30
michael@0 31 /**
michael@0 32 * RTP Transport Function to be implemented by concrete transport implementation
michael@0 33 * @param data : RTP Packet (audio/video) to be transported
michael@0 34 * @param len : Length of the media packet
michael@0 35 * @result : NS_OK on success, NS_ERROR_FAILURE otherwise
michael@0 36 */
michael@0 37 virtual nsresult SendRtpPacket(const void* data, int len) = 0;
michael@0 38
michael@0 39 /**
michael@0 40 * RTCP Transport Function to be implemented by concrete transport implementation
michael@0 41 * @param data : RTCP Packet to be transported
michael@0 42 * @param len : Length of the RTCP packet
michael@0 43 * @result : NS_OK on success, NS_ERROR_FAILURE otherwise
michael@0 44 */
michael@0 45 virtual nsresult SendRtcpPacket(const void* data, int len) = 0;
michael@0 46 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TransportInterface)
michael@0 47 };
michael@0 48
michael@0 49 /**
michael@0 50 * This class wraps image object for VideoRenderer::RenderVideoFrame()
michael@0 51 * callback implementation to use for rendering.
michael@0 52 */
michael@0 53 class ImageHandle
michael@0 54 {
michael@0 55 public:
michael@0 56 ImageHandle(layers::Image* image) : mImage(image) {}
michael@0 57
michael@0 58 const RefPtr<layers::Image>& GetImage() const { return mImage; }
michael@0 59
michael@0 60 private:
michael@0 61 RefPtr<layers::Image> mImage;
michael@0 62 };
michael@0 63
michael@0 64 /**
michael@0 65 * 1. Abstract renderer for video data
michael@0 66 * 2. This class acts as abstract interface between the video-engine and
michael@0 67 * video-engine agnostic renderer implementation.
michael@0 68 * 3. Concrete implementation of this interface is responsible for
michael@0 69 * processing and/or rendering the obtained raw video frame to appropriate
michael@0 70 * output , say, <video>
michael@0 71 */
michael@0 72 class VideoRenderer
michael@0 73 {
michael@0 74 public:
michael@0 75 virtual ~VideoRenderer() {}
michael@0 76
michael@0 77 /**
michael@0 78 * Callback Function reportng any change in the video-frame dimensions
michael@0 79 * @param width: current width of the video @ decoder
michael@0 80 * @param height: current height of the video @ decoder
michael@0 81 * @param number_of_streams: number of participating video streams
michael@0 82 */
michael@0 83 virtual void FrameSizeChange(unsigned int width,
michael@0 84 unsigned int height,
michael@0 85 unsigned int number_of_streams) = 0;
michael@0 86
michael@0 87 /**
michael@0 88 * Callback Function reporting decoded I420 frame for processing.
michael@0 89 * @param buffer: pointer to decoded video frame
michael@0 90 * @param buffer_size: size of the decoded frame
michael@0 91 * @param time_stamp: Decoder timestamp, typically 90KHz as per RTP
michael@0 92 * @render_time: Wall-clock time at the decoder for synchronization
michael@0 93 * purposes in milliseconds
michael@0 94 * @handle: opaque handle for image object of decoded video frame.
michael@0 95 * NOTE: If decoded video frame is passed through buffer , it is the
michael@0 96 * responsibility of the concrete implementations of this class to own copy
michael@0 97 * of the frame if needed for time longer than scope of this callback.
michael@0 98 * Such implementations should be quick in processing the frames and return
michael@0 99 * immediately.
michael@0 100 * On the other hand, if decoded video frame is passed through handle, the
michael@0 101 * implementations should keep a reference to the (ref-counted) image object
michael@0 102 * inside until it's no longer needed.
michael@0 103 */
michael@0 104 virtual void RenderVideoFrame(const unsigned char* buffer,
michael@0 105 unsigned int buffer_size,
michael@0 106 uint32_t time_stamp,
michael@0 107 int64_t render_time,
michael@0 108 const ImageHandle& handle) = 0;
michael@0 109
michael@0 110 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VideoRenderer)
michael@0 111 };
michael@0 112
michael@0 113
michael@0 114 /**
michael@0 115 * Generic Interface for representing Audio/Video Session
michael@0 116 * MediaSession conduit is identified by 2 main components
michael@0 117 * 1. Attached Transport Interface for inbound and outbound RTP transport
michael@0 118 * 2. Attached Renderer Interface for rendering media data off the network
michael@0 119 * This class hides specifics of Media-Engine implementation from the consumers
michael@0 120 * of this interface.
michael@0 121 * Also provides codec configuration API for the media sent and recevied
michael@0 122 */
michael@0 123 class MediaSessionConduit
michael@0 124 {
michael@0 125 public:
michael@0 126 enum Type { AUDIO, VIDEO } ;
michael@0 127
michael@0 128 virtual ~MediaSessionConduit() {}
michael@0 129
michael@0 130 virtual Type type() const = 0;
michael@0 131
michael@0 132 /**
michael@0 133 * Function triggered on Incoming RTP packet from the remote
michael@0 134 * endpoint by the transport implementation.
michael@0 135 * @param data : RTP Packet (audio/video) to be processed
michael@0 136 * @param len : Length of the media packet
michael@0 137 * Obtained packets are passed to the Media-Engine for further
michael@0 138 * processing , say, decoding
michael@0 139 */
michael@0 140 virtual MediaConduitErrorCode ReceivedRTPPacket(const void *data, int len) = 0;
michael@0 141
michael@0 142 /**
michael@0 143 * Function triggered on Incoming RTCP packet from the remote
michael@0 144 * endpoint by the transport implementation.
michael@0 145 * @param data : RTCP Packet (audio/video) to be processed
michael@0 146 * @param len : Length of the media packet
michael@0 147 * Obtained packets are passed to the Media-Engine for further
michael@0 148 * processing , say, decoding
michael@0 149 */
michael@0 150 virtual MediaConduitErrorCode ReceivedRTCPPacket(const void *data, int len) = 0;
michael@0 151
michael@0 152
michael@0 153 /**
michael@0 154 * Function to attach Transport end-point of the Media conduit.
michael@0 155 * @param aTransport: Reference to the concrete teansport implementation
michael@0 156 * Note: Multiple invocations of this call , replaces existing transport with
michael@0 157 * with the new one.
michael@0 158 */
michael@0 159 virtual MediaConduitErrorCode AttachTransport(RefPtr<TransportInterface> aTransport) = 0;
michael@0 160
michael@0 161 virtual bool GetLocalSSRC(unsigned int* ssrc) = 0;
michael@0 162 virtual bool GetRemoteSSRC(unsigned int* ssrc) = 0;
michael@0 163
michael@0 164 /**
michael@0 165 * Functions returning stats needed by w3c stats model.
michael@0 166 */
michael@0 167 virtual bool GetAVStats(int32_t* jitterBufferDelayMs,
michael@0 168 int32_t* playoutBufferDelayMs,
michael@0 169 int32_t* avSyncOffsetMs) = 0;
michael@0 170 virtual bool GetRTPStats(unsigned int* jitterMs,
michael@0 171 unsigned int* cumulativeLost) = 0;
michael@0 172 virtual bool GetRTCPReceiverReport(DOMHighResTimeStamp* timestamp,
michael@0 173 uint32_t* jitterMs,
michael@0 174 uint32_t* packetsReceived,
michael@0 175 uint64_t* bytesReceived,
michael@0 176 uint32_t* cumulativeLost,
michael@0 177 int32_t* rttMs) = 0;
michael@0 178 virtual bool GetRTCPSenderReport(DOMHighResTimeStamp* timestamp,
michael@0 179 unsigned int* packetsSent,
michael@0 180 uint64_t* bytesSent) = 0;
michael@0 181
michael@0 182 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaSessionConduit)
michael@0 183
michael@0 184 };
michael@0 185
michael@0 186 // Abstract base classes for external encoder/decoder.
michael@0 187 class VideoEncoder
michael@0 188 {
michael@0 189 public:
michael@0 190 virtual ~VideoEncoder() {};
michael@0 191 };
michael@0 192
michael@0 193 class VideoDecoder
michael@0 194 {
michael@0 195 public:
michael@0 196 virtual ~VideoDecoder() {};
michael@0 197 };
michael@0 198
michael@0 199 /**
michael@0 200 * MediaSessionConduit for video
michael@0 201 * Refer to the comments on MediaSessionConduit above for overall
michael@0 202 * information
michael@0 203 */
michael@0 204 class VideoSessionConduit : public MediaSessionConduit
michael@0 205 {
michael@0 206 public:
michael@0 207 /**
michael@0 208 * Factory function to create and initialize a Video Conduit Session
michael@0 209 * return: Concrete VideoSessionConduitObject or nullptr in the case
michael@0 210 * of failure
michael@0 211 */
michael@0 212 static RefPtr<VideoSessionConduit> Create(VideoSessionConduit *aOther);
michael@0 213
michael@0 214 enum FrameRequestType
michael@0 215 {
michael@0 216 FrameRequestNone,
michael@0 217 FrameRequestFir,
michael@0 218 FrameRequestPli,
michael@0 219 FrameRequestUnknown
michael@0 220 };
michael@0 221
michael@0 222 VideoSessionConduit() : mFrameRequestMethod(FrameRequestNone),
michael@0 223 mUsingNackBasic(false) {}
michael@0 224
michael@0 225 virtual ~VideoSessionConduit() {}
michael@0 226
michael@0 227 virtual Type type() const { return VIDEO; }
michael@0 228
michael@0 229 /**
michael@0 230 * Function to attach Renderer end-point of the Media-Video conduit.
michael@0 231 * @param aRenderer : Reference to the concrete Video renderer implementation
michael@0 232 * Note: Multiple invocations of this API shall remove an existing renderer
michael@0 233 * and attaches the new to the Conduit.
michael@0 234 */
michael@0 235 virtual MediaConduitErrorCode AttachRenderer(RefPtr<VideoRenderer> aRenderer) = 0;
michael@0 236 virtual void DetachRenderer() = 0;
michael@0 237
michael@0 238 /**
michael@0 239 * Function to deliver a capture video frame for encoding and transport
michael@0 240 * @param video_frame: pointer to captured video-frame.
michael@0 241 * @param video_frame_length: size of the frame
michael@0 242 * @param width, height: dimensions of the frame
michael@0 243 * @param video_type: Type of the video frame - I420, RAW
michael@0 244 * @param captured_time: timestamp when the frame was captured.
michael@0 245 * if 0 timestamp is automatcally generated
michael@0 246 * NOTE: ConfigureSendMediaCodec() MUST be called before this function can be invoked
michael@0 247 * This ensures the inserted video-frames can be transmitted by the conduit
michael@0 248 */
michael@0 249 virtual MediaConduitErrorCode SendVideoFrame(unsigned char* video_frame,
michael@0 250 unsigned int video_frame_length,
michael@0 251 unsigned short width,
michael@0 252 unsigned short height,
michael@0 253 VideoType video_type,
michael@0 254 uint64_t capture_time) = 0;
michael@0 255
michael@0 256 /**
michael@0 257 * Function to configure send codec for the video session
michael@0 258 * @param sendSessionConfig: CodecConfiguration
michael@0 259 * @result: On Success, the video engine is configured with passed in codec for send
michael@0 260 * On failure, video engine transmit functionality is disabled.
michael@0 261 * NOTE: This API can be invoked multiple time. Invoking this API may involve restarting
michael@0 262 * transmission sub-system on the engine
michael@0 263 *
michael@0 264 */
michael@0 265 virtual MediaConduitErrorCode ConfigureSendMediaCodec(const VideoCodecConfig* sendSessionConfig) = 0;
michael@0 266
michael@0 267 /**
michael@0 268 * Function to configurelist of receive codecs for the video session
michael@0 269 * @param sendSessionConfig: CodecConfiguration
michael@0 270 * NOTE: This API can be invoked multiple time. Invoking this API may involve restarting
michael@0 271 * reception sub-system on the engine
michael@0 272 *
michael@0 273 */
michael@0 274 virtual MediaConduitErrorCode ConfigureRecvMediaCodecs(
michael@0 275 const std::vector<VideoCodecConfig* >& recvCodecConfigList) = 0;
michael@0 276
michael@0 277 /**
michael@0 278 * Set an external encoder
michael@0 279 * @param encoder
michael@0 280 * @result: on success, we will use the specified encoder
michael@0 281 */
michael@0 282 virtual MediaConduitErrorCode SetExternalSendCodec(int pltype,
michael@0 283 VideoEncoder* encoder) = 0;
michael@0 284
michael@0 285 /**
michael@0 286 * Set an external decoder
michael@0 287 * @param decoder
michael@0 288 * @result: on success, we will use the specified decoder
michael@0 289 */
michael@0 290 virtual MediaConduitErrorCode SetExternalRecvCodec(int pltype,
michael@0 291 VideoDecoder* decoder) = 0;
michael@0 292
michael@0 293 /**
michael@0 294 * These methods allow unit tests to double-check that the
michael@0 295 * max-fs and max-fr related settings are as expected.
michael@0 296 */
michael@0 297 virtual unsigned short SendingWidth() = 0;
michael@0 298
michael@0 299 virtual unsigned short SendingHeight() = 0;
michael@0 300
michael@0 301 virtual unsigned int SendingMaxFs() = 0;
michael@0 302
michael@0 303 virtual unsigned int SendingMaxFr() = 0;
michael@0 304
michael@0 305 /**
michael@0 306 * These methods allow unit tests to double-check that the
michael@0 307 * rtcp-fb settings are as expected.
michael@0 308 */
michael@0 309 FrameRequestType FrameRequestMethod() const {
michael@0 310 return mFrameRequestMethod;
michael@0 311 }
michael@0 312
michael@0 313 bool UsingNackBasic() const {
michael@0 314 return mUsingNackBasic;
michael@0 315 }
michael@0 316
michael@0 317 protected:
michael@0 318 /* RTCP feedback settings, for unit testing purposes */
michael@0 319 FrameRequestType mFrameRequestMethod;
michael@0 320 bool mUsingNackBasic;
michael@0 321 };
michael@0 322
michael@0 323 /**
michael@0 324 * MediaSessionConduit for audio
michael@0 325 * Refer to the comments on MediaSessionConduit above for overall
michael@0 326 * information
michael@0 327 */
michael@0 328 class AudioSessionConduit : public MediaSessionConduit
michael@0 329 {
michael@0 330 public:
michael@0 331
michael@0 332 /**
michael@0 333 * Factory function to create and initialize an Audio Conduit Session
michael@0 334 * return: Concrete AudioSessionConduitObject or nullptr in the case
michael@0 335 * of failure
michael@0 336 */
michael@0 337 static mozilla::RefPtr<AudioSessionConduit> Create(AudioSessionConduit *aOther);
michael@0 338
michael@0 339 virtual ~AudioSessionConduit() {}
michael@0 340
michael@0 341 virtual Type type() const { return AUDIO; }
michael@0 342
michael@0 343
michael@0 344 /**
michael@0 345 * Function to deliver externally captured audio sample for encoding and transport
michael@0 346 * @param audioData [in]: Pointer to array containing a frame of audio
michael@0 347 * @param lengthSamples [in]: Length of audio frame in samples in multiple of 10 milliseconds
michael@0 348 * Ex: Frame length is 160, 320, 440 for 16, 32, 44 kHz sampling rates
michael@0 349 respectively.
michael@0 350 audioData[] is lengthSamples in size
michael@0 351 say, for 16kz sampling rate, audioData[] should contain 160
michael@0 352 samples of 16-bits each for a 10m audio frame.
michael@0 353 * @param samplingFreqHz [in]: Frequency/rate of the sampling in Hz ( 16000, 32000 ...)
michael@0 354 * @param capture_delay [in]: Approx Delay from recording until it is delivered to VoiceEngine
michael@0 355 in milliseconds.
michael@0 356 * NOTE: ConfigureSendMediaCodec() SHOULD be called before this function can be invoked
michael@0 357 * This ensures the inserted audio-samples can be transmitted by the conduit
michael@0 358 *
michael@0 359 */
michael@0 360 virtual MediaConduitErrorCode SendAudioFrame(const int16_t audioData[],
michael@0 361 int32_t lengthSamples,
michael@0 362 int32_t samplingFreqHz,
michael@0 363 int32_t capture_delay) = 0;
michael@0 364
michael@0 365 /**
michael@0 366 * Function to grab a decoded audio-sample from the media engine for rendering
michael@0 367 * / playoutof length 10 milliseconds.
michael@0 368 *
michael@0 369 * @param speechData [in]: Pointer to a array to which a 10ms frame of audio will be copied
michael@0 370 * @param samplingFreqHz [in]: Frequency of the sampling for playback in Hertz (16000, 32000,..)
michael@0 371 * @param capture_delay [in]: Estimated Time between reading of the samples to rendering/playback
michael@0 372 * @param lengthSamples [out]: Will contain length of the audio frame in samples at return.
michael@0 373 Ex: A value of 160 implies 160 samples each of 16-bits was copied
michael@0 374 into speechData
michael@0 375 * NOTE: This function should be invoked every 10 milliseconds for the best
michael@0 376 * peformance
michael@0 377 * NOTE: ConfigureRecvMediaCodec() SHOULD be called before this function can be invoked
michael@0 378 * This ensures the decoded samples are ready for reading.
michael@0 379 *
michael@0 380 */
michael@0 381 virtual MediaConduitErrorCode GetAudioFrame(int16_t speechData[],
michael@0 382 int32_t samplingFreqHz,
michael@0 383 int32_t capture_delay,
michael@0 384 int& lengthSamples) = 0;
michael@0 385
michael@0 386 /**
michael@0 387 * Function to configure send codec for the audio session
michael@0 388 * @param sendSessionConfig: CodecConfiguration
michael@0 389 * NOTE: See VideoConduit for more information
michael@0 390 */
michael@0 391
michael@0 392 virtual MediaConduitErrorCode ConfigureSendMediaCodec(const AudioCodecConfig* sendCodecConfig) = 0;
michael@0 393
michael@0 394 /**
michael@0 395 * Function to configure list of receive codecs for the audio session
michael@0 396 * @param sendSessionConfig: CodecConfiguration
michael@0 397 * NOTE: See VideoConduit for more information
michael@0 398 */
michael@0 399 virtual MediaConduitErrorCode ConfigureRecvMediaCodecs(
michael@0 400 const std::vector<AudioCodecConfig* >& recvCodecConfigList) = 0;
michael@0 401 /**
michael@0 402 * Function to enable the audio level extension
michael@0 403 * @param enabled: enable extension
michael@0 404 * @param id: id to be used for this rtp header extension
michael@0 405 * NOTE: See AudioConduit for more information
michael@0 406 */
michael@0 407 virtual MediaConduitErrorCode EnableAudioLevelExtension(bool enabled, uint8_t id) = 0;
michael@0 408
michael@0 409 };
michael@0 410 }
michael@0 411 #endif

mercurial