You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "call/rtp_stream_receiver_controller.h"
  11. #include <memory>
  12. #include "rtc_base/logging.h"
  13. namespace webrtc {
  14. RtpStreamReceiverController::Receiver::Receiver(
  15. RtpStreamReceiverController* controller,
  16. uint32_t ssrc,
  17. RtpPacketSinkInterface* sink)
  18. : controller_(controller), sink_(sink) {
  19. const bool sink_added = controller_->AddSink(ssrc, sink_);
  20. if (!sink_added) {
  21. RTC_LOG(LS_ERROR)
  22. << "RtpStreamReceiverController::Receiver::Receiver: Sink "
  23. << "could not be added for SSRC=" << ssrc << ".";
  24. }
  25. }
  26. RtpStreamReceiverController::Receiver::~Receiver() {
  27. // Don't require return value > 0, since for RTX we currently may
  28. // have multiple Receiver objects with the same sink.
  29. // TODO(nisse): Consider adding a DCHECK when RtxReceiveStream is wired up.
  30. controller_->RemoveSink(sink_);
  31. }
  32. RtpStreamReceiverController::RtpStreamReceiverController() {
  33. // At this level the demuxer is only configured to demux by SSRC, so don't
  34. // worry about MIDs (MIDs are handled by upper layers).
  35. demuxer_.set_use_mid(false);
  36. }
  37. RtpStreamReceiverController::~RtpStreamReceiverController() = default;
  38. std::unique_ptr<RtpStreamReceiverInterface>
  39. RtpStreamReceiverController::CreateReceiver(uint32_t ssrc,
  40. RtpPacketSinkInterface* sink) {
  41. return std::make_unique<Receiver>(this, ssrc, sink);
  42. }
  43. bool RtpStreamReceiverController::OnRtpPacket(const RtpPacketReceived& packet) {
  44. rtc::CritScope cs(&lock_);
  45. return demuxer_.OnRtpPacket(packet);
  46. }
  47. bool RtpStreamReceiverController::AddSink(uint32_t ssrc,
  48. RtpPacketSinkInterface* sink) {
  49. rtc::CritScope cs(&lock_);
  50. return demuxer_.AddSink(ssrc, sink);
  51. }
  52. size_t RtpStreamReceiverController::RemoveSink(
  53. const RtpPacketSinkInterface* sink) {
  54. rtc::CritScope cs(&lock_);
  55. return demuxer_.RemoveSink(sink);
  56. }
  57. } // namespace webrtc