audio_rtp_receiver.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright 2019 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. #ifndef PC_AUDIO_RTP_RECEIVER_H_
  11. #define PC_AUDIO_RTP_RECEIVER_H_
  12. #include <stdint.h>
  13. #include <string>
  14. #include <vector>
  15. #include "absl/types/optional.h"
  16. #include "api/crypto/frame_decryptor_interface.h"
  17. #include "api/media_stream_interface.h"
  18. #include "api/media_stream_track_proxy.h"
  19. #include "api/media_types.h"
  20. #include "api/rtp_parameters.h"
  21. #include "api/scoped_refptr.h"
  22. #include "media/base/media_channel.h"
  23. #include "pc/audio_track.h"
  24. #include "pc/jitter_buffer_delay_interface.h"
  25. #include "pc/remote_audio_source.h"
  26. #include "pc/rtp_receiver.h"
  27. #include "rtc_base/ref_counted_object.h"
  28. #include "rtc_base/thread.h"
  29. namespace webrtc {
  30. class AudioRtpReceiver : public ObserverInterface,
  31. public AudioSourceInterface::AudioObserver,
  32. public rtc::RefCountedObject<RtpReceiverInternal> {
  33. public:
  34. AudioRtpReceiver(rtc::Thread* worker_thread,
  35. std::string receiver_id,
  36. std::vector<std::string> stream_ids);
  37. // TODO(https://crbug.com/webrtc/9480): Remove this when streams() is removed.
  38. AudioRtpReceiver(
  39. rtc::Thread* worker_thread,
  40. const std::string& receiver_id,
  41. const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams);
  42. virtual ~AudioRtpReceiver();
  43. // ObserverInterface implementation
  44. void OnChanged() override;
  45. // AudioSourceInterface::AudioObserver implementation
  46. void OnSetVolume(double volume) override;
  47. rtc::scoped_refptr<AudioTrackInterface> audio_track() const {
  48. return track_.get();
  49. }
  50. // RtpReceiverInterface implementation
  51. rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
  52. return track_.get();
  53. }
  54. rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const override {
  55. return dtls_transport_;
  56. }
  57. std::vector<std::string> stream_ids() const override;
  58. std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams()
  59. const override {
  60. return streams_;
  61. }
  62. cricket::MediaType media_type() const override {
  63. return cricket::MEDIA_TYPE_AUDIO;
  64. }
  65. std::string id() const override { return id_; }
  66. RtpParameters GetParameters() const override;
  67. void SetFrameDecryptor(
  68. rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) override;
  69. rtc::scoped_refptr<FrameDecryptorInterface> GetFrameDecryptor()
  70. const override;
  71. // RtpReceiverInternal implementation.
  72. void Stop() override;
  73. void StopAndEndTrack() override;
  74. void SetupMediaChannel(uint32_t ssrc) override;
  75. void SetupUnsignaledMediaChannel() override;
  76. uint32_t ssrc() const override { return ssrc_.value_or(0); }
  77. void NotifyFirstPacketReceived() override;
  78. void set_stream_ids(std::vector<std::string> stream_ids) override;
  79. void set_transport(
  80. rtc::scoped_refptr<DtlsTransportInterface> dtls_transport) override {
  81. dtls_transport_ = dtls_transport;
  82. }
  83. void SetStreams(const std::vector<rtc::scoped_refptr<MediaStreamInterface>>&
  84. streams) override;
  85. void SetObserver(RtpReceiverObserverInterface* observer) override;
  86. void SetJitterBufferMinimumDelay(
  87. absl::optional<double> delay_seconds) override;
  88. void SetMediaChannel(cricket::MediaChannel* media_channel) override;
  89. std::vector<RtpSource> GetSources() const override;
  90. int AttachmentId() const override { return attachment_id_; }
  91. void SetDepacketizerToDecoderFrameTransformer(
  92. rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer)
  93. override;
  94. private:
  95. void RestartMediaChannel(absl::optional<uint32_t> ssrc);
  96. void Reconfigure();
  97. bool SetOutputVolume(double volume);
  98. rtc::Thread* const worker_thread_;
  99. const std::string id_;
  100. const rtc::scoped_refptr<RemoteAudioSource> source_;
  101. const rtc::scoped_refptr<AudioTrackProxyWithInternal<AudioTrack>> track_;
  102. cricket::VoiceMediaChannel* media_channel_ = nullptr;
  103. absl::optional<uint32_t> ssrc_;
  104. std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_;
  105. bool cached_track_enabled_;
  106. double cached_volume_ = 1;
  107. bool stopped_ = true;
  108. RtpReceiverObserverInterface* observer_ = nullptr;
  109. bool received_first_packet_ = false;
  110. int attachment_id_ = 0;
  111. rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor_;
  112. rtc::scoped_refptr<DtlsTransportInterface> dtls_transport_;
  113. // Allows to thread safely change playout delay. Handles caching cases if
  114. // |SetJitterBufferMinimumDelay| is called before start.
  115. rtc::scoped_refptr<JitterBufferDelayInterface> delay_;
  116. rtc::scoped_refptr<FrameTransformerInterface> frame_transformer_
  117. RTC_GUARDED_BY(worker_thread_);
  118. };
  119. } // namespace webrtc
  120. #endif // PC_AUDIO_RTP_RECEIVER_H_