OLD | NEW |
---|---|
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004--2011 Google Inc. | 3 * Copyright 2004--2011 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
11 * this list of conditions and the following disclaimer in the documentation | 11 * this list of conditions and the following disclaimer in the documentation |
12 * and/or other materials provided with the distribution. | 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 | 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. | 14 * derived from this software without specific prior written permission. |
15 * | 15 * |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 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 | 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 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, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 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 | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include "talk/app/webrtc/audiotrack.h" | 28 #include "talk/app/webrtc/audiotrack.h" |
29 | 29 |
30 #include <string> | 30 #include "webrtc/base/checks.h" |
31 | |
32 using rtc::scoped_refptr; | |
31 | 33 |
32 namespace webrtc { | 34 namespace webrtc { |
33 | 35 |
34 const char MediaStreamTrackInterface::kAudioKind[] = "audio"; | 36 const char MediaStreamTrackInterface::kAudioKind[] = "audio"; |
35 | 37 |
38 // static | |
39 scoped_refptr<AudioTrack> AudioTrack::Create( | |
40 const std::string& id, | |
41 const scoped_refptr<AudioSourceInterface>& source) { | |
42 return new rtc::RefCountedObject<AudioTrack>(id, source); | |
43 } | |
44 | |
36 AudioTrack::AudioTrack(const std::string& label, | 45 AudioTrack::AudioTrack(const std::string& label, |
37 AudioSourceInterface* audio_source) | 46 const scoped_refptr<AudioSourceInterface>& source) |
38 : MediaStreamTrack<AudioTrackInterface>(label), | 47 : MediaStreamTrack<AudioTrackInterface>(label), audio_source_(source) { |
39 audio_source_(audio_source) { | 48 if (audio_source_) { |
49 audio_source_->RegisterObserver(this); | |
50 TrackState new_state = kInitializing; | |
51 switch (audio_source_->state()) { | |
52 case MediaSourceInterface::kLive: | |
53 case MediaSourceInterface::kMuted: | |
54 new_state = kLive; | |
55 break; | |
56 case MediaSourceInterface::kEnded: | |
57 new_state = kEnded; | |
58 break; | |
59 case MediaSourceInterface::kInitializing: | |
60 default: | |
61 // kInitializing; | |
62 break; | |
63 } | |
64 set_state(new_state); | |
65 } | |
66 } | |
67 | |
68 AudioTrack::~AudioTrack() { | |
69 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
70 set_state(MediaStreamTrackInterface::kEnded); | |
71 if (audio_source_) | |
72 audio_source_->UnregisterObserver(this); | |
40 } | 73 } |
41 | 74 |
42 std::string AudioTrack::kind() const { | 75 std::string AudioTrack::kind() const { |
76 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
43 return kAudioKind; | 77 return kAudioKind; |
44 } | 78 } |
45 | 79 |
46 rtc::scoped_refptr<AudioTrack> AudioTrack::Create( | 80 AudioSourceInterface* AudioTrack::GetSource() const { |
47 const std::string& id, AudioSourceInterface* source) { | 81 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
48 rtc::RefCountedObject<AudioTrack>* track = | 82 return audio_source_.get(); |
49 new rtc::RefCountedObject<AudioTrack>(id, source); | 83 } |
50 return track; | 84 |
85 void AudioTrack::AddSink(AudioTrackSinkInterface* sink) { | |
86 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
87 if (audio_source_) | |
88 audio_source_->AddSink(sink); | |
89 } | |
90 | |
91 void AudioTrack::RemoveSink(AudioTrackSinkInterface* sink) { | |
92 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
93 if (audio_source_) | |
94 audio_source_->RemoveSink(sink); | |
95 } | |
96 | |
97 void AudioTrack::OnChanged() { | |
98 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | |
99 // |audio_source_| must be non-null if we ever get here. | |
100 if (audio_source_->state() == MediaSourceInterface::kEnded) | |
perkj_webrtc
2015/12/15 10:15:31
Should we allow the track to change to live again?
tommi
2015/12/15 11:00:54
Interesting. OK, moved the switch() statement in t
| |
101 set_state(MediaStreamTrackInterface::kEnded); | |
51 } | 102 } |
52 | 103 |
53 } // namespace webrtc | 104 } // namespace webrtc |
OLD | NEW |