@@ -496,15 +496,6 @@ static bool SubOptionAllowed(
496
496
// specifies codec, though signaling allows specifying sample rate and channel
497
497
// number.
498
498
499
- // If rid is specified, search in publication_settings for rid;
500
- if (subscribe_options.video .rid != " " ) {
501
- for (auto video_setting : publication_settings.video ) {
502
- if (video_setting.rid == subscribe_options.video .rid )
503
- return true ;
504
- }
505
- return false ;
506
- }
507
-
508
499
bool resolution_supported = (subscribe_options.video .resolution .width == 0 &&
509
500
subscribe_options.video .resolution .height == 0 );
510
501
bool frame_rate_supported = (subscribe_options.video .frameRate == 0 );
@@ -647,19 +638,7 @@ void ConferencePeerConnectionChannel::Subscribe(
647
638
video_options->get_map ()[" mid" ] = sio::string_message::create (" 1" );
648
639
}
649
640
auto publication_settings = stream->Settings ();
650
- if (subscribe_options.video .rid != " " ) {
651
- for (auto video_setting : publication_settings.video ) {
652
- if (video_setting.rid == subscribe_options.video .rid ) {
653
- std::string track_id = video_setting.track_id ;
654
- video_options->get_map ()[" from" ] =
655
- sio::string_message::create (track_id);
656
- break ;
657
- }
658
- }
659
- } else {
660
- video_options->get_map ()[" from" ] =
661
- sio::string_message::create (stream->Id ());
662
- }
641
+ video_options->get_map ()[" from" ] = sio::string_message::create (stream->Id ());
663
642
sio::message::ptr video_spec = sio::object_message::create ();
664
643
sio::message::ptr resolution_options = sio::object_message::create ();
665
644
if (subscribe_options.video .resolution .width != 0 &&
@@ -691,10 +670,121 @@ void ConferencePeerConnectionChannel::Subscribe(
691
670
sio::int_message::create (subscribe_options.video .frameRate );
692
671
}
693
672
video_options->get_map ()[" parameters" ] = video_spec;
673
+ tracks_options->get_vector ().push_back (video_options);
674
+ }
675
+
676
+ media_options->get_map ()[" tracks" ] = tracks_options;
677
+ sio_options->get_map ()[" media" ] = media_options;
678
+ sio::message::ptr transport_ptr = sio::object_message::create ();
679
+ transport_ptr->get_map ()[" type" ] = sio::string_message::create (" webrtc" );
680
+ sio_options->get_map ()[" transport" ] = transport_ptr;
681
+
682
+ signaling_channel_->SendInitializationMessage (
683
+ sio_options, " " , stream->Id (),
684
+ [this ](std::string session_id, std::string transport_id) {
685
+ // Pre-set the session's ID.
686
+ SetSessionId (session_id);
687
+ CreateOffer ();
688
+ },
689
+ on_failure); // TODO: on_failure
690
+ subscribed_stream_ = stream;
691
+ }
692
+
693
+ void ConferencePeerConnectionChannel::Subscribe (
694
+ std::shared_ptr<RemoteStream> stream,
695
+ const SubscribeOptions2& subscribe_options,
696
+ std::function<void (std::string)> on_success,
697
+ std::function<void(std::unique_ptr<Exception>)> on_failure) {
698
+ if (!CheckNullPointer ((uintptr_t )stream.get (), on_failure)) {
699
+ RTC_LOG (LS_ERROR) << " Remote stream cannot be nullptr." ;
700
+ return ;
701
+ }
702
+ if (subscribe_success_callback_) {
703
+ if (on_failure) {
704
+ event_queue_->PostTask ([on_failure]() {
705
+ std::unique_ptr<Exception> e (new Exception (
706
+ ExceptionType::kConferenceUnknown , " Subscribing this stream." ));
707
+ on_failure (std::move (e));
708
+ });
709
+ }
710
+ }
711
+ if ((subscribe_options.video .rid == " " ) &&
712
+ (subscribe_options.video .spatialLayerId == -1 ) &&
713
+ (subscribe_options.video .temporalLayerId == -1 )) {
714
+ if (on_failure) {
715
+ event_queue_->PostTask ([on_failure]() {
716
+ std::unique_ptr<Exception> e (new Exception (
717
+ ExceptionType::kConferenceUnknown ,
718
+ " Either rid/spatialLayer/temporalLayer needs to be set for subscribing." ));
719
+ on_failure (std::move (e));
720
+ });
721
+ }
722
+ }
723
+ subscribe_success_callback_ = on_success;
724
+ failure_callback_ = on_failure;
725
+ int audio_track_count = 0 , video_track_count = 0 ;
726
+ if (stream->has_audio_ && !subscribe_options.audio .disabled ) {
727
+ webrtc::RtpTransceiverInit transceiver_init;
728
+ transceiver_init.direction = webrtc::RtpTransceiverDirection::kRecvOnly ;
729
+ AddTransceiver (cricket::MediaType::MEDIA_TYPE_AUDIO, transceiver_init);
730
+ audio_track_count = 1 ;
731
+ }
732
+ if (stream->has_video_ ) {
733
+ webrtc::RtpTransceiverInit transceiver_init;
734
+ transceiver_init.direction = webrtc::RtpTransceiverDirection::kRecvOnly ;
735
+ AddTransceiver (cricket::MediaType::MEDIA_TYPE_VIDEO, transceiver_init);
736
+ video_track_count = 1 ;
737
+ }
738
+ sio::message::ptr sio_options = sio::object_message::create ();
739
+ sio::message::ptr media_options = sio::object_message::create ();
740
+ sio::message::ptr tracks_options = sio::array_message::create ();
741
+ if (audio_track_count > 0 ) {
742
+ sio::message::ptr audio_options = sio::object_message::create ();
743
+ audio_options->get_map ()[" type" ] = sio::string_message::create (" audio" );
744
+ audio_options->get_map ()[" mid" ] = sio::string_message::create (" 0" );
745
+ audio_options->get_map ()[" from" ] =
746
+ sio::string_message::create (stream->Id ());
747
+ tracks_options->get_vector ().push_back (audio_options);
748
+ }
749
+ if (video_track_count > 0 ) {
750
+ sio::message::ptr video_options = sio::object_message::create ();
751
+ video_options->get_map ()[" type" ] = sio::string_message::create (" video" );
752
+ if (audio_track_count == 0 ) {
753
+ video_options->get_map ()[" mid" ] = sio::string_message::create (" 0" );
754
+ } else {
755
+ video_options->get_map ()[" mid" ] = sio::string_message::create (" 1" );
756
+ }
757
+ auto publication_settings = stream->Settings ();
758
+ if (subscribe_options.video .rid != " " ) {
759
+ for (auto video_setting : publication_settings.video ) {
760
+ if (video_setting.rid == subscribe_options.video .rid ) {
761
+ std::string track_id = video_setting.track_id ;
762
+ video_options->get_map ()[" from" ] =
763
+ sio::string_message::create (track_id);
764
+ break ;
765
+ }
766
+ }
767
+ } else {
768
+ video_options->get_map ()[" from" ] =
769
+ sio::string_message::create (stream->Id ());
770
+ }
771
+ sio::message::ptr layer_spec = sio::object_message::create ();
772
+ if (subscribe_options.video .spatialLayerId >= 0 ) {
773
+ sio::message::ptr spatial_layer_options =
774
+ sio::int_message::create (subscribe_options.video .spatialLayerId );
775
+ layer_spec->get_map ()[" spatialLayer" ] = spatial_layer_options;
776
+ }
777
+ if (subscribe_options.video .temporalLayerId >= 0 ) {
778
+ sio::message::ptr temporal_layer_options =
779
+ sio::int_message::create (subscribe_options.video .temporalLayerId );
780
+ layer_spec->get_map ()[" temporallLayer" ] = temporal_layer_options;
781
+ }
694
782
if (subscribe_options.video .rid != " " ) {
695
- video_options-> get_map ()[ " simulcastRid " ] =
783
+ sio::message::ptr rid_options =
696
784
sio::string_message::create (subscribe_options.video .rid );
785
+ layer_spec->get_map ()[" rid" ] = rid_options;
697
786
}
787
+ video_options->get_map ()[" parameters" ] = layer_spec;
698
788
tracks_options->get_vector ().push_back (video_options);
699
789
}
700
790
0 commit comments