OLD | NEW |
(Empty) | |
| 1 /* |
| 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 |
| 28 // 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 |
| 44 namespace webrtc { |
| 45 |
| 46 // LocalAudioSinkAdapter receives data callback as a sink to the local |
| 47 // AudioTrack, and passes the data to the sink of AudioRenderer. |
| 48 class 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 |
| 70 class AudioRtpSender : public ObserverInterface, |
| 71 public rtc::RefCountedObject<RtpSenderInterface> { |
| 72 public: |
| 73 AudioRtpSender(AudioTrackInterface* track, |
| 74 uint32 ssrc, |
| 75 AudioProviderInterface* provider); |
| 76 |
| 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: |
| 93 void Reconfigure(); |
| 94 |
| 95 std::string id_; |
| 96 rtc::scoped_refptr<AudioTrackInterface> track_; |
| 97 uint32 ssrc_; |
| 98 AudioProviderInterface* provider_; |
| 99 bool cached_track_enabled_; |
| 100 |
| 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 |
| 106 class VideoRtpSender : public ObserverInterface, |
| 107 public rtc::RefCountedObject<RtpSenderInterface> { |
| 108 public: |
| 109 VideoRtpSender(VideoTrackInterface* track, |
| 110 uint32 ssrc, |
| 111 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: |
| 129 void Reconfigure(); |
| 130 |
| 131 std::string id_; |
| 132 rtc::scoped_refptr<VideoTrackInterface> track_; |
| 133 uint32 ssrc_; |
| 134 VideoProviderInterface* provider_; |
| 135 bool cached_track_enabled_; |
| 136 }; |
| 137 |
| 138 } // namespace webrtc |
| 139 |
| 140 #endif // TALK_APP_WEBRTC_RTPSENDER_H_ |
OLD | NEW |