Ruslan Burakov | 501bfba | 2019-02-11 10:29:19 +0100 | [diff] [blame^] | 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 | |
| 11 | #ifndef PC_AUDIO_RTP_RECEIVER_H_ |
| 12 | #define PC_AUDIO_RTP_RECEIVER_H_ |
| 13 | |
| 14 | #include <stdint.h> |
| 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
| 18 | #include "absl/types/optional.h" |
| 19 | #include "api/crypto/frame_decryptor_interface.h" |
| 20 | #include "api/media_stream_interface.h" |
| 21 | #include "api/media_types.h" |
| 22 | #include "api/rtp_parameters.h" |
| 23 | #include "api/scoped_refptr.h" |
| 24 | #include "media/base/media_channel.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 | |
| 30 | namespace webrtc { |
| 31 | |
| 32 | class AudioRtpReceiver : public ObserverInterface, |
| 33 | public AudioSourceInterface::AudioObserver, |
| 34 | public rtc::RefCountedObject<RtpReceiverInternal> { |
| 35 | public: |
| 36 | AudioRtpReceiver(rtc::Thread* worker_thread, |
| 37 | std::string receiver_id, |
| 38 | std::vector<std::string> stream_ids); |
| 39 | // TODO(https://crbug.com/webrtc/9480): Remove this when streams() is removed. |
| 40 | AudioRtpReceiver( |
| 41 | rtc::Thread* worker_thread, |
| 42 | const std::string& receiver_id, |
| 43 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams); |
| 44 | virtual ~AudioRtpReceiver(); |
| 45 | |
| 46 | // ObserverInterface implementation |
| 47 | void OnChanged() override; |
| 48 | |
| 49 | // AudioSourceInterface::AudioObserver implementation |
| 50 | void OnSetVolume(double volume) override; |
| 51 | |
| 52 | rtc::scoped_refptr<AudioTrackInterface> audio_track() const { |
| 53 | return track_.get(); |
| 54 | } |
| 55 | |
| 56 | // RtpReceiverInterface implementation |
| 57 | rtc::scoped_refptr<MediaStreamTrackInterface> track() const override { |
| 58 | return track_.get(); |
| 59 | } |
| 60 | rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const override { |
| 61 | return dtls_transport_; |
| 62 | } |
| 63 | std::vector<std::string> stream_ids() const override; |
| 64 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams() |
| 65 | const override { |
| 66 | return streams_; |
| 67 | } |
| 68 | |
| 69 | cricket::MediaType media_type() const override { |
| 70 | return cricket::MEDIA_TYPE_AUDIO; |
| 71 | } |
| 72 | |
| 73 | std::string id() const override { return id_; } |
| 74 | |
| 75 | RtpParameters GetParameters() const override; |
| 76 | bool SetParameters(const RtpParameters& parameters) override; |
| 77 | |
| 78 | void SetFrameDecryptor( |
| 79 | rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) override; |
| 80 | |
| 81 | rtc::scoped_refptr<FrameDecryptorInterface> GetFrameDecryptor() |
| 82 | const override; |
| 83 | |
| 84 | // RtpReceiverInternal implementation. |
| 85 | void Stop() override; |
| 86 | void SetupMediaChannel(uint32_t ssrc) override; |
| 87 | uint32_t ssrc() const override { return ssrc_.value_or(0); } |
| 88 | void NotifyFirstPacketReceived() override; |
| 89 | void set_stream_ids(std::vector<std::string> stream_ids) override; |
| 90 | void set_transport( |
| 91 | rtc::scoped_refptr<DtlsTransportInterface> dtls_transport) override { |
| 92 | dtls_transport_ = dtls_transport; |
| 93 | } |
| 94 | void SetStreams(const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& |
| 95 | streams) override; |
| 96 | void SetObserver(RtpReceiverObserverInterface* observer) override; |
| 97 | |
| 98 | void SetMediaChannel(cricket::MediaChannel* media_channel) override; |
| 99 | |
| 100 | std::vector<RtpSource> GetSources() const override; |
| 101 | int AttachmentId() const override { return attachment_id_; } |
| 102 | |
| 103 | private: |
| 104 | void Reconfigure(); |
| 105 | bool SetOutputVolume(double volume); |
| 106 | |
| 107 | rtc::Thread* const worker_thread_; |
| 108 | const std::string id_; |
| 109 | const rtc::scoped_refptr<RemoteAudioSource> source_; |
| 110 | const rtc::scoped_refptr<AudioTrackInterface> track_; |
| 111 | cricket::VoiceMediaChannel* media_channel_ = nullptr; |
| 112 | absl::optional<uint32_t> ssrc_; |
| 113 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_; |
| 114 | bool cached_track_enabled_; |
| 115 | double cached_volume_ = 1; |
| 116 | bool stopped_ = false; |
| 117 | RtpReceiverObserverInterface* observer_ = nullptr; |
| 118 | bool received_first_packet_ = false; |
| 119 | int attachment_id_ = 0; |
| 120 | rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor_; |
| 121 | rtc::scoped_refptr<DtlsTransportInterface> dtls_transport_; |
| 122 | }; |
| 123 | |
| 124 | } // namespace webrtc |
| 125 | |
| 126 | #endif // PC_AUDIO_RTP_RECEIVER_H_ |