@@ -307,58 +307,57 @@ namespace WebRTC
307307 nullptr ,
308308 nullptr );
309309
310- mediaStream = peerConnectionFactory->CreateLocalMediaStream (" mediaStream" );
311310 }
312311
313312 Context::~Context ()
314313 {
315314 clients.clear ();
316315 peerConnectionFactory = nullptr ;
317- mediaStream = nullptr ;
316+
317+ videoTrack = nullptr ;
318+ audioTrack = nullptr ;
319+
320+ mediaStreamMap.clear ();
318321
319322 workerThread->Quit ();
320323 workerThread.reset ();
321324 signalingThread->Quit ();
322325 signalingThread.reset ();
323326 }
324327
325- webrtc::MediaStreamInterface* Context::CreateVideoStream (UnityFrameBuffer* frameBuffer, int32 width, int32 height )
328+ webrtc::MediaStreamInterface* Context::CreateMediaStream ( const std::string& stream_id )
326329 {
327- // //TODO: label and stream id should be maintained in some way for multi-stream
328- auto videoTrack = CreateVideoTrack (" video" , frameBuffer, width, height);
329- mediaStream->AddTrack (videoTrack);
330- return mediaStream.get ();
330+ if (mediaStreamMap.count (stream_id) == 0 )
331+ {
332+ mediaStreamMap[stream_id] = peerConnectionFactory->CreateLocalMediaStream (stream_id);
333+ }
334+
335+ return mediaStreamMap[stream_id];
331336 }
332337
333- rtc::scoped_refptr< webrtc::VideoTrackInterface> Context::CreateVideoTrack (const std::string& label, UnityFrameBuffer* frameBuffer, int32 width, int32 height)
338+ webrtc::MediaStreamTrackInterface* Context::CreateVideoTrack (const std::string& label, UnityFrameBuffer* frameBuffer, int32 width, int32 height)
334339 {
335340 nvVideoCapturerUnique = std::make_unique<NvVideoCapturer>();
336341 nvVideoCapturer = nvVideoCapturerUnique.get ();
337342 nvVideoCapturer->InitializeEncoder (width, height);
338343 pDummyVideoEncoderFactory->SetCapturer (nvVideoCapturer);
339- auto videoTrack = peerConnectionFactory->CreateVideoTrack (label, peerConnectionFactory->CreateVideoSource (std::move (nvVideoCapturerUnique)));
344+
345+ videoTrack = peerConnectionFactory->CreateVideoTrack (label, peerConnectionFactory->CreateVideoSource (std::move (nvVideoCapturerUnique)));
340346 nvVideoCapturer->unityRT = frameBuffer;
341347 nvVideoCapturer->StartEncoder ();
342348
343349 return videoTrack;
344350 }
345351
346- webrtc::MediaStreamInterface* Context::CreateAudioStream ()
347- {
348- auto audioTrack = CreateAudioTrack ();
349- mediaStream->AddTrack (audioTrack);
350- return mediaStream.get ();
351- }
352-
353- rtc::scoped_refptr<webrtc::AudioTrackInterface> Context::CreateAudioTrack ()
352+ webrtc::MediaStreamTrackInterface* Context::CreateAudioTrack (const std::string& label)
354353 {
355354 // avoid optimization specially for voice
356355 cricket::AudioOptions audioOptions;
357356 audioOptions.auto_gain_control = false ;
358357 audioOptions.noise_suppression = false ;
359358 audioOptions.highpass_filter = false ;
360359 // TODO: label and stream id should be maintained in some way for multi-stream
361- auto audioTrack = peerConnectionFactory->CreateAudioTrack (" audio " , peerConnectionFactory->CreateAudioSource (audioOptions));
360+ audioTrack = peerConnectionFactory->CreateAudioTrack (label , peerConnectionFactory->CreateAudioSource (audioOptions));
362361 return audioTrack;
363362 }
364363
0 commit comments