blob: e1b1888aa7573b4c19268d4073137b8a18120aa3 [file] [log] [blame]
Ruslan Burakov501bfba2019-02-11 10:29:19 +01001/*
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>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
Ruslan Burakov501bfba2019-02-11 10:29:19 +010016#include <string>
17#include <vector>
18
19#include "absl/types/optional.h"
20#include "api/crypto/frame_decryptor_interface.h"
21#include "api/media_stream_interface.h"
22#include "api/media_types.h"
23#include "api/rtp_parameters.h"
24#include "api/scoped_refptr.h"
25#include "media/base/media_channel.h"
Ruslan Burakov428dcb22019-04-18 17:49:49 +020026#include "pc/jitter_buffer_delay_interface.h"
Ruslan Burakov501bfba2019-02-11 10:29:19 +010027#include "pc/remote_audio_source.h"
28#include "pc/rtp_receiver.h"
29#include "rtc_base/ref_counted_object.h"
30#include "rtc_base/thread.h"
31
32namespace webrtc {
33
34class AudioRtpReceiver : public ObserverInterface,
35 public AudioSourceInterface::AudioObserver,
36 public rtc::RefCountedObject<RtpReceiverInternal> {
37 public:
38 AudioRtpReceiver(rtc::Thread* worker_thread,
39 std::string receiver_id,
40 std::vector<std::string> stream_ids);
41 // TODO(https://crbug.com/webrtc/9480): Remove this when streams() is removed.
42 AudioRtpReceiver(
43 rtc::Thread* worker_thread,
44 const std::string& receiver_id,
45 const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams);
46 virtual ~AudioRtpReceiver();
47
48 // ObserverInterface implementation
49 void OnChanged() override;
50
51 // AudioSourceInterface::AudioObserver implementation
52 void OnSetVolume(double volume) override;
53
54 rtc::scoped_refptr<AudioTrackInterface> audio_track() const {
55 return track_.get();
56 }
57
58 // RtpReceiverInterface implementation
59 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
60 return track_.get();
61 }
62 rtc::scoped_refptr<DtlsTransportInterface> dtls_transport() const override {
63 return dtls_transport_;
64 }
65 std::vector<std::string> stream_ids() const override;
66 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams()
67 const override {
68 return streams_;
69 }
70
71 cricket::MediaType media_type() const override {
72 return cricket::MEDIA_TYPE_AUDIO;
73 }
74
75 std::string id() const override { return id_; }
76
77 RtpParameters GetParameters() const override;
78 bool SetParameters(const RtpParameters& parameters) override;
79
80 void SetFrameDecryptor(
81 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) override;
82
83 rtc::scoped_refptr<FrameDecryptorInterface> GetFrameDecryptor()
84 const override;
85
86 // RtpReceiverInternal implementation.
87 void Stop() override;
88 void SetupMediaChannel(uint32_t ssrc) override;
Saurav Das7262fc22019-09-11 16:23:05 -070089 void SetupUnsignaledMediaChannel() override;
Ruslan Burakov501bfba2019-02-11 10:29:19 +010090 uint32_t ssrc() const override { return ssrc_.value_or(0); }
91 void NotifyFirstPacketReceived() override;
92 void set_stream_ids(std::vector<std::string> stream_ids) override;
93 void set_transport(
94 rtc::scoped_refptr<DtlsTransportInterface> dtls_transport) override {
95 dtls_transport_ = dtls_transport;
96 }
97 void SetStreams(const std::vector<rtc::scoped_refptr<MediaStreamInterface>>&
98 streams) override;
99 void SetObserver(RtpReceiverObserverInterface* observer) override;
100
Ruslan Burakov4bac79e2019-04-03 19:55:33 +0200101 void SetJitterBufferMinimumDelay(
102 absl::optional<double> delay_seconds) override;
103
Ruslan Burakov501bfba2019-02-11 10:29:19 +0100104 void SetMediaChannel(cricket::MediaChannel* media_channel) override;
105
106 std::vector<RtpSource> GetSources() const override;
107 int AttachmentId() const override { return attachment_id_; }
108
109 private:
Saurav Das7262fc22019-09-11 16:23:05 -0700110 void RestartMediaChannel(absl::optional<uint32_t> ssrc);
Ruslan Burakov501bfba2019-02-11 10:29:19 +0100111 void Reconfigure();
112 bool SetOutputVolume(double volume);
113
114 rtc::Thread* const worker_thread_;
115 const std::string id_;
116 const rtc::scoped_refptr<RemoteAudioSource> source_;
117 const rtc::scoped_refptr<AudioTrackInterface> track_;
118 cricket::VoiceMediaChannel* media_channel_ = nullptr;
119 absl::optional<uint32_t> ssrc_;
120 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_;
121 bool cached_track_enabled_;
122 double cached_volume_ = 1;
Saurav Das7262fc22019-09-11 16:23:05 -0700123 bool stopped_ = true;
Ruslan Burakov501bfba2019-02-11 10:29:19 +0100124 RtpReceiverObserverInterface* observer_ = nullptr;
125 bool received_first_packet_ = false;
126 int attachment_id_ = 0;
127 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor_;
128 rtc::scoped_refptr<DtlsTransportInterface> dtls_transport_;
Ruslan Burakov428dcb22019-04-18 17:49:49 +0200129 // Allows to thread safely change playout delay. Handles caching cases if
130 // |SetJitterBufferMinimumDelay| is called before start.
131 rtc::scoped_refptr<JitterBufferDelayInterface> delay_;
Ruslan Burakov501bfba2019-02-11 10:29:19 +0100132};
133
134} // namespace webrtc
135
136#endif // PC_AUDIO_RTP_RECEIVER_H_