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

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

Issue 2049683003: FileRecorder + FilePlayer: Let Create functions return unique_ptr (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@remove3
Patch Set: Created 4 years, 4 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) 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 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 _channelId, kPlaybackPerChannel, (int16_t*)audioFrame->data_, 670 _channelId, kPlaybackPerChannel, (int16_t*)audioFrame->data_,
671 audioFrame->samples_per_channel_, audioFrame->sample_rate_hz_, 671 audioFrame->samples_per_channel_, audioFrame->sample_rate_hz_,
672 isStereo); 672 isStereo);
673 } 673 }
674 } 674 }
675 675
676 // Record playout if enabled 676 // Record playout if enabled
677 { 677 {
678 rtc::CritScope cs(&_fileCritSect); 678 rtc::CritScope cs(&_fileCritSect);
679 679
680 if (_outputFileRecording && _outputFileRecorderPtr) { 680 if (_outputFileRecording && output_file_recorder_) {
681 _outputFileRecorderPtr->RecordAudioToFile(*audioFrame); 681 output_file_recorder_->RecordAudioToFile(*audioFrame);
682 } 682 }
683 } 683 }
684 684
685 // Measure audio level (0-9) 685 // Measure audio level (0-9)
686 // TODO(henrik.lundin) Use the |muted| information here too. 686 // TODO(henrik.lundin) Use the |muted| information here too.
687 _outputAudioLevel.ComputeLevel(*audioFrame); 687 _outputAudioLevel.ComputeLevel(*audioFrame);
688 688
689 if (capture_start_rtp_time_stamp_ < 0 && audioFrame->timestamp_ != 0) { 689 if (capture_start_rtp_time_stamp_ < 0 && audioFrame->timestamp_ != 0) {
690 // The first frame with a valid rtp timestamp. 690 // The first frame with a valid rtp timestamp.
691 capture_start_rtp_time_stamp_ = audioFrame->timestamp_; 691 capture_start_rtp_time_stamp_ = audioFrame->timestamp_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 } else { 735 } else {
736 highestNeeded = receiveFrequency; 736 highestNeeded = receiveFrequency;
737 } 737 }
738 738
739 // Special case, if we're playing a file on the playout side 739 // Special case, if we're playing a file on the playout side
740 // we take that frequency into consideration as well 740 // we take that frequency into consideration as well
741 // This is not needed on sending side, since the codec will 741 // This is not needed on sending side, since the codec will
742 // limit the spectrum anyway. 742 // limit the spectrum anyway.
743 if (channel_state_.Get().output_file_playing) { 743 if (channel_state_.Get().output_file_playing) {
744 rtc::CritScope cs(&_fileCritSect); 744 rtc::CritScope cs(&_fileCritSect);
745 if (_outputFilePlayerPtr) { 745 if (output_file_player_) {
746 if (_outputFilePlayerPtr->Frequency() > highestNeeded) { 746 if (output_file_player_->Frequency() > highestNeeded) {
747 highestNeeded = _outputFilePlayerPtr->Frequency(); 747 highestNeeded = output_file_player_->Frequency();
748 } 748 }
749 } 749 }
750 } 750 }
751 751
752 return (highestNeeded); 752 return (highestNeeded);
753 } 753 }
754 754
755 int32_t Channel::CreateChannel(Channel*& channel, 755 int32_t Channel::CreateChannel(Channel*& channel,
756 int32_t channelId, 756 int32_t channelId,
757 uint32_t instanceId, 757 uint32_t instanceId,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 rtp_receive_statistics_( 840 rtp_receive_statistics_(
841 ReceiveStatistics::Create(Clock::GetRealTimeClock())), 841 ReceiveStatistics::Create(Clock::GetRealTimeClock())),
842 rtp_receiver_( 842 rtp_receiver_(
843 RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(), 843 RtpReceiver::CreateAudioReceiver(Clock::GetRealTimeClock(),
844 this, 844 this,
845 this, 845 this,
846 rtp_payload_registry_.get())), 846 rtp_payload_registry_.get())),
847 telephone_event_handler_(rtp_receiver_->GetTelephoneEventHandler()), 847 telephone_event_handler_(rtp_receiver_->GetTelephoneEventHandler()),
848 _outputAudioLevel(), 848 _outputAudioLevel(),
849 _externalTransport(false), 849 _externalTransport(false),
850 _inputFilePlayerPtr(NULL),
851 _outputFilePlayerPtr(NULL),
852 _outputFileRecorderPtr(NULL),
853 // Avoid conflict with other channels by adding 1024 - 1026, 850 // Avoid conflict with other channels by adding 1024 - 1026,
854 // won't use as much as 1024 channels. 851 // won't use as much as 1024 channels.
855 _inputFilePlayerId(VoEModuleId(instanceId, channelId) + 1024), 852 _inputFilePlayerId(VoEModuleId(instanceId, channelId) + 1024),
856 _outputFilePlayerId(VoEModuleId(instanceId, channelId) + 1025), 853 _outputFilePlayerId(VoEModuleId(instanceId, channelId) + 1025),
857 _outputFileRecorderId(VoEModuleId(instanceId, channelId) + 1026), 854 _outputFileRecorderId(VoEModuleId(instanceId, channelId) + 1026),
858 _outputFileRecording(false), 855 _outputFileRecording(false),
859 _outputExternalMedia(false), 856 _outputExternalMedia(false),
860 _inputExternalMediaCallbackPtr(NULL), 857 _inputExternalMediaCallbackPtr(NULL),
861 _outputExternalMediaCallbackPtr(NULL), 858 _outputExternalMediaCallbackPtr(NULL),
862 _timeStamp(0), // This is just an offset, RTP module will add it's own 859 _timeStamp(0), // This is just an offset, RTP module will add it's own
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 DeRegisterExternalMediaProcessing(kPlaybackPerChannel); 960 DeRegisterExternalMediaProcessing(kPlaybackPerChannel);
964 } 961 }
965 if (channel_state_.Get().input_external_media) { 962 if (channel_state_.Get().input_external_media) {
966 DeRegisterExternalMediaProcessing(kRecordingPerChannel); 963 DeRegisterExternalMediaProcessing(kRecordingPerChannel);
967 } 964 }
968 StopSend(); 965 StopSend();
969 StopPlayout(); 966 StopPlayout();
970 967
971 { 968 {
972 rtc::CritScope cs(&_fileCritSect); 969 rtc::CritScope cs(&_fileCritSect);
973 if (_inputFilePlayerPtr) { 970 if (input_file_player_) {
974 _inputFilePlayerPtr->RegisterModuleFileCallback(NULL); 971 input_file_player_->RegisterModuleFileCallback(NULL);
975 _inputFilePlayerPtr->StopPlayingFile(); 972 input_file_player_->StopPlayingFile();
976 FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr);
977 _inputFilePlayerPtr = NULL;
978 } 973 }
979 if (_outputFilePlayerPtr) { 974 if (output_file_player_) {
980 _outputFilePlayerPtr->RegisterModuleFileCallback(NULL); 975 output_file_player_->RegisterModuleFileCallback(NULL);
981 _outputFilePlayerPtr->StopPlayingFile(); 976 output_file_player_->StopPlayingFile();
982 FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr);
983 _outputFilePlayerPtr = NULL;
984 } 977 }
985 if (_outputFileRecorderPtr) { 978 if (output_file_recorder_) {
986 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); 979 output_file_recorder_->RegisterModuleFileCallback(NULL);
987 _outputFileRecorderPtr->StopRecording(); 980 output_file_recorder_->StopRecording();
988 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr);
989 _outputFileRecorderPtr = NULL;
990 } 981 }
991 } 982 }
992 983
993 // The order to safely shutdown modules in a channel is: 984 // The order to safely shutdown modules in a channel is:
994 // 1. De-register callbacks in modules 985 // 1. De-register callbacks in modules
995 // 2. De-register modules in process thread 986 // 2. De-register modules in process thread
996 // 3. Destroy modules 987 // 3. Destroy modules
997 if (audio_coding_->RegisterTransportCallback(NULL) == -1) { 988 if (audio_coding_->RegisterTransportCallback(NULL) == -1) {
998 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), 989 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId),
999 "~Channel() failed to de-register transport callback" 990 "~Channel() failed to de-register transport callback"
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 if (channel_state_.Get().output_file_playing) { 1753 if (channel_state_.Get().output_file_playing) {
1763 _engineStatisticsPtr->SetLastError( 1754 _engineStatisticsPtr->SetLastError(
1764 VE_ALREADY_PLAYING, kTraceError, 1755 VE_ALREADY_PLAYING, kTraceError,
1765 "StartPlayingFileLocally() is already playing"); 1756 "StartPlayingFileLocally() is already playing");
1766 return -1; 1757 return -1;
1767 } 1758 }
1768 1759
1769 { 1760 {
1770 rtc::CritScope cs(&_fileCritSect); 1761 rtc::CritScope cs(&_fileCritSect);
1771 1762
1772 if (_outputFilePlayerPtr) { 1763 if (output_file_player_) {
1773 _outputFilePlayerPtr->RegisterModuleFileCallback(NULL); 1764 output_file_player_->RegisterModuleFileCallback(NULL);
1774 FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); 1765 output_file_player_.reset();
1775 _outputFilePlayerPtr = NULL;
1776 } 1766 }
1777 1767
1778 _outputFilePlayerPtr = FilePlayer::CreateFilePlayer( 1768 output_file_player_ = FilePlayer::NewFilePlayer(
1779 _outputFilePlayerId, (const FileFormats)format); 1769 _outputFilePlayerId, (const FileFormats)format);
1780 1770
1781 if (_outputFilePlayerPtr == NULL) { 1771 if (!output_file_player_) {
1782 _engineStatisticsPtr->SetLastError( 1772 _engineStatisticsPtr->SetLastError(
1783 VE_INVALID_ARGUMENT, kTraceError, 1773 VE_INVALID_ARGUMENT, kTraceError,
1784 "StartPlayingFileLocally() filePlayer format is not correct"); 1774 "StartPlayingFileLocally() filePlayer format is not correct");
1785 return -1; 1775 return -1;
1786 } 1776 }
1787 1777
1788 const uint32_t notificationTime(0); 1778 const uint32_t notificationTime(0);
1789 1779
1790 if (_outputFilePlayerPtr->StartPlayingFile( 1780 if (output_file_player_->StartPlayingFile(
1791 fileName, loop, startPosition, volumeScaling, notificationTime, 1781 fileName, loop, startPosition, volumeScaling, notificationTime,
1792 stopPosition, (const CodecInst*)codecInst) != 0) { 1782 stopPosition, (const CodecInst*)codecInst) != 0) {
1793 _engineStatisticsPtr->SetLastError( 1783 _engineStatisticsPtr->SetLastError(
1794 VE_BAD_FILE, kTraceError, 1784 VE_BAD_FILE, kTraceError,
1795 "StartPlayingFile() failed to start file playout"); 1785 "StartPlayingFile() failed to start file playout");
1796 _outputFilePlayerPtr->StopPlayingFile(); 1786 output_file_player_->StopPlayingFile();
1797 FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); 1787 output_file_player_.reset();
1798 _outputFilePlayerPtr = NULL;
1799 return -1; 1788 return -1;
1800 } 1789 }
1801 _outputFilePlayerPtr->RegisterModuleFileCallback(this); 1790 output_file_player_->RegisterModuleFileCallback(this);
1802 channel_state_.SetOutputFilePlaying(true); 1791 channel_state_.SetOutputFilePlaying(true);
1803 } 1792 }
1804 1793
1805 if (RegisterFilePlayingToMixer() != 0) 1794 if (RegisterFilePlayingToMixer() != 0)
1806 return -1; 1795 return -1;
1807 1796
1808 return 0; 1797 return 0;
1809 } 1798 }
1810 1799
1811 int Channel::StartPlayingFileLocally(InStream* stream, 1800 int Channel::StartPlayingFileLocally(InStream* stream,
(...skipping 18 matching lines...) Expand all
1830 _engineStatisticsPtr->SetLastError( 1819 _engineStatisticsPtr->SetLastError(
1831 VE_ALREADY_PLAYING, kTraceError, 1820 VE_ALREADY_PLAYING, kTraceError,
1832 "StartPlayingFileLocally() is already playing"); 1821 "StartPlayingFileLocally() is already playing");
1833 return -1; 1822 return -1;
1834 } 1823 }
1835 1824
1836 { 1825 {
1837 rtc::CritScope cs(&_fileCritSect); 1826 rtc::CritScope cs(&_fileCritSect);
1838 1827
1839 // Destroy the old instance 1828 // Destroy the old instance
1840 if (_outputFilePlayerPtr) { 1829 if (output_file_player_) {
1841 _outputFilePlayerPtr->RegisterModuleFileCallback(NULL); 1830 output_file_player_->RegisterModuleFileCallback(NULL);
1842 FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); 1831 output_file_player_.reset();
1843 _outputFilePlayerPtr = NULL;
1844 } 1832 }
1845 1833
1846 // Create the instance 1834 // Create the instance
1847 _outputFilePlayerPtr = FilePlayer::CreateFilePlayer( 1835 output_file_player_ = FilePlayer::NewFilePlayer(
1848 _outputFilePlayerId, (const FileFormats)format); 1836 _outputFilePlayerId, (const FileFormats)format);
1849 1837
1850 if (_outputFilePlayerPtr == NULL) { 1838 if (!output_file_player_) {
1851 _engineStatisticsPtr->SetLastError( 1839 _engineStatisticsPtr->SetLastError(
1852 VE_INVALID_ARGUMENT, kTraceError, 1840 VE_INVALID_ARGUMENT, kTraceError,
1853 "StartPlayingFileLocally() filePlayer format isnot correct"); 1841 "StartPlayingFileLocally() filePlayer format isnot correct");
1854 return -1; 1842 return -1;
1855 } 1843 }
1856 1844
1857 const uint32_t notificationTime(0); 1845 const uint32_t notificationTime(0);
1858 1846
1859 if (_outputFilePlayerPtr->StartPlayingFile(*stream, startPosition, 1847 if (output_file_player_->StartPlayingFile(*stream, startPosition,
1860 volumeScaling, notificationTime, 1848 volumeScaling, notificationTime,
1861 stopPosition, codecInst) != 0) { 1849 stopPosition, codecInst) != 0) {
1862 _engineStatisticsPtr->SetLastError(VE_BAD_FILE, kTraceError, 1850 _engineStatisticsPtr->SetLastError(VE_BAD_FILE, kTraceError,
1863 "StartPlayingFile() failed to " 1851 "StartPlayingFile() failed to "
1864 "start file playout"); 1852 "start file playout");
1865 _outputFilePlayerPtr->StopPlayingFile(); 1853 output_file_player_->StopPlayingFile();
1866 FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); 1854 output_file_player_.reset();
1867 _outputFilePlayerPtr = NULL;
1868 return -1; 1855 return -1;
1869 } 1856 }
1870 _outputFilePlayerPtr->RegisterModuleFileCallback(this); 1857 output_file_player_->RegisterModuleFileCallback(this);
1871 channel_state_.SetOutputFilePlaying(true); 1858 channel_state_.SetOutputFilePlaying(true);
1872 } 1859 }
1873 1860
1874 if (RegisterFilePlayingToMixer() != 0) 1861 if (RegisterFilePlayingToMixer() != 0)
1875 return -1; 1862 return -1;
1876 1863
1877 return 0; 1864 return 0;
1878 } 1865 }
1879 1866
1880 int Channel::StopPlayingFileLocally() { 1867 int Channel::StopPlayingFileLocally() {
1881 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), 1868 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId),
1882 "Channel::StopPlayingFileLocally()"); 1869 "Channel::StopPlayingFileLocally()");
1883 1870
1884 if (!channel_state_.Get().output_file_playing) { 1871 if (!channel_state_.Get().output_file_playing) {
1885 return 0; 1872 return 0;
1886 } 1873 }
1887 1874
1888 { 1875 {
1889 rtc::CritScope cs(&_fileCritSect); 1876 rtc::CritScope cs(&_fileCritSect);
1890 1877
1891 if (_outputFilePlayerPtr->StopPlayingFile() != 0) { 1878 if (output_file_player_->StopPlayingFile() != 0) {
1892 _engineStatisticsPtr->SetLastError( 1879 _engineStatisticsPtr->SetLastError(
1893 VE_STOP_RECORDING_FAILED, kTraceError, 1880 VE_STOP_RECORDING_FAILED, kTraceError,
1894 "StopPlayingFile() could not stop playing"); 1881 "StopPlayingFile() could not stop playing");
1895 return -1; 1882 return -1;
1896 } 1883 }
1897 _outputFilePlayerPtr->RegisterModuleFileCallback(NULL); 1884 output_file_player_->RegisterModuleFileCallback(NULL);
1898 FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); 1885 output_file_player_.reset();
1899 _outputFilePlayerPtr = NULL;
1900 channel_state_.SetOutputFilePlaying(false); 1886 channel_state_.SetOutputFilePlaying(false);
1901 } 1887 }
1902 // _fileCritSect cannot be taken while calling 1888 // _fileCritSect cannot be taken while calling
1903 // SetAnonymousMixibilityStatus. Refer to comments in 1889 // SetAnonymousMixibilityStatus. Refer to comments in
1904 // StartPlayingFileLocally(const char* ...) for more details. 1890 // StartPlayingFileLocally(const char* ...) for more details.
1905 if (_outputMixerPtr->SetAnonymousMixabilityStatus(*this, false) != 0) { 1891 if (_outputMixerPtr->SetAnonymousMixabilityStatus(*this, false) != 0) {
1906 _engineStatisticsPtr->SetLastError( 1892 _engineStatisticsPtr->SetLastError(
1907 VE_AUDIO_CONF_MIX_MODULE_ERROR, kTraceError, 1893 VE_AUDIO_CONF_MIX_MODULE_ERROR, kTraceError,
1908 "StopPlayingFile() failed to stop participant from playing as" 1894 "StopPlayingFile() failed to stop participant from playing as"
1909 "file in the mixer"); 1895 "file in the mixer");
(...skipping 19 matching lines...) Expand all
1929 // |_fileCritSect| cannot be taken while calling 1915 // |_fileCritSect| cannot be taken while calling
1930 // SetAnonymousMixabilityStatus() since as soon as the participant is added 1916 // SetAnonymousMixabilityStatus() since as soon as the participant is added
1931 // frames can be pulled by the mixer. Since the frames are generated from 1917 // frames can be pulled by the mixer. Since the frames are generated from
1932 // the file, _fileCritSect will be taken. This would result in a deadlock. 1918 // the file, _fileCritSect will be taken. This would result in a deadlock.
1933 if (_outputMixerPtr->SetAnonymousMixabilityStatus(*this, true) != 0) { 1919 if (_outputMixerPtr->SetAnonymousMixabilityStatus(*this, true) != 0) {
1934 channel_state_.SetOutputFilePlaying(false); 1920 channel_state_.SetOutputFilePlaying(false);
1935 rtc::CritScope cs(&_fileCritSect); 1921 rtc::CritScope cs(&_fileCritSect);
1936 _engineStatisticsPtr->SetLastError( 1922 _engineStatisticsPtr->SetLastError(
1937 VE_AUDIO_CONF_MIX_MODULE_ERROR, kTraceError, 1923 VE_AUDIO_CONF_MIX_MODULE_ERROR, kTraceError,
1938 "StartPlayingFile() failed to add participant as file to mixer"); 1924 "StartPlayingFile() failed to add participant as file to mixer");
1939 _outputFilePlayerPtr->StopPlayingFile(); 1925 output_file_player_->StopPlayingFile();
1940 FilePlayer::DestroyFilePlayer(_outputFilePlayerPtr); 1926 output_file_player_.reset();
1941 _outputFilePlayerPtr = NULL;
1942 return -1; 1927 return -1;
1943 } 1928 }
1944 1929
1945 return 0; 1930 return 0;
1946 } 1931 }
1947 1932
1948 int Channel::StartPlayingFileAsMicrophone(const char* fileName, 1933 int Channel::StartPlayingFileAsMicrophone(const char* fileName,
1949 bool loop, 1934 bool loop,
1950 FileFormats format, 1935 FileFormats format,
1951 int startPosition, 1936 int startPosition,
(...skipping 10 matching lines...) Expand all
1962 rtc::CritScope cs(&_fileCritSect); 1947 rtc::CritScope cs(&_fileCritSect);
1963 1948
1964 if (channel_state_.Get().input_file_playing) { 1949 if (channel_state_.Get().input_file_playing) {
1965 _engineStatisticsPtr->SetLastError( 1950 _engineStatisticsPtr->SetLastError(
1966 VE_ALREADY_PLAYING, kTraceWarning, 1951 VE_ALREADY_PLAYING, kTraceWarning,
1967 "StartPlayingFileAsMicrophone() filePlayer is playing"); 1952 "StartPlayingFileAsMicrophone() filePlayer is playing");
1968 return 0; 1953 return 0;
1969 } 1954 }
1970 1955
1971 // Destroy the old instance 1956 // Destroy the old instance
1972 if (_inputFilePlayerPtr) { 1957 if (input_file_player_) {
1973 _inputFilePlayerPtr->RegisterModuleFileCallback(NULL); 1958 input_file_player_->RegisterModuleFileCallback(NULL);
1974 FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr); 1959 input_file_player_.reset();
1975 _inputFilePlayerPtr = NULL;
1976 } 1960 }
1977 1961
1978 // Create the instance 1962 // Create the instance
1979 _inputFilePlayerPtr = FilePlayer::CreateFilePlayer(_inputFilePlayerId, 1963 input_file_player_ = FilePlayer::NewFilePlayer(_inputFilePlayerId,
1980 (const FileFormats)format); 1964 (const FileFormats)format);
1981 1965
1982 if (_inputFilePlayerPtr == NULL) { 1966 if (!input_file_player_) {
1983 _engineStatisticsPtr->SetLastError( 1967 _engineStatisticsPtr->SetLastError(
1984 VE_INVALID_ARGUMENT, kTraceError, 1968 VE_INVALID_ARGUMENT, kTraceError,
1985 "StartPlayingFileAsMicrophone() filePlayer format isnot correct"); 1969 "StartPlayingFileAsMicrophone() filePlayer format isnot correct");
1986 return -1; 1970 return -1;
1987 } 1971 }
1988 1972
1989 const uint32_t notificationTime(0); 1973 const uint32_t notificationTime(0);
1990 1974
1991 if (_inputFilePlayerPtr->StartPlayingFile( 1975 if (input_file_player_->StartPlayingFile(
1992 fileName, loop, startPosition, volumeScaling, notificationTime, 1976 fileName, loop, startPosition, volumeScaling, notificationTime,
1993 stopPosition, (const CodecInst*)codecInst) != 0) { 1977 stopPosition, (const CodecInst*)codecInst) != 0) {
1994 _engineStatisticsPtr->SetLastError( 1978 _engineStatisticsPtr->SetLastError(
1995 VE_BAD_FILE, kTraceError, 1979 VE_BAD_FILE, kTraceError,
1996 "StartPlayingFile() failed to start file playout"); 1980 "StartPlayingFile() failed to start file playout");
1997 _inputFilePlayerPtr->StopPlayingFile(); 1981 input_file_player_->StopPlayingFile();
1998 FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr); 1982 input_file_player_.reset();
1999 _inputFilePlayerPtr = NULL;
2000 return -1; 1983 return -1;
2001 } 1984 }
2002 _inputFilePlayerPtr->RegisterModuleFileCallback(this); 1985 input_file_player_->RegisterModuleFileCallback(this);
2003 channel_state_.SetInputFilePlaying(true); 1986 channel_state_.SetInputFilePlaying(true);
2004 1987
2005 return 0; 1988 return 0;
2006 } 1989 }
2007 1990
2008 int Channel::StartPlayingFileAsMicrophone(InStream* stream, 1991 int Channel::StartPlayingFileAsMicrophone(InStream* stream,
2009 FileFormats format, 1992 FileFormats format,
2010 int startPosition, 1993 int startPosition,
2011 float volumeScaling, 1994 float volumeScaling,
2012 int stopPosition, 1995 int stopPosition,
(...skipping 13 matching lines...) Expand all
2026 rtc::CritScope cs(&_fileCritSect); 2009 rtc::CritScope cs(&_fileCritSect);
2027 2010
2028 if (channel_state_.Get().input_file_playing) { 2011 if (channel_state_.Get().input_file_playing) {
2029 _engineStatisticsPtr->SetLastError( 2012 _engineStatisticsPtr->SetLastError(
2030 VE_ALREADY_PLAYING, kTraceWarning, 2013 VE_ALREADY_PLAYING, kTraceWarning,
2031 "StartPlayingFileAsMicrophone() is playing"); 2014 "StartPlayingFileAsMicrophone() is playing");
2032 return 0; 2015 return 0;
2033 } 2016 }
2034 2017
2035 // Destroy the old instance 2018 // Destroy the old instance
2036 if (_inputFilePlayerPtr) { 2019 if (input_file_player_) {
2037 _inputFilePlayerPtr->RegisterModuleFileCallback(NULL); 2020 input_file_player_->RegisterModuleFileCallback(NULL);
2038 FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr); 2021 input_file_player_.reset();
2039 _inputFilePlayerPtr = NULL;
2040 } 2022 }
2041 2023
2042 // Create the instance 2024 // Create the instance
2043 _inputFilePlayerPtr = FilePlayer::CreateFilePlayer(_inputFilePlayerId, 2025 input_file_player_ = FilePlayer::NewFilePlayer(_inputFilePlayerId,
2044 (const FileFormats)format); 2026 (const FileFormats)format);
2045 2027
2046 if (_inputFilePlayerPtr == NULL) { 2028 if (!input_file_player_) {
2047 _engineStatisticsPtr->SetLastError( 2029 _engineStatisticsPtr->SetLastError(
2048 VE_INVALID_ARGUMENT, kTraceError, 2030 VE_INVALID_ARGUMENT, kTraceError,
2049 "StartPlayingInputFile() filePlayer format isnot correct"); 2031 "StartPlayingInputFile() filePlayer format isnot correct");
2050 return -1; 2032 return -1;
2051 } 2033 }
2052 2034
2053 const uint32_t notificationTime(0); 2035 const uint32_t notificationTime(0);
2054 2036
2055 if (_inputFilePlayerPtr->StartPlayingFile(*stream, startPosition, 2037 if (input_file_player_->StartPlayingFile(*stream, startPosition,
2056 volumeScaling, notificationTime, 2038 volumeScaling, notificationTime,
2057 stopPosition, codecInst) != 0) { 2039 stopPosition, codecInst) != 0) {
2058 _engineStatisticsPtr->SetLastError(VE_BAD_FILE, kTraceError, 2040 _engineStatisticsPtr->SetLastError(VE_BAD_FILE, kTraceError,
2059 "StartPlayingFile() failed to start " 2041 "StartPlayingFile() failed to start "
2060 "file playout"); 2042 "file playout");
2061 _inputFilePlayerPtr->StopPlayingFile(); 2043 input_file_player_->StopPlayingFile();
2062 FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr); 2044 input_file_player_.reset();
2063 _inputFilePlayerPtr = NULL;
2064 return -1; 2045 return -1;
2065 } 2046 }
2066 2047
2067 _inputFilePlayerPtr->RegisterModuleFileCallback(this); 2048 input_file_player_->RegisterModuleFileCallback(this);
2068 channel_state_.SetInputFilePlaying(true); 2049 channel_state_.SetInputFilePlaying(true);
2069 2050
2070 return 0; 2051 return 0;
2071 } 2052 }
2072 2053
2073 int Channel::StopPlayingFileAsMicrophone() { 2054 int Channel::StopPlayingFileAsMicrophone() {
2074 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), 2055 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId),
2075 "Channel::StopPlayingFileAsMicrophone()"); 2056 "Channel::StopPlayingFileAsMicrophone()");
2076 2057
2077 rtc::CritScope cs(&_fileCritSect); 2058 rtc::CritScope cs(&_fileCritSect);
2078 2059
2079 if (!channel_state_.Get().input_file_playing) { 2060 if (!channel_state_.Get().input_file_playing) {
2080 return 0; 2061 return 0;
2081 } 2062 }
2082 2063
2083 if (_inputFilePlayerPtr->StopPlayingFile() != 0) { 2064 if (input_file_player_->StopPlayingFile() != 0) {
2084 _engineStatisticsPtr->SetLastError( 2065 _engineStatisticsPtr->SetLastError(
2085 VE_STOP_RECORDING_FAILED, kTraceError, 2066 VE_STOP_RECORDING_FAILED, kTraceError,
2086 "StopPlayingFile() could not stop playing"); 2067 "StopPlayingFile() could not stop playing");
2087 return -1; 2068 return -1;
2088 } 2069 }
2089 _inputFilePlayerPtr->RegisterModuleFileCallback(NULL); 2070 input_file_player_->RegisterModuleFileCallback(NULL);
2090 FilePlayer::DestroyFilePlayer(_inputFilePlayerPtr); 2071 input_file_player_.reset();
2091 _inputFilePlayerPtr = NULL;
2092 channel_state_.SetInputFilePlaying(false); 2072 channel_state_.SetInputFilePlaying(false);
2093 2073
2094 return 0; 2074 return 0;
2095 } 2075 }
2096 2076
2097 int Channel::IsPlayingFileAsMicrophone() const { 2077 int Channel::IsPlayingFileAsMicrophone() const {
2098 return channel_state_.Get().input_file_playing; 2078 return channel_state_.Get().input_file_playing;
2099 } 2079 }
2100 2080
2101 int Channel::StartRecordingPlayout(const char* fileName, 2081 int Channel::StartRecordingPlayout(const char* fileName,
(...skipping 25 matching lines...) Expand all
2127 (STR_CASE_CMP(codecInst->plname, "PCMU") == 0) || 2107 (STR_CASE_CMP(codecInst->plname, "PCMU") == 0) ||
2128 (STR_CASE_CMP(codecInst->plname, "PCMA") == 0)) { 2108 (STR_CASE_CMP(codecInst->plname, "PCMA") == 0)) {
2129 format = kFileFormatWavFile; 2109 format = kFileFormatWavFile;
2130 } else { 2110 } else {
2131 format = kFileFormatCompressedFile; 2111 format = kFileFormatCompressedFile;
2132 } 2112 }
2133 2113
2134 rtc::CritScope cs(&_fileCritSect); 2114 rtc::CritScope cs(&_fileCritSect);
2135 2115
2136 // Destroy the old instance 2116 // Destroy the old instance
2137 if (_outputFileRecorderPtr) { 2117 if (output_file_recorder_) {
2138 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); 2118 output_file_recorder_->RegisterModuleFileCallback(NULL);
2139 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); 2119 output_file_recorder_.reset();
2140 _outputFileRecorderPtr = NULL;
2141 } 2120 }
2142 2121
2143 _outputFileRecorderPtr = FileRecorder::CreateFileRecorder( 2122 output_file_recorder_ = FileRecorder::CreateFileRecorder(
2144 _outputFileRecorderId, (const FileFormats)format); 2123 _outputFileRecorderId, (const FileFormats)format);
2145 if (_outputFileRecorderPtr == NULL) { 2124 if (!output_file_recorder_) {
2146 _engineStatisticsPtr->SetLastError( 2125 _engineStatisticsPtr->SetLastError(
2147 VE_INVALID_ARGUMENT, kTraceError, 2126 VE_INVALID_ARGUMENT, kTraceError,
2148 "StartRecordingPlayout() fileRecorder format isnot correct"); 2127 "StartRecordingPlayout() fileRecorder format isnot correct");
2149 return -1; 2128 return -1;
2150 } 2129 }
2151 2130
2152 if (_outputFileRecorderPtr->StartRecordingAudioFile( 2131 if (output_file_recorder_->StartRecordingAudioFile(
2153 fileName, (const CodecInst&)*codecInst, notificationTime) != 0) { 2132 fileName, (const CodecInst&)*codecInst, notificationTime) != 0) {
2154 _engineStatisticsPtr->SetLastError( 2133 _engineStatisticsPtr->SetLastError(
2155 VE_BAD_FILE, kTraceError, 2134 VE_BAD_FILE, kTraceError,
2156 "StartRecordingAudioFile() failed to start file recording"); 2135 "StartRecordingAudioFile() failed to start file recording");
2157 _outputFileRecorderPtr->StopRecording(); 2136 output_file_recorder_->StopRecording();
2158 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); 2137 output_file_recorder_.reset();
2159 _outputFileRecorderPtr = NULL;
2160 return -1; 2138 return -1;
2161 } 2139 }
2162 _outputFileRecorderPtr->RegisterModuleFileCallback(this); 2140 output_file_recorder_->RegisterModuleFileCallback(this);
2163 _outputFileRecording = true; 2141 _outputFileRecording = true;
2164 2142
2165 return 0; 2143 return 0;
2166 } 2144 }
2167 2145
2168 int Channel::StartRecordingPlayout(OutStream* stream, 2146 int Channel::StartRecordingPlayout(OutStream* stream,
2169 const CodecInst* codecInst) { 2147 const CodecInst* codecInst) {
2170 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId), 2148 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId),
2171 "Channel::StartRecordingPlayout()"); 2149 "Channel::StartRecordingPlayout()");
2172 2150
(...skipping 20 matching lines...) Expand all
2193 (STR_CASE_CMP(codecInst->plname, "PCMU") == 0) || 2171 (STR_CASE_CMP(codecInst->plname, "PCMU") == 0) ||
2194 (STR_CASE_CMP(codecInst->plname, "PCMA") == 0)) { 2172 (STR_CASE_CMP(codecInst->plname, "PCMA") == 0)) {
2195 format = kFileFormatWavFile; 2173 format = kFileFormatWavFile;
2196 } else { 2174 } else {
2197 format = kFileFormatCompressedFile; 2175 format = kFileFormatCompressedFile;
2198 } 2176 }
2199 2177
2200 rtc::CritScope cs(&_fileCritSect); 2178 rtc::CritScope cs(&_fileCritSect);
2201 2179
2202 // Destroy the old instance 2180 // Destroy the old instance
2203 if (_outputFileRecorderPtr) { 2181 if (output_file_recorder_) {
2204 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); 2182 output_file_recorder_->RegisterModuleFileCallback(NULL);
2205 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); 2183 output_file_recorder_.reset();
2206 _outputFileRecorderPtr = NULL;
2207 } 2184 }
2208 2185
2209 _outputFileRecorderPtr = FileRecorder::CreateFileRecorder( 2186 output_file_recorder_ = FileRecorder::CreateFileRecorder(
2210 _outputFileRecorderId, (const FileFormats)format); 2187 _outputFileRecorderId, (const FileFormats)format);
2211 if (_outputFileRecorderPtr == NULL) { 2188 if (!output_file_recorder_) {
2212 _engineStatisticsPtr->SetLastError( 2189 _engineStatisticsPtr->SetLastError(
2213 VE_INVALID_ARGUMENT, kTraceError, 2190 VE_INVALID_ARGUMENT, kTraceError,
2214 "StartRecordingPlayout() fileRecorder format isnot correct"); 2191 "StartRecordingPlayout() fileRecorder format isnot correct");
2215 return -1; 2192 return -1;
2216 } 2193 }
2217 2194
2218 if (_outputFileRecorderPtr->StartRecordingAudioFile(*stream, *codecInst, 2195 if (output_file_recorder_->StartRecordingAudioFile(*stream, *codecInst,
2219 notificationTime) != 0) { 2196 notificationTime) != 0) {
2220 _engineStatisticsPtr->SetLastError(VE_BAD_FILE, kTraceError, 2197 _engineStatisticsPtr->SetLastError(VE_BAD_FILE, kTraceError,
2221 "StartRecordingPlayout() failed to " 2198 "StartRecordingPlayout() failed to "
2222 "start file recording"); 2199 "start file recording");
2223 _outputFileRecorderPtr->StopRecording(); 2200 output_file_recorder_->StopRecording();
2224 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); 2201 output_file_recorder_.reset();
2225 _outputFileRecorderPtr = NULL;
2226 return -1; 2202 return -1;
2227 } 2203 }
2228 2204
2229 _outputFileRecorderPtr->RegisterModuleFileCallback(this); 2205 output_file_recorder_->RegisterModuleFileCallback(this);
2230 _outputFileRecording = true; 2206 _outputFileRecording = true;
2231 2207
2232 return 0; 2208 return 0;
2233 } 2209 }
2234 2210
2235 int Channel::StopRecordingPlayout() { 2211 int Channel::StopRecordingPlayout() {
2236 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), 2212 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1),
2237 "Channel::StopRecordingPlayout()"); 2213 "Channel::StopRecordingPlayout()");
2238 2214
2239 if (!_outputFileRecording) { 2215 if (!_outputFileRecording) {
2240 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, -1), 2216 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, -1),
2241 "StopRecordingPlayout() isnot recording"); 2217 "StopRecordingPlayout() isnot recording");
2242 return -1; 2218 return -1;
2243 } 2219 }
2244 2220
2245 rtc::CritScope cs(&_fileCritSect); 2221 rtc::CritScope cs(&_fileCritSect);
2246 2222
2247 if (_outputFileRecorderPtr->StopRecording() != 0) { 2223 if (output_file_recorder_->StopRecording() != 0) {
2248 _engineStatisticsPtr->SetLastError( 2224 _engineStatisticsPtr->SetLastError(
2249 VE_STOP_RECORDING_FAILED, kTraceError, 2225 VE_STOP_RECORDING_FAILED, kTraceError,
2250 "StopRecording() could not stop recording"); 2226 "StopRecording() could not stop recording");
2251 return (-1); 2227 return (-1);
2252 } 2228 }
2253 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); 2229 output_file_recorder_->RegisterModuleFileCallback(NULL);
2254 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); 2230 output_file_recorder_.reset();
2255 _outputFileRecorderPtr = NULL;
2256 _outputFileRecording = false; 2231 _outputFileRecording = false;
2257 2232
2258 return 0; 2233 return 0;
2259 } 2234 }
2260 2235
2261 void Channel::SetMixWithMicStatus(bool mix) { 2236 void Channel::SetMixWithMicStatus(bool mix) {
2262 rtc::CritScope cs(&_fileCritSect); 2237 rtc::CritScope cs(&_fileCritSect);
2263 _mixFileWithMicrophone = mix; 2238 _mixFileWithMicrophone = mix;
2264 } 2239 }
2265 2240
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after
3295 3270
3296 // TODO(andrew): refactor Mix functions here and in transmit_mixer.cc to use 3271 // TODO(andrew): refactor Mix functions here and in transmit_mixer.cc to use
3297 // a shared helper. 3272 // a shared helper.
3298 int32_t Channel::MixOrReplaceAudioWithFile(int mixingFrequency) { 3273 int32_t Channel::MixOrReplaceAudioWithFile(int mixingFrequency) {
3299 std::unique_ptr<int16_t[]> fileBuffer(new int16_t[640]); 3274 std::unique_ptr<int16_t[]> fileBuffer(new int16_t[640]);
3300 size_t fileSamples(0); 3275 size_t fileSamples(0);
3301 3276
3302 { 3277 {
3303 rtc::CritScope cs(&_fileCritSect); 3278 rtc::CritScope cs(&_fileCritSect);
3304 3279
3305 if (_inputFilePlayerPtr == NULL) { 3280 if (!input_file_player_) {
3306 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), 3281 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId),
3307 "Channel::MixOrReplaceAudioWithFile() fileplayer" 3282 "Channel::MixOrReplaceAudioWithFile() fileplayer"
3308 " doesnt exist"); 3283 " doesnt exist");
3309 return -1; 3284 return -1;
3310 } 3285 }
3311 3286
3312 if (_inputFilePlayerPtr->Get10msAudioFromFile(fileBuffer.get(), fileSamples, 3287 if (input_file_player_->Get10msAudioFromFile(fileBuffer.get(), fileSamples,
3313 mixingFrequency) == -1) { 3288 mixingFrequency) == -1) {
3314 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), 3289 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId),
3315 "Channel::MixOrReplaceAudioWithFile() file mixing " 3290 "Channel::MixOrReplaceAudioWithFile() file mixing "
3316 "failed"); 3291 "failed");
3317 return -1; 3292 return -1;
3318 } 3293 }
3319 if (fileSamples == 0) { 3294 if (fileSamples == 0) {
3320 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), 3295 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId),
3321 "Channel::MixOrReplaceAudioWithFile() file is ended"); 3296 "Channel::MixOrReplaceAudioWithFile() file is ended");
3322 return 0; 3297 return 0;
3323 } 3298 }
(...skipping 19 matching lines...) Expand all
3343 3318
3344 int32_t Channel::MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency) { 3319 int32_t Channel::MixAudioWithFile(AudioFrame& audioFrame, int mixingFrequency) {
3345 assert(mixingFrequency <= 48000); 3320 assert(mixingFrequency <= 48000);
3346 3321
3347 std::unique_ptr<int16_t[]> fileBuffer(new int16_t[960]); 3322 std::unique_ptr<int16_t[]> fileBuffer(new int16_t[960]);
3348 size_t fileSamples(0); 3323 size_t fileSamples(0);
3349 3324
3350 { 3325 {
3351 rtc::CritScope cs(&_fileCritSect); 3326 rtc::CritScope cs(&_fileCritSect);
3352 3327
3353 if (_outputFilePlayerPtr == NULL) { 3328 if (!output_file_player_) {
3354 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), 3329 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId),
3355 "Channel::MixAudioWithFile() file mixing failed"); 3330 "Channel::MixAudioWithFile() file mixing failed");
3356 return -1; 3331 return -1;
3357 } 3332 }
3358 3333
3359 // We should get the frequency we ask for. 3334 // We should get the frequency we ask for.
3360 if (_outputFilePlayerPtr->Get10msAudioFromFile( 3335 if (output_file_player_->Get10msAudioFromFile(fileBuffer.get(), fileSamples,
3361 fileBuffer.get(), fileSamples, mixingFrequency) == -1) { 3336 mixingFrequency) == -1) {
3362 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId), 3337 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, _channelId),
3363 "Channel::MixAudioWithFile() file mixing failed"); 3338 "Channel::MixAudioWithFile() file mixing failed");
3364 return -1; 3339 return -1;
3365 } 3340 }
3366 } 3341 }
3367 3342
3368 if (audioFrame.samples_per_channel_ == fileSamples) { 3343 if (audioFrame.samples_per_channel_ == fileSamples) {
3369 // Currently file stream is always mono. 3344 // Currently file stream is always mono.
3370 // TODO(xians): Change the code when FilePlayer supports real stereo. 3345 // TODO(xians): Change the code when FilePlayer supports real stereo.
3371 MixWithSat(audioFrame.data_, audioFrame.num_channels_, fileBuffer.get(), 1, 3346 MixWithSat(audioFrame.data_, audioFrame.num_channels_, fileBuffer.get(), 1,
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
3591 int64_t min_rtt = 0; 3566 int64_t min_rtt = 0;
3592 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != 3567 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) !=
3593 0) { 3568 0) {
3594 return 0; 3569 return 0;
3595 } 3570 }
3596 return rtt; 3571 return rtt;
3597 } 3572 }
3598 3573
3599 } // namespace voe 3574 } // namespace voe
3600 } // namespace webrtc 3575 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698