blob: 374190932325bb9715ed4b477b61556177833935 [file] [log] [blame]
deadbeef6979b022015-09-24 16:47:53 -07001/*
2 * libjingle
3 * Copyright 2015 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
deadbeef70ab1a12015-09-28 16:53:55 -070028// This file contains classes that implement RtpSenderInterface.
29// An RtpSender associates a MediaStreamTrackInterface with an underlying
30// transport (provided by AudioProviderInterface/VideoProviderInterface)
31
32#ifndef TALK_APP_WEBRTC_RTPSENDER_H_
33#define TALK_APP_WEBRTC_RTPSENDER_H_
34
35#include <string>
36
37#include "talk/app/webrtc/mediastreamprovider.h"
38#include "talk/app/webrtc/rtpsenderinterface.h"
39#include "talk/media/base/audiorenderer.h"
40#include "webrtc/base/basictypes.h"
41#include "webrtc/base/criticalsection.h"
42#include "webrtc/base/scoped_ptr.h"
43
44namespace webrtc {
45
46// LocalAudioSinkAdapter receives data callback as a sink to the local
47// AudioTrack, and passes the data to the sink of AudioRenderer.
48class LocalAudioSinkAdapter : public AudioTrackSinkInterface,
49 public cricket::AudioRenderer {
50 public:
51 LocalAudioSinkAdapter();
52 virtual ~LocalAudioSinkAdapter();
53
54 private:
55 // AudioSinkInterface implementation.
56 void OnData(const void* audio_data,
57 int bits_per_sample,
58 int sample_rate,
59 int number_of_channels,
60 size_t number_of_frames) override;
61
62 // cricket::AudioRenderer implementation.
63 void SetSink(cricket::AudioRenderer::Sink* sink) override;
64
65 cricket::AudioRenderer::Sink* sink_;
66 // Critical section protecting |sink_|.
67 rtc::CriticalSection lock_;
68};
69
70class AudioRtpSender : public ObserverInterface,
71 public rtc::RefCountedObject<RtpSenderInterface> {
72 public:
73 AudioRtpSender(AudioTrackInterface* track,
deadbeef5def7b92015-11-20 11:43:22 -080074 uint32_t ssrc,
75 AudioProviderInterface* provider);
deadbeef70ab1a12015-09-28 16:53:55 -070076
77 virtual ~AudioRtpSender();
78
79 // ObserverInterface implementation
80 void OnChanged() override;
81
82 // RtpSenderInterface implementation
83 bool SetTrack(MediaStreamTrackInterface* track) override;
84 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
85 return track_.get();
86 }
87
88 std::string id() const override { return id_; }
89
90 void Stop() override;
91
92 private:
deadbeef5def7b92015-11-20 11:43:22 -080093 void Reconfigure();
deadbeef70ab1a12015-09-28 16:53:55 -070094
95 std::string id_;
deadbeef6834fa12015-11-20 09:49:59 -080096 rtc::scoped_refptr<AudioTrackInterface> track_;
deadbeef5def7b92015-11-20 11:43:22 -080097 uint32_t ssrc_;
98 AudioProviderInterface* provider_;
99 bool cached_track_enabled_;
deadbeef70ab1a12015-09-28 16:53:55 -0700100
101 // Used to pass the data callback from the |track_| to the other end of
102 // cricket::AudioRenderer.
103 rtc::scoped_ptr<LocalAudioSinkAdapter> sink_adapter_;
104};
105
106class VideoRtpSender : public ObserverInterface,
107 public rtc::RefCountedObject<RtpSenderInterface> {
108 public:
109 VideoRtpSender(VideoTrackInterface* track,
deadbeef5def7b92015-11-20 11:43:22 -0800110 uint32_t ssrc,
deadbeef70ab1a12015-09-28 16:53:55 -0700111 VideoProviderInterface* provider);
112
113 virtual ~VideoRtpSender();
114
115 // ObserverInterface implementation
116 void OnChanged() override;
117
118 // RtpSenderInterface implementation
119 bool SetTrack(MediaStreamTrackInterface* track) override;
120 rtc::scoped_refptr<MediaStreamTrackInterface> track() const override {
121 return track_.get();
122 }
123
124 std::string id() const override { return id_; }
125
126 void Stop() override;
127
128 private:
deadbeef5def7b92015-11-20 11:43:22 -0800129 void Reconfigure();
deadbeef70ab1a12015-09-28 16:53:55 -0700130
131 std::string id_;
deadbeef6834fa12015-11-20 09:49:59 -0800132 rtc::scoped_refptr<VideoTrackInterface> track_;
deadbeef5def7b92015-11-20 11:43:22 -0800133 uint32_t ssrc_;
134 VideoProviderInterface* provider_;
135 bool cached_track_enabled_;
deadbeef70ab1a12015-09-28 16:53:55 -0700136};
137
138} // namespace webrtc
139
140#endif // TALK_APP_WEBRTC_RTPSENDER_H_