OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2004 Google Inc. | 3 * Copyright 2004 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, |
(...skipping 114 matching lines...) Loading... |
125 #else | 125 #else |
126 const char kAecDumpByAudioOptionFilename[] = "audio.aecdump"; | 126 const char kAecDumpByAudioOptionFilename[] = "audio.aecdump"; |
127 #endif | 127 #endif |
128 | 128 |
129 // Constants from voice_engine_defines.h. | 129 // Constants from voice_engine_defines.h. |
130 const int kMinTelephoneEventCode = 0; // RFC4733 (Section 2.3.1) | 130 const int kMinTelephoneEventCode = 0; // RFC4733 (Section 2.3.1) |
131 const int kMaxTelephoneEventCode = 255; | 131 const int kMaxTelephoneEventCode = 255; |
132 const int kMinTelephoneEventDuration = 100; | 132 const int kMinTelephoneEventDuration = 100; |
133 const int kMaxTelephoneEventDuration = 60000; // Actual limit is 2^16 | 133 const int kMaxTelephoneEventDuration = 60000; // Actual limit is 2^16 |
134 | 134 |
| 135 class ProxySink : public webrtc::AudioSinkInterface { |
| 136 public: |
| 137 ProxySink(AudioSinkInterface* sink) : sink_(sink) { RTC_DCHECK(sink); } |
| 138 |
| 139 void OnData(const Data& audio) override { sink_->OnData(audio); } |
| 140 |
| 141 private: |
| 142 webrtc::AudioSinkInterface* sink_; |
| 143 }; |
| 144 |
135 bool ValidateStreamParams(const StreamParams& sp) { | 145 bool ValidateStreamParams(const StreamParams& sp) { |
136 if (sp.ssrcs.empty()) { | 146 if (sp.ssrcs.empty()) { |
137 LOG(LS_ERROR) << "No SSRCs in stream parameters: " << sp.ToString(); | 147 LOG(LS_ERROR) << "No SSRCs in stream parameters: " << sp.ToString(); |
138 return false; | 148 return false; |
139 } | 149 } |
140 if (sp.ssrcs.size() > 1) { | 150 if (sp.ssrcs.size() > 1) { |
141 LOG(LS_ERROR) << "Multiple SSRCs in stream parameters: " << sp.ToString(); | 151 LOG(LS_ERROR) << "Multiple SSRCs in stream parameters: " << sp.ToString(); |
142 return false; | 152 return false; |
143 } | 153 } |
144 return true; | 154 return true; |
(...skipping 2034 matching lines...) Loading... |
2179 if (default_recv_ssrc_ == -1 && GetReceiveChannelId(ssrc) == -1) { | 2189 if (default_recv_ssrc_ == -1 && GetReceiveChannelId(ssrc) == -1) { |
2180 StreamParams sp; | 2190 StreamParams sp; |
2181 sp.ssrcs.push_back(ssrc); | 2191 sp.ssrcs.push_back(ssrc); |
2182 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; | 2192 LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; |
2183 if (!AddRecvStream(sp)) { | 2193 if (!AddRecvStream(sp)) { |
2184 LOG(LS_WARNING) << "Could not create default receive stream."; | 2194 LOG(LS_WARNING) << "Could not create default receive stream."; |
2185 return; | 2195 return; |
2186 } | 2196 } |
2187 default_recv_ssrc_ = ssrc; | 2197 default_recv_ssrc_ = ssrc; |
2188 SetOutputVolume(default_recv_ssrc_, default_recv_volume_); | 2198 SetOutputVolume(default_recv_ssrc_, default_recv_volume_); |
| 2199 if (default_sink_) { |
| 2200 rtc::scoped_ptr<webrtc::AudioSinkInterface> proxy_sink( |
| 2201 new ProxySink(default_sink_.get())); |
| 2202 SetRawAudioSink(default_recv_ssrc_, std::move(proxy_sink)); |
| 2203 } |
2189 } | 2204 } |
2190 | 2205 |
2191 // Forward packet to Call. If the SSRC is unknown we'll return after this. | 2206 // Forward packet to Call. If the SSRC is unknown we'll return after this. |
2192 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, | 2207 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, |
2193 packet_time.not_before); | 2208 packet_time.not_before); |
2194 webrtc::PacketReceiver::DeliveryStatus delivery_result = | 2209 webrtc::PacketReceiver::DeliveryStatus delivery_result = |
2195 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, | 2210 call_->Receiver()->DeliverPacket(webrtc::MediaType::AUDIO, |
2196 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), | 2211 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), |
2197 webrtc_packet_time); | 2212 webrtc_packet_time); |
2198 if (webrtc::PacketReceiver::DELIVERY_OK != delivery_result) { | 2213 if (webrtc::PacketReceiver::DELIVERY_OK != delivery_result) { |
(...skipping 208 matching lines...) Loading... |
2407 info->receivers.push_back(rinfo); | 2422 info->receivers.push_back(rinfo); |
2408 } | 2423 } |
2409 | 2424 |
2410 return true; | 2425 return true; |
2411 } | 2426 } |
2412 | 2427 |
2413 void WebRtcVoiceMediaChannel::SetRawAudioSink( | 2428 void WebRtcVoiceMediaChannel::SetRawAudioSink( |
2414 uint32_t ssrc, | 2429 uint32_t ssrc, |
2415 rtc::scoped_ptr<webrtc::AudioSinkInterface> sink) { | 2430 rtc::scoped_ptr<webrtc::AudioSinkInterface> sink) { |
2416 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); | 2431 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); |
2417 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::SetRawAudioSink"; | 2432 LOG(LS_VERBOSE) << "WebRtcVoiceMediaChannel::SetRawAudioSink: ssrc:" << ssrc |
| 2433 << " " << (sink ? "(ptr)" : "NULL"); |
| 2434 if (ssrc == 0) { |
| 2435 if (default_recv_ssrc_ != -1) { |
| 2436 rtc::scoped_ptr<webrtc::AudioSinkInterface> proxy_sink( |
| 2437 sink ? new ProxySink(sink.get()) : nullptr); |
| 2438 SetRawAudioSink(default_recv_ssrc_, std::move(proxy_sink)); |
| 2439 } |
| 2440 default_sink_ = std::move(sink); |
| 2441 return; |
| 2442 } |
2418 const auto it = recv_streams_.find(ssrc); | 2443 const auto it = recv_streams_.find(ssrc); |
2419 if (it == recv_streams_.end()) { | 2444 if (it == recv_streams_.end()) { |
2420 LOG(LS_WARNING) << "SetRawAudioSink: no recv stream" << ssrc; | 2445 LOG(LS_WARNING) << "SetRawAudioSink: no recv stream" << ssrc; |
2421 return; | 2446 return; |
2422 } | 2447 } |
2423 it->second->SetRawAudioSink(std::move(sink)); | 2448 it->second->SetRawAudioSink(std::move(sink)); |
2424 } | 2449 } |
2425 | 2450 |
2426 int WebRtcVoiceMediaChannel::GetOutputLevel(int channel) { | 2451 int WebRtcVoiceMediaChannel::GetOutputLevel(int channel) { |
2427 unsigned int ulevel = 0; | 2452 unsigned int ulevel = 0; |
(...skipping 72 matching lines...) Loading... |
2500 } | 2525 } |
2501 } else { | 2526 } else { |
2502 LOG(LS_INFO) << "Stopping playout for channel #" << channel; | 2527 LOG(LS_INFO) << "Stopping playout for channel #" << channel; |
2503 engine()->voe()->base()->StopPlayout(channel); | 2528 engine()->voe()->base()->StopPlayout(channel); |
2504 } | 2529 } |
2505 return true; | 2530 return true; |
2506 } | 2531 } |
2507 } // namespace cricket | 2532 } // namespace cricket |
2508 | 2533 |
2509 #endif // HAVE_WEBRTC_VOICE | 2534 #endif // HAVE_WEBRTC_VOICE |
OLD | NEW |