diff --git a/media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h b/media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h index 2db6a15e88c..6a7b6e6524b 100755 --- a/media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h +++ b/media/webrtc/signaling/src/media-conduit/MediaConduitInterface.h @@ -15,6 +15,8 @@ #include "ImageContainer.h" +#include "webrtc/common_types.h" + #include namespace mozilla { @@ -298,6 +300,7 @@ public: VideoType video_type, uint64_t capture_time) = 0; + virtual MediaConduitErrorCode ConfigureCodecMode(webrtc::VideoCodecMode) = 0; /** * Function to configure send codec for the video session * @param sendSessionConfig: CodecConfiguration diff --git a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp index 2cb65624586..5b76307472b 100755 --- a/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp +++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.cpp @@ -81,7 +81,8 @@ WebrtcVideoConduit::WebrtcVideoConduit(): mVideoLatencyAvg(0), mMinBitrate(200), mStartBitrate(300), - mMaxBitrate(2000) + mMaxBitrate(2000), + mCodecMode(webrtc::kRealtimeVideo) { } @@ -538,7 +539,13 @@ WebrtcVideoConduit::SetReceiverTransport(mozilla::RefPtr aTr mReceiverTransport = aTransport; return kMediaConduitNoError; } - +MediaConduitErrorCode +WebrtcVideoConduit::ConfigureCodecMode(webrtc::VideoCodecMode mode) +{ + CSFLogDebug(logTag, "%s ", __FUNCTION__); + mCodecMode = mode; + return kMediaConduitNoError; +} /** * Note: Setting the send-codec on the Video Engine will restart the encoder, * sets up new SSRC and reset RTP_RTCP module with the new codec setting. @@ -590,7 +597,7 @@ WebrtcVideoConduit::ConfigureSendMediaCodec(const VideoCodecConfig* codecConfig) #endif video_codec.qpMax = 56; video_codec.numberOfSimulcastStreams = 1; - video_codec.mode = webrtc::kRealtimeVideo; + video_codec.mode = mCodecMode; codecFound = true; } else { diff --git a/media/webrtc/signaling/src/media-conduit/VideoConduit.h b/media/webrtc/signaling/src/media-conduit/VideoConduit.h index 073f4b444e3..c17cc333d55 100755 --- a/media/webrtc/signaling/src/media-conduit/VideoConduit.h +++ b/media/webrtc/signaling/src/media-conduit/VideoConduit.h @@ -99,6 +99,11 @@ public: virtual MediaConduitErrorCode StopReceiving() MOZ_OVERRIDE; virtual MediaConduitErrorCode StartReceiving() MOZ_OVERRIDE; + /** + * Function to configure sending codec mode for different content + */ + virtual MediaConduitErrorCode ConfigureCodecMode(webrtc::VideoCodecMode) MOZ_OVERRIDE; + /** * Function to configure send codec for the video session * @param sendSessionConfig: CodecConfiguration @@ -354,6 +359,7 @@ private: nsAutoPtr mVideoCodecStat; nsAutoPtr mLoadManager; + webrtc::VideoCodecMode mCodecMode; }; } // end namespace diff --git a/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp index 51a6eb2b389..51e9615a8bd 100644 --- a/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp +++ b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.cpp @@ -20,6 +20,7 @@ #include "nsIPrincipal.h" #include "nsIDocument.h" #include "mozilla/Preferences.h" +#include "MediaEngine.h" #endif #include "GmpVideoCodec.h" @@ -753,6 +754,11 @@ MediaPipelineFactory::GetOrCreateVideoConduit( if (NS_FAILED(rv)) return rv; + rv = ConfigureVideoCodecMode(aTrack,*conduit); + if (NS_FAILED(rv)) { + return rv; + } + // Take possession of this pointer ScopedDeletePtr config(configRaw); @@ -774,6 +780,61 @@ MediaPipelineFactory::GetOrCreateVideoConduit( return NS_OK; } +nsresult +MediaPipelineFactory::ConfigureVideoCodecMode(const JsepTrack& aTrack, + VideoSessionConduit& aConduit) +{ +#ifdef MOZILLA_INTERNAL_API + nsRefPtr stream = + mPCMedia->GetLocalStreamById(aTrack.GetStreamId()); + + //get video track + nsRefPtr videotrack = + stream->GetVideoTrackByTrackId(aTrack.GetTrackId()); + + if (!videotrack) { + MOZ_MTLOG(ML_ERROR, "video track not available"); + return NS_ERROR_FAILURE; + } + + //get video source type + nsRefPtr mediastream = + mPCMedia->GetLocalStreamById(aTrack.GetStreamId())->GetMediaStream(); + + DOMLocalMediaStream* domLocalStream = mediastream->AsDOMLocalMediaStream(); + if (!domLocalStream) { + return NS_OK; + } + + MediaEngineSource *engine = + domLocalStream->GetMediaEngine(videotrack->GetTrackID()); + + dom::MediaSourceEnum source = engine->GetMediaSource(); + webrtc::VideoCodecMode mode = webrtc::kRealtimeVideo; + switch (source) { + case dom::MediaSourceEnum::Browser: + case dom::MediaSourceEnum::Screen: + case dom::MediaSourceEnum::Application: + case dom::MediaSourceEnum::Window: + mode = webrtc::kScreensharing; + break; + + case dom::MediaSourceEnum::Camera: + default: + mode = webrtc::kRealtimeVideo; + break; + } + + auto error = aConduit.ConfigureCodecMode(mode); + if (error) { + MOZ_MTLOG(ML_ERROR, "ConfigureCodecMode failed: " << error); + return NS_ERROR_FAILURE; + } + +#endif + return NS_OK; +} + /* * Add external H.264 video codec. */ diff --git a/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.h b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.h index b0668c67ce9..972c4368a69 100644 --- a/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.h +++ b/media/webrtc/signaling/src/peerconnection/MediaPipelineFactory.h @@ -67,6 +67,9 @@ private: RefPtr* aRtcpOut, nsAutoPtr* aFilterOut); + nsresult ConfigureVideoCodecMode(const JsepTrack& aTrack, + VideoSessionConduit& aConduit); + private: // Not owned, and assumed to exist as long as the factory. // The factory is a transient object, so this is fairly easy. diff --git a/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp b/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp index ce70a483885..c8ed6b771a1 100644 --- a/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp @@ -35,6 +35,8 @@ #include "nsIScriptGlobalObject.h" #include "mozilla/Preferences.h" #include "mozilla/dom/RTCStatsReportBinding.h" +#include "MediaStreamTrack.h" +#include "VideoStreamTrack.h" #endif @@ -1111,6 +1113,26 @@ SourceStreamInfo::AnyCodecHasPluginID(uint64_t aPluginID) return false; } +#ifdef MOZILLA_INTERNAL_API +nsRefPtr +SourceStreamInfo::GetVideoTrackByTrackId(const std::string& trackId) +{ + nsTArray> videoTracks; + + mMediaStream->GetVideoTracks(videoTracks); + + for (size_t i = 0; i < videoTracks.Length(); ++i) { + nsString aTrackId; + videoTracks[i]->GetId(aTrackId); + if (aTrackId.EqualsIgnoreCase(trackId.c_str())) { + return videoTracks[i]; + } + } + + return nullptr; +} +#endif + nsresult SourceStreamInfo::StorePipeline( const std::string& trackId, diff --git a/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.h b/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.h index 08b358d2131..8dc06848931 100644 --- a/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.h +++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.h @@ -32,6 +32,7 @@ #include "VideoUtils.h" #include "ImageLayers.h" #include "VideoSegment.h" +#include "MediaStreamTrack.h" #endif class nsIPrincipal; @@ -104,6 +105,9 @@ public: void DetachTransport_s(); void DetachMedia_m(); bool AnyCodecHasPluginID(uint64_t aPluginID); +#ifdef MOZILLA_INTERNAL_API + nsRefPtr GetVideoTrackByTrackId(const std::string& trackId); +#endif protected: nsRefPtr mMediaStream; PeerConnectionMedia *mParent;