@@ -538,10 +538,8 @@ void TraceBasedDeliveryFilter::ProceedToNextSlot() {
538
538
PacketSender::PacketSender (PacketProcessorListener* listener)
539
539
: PacketProcessor(listener, true ) {}
540
540
541
- PacketSender::PacketSender (PacketProcessorListener* listener,
542
- const FlowIds& flow_ids)
543
- : PacketProcessor(listener, flow_ids, true ) {
544
-
541
+ PacketSender::PacketSender (PacketProcessorListener* listener, int flow_id)
542
+ : PacketProcessor(listener, FlowIds(1 , flow_id), true ) {
545
543
}
546
544
547
545
VideoSender::VideoSender (int flow_id,
@@ -550,7 +548,7 @@ VideoSender::VideoSender(int flow_id,
550
548
uint32_t kbps,
551
549
uint32_t ssrc,
552
550
int64_t first_frame_offset_ms)
553
- : PacketSender(listener, FlowIds( 1 , flow_id) ),
551
+ : PacketSender(listener, flow_id),
554
552
kMaxPayloadSizeBytes (1200 ),
555
553
kTimestampBase(0xff80ff00ul ),
556
554
frame_period_ms_(1000.0 / fps),
@@ -677,17 +675,73 @@ uint32_t PeriodicKeyFrameSender::NextPacketSize(uint32_t frame_size,
677
675
return std::min (avg_size, remaining_payload);
678
676
}
679
677
678
+ RegularVideoSender::RegularVideoSender (PacketProcessorListener* listener,
679
+ uint32_t kbps,
680
+ AdaptiveVideoSender* source)
681
+ // It is important that the first_frame_offset and the initial time of
682
+ // clock_ are both zero, otherwise we can't have absolute time in this
683
+ // class.
684
+ : PacketSender(listener, source->flow_ids ()[0]),
685
+ clock_(0 ),
686
+ start_of_run_ms_(0 ),
687
+ bitrate_controller_(BitrateController::CreateBitrateController(&clock_,
688
+ false )),
689
+ feedback_observer_(bitrate_controller_->CreateRtcpBandwidthObserver ()),
690
+ source_(source),
691
+ modules_() {
692
+ const int kMinBitrateBps = 10000 ;
693
+ const int kMaxBitrateBps = 20000000 ;
694
+ bitrate_controller_->SetBitrateObserver (this , 1000 * kbps, kMinBitrateBps ,
695
+ kMaxBitrateBps );
696
+ modules_.push_back (bitrate_controller_.get ());
697
+ }
698
+
699
+ RegularVideoSender::~RegularVideoSender () {
700
+ }
701
+
702
+ void RegularVideoSender::GiveFeedback (const Feedback& feedback) {
703
+ feedback_observer_->OnReceivedEstimatedBitrate (feedback.estimated_bps );
704
+ ReportBlockList report_blocks;
705
+ report_blocks.push_back (feedback.report_block );
706
+ feedback_observer_->OnReceivedRtcpReceiverReport (report_blocks, 0 ,
707
+ clock_.TimeInMilliseconds ());
708
+ bitrate_controller_->Process ();
709
+ }
710
+
711
+ void RegularVideoSender::RunFor (int64_t time_ms, Packets* in_out) {
712
+ start_of_run_ms_ = clock_.TimeInMilliseconds ();
713
+ source_->RunFor (time_ms, in_out);
714
+ clock_.AdvanceTimeMilliseconds (time_ms);
715
+ }
716
+
717
+ void RegularVideoSender::OnNetworkChanged (uint32_t target_bitrate_bps,
718
+ uint8_t fraction_lost,
719
+ int64_t rtt) {
720
+ PacketSender::Feedback feedback;
721
+ feedback.estimated_bps = target_bitrate_bps;
722
+ source_->GiveFeedback (feedback);
723
+ std::stringstream ss;
724
+ ss << " SendEstimate_" << flow_ids ()[0 ] << " #1" ;
725
+ BWE_TEST_LOGGING_PLOT (ss.str (), clock_.TimeInMilliseconds (),
726
+ target_bitrate_bps / 1000 );
727
+ }
728
+
680
729
PacedVideoSender::PacedVideoSender (PacketProcessorListener* listener,
681
730
uint32_t kbps,
682
731
AdaptiveVideoSender* source)
683
732
// It is important that the first_frame_offset and the initial time of
684
733
// clock_ are both zero, otherwise we can't have absolute time in this
685
734
// class.
686
- : PacketSender(listener, source->flow_ids ()),
687
- clock_(0 ),
688
- start_of_run_ms_(0 ),
689
- pacer_(&clock_, this , kbps, PacedSender::kDefaultPaceMultiplier * kbps, 0 ),
690
- source_(source) {
735
+ : RegularVideoSender(listener, kbps, source),
736
+ pacer_(&clock_,
737
+ this ,
738
+ kbps,
739
+ PacedSender::kDefaultPaceMultiplier * kbps,
740
+ 0 ) {
741
+ modules_.push_back (&pacer_);
742
+ }
743
+
744
+ PacedVideoSender::~PacedVideoSender () {
691
745
}
692
746
693
747
void PacedVideoSender::RunFor (int64_t time_ms, Packets* in_out) {
@@ -698,18 +752,18 @@ void PacedVideoSender::RunFor(int64_t time_ms, Packets* in_out) {
698
752
int64_t end_time_ms = clock_.TimeInMilliseconds () + time_ms;
699
753
Packets::iterator it = generated_packets.begin ();
700
754
while (clock_.TimeInMilliseconds () <= end_time_ms) {
701
- int64_t time_until_process_ms = pacer_.TimeUntilNextProcess ();
702
- if (time_until_process_ms < 0 )
703
- time_until_process_ms = 0 ;
755
+ int64_t time_until_process_ms = TimeUntilNextProcess (modules_);
756
+
704
757
int time_until_packet_ms = time_ms;
705
758
if (it != generated_packets.end ())
706
759
time_until_packet_ms =
707
760
(it->send_time_us () + 500 ) / 1000 - clock_.TimeInMilliseconds ();
708
761
assert (time_until_packet_ms >= 0 );
762
+
709
763
int time_until_next_event_ms = time_until_packet_ms;
710
- if (time_until_process_ms < time_until_packet_ms &&
711
- pacer_.QueueSizePackets () > 0 )
764
+ if (time_until_process_ms < time_until_packet_ms) {
712
765
time_until_next_event_ms = time_until_process_ms;
766
+ }
713
767
714
768
if (clock_.TimeInMilliseconds () + time_until_next_event_ms > end_time_ms) {
715
769
clock_.AdvanceTimeMilliseconds (end_time_ms - clock_.TimeInMilliseconds ());
@@ -718,7 +772,7 @@ void PacedVideoSender::RunFor(int64_t time_ms, Packets* in_out) {
718
772
clock_.AdvanceTimeMilliseconds (time_until_next_event_ms);
719
773
if (time_until_process_ms < time_until_packet_ms) {
720
774
// Time to process.
721
- pacer_. Process ( );
775
+ CallProcess (modules_ );
722
776
} else {
723
777
// Time to send next packet to pacer.
724
778
pacer_.SendPacket (PacedSender::kNormalPriority ,
@@ -738,6 +792,27 @@ void PacedVideoSender::RunFor(int64_t time_ms, Packets* in_out) {
738
792
QueuePackets (in_out, end_time_ms * 1000 );
739
793
}
740
794
795
+ int64_t PacedVideoSender::TimeUntilNextProcess (
796
+ const std::list<Module*>& modules) {
797
+ int64_t time_until_next_process_ms = 10 ;
798
+ for (auto * module : modules) {
799
+ int64_t next_process_ms = module->TimeUntilNextProcess ();
800
+ if (next_process_ms < time_until_next_process_ms)
801
+ time_until_next_process_ms = next_process_ms;
802
+ }
803
+ if (time_until_next_process_ms < 0 )
804
+ time_until_next_process_ms = 0 ;
805
+ return time_until_next_process_ms;
806
+ }
807
+
808
+ void PacedVideoSender::CallProcess (const std::list<Module*>& modules) {
809
+ for (auto * module : modules) {
810
+ if (module->TimeUntilNextProcess () <= 0 ) {
811
+ module->Process ();
812
+ }
813
+ }
814
+ }
815
+
741
816
void PacedVideoSender::QueuePackets (Packets* batch,
742
817
int64_t end_of_batch_time_us) {
743
818
queue_.merge (*batch);
@@ -755,14 +830,6 @@ void PacedVideoSender::QueuePackets(Packets* batch,
755
830
batch->merge (to_transfer);
756
831
}
757
832
758
- void PacedVideoSender::GiveFeedback (const PacketSender::Feedback& feedback) {
759
- source_->GiveFeedback (feedback);
760
- pacer_.UpdateBitrate (
761
- feedback.estimated_bps / 1000 ,
762
- PacedSender::kDefaultPaceMultiplier * feedback.estimated_bps / 1000 ,
763
- 0 );
764
- }
765
-
766
833
bool PacedVideoSender::TimeToSendPacket (uint32_t ssrc,
767
834
uint16_t sequence_number,
768
835
int64_t capture_time_ms,
@@ -786,6 +853,15 @@ bool PacedVideoSender::TimeToSendPacket(uint32_t ssrc,
786
853
size_t PacedVideoSender::TimeToSendPadding (size_t bytes) {
787
854
return 0 ;
788
855
}
856
+
857
+ void PacedVideoSender::OnNetworkChanged (uint32_t target_bitrate_bps,
858
+ uint8_t fraction_lost,
859
+ int64_t rtt) {
860
+ RegularVideoSender::OnNetworkChanged (target_bitrate_bps, fraction_lost, rtt);
861
+ pacer_.UpdateBitrate (
862
+ target_bitrate_bps / 1000 ,
863
+ PacedSender::kDefaultPaceMultiplier * target_bitrate_bps / 1000 , 0 );
864
+ }
789
865
} // namespace bwe
790
866
} // namespace testing
791
867
} // namespace webrtc
0 commit comments