| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 #include "webrtc/audio_sink.h" | 24 #include "webrtc/audio_sink.h" |
| 25 #include "webrtc/base/arraysize.h" | 25 #include "webrtc/base/arraysize.h" |
| 26 #include "webrtc/base/base64.h" | 26 #include "webrtc/base/base64.h" |
| 27 #include "webrtc/base/byteorder.h" | 27 #include "webrtc/base/byteorder.h" |
| 28 #include "webrtc/base/common.h" | 28 #include "webrtc/base/common.h" |
| 29 #include "webrtc/base/helpers.h" | 29 #include "webrtc/base/helpers.h" |
| 30 #include "webrtc/base/logging.h" | 30 #include "webrtc/base/logging.h" |
| 31 #include "webrtc/base/stringencode.h" | 31 #include "webrtc/base/stringencode.h" |
| 32 #include "webrtc/base/stringutils.h" | 32 #include "webrtc/base/stringutils.h" |
| 33 #include "webrtc/base/trace_event.h" |
| 33 #include "webrtc/call/rtc_event_log.h" | 34 #include "webrtc/call/rtc_event_log.h" |
| 34 #include "webrtc/common.h" | 35 #include "webrtc/common.h" |
| 35 #include "webrtc/media/base/audioframe.h" | 36 #include "webrtc/media/base/audioframe.h" |
| 36 #include "webrtc/media/base/audiorenderer.h" | 37 #include "webrtc/media/base/audiorenderer.h" |
| 37 #include "webrtc/media/base/mediaconstants.h" | 38 #include "webrtc/media/base/mediaconstants.h" |
| 38 #include "webrtc/media/base/streamparams.h" | 39 #include "webrtc/media/base/streamparams.h" |
| 39 #include "webrtc/media/engine/webrtcmediaengine.h" | 40 #include "webrtc/media/engine/webrtcmediaengine.h" |
| 40 #include "webrtc/media/engine/webrtcvoe.h" | 41 #include "webrtc/media/engine/webrtcvoe.h" |
| 41 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" | 42 #include "webrtc/modules/audio_coding/acm2/rent_a_codec.h" |
| 42 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 43 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| (...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 } | 1367 } |
| 1367 engine()->UnregisterChannel(this); | 1368 engine()->UnregisterChannel(this); |
| 1368 } | 1369 } |
| 1369 | 1370 |
| 1370 rtc::DiffServCodePoint WebRtcVoiceMediaChannel::PreferredDscp() const { | 1371 rtc::DiffServCodePoint WebRtcVoiceMediaChannel::PreferredDscp() const { |
| 1371 return kAudioDscpValue; | 1372 return kAudioDscpValue; |
| 1372 } | 1373 } |
| 1373 | 1374 |
| 1374 bool WebRtcVoiceMediaChannel::SetSendParameters( | 1375 bool WebRtcVoiceMediaChannel::SetSendParameters( |
| 1375 const AudioSendParameters& params) { | 1376 const AudioSendParameters& params) { |
| 1377 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::SetSendParameters"); |
| 1376 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1378 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1377 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetSendParameters: " | 1379 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetSendParameters: " |
| 1378 << params.ToString(); | 1380 << params.ToString(); |
| 1379 // TODO(pthatcher): Refactor this to be more clean now that we have | 1381 // TODO(pthatcher): Refactor this to be more clean now that we have |
| 1380 // all the information at once. | 1382 // all the information at once. |
| 1381 | 1383 |
| 1382 if (!SetSendCodecs(params.codecs)) { | 1384 if (!SetSendCodecs(params.codecs)) { |
| 1383 return false; | 1385 return false; |
| 1384 } | 1386 } |
| 1385 | 1387 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1397 } | 1399 } |
| 1398 | 1400 |
| 1399 if (!SetMaxSendBandwidth(params.max_bandwidth_bps)) { | 1401 if (!SetMaxSendBandwidth(params.max_bandwidth_bps)) { |
| 1400 return false; | 1402 return false; |
| 1401 } | 1403 } |
| 1402 return SetOptions(params.options); | 1404 return SetOptions(params.options); |
| 1403 } | 1405 } |
| 1404 | 1406 |
| 1405 bool WebRtcVoiceMediaChannel::SetRecvParameters( | 1407 bool WebRtcVoiceMediaChannel::SetRecvParameters( |
| 1406 const AudioRecvParameters& params) { | 1408 const AudioRecvParameters& params) { |
| 1409 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::SetRecvParameters"); |
| 1407 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1410 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1408 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetRecvParameters: " | 1411 LOG(LS_INFO) << "WebRtcVoiceMediaChannel::SetRecvParameters: " |
| 1409 << params.ToString(); | 1412 << params.ToString(); |
| 1410 // TODO(pthatcher): Refactor this to be more clean now that we have | 1413 // TODO(pthatcher): Refactor this to be more clean now that we have |
| 1411 // all the information at once. | 1414 // all the information at once. |
| 1412 | 1415 |
| 1413 if (!SetRecvCodecs(params.codecs)) { | 1416 if (!SetRecvCodecs(params.codecs)) { |
| 1414 return false; | 1417 return false; |
| 1415 } | 1418 } |
| 1416 | 1419 |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1780 | 1783 |
| 1781 bool WebRtcVoiceMediaChannel::PausePlayout() { | 1784 bool WebRtcVoiceMediaChannel::PausePlayout() { |
| 1782 return ChangePlayout(false); | 1785 return ChangePlayout(false); |
| 1783 } | 1786 } |
| 1784 | 1787 |
| 1785 bool WebRtcVoiceMediaChannel::ResumePlayout() { | 1788 bool WebRtcVoiceMediaChannel::ResumePlayout() { |
| 1786 return ChangePlayout(desired_playout_); | 1789 return ChangePlayout(desired_playout_); |
| 1787 } | 1790 } |
| 1788 | 1791 |
| 1789 bool WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { | 1792 bool WebRtcVoiceMediaChannel::ChangePlayout(bool playout) { |
| 1793 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::ChangePlayout"); |
| 1790 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1794 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1791 if (playout_ == playout) { | 1795 if (playout_ == playout) { |
| 1792 return true; | 1796 return true; |
| 1793 } | 1797 } |
| 1794 | 1798 |
| 1795 for (const auto& ch : recv_streams_) { | 1799 for (const auto& ch : recv_streams_) { |
| 1796 if (!SetPlayout(ch.second->channel(), playout)) { | 1800 if (!SetPlayout(ch.second->channel(), playout)) { |
| 1797 LOG(LS_ERROR) << "SetPlayout " << playout << " on channel " | 1801 LOG(LS_ERROR) << "SetPlayout " << playout << " on channel " |
| 1798 << ch.second->channel() << " failed"; | 1802 << ch.second->channel() << " failed"; |
| 1799 return false; | 1803 return false; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1813 | 1817 |
| 1814 bool WebRtcVoiceMediaChannel::PauseSend() { | 1818 bool WebRtcVoiceMediaChannel::PauseSend() { |
| 1815 return ChangeSend(SEND_NOTHING); | 1819 return ChangeSend(SEND_NOTHING); |
| 1816 } | 1820 } |
| 1817 | 1821 |
| 1818 bool WebRtcVoiceMediaChannel::ResumeSend() { | 1822 bool WebRtcVoiceMediaChannel::ResumeSend() { |
| 1819 return ChangeSend(desired_send_); | 1823 return ChangeSend(desired_send_); |
| 1820 } | 1824 } |
| 1821 | 1825 |
| 1822 bool WebRtcVoiceMediaChannel::ChangeSend(SendFlags send) { | 1826 bool WebRtcVoiceMediaChannel::ChangeSend(SendFlags send) { |
| 1827 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::ChangeSend"); |
| 1823 if (send_ == send) { | 1828 if (send_ == send) { |
| 1824 return true; | 1829 return true; |
| 1825 } | 1830 } |
| 1826 | 1831 |
| 1827 // Apply channel specific options when channel is enabled for sending. | 1832 // Apply channel specific options when channel is enabled for sending. |
| 1828 if (send == SEND_MICROPHONE) { | 1833 if (send == SEND_MICROPHONE) { |
| 1829 engine()->ApplyOptions(options_); | 1834 engine()->ApplyOptions(options_); |
| 1830 } | 1835 } |
| 1831 | 1836 |
| 1832 // Change the settings on each send channel. | 1837 // Change the settings on each send channel. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1895 LOG_RTCERR1(DeRegisterExternalTransport, channel); | 1900 LOG_RTCERR1(DeRegisterExternalTransport, channel); |
| 1896 } | 1901 } |
| 1897 if (engine()->voe()->base()->DeleteChannel(channel) == -1) { | 1902 if (engine()->voe()->base()->DeleteChannel(channel) == -1) { |
| 1898 LOG_RTCERR1(DeleteChannel, channel); | 1903 LOG_RTCERR1(DeleteChannel, channel); |
| 1899 return false; | 1904 return false; |
| 1900 } | 1905 } |
| 1901 return true; | 1906 return true; |
| 1902 } | 1907 } |
| 1903 | 1908 |
| 1904 bool WebRtcVoiceMediaChannel::AddSendStream(const StreamParams& sp) { | 1909 bool WebRtcVoiceMediaChannel::AddSendStream(const StreamParams& sp) { |
| 1910 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::AddSendStream"); |
| 1905 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1911 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1906 LOG(LS_INFO) << "AddSendStream: " << sp.ToString(); | 1912 LOG(LS_INFO) << "AddSendStream: " << sp.ToString(); |
| 1907 | 1913 |
| 1908 uint32_t ssrc = sp.first_ssrc(); | 1914 uint32_t ssrc = sp.first_ssrc(); |
| 1909 RTC_DCHECK(0 != ssrc); | 1915 RTC_DCHECK(0 != ssrc); |
| 1910 | 1916 |
| 1911 if (GetSendChannelId(ssrc) != -1) { | 1917 if (GetSendChannelId(ssrc) != -1) { |
| 1912 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; | 1918 LOG(LS_ERROR) << "Stream already exists with ssrc " << ssrc; |
| 1913 return false; | 1919 return false; |
| 1914 } | 1920 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1948 engine()->voe()->base()->AssociateSendChannel(recv_channel, channel); | 1954 engine()->voe()->base()->AssociateSendChannel(recv_channel, channel); |
| 1949 LOG(LS_INFO) << "VoiceEngine channel #" << recv_channel | 1955 LOG(LS_INFO) << "VoiceEngine channel #" << recv_channel |
| 1950 << " is associated with channel #" << channel << "."; | 1956 << " is associated with channel #" << channel << "."; |
| 1951 } | 1957 } |
| 1952 } | 1958 } |
| 1953 | 1959 |
| 1954 return ChangeSend(channel, desired_send_); | 1960 return ChangeSend(channel, desired_send_); |
| 1955 } | 1961 } |
| 1956 | 1962 |
| 1957 bool WebRtcVoiceMediaChannel::RemoveSendStream(uint32_t ssrc) { | 1963 bool WebRtcVoiceMediaChannel::RemoveSendStream(uint32_t ssrc) { |
| 1964 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::RemoveSendStream"); |
| 1958 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1965 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1959 LOG(LS_INFO) << "RemoveSendStream: " << ssrc; | 1966 LOG(LS_INFO) << "RemoveSendStream: " << ssrc; |
| 1960 | 1967 |
| 1961 auto it = send_streams_.find(ssrc); | 1968 auto it = send_streams_.find(ssrc); |
| 1962 if (it == send_streams_.end()) { | 1969 if (it == send_streams_.end()) { |
| 1963 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc | 1970 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc |
| 1964 << " which doesn't exist."; | 1971 << " which doesn't exist."; |
| 1965 return false; | 1972 return false; |
| 1966 } | 1973 } |
| 1967 | 1974 |
| 1968 int channel = it->second->channel(); | 1975 int channel = it->second->channel(); |
| 1969 ChangeSend(channel, SEND_NOTHING); | 1976 ChangeSend(channel, SEND_NOTHING); |
| 1970 | 1977 |
| 1971 // Clean up and delete the send stream+channel. | 1978 // Clean up and delete the send stream+channel. |
| 1972 LOG(LS_INFO) << "Removing audio send stream " << ssrc | 1979 LOG(LS_INFO) << "Removing audio send stream " << ssrc |
| 1973 << " with VoiceEngine channel #" << channel << "."; | 1980 << " with VoiceEngine channel #" << channel << "."; |
| 1974 delete it->second; | 1981 delete it->second; |
| 1975 send_streams_.erase(it); | 1982 send_streams_.erase(it); |
| 1976 if (!DeleteVoEChannel(channel)) { | 1983 if (!DeleteVoEChannel(channel)) { |
| 1977 return false; | 1984 return false; |
| 1978 } | 1985 } |
| 1979 if (send_streams_.empty()) { | 1986 if (send_streams_.empty()) { |
| 1980 ChangeSend(SEND_NOTHING); | 1987 ChangeSend(SEND_NOTHING); |
| 1981 } | 1988 } |
| 1982 return true; | 1989 return true; |
| 1983 } | 1990 } |
| 1984 | 1991 |
| 1985 bool WebRtcVoiceMediaChannel::AddRecvStream(const StreamParams& sp) { | 1992 bool WebRtcVoiceMediaChannel::AddRecvStream(const StreamParams& sp) { |
| 1993 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::AddRecvStream"); |
| 1986 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 1994 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 1987 LOG(LS_INFO) << "AddRecvStream: " << sp.ToString(); | 1995 LOG(LS_INFO) << "AddRecvStream: " << sp.ToString(); |
| 1988 | 1996 |
| 1989 if (!ValidateStreamParams(sp)) { | 1997 if (!ValidateStreamParams(sp)) { |
| 1990 return false; | 1998 return false; |
| 1991 } | 1999 } |
| 1992 | 2000 |
| 1993 const uint32_t ssrc = sp.first_ssrc(); | 2001 const uint32_t ssrc = sp.first_ssrc(); |
| 1994 if (ssrc == 0) { | 2002 if (ssrc == 0) { |
| 1995 LOG(LS_WARNING) << "AddRecvStream with ssrc==0 is not supported."; | 2003 LOG(LS_WARNING) << "AddRecvStream with ssrc==0 is not supported."; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2055 transport_cc_enabled_, sp.sync_label, | 2063 transport_cc_enabled_, sp.sync_label, |
| 2056 recv_rtp_extensions_, call_))); | 2064 recv_rtp_extensions_, call_))); |
| 2057 | 2065 |
| 2058 SetNack(channel, nack_enabled_); | 2066 SetNack(channel, nack_enabled_); |
| 2059 SetPlayout(channel, playout_); | 2067 SetPlayout(channel, playout_); |
| 2060 | 2068 |
| 2061 return true; | 2069 return true; |
| 2062 } | 2070 } |
| 2063 | 2071 |
| 2064 bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32_t ssrc) { | 2072 bool WebRtcVoiceMediaChannel::RemoveRecvStream(uint32_t ssrc) { |
| 2073 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::RemoveRecvStream"); |
| 2065 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2074 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 2066 LOG(LS_INFO) << "RemoveRecvStream: " << ssrc; | 2075 LOG(LS_INFO) << "RemoveRecvStream: " << ssrc; |
| 2067 | 2076 |
| 2068 const auto it = recv_streams_.find(ssrc); | 2077 const auto it = recv_streams_.find(ssrc); |
| 2069 if (it == recv_streams_.end()) { | 2078 if (it == recv_streams_.end()) { |
| 2070 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc | 2079 LOG(LS_WARNING) << "Try to remove stream with ssrc " << ssrc |
| 2071 << " which doesn't exist."; | 2080 << " which doesn't exist."; |
| 2072 return false; | 2081 return false; |
| 2073 } | 2082 } |
| 2074 | 2083 |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2393 LOG(LS_INFO) << "Failed to set codec " << codec.plname | 2402 LOG(LS_INFO) << "Failed to set codec " << codec.plname |
| 2394 << " to bitrate " << bps << " bps" | 2403 << " to bitrate " << bps << " bps" |
| 2395 << ", requires at least " << codec.rate << " bps."; | 2404 << ", requires at least " << codec.rate << " bps."; |
| 2396 return false; | 2405 return false; |
| 2397 } | 2406 } |
| 2398 return true; | 2407 return true; |
| 2399 } | 2408 } |
| 2400 } | 2409 } |
| 2401 | 2410 |
| 2402 bool WebRtcVoiceMediaChannel::GetStats(VoiceMediaInfo* info) { | 2411 bool WebRtcVoiceMediaChannel::GetStats(VoiceMediaInfo* info) { |
| 2412 TRACE_EVENT0("webrtc", "WebRtcVoiceMediaChannel::GetStats"); |
| 2403 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2413 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
| 2404 RTC_DCHECK(info); | 2414 RTC_DCHECK(info); |
| 2405 | 2415 |
| 2406 // Get SSRC and stats for each sender. | 2416 // Get SSRC and stats for each sender. |
| 2407 RTC_DCHECK(info->senders.size() == 0); | 2417 RTC_DCHECK(info->senders.size() == 0); |
| 2408 for (const auto& stream : send_streams_) { | 2418 for (const auto& stream : send_streams_) { |
| 2409 webrtc::AudioSendStream::Stats stats = stream.second->GetStats(); | 2419 webrtc::AudioSendStream::Stats stats = stream.second->GetStats(); |
| 2410 VoiceSenderInfo sinfo; | 2420 VoiceSenderInfo sinfo; |
| 2411 sinfo.add_ssrc(stats.local_ssrc); | 2421 sinfo.add_ssrc(stats.local_ssrc); |
| 2412 sinfo.bytes_sent = stats.bytes_sent; | 2422 sinfo.bytes_sent = stats.bytes_sent; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2520 } | 2530 } |
| 2521 } else { | 2531 } else { |
| 2522 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 2532 LOG(LS_INFO) << "Stopping playout for channel #" << channel; |
| 2523 engine()->voe()->base()->StopPlayout(channel); | 2533 engine()->voe()->base()->StopPlayout(channel); |
| 2524 } | 2534 } |
| 2525 return true; | 2535 return true; |
| 2526 } | 2536 } |
| 2527 } // namespace cricket | 2537 } // namespace cricket |
| 2528 | 2538 |
| 2529 #endif // HAVE_WEBRTC_VOICE | 2539 #endif // HAVE_WEBRTC_VOICE |
| OLD | NEW |