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

Side by Side Diff: webrtc/voice_engine/voe_base_impl.cc

Issue 1493663002: Removing some unnecessary string manipulation code from VoEBase::GetVersion(). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: comment Created 5 years 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
« no previous file with comments | « webrtc/voice_engine/voe_base_impl.h ('k') | webrtc/voice_engine/voe_base_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 return -1; 575 return -1;
576 } 576 }
577 if (channelPtr->StopSend() != 0) { 577 if (channelPtr->StopSend() != 0) {
578 LOG_F(LS_WARNING) << "StopSend() failed to stop sending for channel " 578 LOG_F(LS_WARNING) << "StopSend() failed to stop sending for channel "
579 << channel; 579 << channel;
580 } 580 }
581 return StopSend(); 581 return StopSend();
582 } 582 }
583 583
584 int VoEBaseImpl::GetVersion(char version[1024]) { 584 int VoEBaseImpl::GetVersion(char version[1024]) {
585 static_assert(kVoiceEngineVersionMaxMessageSize == 1024, "");
586
587 if (version == nullptr) { 585 if (version == nullptr) {
588 shared_->SetLastError(VE_INVALID_ARGUMENT, kTraceError); 586 shared_->SetLastError(VE_INVALID_ARGUMENT, kTraceError);
589 return (-1); 587 return -1;
590 } 588 }
591 589
592 char versionBuf[kVoiceEngineVersionMaxMessageSize]; 590 std::string versionString = VoiceEngine::GetVersionString();
593 char* versionPtr = versionBuf; 591 RTC_DCHECK_GT(1024u, versionString.size() + 1);
594 592 char* end = std::copy(versionString.cbegin(), versionString.cend(), version);
595 int32_t len = 0; 593 end[0] = '\n';
596 int32_t accLen = 0; 594 end[1] = '\0';
597
598 len = AddVoEVersion(versionPtr);
599 if (len == -1) {
600 return -1;
601 }
602 versionPtr += len;
603 accLen += len;
604 assert(accLen < kVoiceEngineVersionMaxMessageSize);
605
606 #ifdef WEBRTC_EXTERNAL_TRANSPORT
607 len = AddExternalTransportBuild(versionPtr);
608 if (len == -1) {
609 return -1;
610 }
611 versionPtr += len;
612 accLen += len;
613 assert(accLen < kVoiceEngineVersionMaxMessageSize);
614 #endif
615
616 memcpy(version, versionBuf, accLen);
617 version[accLen] = '\0';
618
619 // to avoid the truncation in the trace, split the string into parts
620 char partOfVersion[256];
621 for (int partStart = 0; partStart < accLen;) {
622 memset(partOfVersion, 0, sizeof(partOfVersion));
623 int partEnd = partStart + 180;
624 while (version[partEnd] != '\n' && version[partEnd] != '\0') {
625 partEnd--;
626 }
627 if (partEnd < accLen) {
628 memcpy(partOfVersion, &version[partStart], partEnd - partStart);
629 } else {
630 memcpy(partOfVersion, &version[partStart], accLen - partStart);
631 }
632 partStart = partEnd;
633 }
634
635 return 0; 595 return 0;
636 } 596 }
637 597
638 int32_t VoEBaseImpl::AddVoEVersion(char* str) const {
639 return sprintf(str, "VoiceEngine 4.1.0\n");
640 }
641
642 #ifdef WEBRTC_EXTERNAL_TRANSPORT
643 int32_t VoEBaseImpl::AddExternalTransportBuild(char* str) const {
644 return sprintf(str, "External transport build\n");
645 }
646 #endif
647
648 int VoEBaseImpl::LastError() { return (shared_->statistics().LastError()); } 598 int VoEBaseImpl::LastError() { return (shared_->statistics().LastError()); }
649 599
650 int32_t VoEBaseImpl::StartPlayout() { 600 int32_t VoEBaseImpl::StartPlayout() {
651 if (!shared_->audio_device()->Playing()) { 601 if (!shared_->audio_device()->Playing()) {
652 if (shared_->audio_device()->InitPlayout() != 0) { 602 if (shared_->audio_device()->InitPlayout() != 0) {
653 LOG_F(LS_ERROR) << "Failed to initialize playout"; 603 LOG_F(LS_ERROR) << "Failed to initialize playout";
654 return -1; 604 return -1;
655 } 605 }
656 if (shared_->audio_device()->StartPlayout() != 0) { 606 if (shared_->audio_device()->StartPlayout() != 0) {
657 LOG_F(LS_ERROR) << "Failed to start playout"; 607 LOG_F(LS_ERROR) << "Failed to start playout";
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, 817 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
868 "AssociateSendChannel() failed to locate accociate_send_channel"); 818 "AssociateSendChannel() failed to locate accociate_send_channel");
869 return -1; 819 return -1;
870 } 820 }
871 821
872 channel_ptr->set_associate_send_channel(ch); 822 channel_ptr->set_associate_send_channel(ch);
873 return 0; 823 return 0;
874 } 824 }
875 825
876 } // namespace webrtc 826 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/voice_engine/voe_base_impl.h ('k') | webrtc/voice_engine/voe_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698