blob: b6807c43b76af15bc98f26fb8af155ef63458506 [file] [log] [blame]
deadbeef6979b022015-09-24 23:47:531/*
kjellanderb24317b2016-02-10 15:54:432 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
deadbeef6979b022015-09-24 23:47:533 *
kjellanderb24317b2016-02-10 15:54:434 * 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.
deadbeef6979b022015-09-24 23:47:539 */
10
deadbeef70ab1a12015-09-28 23:53:5511// This file contains classes that implement RtpReceiverInterface.
12// An RtpReceiver associates a MediaStreamTrackInterface with an underlying
Taylor Brandstetterba29c6a2016-06-27 23:30:3513// transport (provided by cricket::VoiceChannel/cricket::VideoChannel)
deadbeef70ab1a12015-09-28 23:53:5514
Henrik Kjellander15583c12016-02-10 09:53:1215#ifndef WEBRTC_API_RTPRECEIVER_H_
16#define WEBRTC_API_RTPRECEIVER_H_
deadbeef70ab1a12015-09-28 23:53:5517
pbosc7c26a02017-01-02 16:42:3218#include <stdint.h>
19
deadbeef70ab1a12015-09-28 23:53:5520#include <string>
21
Taylor Brandstetterba29c6a2016-06-27 23:30:3522#include "webrtc/api/mediastreaminterface.h"
Henrik Kjellander15583c12016-02-10 09:53:1223#include "webrtc/api/rtpreceiverinterface.h"
perkjd61bf802016-03-24 10:16:1924#include "webrtc/api/remoteaudiosource.h"
perkjf0dcfe22016-03-10 17:32:0025#include "webrtc/api/videotracksource.h"
zhihuang184a3fd2016-06-14 18:47:1426#include "webrtc/base/sigslot.h"
perkjf0dcfe22016-03-10 17:32:0027#include "webrtc/media/base/videobroadcaster.h"
Taylor Brandstetterba29c6a2016-06-27 23:30:3528#include "webrtc/pc/channel.h"
deadbeef70ab1a12015-09-28 23:53:5529
30namespace webrtc {
31
deadbeefa601f5c2016-06-06 21:27:3932// Internal class used by PeerConnection.
33class RtpReceiverInternal : public RtpReceiverInterface {
34 public:
35 virtual void Stop() = 0;
36};
37
deadbeef70ab1a12015-09-28 23:53:5538class AudioRtpReceiver : public ObserverInterface,
39 public AudioSourceInterface::AudioObserver,
zhihuang184a3fd2016-06-14 18:47:1440 public rtc::RefCountedObject<RtpReceiverInternal>,
41 public sigslot::has_slots<> {
deadbeef70ab1a12015-09-28 23:53:5542 public:
perkjd61bf802016-03-24 10:16:1943 AudioRtpReceiver(MediaStreamInterface* stream,
44 const std::string& track_id,
Peter Boström0c4e06b2015-10-07 10:23:2145 uint32_t ssrc,
Taylor Brandstetterba29c6a2016-06-27 23:30:3546 cricket::VoiceChannel* channel);
deadbeef70ab1a12015-09-28 23:53:5547
48 virtual ~AudioRtpReceiver();
49
50 // ObserverInterface implementation
51 void OnChanged() override;
52
53 // AudioSourceInterface::AudioObserver implementation
54 void OnSetVolume(double volume) override;
55
perkjd61bf802016-03-24 10:16:1956 rtc::scoped_refptr<AudioTrackInterface> audio_track() const {
57 return track_.get();
58 }
59
deadbeef70ab1a12015-09-28 23:53:5560 // RtpReceiverInterface implementation
61 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
62 return track_.get();
63 }
64
Taylor Brandstetterba29c6a2016-06-27 23:30:3565 cricket::MediaType media_type() const override {
66 return cricket::MEDIA_TYPE_AUDIO;
67 }
68
deadbeef70ab1a12015-09-28 23:53:5569 std::string id() const override { return id_; }
70
Taylor Brandstetterdb0cd9e2016-05-16 18:40:3071 RtpParameters GetParameters() const override;
72 bool SetParameters(const RtpParameters& parameters) override;
73
deadbeefa601f5c2016-06-06 21:27:3974 // RtpReceiverInternal implementation.
75 void Stop() override;
76
zhihuang184a3fd2016-06-14 18:47:1477 void SetObserver(RtpReceiverObserverInterface* observer) override;
78
Taylor Brandstetterba29c6a2016-06-27 23:30:3579 // Does not take ownership.
80 // Should call SetChannel(nullptr) before |channel| is destroyed.
81 void SetChannel(cricket::VoiceChannel* channel);
zhihuang184a3fd2016-06-14 18:47:1482
deadbeef70ab1a12015-09-28 23:53:5583 private:
84 void Reconfigure();
Taylor Brandstetterba29c6a2016-06-27 23:30:3585 void OnFirstPacketReceived(cricket::BaseChannel* channel);
deadbeef70ab1a12015-09-28 23:53:5586
Tommif888bb52015-12-12 00:37:0187 const std::string id_;
Tommif888bb52015-12-12 00:37:0188 const uint32_t ssrc_;
Taylor Brandstetterba29c6a2016-06-27 23:30:3589 cricket::VoiceChannel* channel_;
perkjd61bf802016-03-24 10:16:1990 const rtc::scoped_refptr<AudioTrackInterface> track_;
deadbeef70ab1a12015-09-28 23:53:5591 bool cached_track_enabled_;
Taylor Brandstetterba29c6a2016-06-27 23:30:3592 double cached_volume_ = 1;
93 bool stopped_ = false;
zhihuang184a3fd2016-06-14 18:47:1494 RtpReceiverObserverInterface* observer_ = nullptr;
95 bool received_first_packet_ = false;
deadbeef70ab1a12015-09-28 23:53:5596};
97
zhihuang184a3fd2016-06-14 18:47:1498class VideoRtpReceiver : public rtc::RefCountedObject<RtpReceiverInternal>,
99 public sigslot::has_slots<> {
deadbeef70ab1a12015-09-28 23:53:55100 public:
perkjf0dcfe22016-03-10 17:32:00101 VideoRtpReceiver(MediaStreamInterface* stream,
102 const std::string& track_id,
103 rtc::Thread* worker_thread,
Peter Boström0c4e06b2015-10-07 10:23:21104 uint32_t ssrc,
Taylor Brandstetterba29c6a2016-06-27 23:30:35105 cricket::VideoChannel* channel);
deadbeef70ab1a12015-09-28 23:53:55106
107 virtual ~VideoRtpReceiver();
108
perkjf0dcfe22016-03-10 17:32:00109 rtc::scoped_refptr<VideoTrackInterface> video_track() const {
110 return track_.get();
111 }
112
deadbeef70ab1a12015-09-28 23:53:55113 // RtpReceiverInterface implementation
114 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
115 return track_.get();
116 }
117
Taylor Brandstetterba29c6a2016-06-27 23:30:35118 cricket::MediaType media_type() const override {
119 return cricket::MEDIA_TYPE_VIDEO;
120 }
121
deadbeef70ab1a12015-09-28 23:53:55122 std::string id() const override { return id_; }
123
Taylor Brandstetterdb0cd9e2016-05-16 18:40:30124 RtpParameters GetParameters() const override;
125 bool SetParameters(const RtpParameters& parameters) override;
126
deadbeefa601f5c2016-06-06 21:27:39127 // RtpReceiverInternal implementation.
128 void Stop() override;
129
zhihuang184a3fd2016-06-14 18:47:14130 void SetObserver(RtpReceiverObserverInterface* observer) override;
131
Taylor Brandstetterba29c6a2016-06-27 23:30:35132 // Does not take ownership.
133 // Should call SetChannel(nullptr) before |channel| is destroyed.
134 void SetChannel(cricket::VideoChannel* channel);
zhihuang184a3fd2016-06-14 18:47:14135
deadbeef70ab1a12015-09-28 23:53:55136 private:
Taylor Brandstetterba29c6a2016-06-27 23:30:35137 void OnFirstPacketReceived(cricket::BaseChannel* channel);
zhihuang184a3fd2016-06-14 18:47:14138
deadbeef70ab1a12015-09-28 23:53:55139 std::string id_;
Peter Boström0c4e06b2015-10-07 10:23:21140 uint32_t ssrc_;
Taylor Brandstetterba29c6a2016-06-27 23:30:35141 cricket::VideoChannel* channel_;
perkjf0dcfe22016-03-10 17:32:00142 // |broadcaster_| is needed since the decoder can only handle one sink.
143 // It might be better if the decoder can handle multiple sinks and consider
144 // the VideoSinkWants.
145 rtc::VideoBroadcaster broadcaster_;
146 // |source_| is held here to be able to change the state of the source when
147 // the VideoRtpReceiver is stopped.
148 rtc::scoped_refptr<VideoTrackSource> source_;
149 rtc::scoped_refptr<VideoTrackInterface> track_;
Taylor Brandstetterba29c6a2016-06-27 23:30:35150 bool stopped_ = false;
zhihuang184a3fd2016-06-14 18:47:14151 RtpReceiverObserverInterface* observer_ = nullptr;
152 bool received_first_packet_ = false;
deadbeef70ab1a12015-09-28 23:53:55153};
154
155} // namespace webrtc
156
Henrik Kjellander15583c12016-02-10 09:53:12157#endif // WEBRTC_API_RTPRECEIVER_H_