Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Side by Side Diff: webrtc/media/engine/webrtcvideoengine2.cc

Issue 1785713005: Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Feedback from tommi. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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
11 #include "webrtc/media/engine/webrtcvideoengine2.h" 11 #include "webrtc/media/engine/webrtcvideoengine2.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <set> 14 #include <set>
15 #include <string> 15 #include <string>
16 16
17 #include "webrtc/base/buffer.h" 17 #include "webrtc/base/copyonwritebuffer.h"
18 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
19 #include "webrtc/base/stringutils.h" 19 #include "webrtc/base/stringutils.h"
20 #include "webrtc/base/timeutils.h" 20 #include "webrtc/base/timeutils.h"
21 #include "webrtc/base/trace_event.h" 21 #include "webrtc/base/trace_event.h"
22 #include "webrtc/call.h" 22 #include "webrtc/call.h"
23 #include "webrtc/media/base/videocapturer.h" 23 #include "webrtc/media/base/videocapturer.h"
24 #include "webrtc/media/base/videorenderer.h" 24 #include "webrtc/media/base/videorenderer.h"
25 #include "webrtc/media/engine/constants.h" 25 #include "webrtc/media/engine/constants.h"
26 #include "webrtc/media/engine/simulcast.h" 26 #include "webrtc/media/engine/simulcast.h"
27 #include "webrtc/media/engine/webrtcmediaengine.h" 27 #include "webrtc/media/engine/webrtcmediaengine.h"
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 return false; 1280 return false;
1281 } 1281 }
1282 if (!kv->second->SetCapturer(capturer)) { 1282 if (!kv->second->SetCapturer(capturer)) {
1283 return false; 1283 return false;
1284 } 1284 }
1285 } 1285 }
1286 return true; 1286 return true;
1287 } 1287 }
1288 1288
1289 void WebRtcVideoChannel2::OnPacketReceived( 1289 void WebRtcVideoChannel2::OnPacketReceived(
1290 rtc::Buffer* packet, 1290 rtc::CopyOnWriteBuffer* packet,
1291 const rtc::PacketTime& packet_time) { 1291 const rtc::PacketTime& packet_time) {
1292 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, 1292 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp,
1293 packet_time.not_before); 1293 packet_time.not_before);
1294 const webrtc::PacketReceiver::DeliveryStatus delivery_result = 1294 const webrtc::PacketReceiver::DeliveryStatus delivery_result =
1295 call_->Receiver()->DeliverPacket( 1295 call_->Receiver()->DeliverPacket(
1296 webrtc::MediaType::VIDEO, 1296 webrtc::MediaType::VIDEO,
1297 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), 1297 packet->cdata(), packet->size(),
1298 webrtc_packet_time); 1298 webrtc_packet_time);
1299 switch (delivery_result) { 1299 switch (delivery_result) {
1300 case webrtc::PacketReceiver::DELIVERY_OK: 1300 case webrtc::PacketReceiver::DELIVERY_OK:
1301 return; 1301 return;
1302 case webrtc::PacketReceiver::DELIVERY_PACKET_ERROR: 1302 case webrtc::PacketReceiver::DELIVERY_PACKET_ERROR:
1303 return; 1303 return;
1304 case webrtc::PacketReceiver::DELIVERY_UNKNOWN_SSRC: 1304 case webrtc::PacketReceiver::DELIVERY_UNKNOWN_SSRC:
1305 break; 1305 break;
1306 } 1306 }
1307 1307
1308 uint32_t ssrc = 0; 1308 uint32_t ssrc = 0;
1309 if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc)) { 1309 if (!GetRtpSsrc(packet->cdata(), packet->size(), &ssrc)) {
1310 return; 1310 return;
1311 } 1311 }
1312 1312
1313 int payload_type = 0; 1313 int payload_type = 0;
1314 if (!GetRtpPayloadType(packet->data(), packet->size(), &payload_type)) { 1314 if (!GetRtpPayloadType(packet->cdata(), packet->size(), &payload_type)) {
1315 return; 1315 return;
1316 } 1316 }
1317 1317
1318 // See if this payload_type is registered as one that usually gets its own 1318 // See if this payload_type is registered as one that usually gets its own
1319 // SSRC (RTX) or at least is safe to drop either way (ULPFEC). If it is, and 1319 // SSRC (RTX) or at least is safe to drop either way (ULPFEC). If it is, and
1320 // it wasn't handled above by DeliverPacket, that means we don't know what 1320 // it wasn't handled above by DeliverPacket, that means we don't know what
1321 // stream it associates with, and we shouldn't ever create an implicit channel 1321 // stream it associates with, and we shouldn't ever create an implicit channel
1322 // for these. 1322 // for these.
1323 for (auto& codec : recv_codecs_) { 1323 for (auto& codec : recv_codecs_) {
1324 if (payload_type == codec.rtx_payload_type || 1324 if (payload_type == codec.rtx_payload_type ||
1325 payload_type == codec.fec.red_rtx_payload_type || 1325 payload_type == codec.fec.red_rtx_payload_type ||
1326 payload_type == codec.fec.ulpfec_payload_type) { 1326 payload_type == codec.fec.ulpfec_payload_type) {
1327 return; 1327 return;
1328 } 1328 }
1329 } 1329 }
1330 1330
1331 switch (unsignalled_ssrc_handler_->OnUnsignalledSsrc(this, ssrc)) { 1331 switch (unsignalled_ssrc_handler_->OnUnsignalledSsrc(this, ssrc)) {
1332 case UnsignalledSsrcHandler::kDropPacket: 1332 case UnsignalledSsrcHandler::kDropPacket:
1333 return; 1333 return;
1334 case UnsignalledSsrcHandler::kDeliverPacket: 1334 case UnsignalledSsrcHandler::kDeliverPacket:
1335 break; 1335 break;
1336 } 1336 }
1337 1337
1338 if (call_->Receiver()->DeliverPacket( 1338 if (call_->Receiver()->DeliverPacket(
1339 webrtc::MediaType::VIDEO, 1339 webrtc::MediaType::VIDEO,
1340 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), 1340 packet->cdata(), packet->size(),
1341 webrtc_packet_time) != webrtc::PacketReceiver::DELIVERY_OK) { 1341 webrtc_packet_time) != webrtc::PacketReceiver::DELIVERY_OK) {
1342 LOG(LS_WARNING) << "Failed to deliver RTP packet on re-delivery."; 1342 LOG(LS_WARNING) << "Failed to deliver RTP packet on re-delivery.";
1343 return; 1343 return;
1344 } 1344 }
1345 } 1345 }
1346 1346
1347 void WebRtcVideoChannel2::OnRtcpReceived( 1347 void WebRtcVideoChannel2::OnRtcpReceived(
1348 rtc::Buffer* packet, 1348 rtc::CopyOnWriteBuffer* packet,
1349 const rtc::PacketTime& packet_time) { 1349 const rtc::PacketTime& packet_time) {
1350 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp, 1350 const webrtc::PacketTime webrtc_packet_time(packet_time.timestamp,
1351 packet_time.not_before); 1351 packet_time.not_before);
1352 // TODO(pbos): Check webrtc::PacketReceiver::DELIVERY_OK once we deliver 1352 // TODO(pbos): Check webrtc::PacketReceiver::DELIVERY_OK once we deliver
1353 // for both audio and video on the same path. Since BundleFilter doesn't 1353 // for both audio and video on the same path. Since BundleFilter doesn't
1354 // filter RTCP anymore incoming RTCP packets could've been going to audio (so 1354 // filter RTCP anymore incoming RTCP packets could've been going to audio (so
1355 // logging failures spam the log). 1355 // logging failures spam the log).
1356 call_->Receiver()->DeliverPacket( 1356 call_->Receiver()->DeliverPacket(
1357 webrtc::MediaType::VIDEO, 1357 webrtc::MediaType::VIDEO,
1358 reinterpret_cast<const uint8_t*>(packet->data()), packet->size(), 1358 packet->cdata(), packet->size(),
1359 webrtc_packet_time); 1359 webrtc_packet_time);
1360 } 1360 }
1361 1361
1362 void WebRtcVideoChannel2::OnReadyToSend(bool ready) { 1362 void WebRtcVideoChannel2::OnReadyToSend(bool ready) {
1363 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready."); 1363 LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready.");
1364 call_->SignalNetworkState(ready ? webrtc::kNetworkUp : webrtc::kNetworkDown); 1364 call_->SignalNetworkState(ready ? webrtc::kNetworkUp : webrtc::kNetworkDown);
1365 } 1365 }
1366 1366
1367 bool WebRtcVideoChannel2::MuteStream(uint32_t ssrc, bool mute) { 1367 bool WebRtcVideoChannel2::MuteStream(uint32_t ssrc, bool mute) {
1368 LOG(LS_VERBOSE) << "MuteStream: " << ssrc << " -> " 1368 LOG(LS_VERBOSE) << "MuteStream: " << ssrc << " -> "
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 // due to lack of socket buffer space, although it's not yet clear what the 1404 // due to lack of socket buffer space, although it's not yet clear what the
1405 // ideal value should be. 1405 // ideal value should be.
1406 MediaChannel::SetOption(NetworkInterface::ST_RTP, 1406 MediaChannel::SetOption(NetworkInterface::ST_RTP,
1407 rtc::Socket::OPT_SNDBUF, 1407 rtc::Socket::OPT_SNDBUF,
1408 kVideoRtpBufferSize); 1408 kVideoRtpBufferSize);
1409 } 1409 }
1410 1410
1411 bool WebRtcVideoChannel2::SendRtp(const uint8_t* data, 1411 bool WebRtcVideoChannel2::SendRtp(const uint8_t* data,
1412 size_t len, 1412 size_t len,
1413 const webrtc::PacketOptions& options) { 1413 const webrtc::PacketOptions& options) {
1414 rtc::Buffer packet(data, len, kMaxRtpPacketLen); 1414 rtc::CopyOnWriteBuffer packet(data, len, kMaxRtpPacketLen);
1415 rtc::PacketOptions rtc_options; 1415 rtc::PacketOptions rtc_options;
1416 rtc_options.packet_id = options.packet_id; 1416 rtc_options.packet_id = options.packet_id;
1417 return MediaChannel::SendPacket(&packet, rtc_options); 1417 return MediaChannel::SendPacket(&packet, rtc_options);
1418 } 1418 }
1419 1419
1420 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { 1420 bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) {
1421 rtc::Buffer packet(data, len, kMaxRtpPacketLen); 1421 rtc::CopyOnWriteBuffer packet(data, len, kMaxRtpPacketLen);
1422 return MediaChannel::SendRtcp(&packet, rtc::PacketOptions()); 1422 return MediaChannel::SendRtcp(&packet, rtc::PacketOptions());
1423 } 1423 }
1424 1424
1425 void WebRtcVideoChannel2::StartAllSendStreams() { 1425 void WebRtcVideoChannel2::StartAllSendStreams() {
1426 rtc::CritScope stream_lock(&stream_crit_); 1426 rtc::CritScope stream_lock(&stream_crit_);
1427 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it = 1427 for (std::map<uint32_t, WebRtcVideoSendStream*>::iterator it =
1428 send_streams_.begin(); 1428 send_streams_.begin();
1429 it != send_streams_.end(); ++it) { 1429 it != send_streams_.end(); ++it) {
1430 it->second->Start(); 1430 it->second->Start();
1431 } 1431 }
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after
2529 rtx_mapping[video_codecs[i].codec.id] != 2529 rtx_mapping[video_codecs[i].codec.id] !=
2530 fec_settings.red_payload_type) { 2530 fec_settings.red_payload_type) {
2531 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; 2531 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id];
2532 } 2532 }
2533 } 2533 }
2534 2534
2535 return video_codecs; 2535 return video_codecs;
2536 } 2536 }
2537 2537
2538 } // namespace cricket 2538 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvideoengine2.h ('k') | webrtc/media/engine/webrtcvideoengine2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698