blob: 9ad5c61bbd1861a2d0e17d8b8de6034f294801f1 [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>
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
30namespace webrtc {
31
32class 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
Ruslan Burakov4bac79e2019-04-03 19:55:33 +020098 void SetJitterBufferMinimumDelay(
99 absl::optional<double> delay_seconds) override;
100
Ruslan Burakov501bfba2019-02-11 10:29:19 +0100101 void SetMediaChannel(cricket::MediaChannel* media_channel) override;
102
103 std::vector<RtpSource> GetSources() const override;
104 int AttachmentId() const override { return attachment_id_; }
105
106 private:
107 void Reconfigure();
108 bool SetOutputVolume(double volume);
109
110 rtc::Thread* const worker_thread_;
111 const std::string id_;
112 const rtc::scoped_refptr<RemoteAudioSource> source_;
113 const rtc::scoped_refptr<AudioTrackInterface> track_;
114 cricket::VoiceMediaChannel* media_channel_ = nullptr;
115 absl::optional<uint32_t> ssrc_;
116 std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams_;
117 bool cached_track_enabled_;
118 double cached_volume_ = 1;
119 bool stopped_ = false;
120 RtpReceiverObserverInterface* observer_ = nullptr;
121 bool received_first_packet_ = false;
122 int attachment_id_ = 0;
123 rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor_;
124 rtc::scoped_refptr<DtlsTransportInterface> dtls_transport_;
125};
126
127} // namespace webrtc
128
129#endif // PC_AUDIO_RTP_RECEIVER_H_