Removes parts of the webrtc::VoEFile sub API as part of a clean-up operation where the goal is to remove unused APIs.

BUG=3206
R=niklas.enbom@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/14429004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6103 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrika@webrtc.org 2014-05-12 12:24:10 +00:00
parent 1cec3957b8
commit 6b02eea6ac
8 changed files with 16 additions and 960 deletions

View File

@ -2087,61 +2087,6 @@ int Channel::RegisterFilePlayingToMixer()
return 0;
}
int Channel::ScaleLocalFilePlayout(float scale)
{
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId),
"Channel::ScaleLocalFilePlayout(scale=%5.3f)", scale);
CriticalSectionScoped cs(&_fileCritSect);
if (!channel_state_.Get().output_file_playing)
{
_engineStatisticsPtr->SetLastError(
VE_INVALID_OPERATION, kTraceError,
"ScaleLocalFilePlayout() isnot playing");
return -1;
}
if ((_outputFilePlayerPtr == NULL) ||
(_outputFilePlayerPtr->SetAudioScaling(scale) != 0))
{
_engineStatisticsPtr->SetLastError(
VE_BAD_ARGUMENT, kTraceError,
"SetAudioScaling() failed to scale the playout");
return -1;
}
return 0;
}
int Channel::GetLocalPlayoutPosition(int& positionMs)
{
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId),
"Channel::GetLocalPlayoutPosition(position=?)");
uint32_t position;
CriticalSectionScoped cs(&_fileCritSect);
if (_outputFilePlayerPtr == NULL)
{
_engineStatisticsPtr->SetLastError(
VE_INVALID_OPERATION, kTraceError,
"GetLocalPlayoutPosition() filePlayer instance doesnot exist");
return -1;
}
if (_outputFilePlayerPtr->GetPlayoutPosition(position) != 0)
{
_engineStatisticsPtr->SetLastError(
VE_BAD_FILE, kTraceError,
"GetLocalPlayoutPosition() failed");
return -1;
}
positionMs = position;
return 0;
}
int Channel::StartPlayingFileAsMicrophone(const char* fileName,
bool loop,
FileFormats format,
@ -2319,33 +2264,6 @@ int Channel::IsPlayingFileAsMicrophone() const
return channel_state_.Get().input_file_playing;
}
int Channel::ScaleFileAsMicrophonePlayout(float scale)
{
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,_channelId),
"Channel::ScaleFileAsMicrophonePlayout(scale=%5.3f)", scale);
CriticalSectionScoped cs(&_fileCritSect);
if (!channel_state_.Get().input_file_playing)
{
_engineStatisticsPtr->SetLastError(
VE_INVALID_OPERATION, kTraceError,
"ScaleFileAsMicrophonePlayout() isnot playing");
return -1;
}
if ((_inputFilePlayerPtr == NULL) ||
(_inputFilePlayerPtr->SetAudioScaling(scale) != 0))
{
_engineStatisticsPtr->SetLastError(
VE_BAD_ARGUMENT, kTraceError,
"SetAudioScaling() failed to scale playout");
return -1;
}
return 0;
}
int Channel::StartRecordingPlayout(const char* fileName,
const CodecInst* codecInst)
{

View File

@ -227,8 +227,6 @@ public:
int StopPlayingFileLocally();
int IsPlayingFileLocally() const;
int RegisterFilePlayingToMixer();
int ScaleLocalFilePlayout(float scale);
int GetLocalPlayoutPosition(int& positionMs);
int StartPlayingFileAsMicrophone(const char* fileName, bool loop,
FileFormats format,
int startPosition,
@ -243,7 +241,6 @@ public:
const CodecInst* codecInst);
int StopPlayingFileAsMicrophone();
int IsPlayingFileAsMicrophone() const;
int ScaleFileAsMicrophonePlayout(float scale);
int StartRecordingPlayout(const char* fileName, const CodecInst* codecInst);
int StartRecordingPlayout(OutStream* stream, const CodecInst* codecInst);
int StopRecordingPlayout();

View File

@ -84,9 +84,6 @@ public:
// Returns the current file playing state for a specific |channel|.
virtual int IsPlayingFileLocally(int channel) = 0;
// Sets the volume scaling for a speaker file that is already playing.
virtual int ScaleLocalFilePlayout(int channel, float scale) = 0;
// Starts reading data from a file and transmits the data either
// mixed with or instead of the microphone signal.
virtual int StartPlayingFileAsMicrophone(
@ -112,9 +109,6 @@ public:
// Returns whether the |channel| is currently playing a file as microphone.
virtual int IsPlayingFileAsMicrophone(int channel) = 0;
// Sets the volume scaling for a microphone file that is already playing.
virtual int ScaleFileAsMicrophonePlayout(int channel, float scale) = 0;
// Starts recording the mixed playout audio.
virtual int StartRecordingPlayout(int channel,
const char* fileNameUTF8,
@ -140,40 +134,31 @@ public:
// Stops recording the microphone signal.
virtual int StopRecordingMicrophone() = 0;
// Gets the duration of a file.
// Don't use. To be removed.
virtual int ScaleLocalFilePlayout(int channel, float scale) { return -1; }
virtual int ScaleFileAsMicrophonePlayout(
int channel, float scale) { return -1; }
virtual int GetFileDuration(const char* fileNameUTF8, int& durationMs,
FileFormats format = kFileFormatPcm16kHzFile) = 0;
// Gets the current played position of a file on a specific |channel|.
virtual int GetPlaybackPosition(int channel, int& positionMs) = 0;
FileFormats format = kFileFormatPcm16kHzFile) { return -1; }
virtual int GetPlaybackPosition(int channel, int& positionMs) { return -1; }
virtual int ConvertPCMToWAV(const char* fileNameInUTF8,
const char* fileNameOutUTF8) = 0;
const char* fileNameOutUTF8) { return -1; }
virtual int ConvertPCMToWAV(InStream* streamIn,
OutStream* streamOut) = 0;
OutStream* streamOut) { return -1; }
virtual int ConvertWAVToPCM(const char* fileNameInUTF8,
const char* fileNameOutUTF8) = 0;
const char* fileNameOutUTF8) { return -1; }
virtual int ConvertWAVToPCM(InStream* streamIn,
OutStream* streamOut) = 0;
OutStream* streamOut) { return -1; }
virtual int ConvertPCMToCompressed(const char* fileNameInUTF8,
const char* fileNameOutUTF8,
CodecInst* compression) = 0;
CodecInst* compression) { return -1; }
virtual int ConvertPCMToCompressed(InStream* streamIn,
OutStream* streamOut,
CodecInst* compression) = 0;
CodecInst* compression) { return -1; }
virtual int ConvertCompressedToPCM(const char* fileNameInUTF8,
const char* fileNameOutUTF8) = 0;
const char* fileNameOutUTF8) { return -1; }
virtual int ConvertCompressedToPCM(InStream* streamIn,
OutStream* streamOut) = 0;
OutStream* streamOut) { return -1; }
protected:
VoEFile() {}
virtual ~VoEFile() {}

View File

@ -45,15 +45,11 @@ TEST_F(FileTest, ManualRecordToFileForThreeSecondsAndPlayback) {
EXPECT_EQ(0, voe_file_->StartPlayingFileLocally(
channel_, recording_filename.c_str()));
// Play the file to the user and ensure the is-playing-locally
// and scaling methods also work. The clip is 3 seconds long.
// Play the file to the user and ensure the is-playing-locally.
// The clip is 3 seconds long.
Sleep(250);
EXPECT_EQ(1, voe_file_->IsPlayingFileLocally(channel_));
Sleep(1500);
TEST_LOG("Decreasing level by 50%%.\n");
EXPECT_EQ(0, voe_file_->ScaleLocalFilePlayout(channel_, 0.5f));
Sleep(1500);
EXPECT_EQ(0, voe_file_->IsPlayingFileLocally(channel_));
}
TEST_F(FileTest, ManualRecordPlayoutToWavFileForThreeSecondsAndPlayback) {
@ -79,11 +75,4 @@ TEST_F(FileTest, ManualRecordPlayoutToWavFileForThreeSecondsAndPlayback) {
Sleep(2000);
// We should still be playing since we're looping.
EXPECT_EQ(1, voe_file_->IsPlayingFileAsMicrophone(channel_));
// Try scaling as well.
TEST_LOG("Decreasing level by 50%%.\n");
EXPECT_EQ(0, voe_file_->ScaleFileAsMicrophonePlayout(channel_, 0.5f));
Sleep(1000);
EXPECT_EQ(0, voe_file_->StopPlayingFileAsMicrophone(channel_));
}

View File

@ -681,34 +681,6 @@ int TransmitMixer::IsPlayingFileAsMicrophone() const
return _filePlaying;
}
int TransmitMixer::ScaleFileAsMicrophonePlayout(float scale)
{
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1),
"TransmitMixer::ScaleFileAsMicrophonePlayout(scale=%5.3f)",
scale);
CriticalSectionScoped cs(&_critSect);
if (!_filePlaying)
{
_engineStatisticsPtr->SetLastError(
VE_INVALID_OPERATION, kTraceError,
"ScaleFileAsMicrophonePlayout() isnot playing file");
return -1;
}
if ((_filePlayerPtr == NULL) ||
(_filePlayerPtr->SetAudioScaling(scale) != 0))
{
_engineStatisticsPtr->SetLastError(
VE_BAD_ARGUMENT, kTraceError,
"SetAudioScaling() failed to scale playout");
return -1;
}
return 0;
}
int TransmitMixer::StartRecordingMicrophone(const char* fileName,
const CodecInst* codecInst)
{

View File

@ -117,8 +117,6 @@ public:
int IsPlayingFileAsMicrophone() const;
int ScaleFileAsMicrophonePlayout(float scale);
int StartRecordingMicrophone(const char* fileName,
const CodecInst* codecInst);

View File

@ -164,27 +164,6 @@ int VoEFileImpl::IsPlayingFileLocally(int channel)
return channelPtr->IsPlayingFileLocally();
}
int VoEFileImpl::ScaleLocalFilePlayout(int channel, float scale)
{
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"ScaleLocalFilePlayout(channel=%d, scale=%5.3f)",
channel, scale);
if (!_shared->statistics().Initialized())
{
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
voe::Channel* channelPtr = ch.channel();
if (channelPtr == NULL)
{
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
"StopPlayingFileLocally() failed to locate channel");
return -1;
}
return channelPtr->ScaleLocalFilePlayout(scale);
}
int VoEFileImpl::StartPlayingFileAsMicrophone(int channel,
const char fileNameUTF8[1024],
bool loop,
@ -395,36 +374,6 @@ int VoEFileImpl::IsPlayingFileAsMicrophone(int channel)
}
}
int VoEFileImpl::ScaleFileAsMicrophonePlayout(int channel, float scale)
{
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"ScaleFileAsMicrophonePlayout(channel=%d, scale=%5.3f)",
channel, scale);
if (!_shared->statistics().Initialized())
{
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
}
if (channel == -1)
{
return _shared->transmit_mixer()->ScaleFileAsMicrophonePlayout(scale);
}
else
{
// Stop adding file after demultiplexing <=> affects one channel only
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
voe::Channel* channelPtr = ch.channel();
if (channelPtr == NULL)
{
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
"IsPlayingFileAsMicrophone() failed to locate channel");
return -1;
}
return channelPtr->ScaleFileAsMicrophonePlayout(scale);
}
}
int VoEFileImpl::StartRecordingPlayout(
int channel, const char* fileNameUTF8, CodecInst* compression,
int maxSizeBytes)
@ -642,717 +591,6 @@ int VoEFileImpl::StopRecordingMicrophone()
return err;
}
// TODO(andrew): a cursory inspection suggests there's a large amount of
// overlap in these convert functions which could be refactored to a helper.
int VoEFileImpl::ConvertPCMToWAV(const char* fileNameInUTF8,
const char* fileNameOutUTF8)
{
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"ConvertPCMToWAV(fileNameInUTF8=%s, fileNameOutUTF8=%s)",
fileNameInUTF8, fileNameOutUTF8);
// Create file player object
FilePlayer& playerObj(*FilePlayer::CreateFilePlayer(
-1,
kFileFormatPcm16kHzFile));
int res=playerObj.StartPlayingFile(fileNameInUTF8,false,0,1.0,0,0, NULL);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertPCMToWAV failed to create player object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
return -1;
}
// Create file recorder object
FileRecorder& recObj(*FileRecorder::CreateFileRecorder(
-1, kFileFormatWavFile));
CodecInst codecInst;
strncpy(codecInst.plname,"L16",32);
codecInst.channels = 1;
codecInst.rate = 256000;
codecInst.plfreq = 16000;
codecInst.pltype = 94;
codecInst.pacsize = 160;
res = recObj.StartRecordingAudioFile(fileNameOutUTF8,codecInst,0);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertPCMToWAV failed to create recorder object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
recObj.StopRecording();
FileRecorder::DestroyFileRecorder(&recObj);
return -1;
}
// Run throught the file
AudioFrame audioFrame;
int16_t decodedData[160];
int decLength=0;
const uint32_t frequency = 16000;
while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency))
{
if(decLength!=frequency/100)
{
// This is an OK way to end
break;
}
audioFrame.UpdateFrame(-1, 0, decodedData,
(uint16_t)decLength,
frequency, AudioFrame::kNormalSpeech,
AudioFrame::kVadActive);
res=recObj.RecordAudioToFile(audioFrame);
if(res)
{
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"ConvertPCMToWAV failed during conversion (write frame)");
}
}
playerObj.StopPlayingFile();
recObj.StopRecording();
FilePlayer::DestroyFilePlayer(&playerObj);
FileRecorder::DestroyFileRecorder(&recObj);
return res;
}
int VoEFileImpl::ConvertPCMToWAV(InStream* streamIn, OutStream* streamOut)
{
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"ConvertPCMToWAV(streamIn, streamOut)");
if ((streamIn == NULL) || (streamOut == NULL))
{
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1), "invalid stream handles");
return (-1);
}
// Create file player object
FilePlayer& playerObj(*FilePlayer::CreateFilePlayer(-1,
kFileFormatPcm16kHzFile));
int res = playerObj.StartPlayingFile(*streamIn,0,1.0,0,0,NULL);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertPCMToWAV failed to create player object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
return -1;
}
// Create file recorder object
FileRecorder& recObj(*FileRecorder::CreateFileRecorder(-1,
kFileFormatWavFile));
CodecInst codecInst;
strncpy(codecInst.plname, "L16", 32);
codecInst.channels = 1;
codecInst.rate = 256000;
codecInst.plfreq = 16000;
codecInst.pltype = 94;
codecInst.pacsize = 160;
res = recObj.StartRecordingAudioFile(*streamOut,codecInst,0);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertPCMToWAV failed to create recorder object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
recObj.StopRecording();
FileRecorder::DestroyFileRecorder(&recObj);
return -1;
}
// Run throught the file
AudioFrame audioFrame;
int16_t decodedData[160];
int decLength=0;
const uint32_t frequency = 16000;
while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency))
{
if(decLength!=frequency/100)
{
// This is an OK way to end
break;
}
audioFrame.UpdateFrame(-1, 0, decodedData,
(uint16_t)decLength, frequency,
AudioFrame::kNormalSpeech,
AudioFrame::kVadActive);
res=recObj.RecordAudioToFile(audioFrame);
if(res)
{
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"ConvertPCMToWAV failed during conversion (write frame)");
}
}
playerObj.StopPlayingFile();
recObj.StopRecording();
FilePlayer::DestroyFilePlayer(&playerObj);
FileRecorder::DestroyFileRecorder(&recObj);
return res;
}
int VoEFileImpl::ConvertWAVToPCM(const char* fileNameInUTF8,
const char* fileNameOutUTF8)
{
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"ConvertWAVToPCM(fileNameInUTF8=%s, fileNameOutUTF8=%s)",
fileNameInUTF8, fileNameOutUTF8);
// Create file player object
FilePlayer& playerObj(*FilePlayer::CreateFilePlayer(-1,
kFileFormatWavFile));
int res = playerObj.StartPlayingFile(fileNameInUTF8,false,0,1.0,0,0,NULL);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertWAVToPCM failed to create player object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
return -1;
}
// Create file recorder object
FileRecorder& recObj(*FileRecorder::CreateFileRecorder(
-1, kFileFormatPcm16kHzFile));
CodecInst codecInst;
strncpy(codecInst.plname,"L16",32);
codecInst.channels = 1;
codecInst.rate = 256000;
codecInst.plfreq = 16000;
codecInst.pltype = 94;
codecInst.pacsize = 160;
res = recObj.StartRecordingAudioFile(fileNameOutUTF8,codecInst,0);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertWAVToPCM failed to create recorder object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
recObj.StopRecording();
FileRecorder::DestroyFileRecorder(&recObj);
return -1;
}
// Run throught the file
AudioFrame audioFrame;
int16_t decodedData[160];
int decLength=0;
const uint32_t frequency = 16000;
while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency))
{
if(decLength!=frequency/100)
{
// This is an OK way to end
break;
}
audioFrame.UpdateFrame(-1, 0, decodedData,
(uint16_t)decLength,
frequency, AudioFrame::kNormalSpeech,
AudioFrame::kVadActive);
res=recObj.RecordAudioToFile(audioFrame);
if(res)
{
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"ConvertWAVToPCM failed during conversion (write frame)");
}
}
playerObj.StopPlayingFile();
recObj.StopRecording();
FilePlayer::DestroyFilePlayer(&playerObj);
FileRecorder::DestroyFileRecorder(&recObj);
return res;
}
int VoEFileImpl::ConvertWAVToPCM(InStream* streamIn, OutStream* streamOut)
{
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"ConvertWAVToPCM(streamIn, streamOut)");
if ((streamIn == NULL) || (streamOut == NULL))
{
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1), "invalid stream handles");
return (-1);
}
// Create file player object
FilePlayer& playerObj(*FilePlayer::CreateFilePlayer(-1,
kFileFormatWavFile));
int res = playerObj.StartPlayingFile(*streamIn,0,1.0,0,0,NULL);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertWAVToPCM failed to create player object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
return -1;
}
// Create file recorder object
FileRecorder& recObj(*FileRecorder::CreateFileRecorder(
-1, kFileFormatPcm16kHzFile));
CodecInst codecInst;
strncpy(codecInst.plname,"L16",32);
codecInst.channels = 1;
codecInst.rate = 256000;
codecInst.plfreq = 16000;
codecInst.pltype = 94;
codecInst.pacsize = 160;
res = recObj.StartRecordingAudioFile(*streamOut,codecInst,0);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertWAVToPCM failed to create recorder object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
recObj.StopRecording();
FileRecorder::DestroyFileRecorder(&recObj);
return -1;
}
// Run throught the file
AudioFrame audioFrame;
int16_t decodedData[160];
int decLength=0;
const uint32_t frequency = 16000;
while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency))
{
if(decLength!=frequency/100)
{
// This is an OK way to end
break;
}
audioFrame.UpdateFrame(-1, 0, decodedData,
(uint16_t)decLength, frequency,
AudioFrame::kNormalSpeech,
AudioFrame::kVadActive);
res=recObj.RecordAudioToFile(audioFrame);
if(res)
{
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"ConvertWAVToPCM failed during conversion (write frame)");
}
}
playerObj.StopPlayingFile();
recObj.StopRecording();
FilePlayer::DestroyFilePlayer(&playerObj);
FileRecorder::DestroyFileRecorder(&recObj);
return res;
}
int VoEFileImpl::ConvertPCMToCompressed(const char* fileNameInUTF8,
const char* fileNameOutUTF8,
CodecInst* compression)
{
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"ConvertPCMToCompressed(fileNameInUTF8=%s, fileNameOutUTF8=%s"
", compression)", fileNameInUTF8, fileNameOutUTF8);
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
" compression: plname=%s, plfreq=%d, pacsize=%d",
compression->plname, compression->plfreq,
compression->pacsize);
// Create file player object
FilePlayer& playerObj(*FilePlayer::CreateFilePlayer(
-1,
kFileFormatPcm16kHzFile));
int res = playerObj.StartPlayingFile(fileNameInUTF8,false,0,1.0,0,0, NULL);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertPCMToCompressed failed to create player object");
// Clean up and shutdown the file player
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
return -1;
}
// Create file recorder object
FileRecorder& recObj(*FileRecorder::CreateFileRecorder(
-1,
kFileFormatCompressedFile));
res = recObj.StartRecordingAudioFile(fileNameOutUTF8, *compression,0);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertPCMToCompressed failed to create recorder object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
recObj.StopRecording();
FileRecorder::DestroyFileRecorder(&recObj);
return -1;
}
// Run throught the file
AudioFrame audioFrame;
int16_t decodedData[160];
int decLength=0;
const uint32_t frequency = 16000;
while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency))
{
if(decLength!=frequency/100)
{
// This is an OK way to end
break;
}
audioFrame.UpdateFrame(-1, 0, decodedData,
(uint16_t)decLength,
frequency, AudioFrame::kNormalSpeech,
AudioFrame::kVadActive);
res=recObj.RecordAudioToFile(audioFrame);
if(res)
{
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"ConvertPCMToCompressed failed during conversion "
"(write frame)");
}
}
playerObj.StopPlayingFile();
recObj.StopRecording();
FilePlayer::DestroyFilePlayer(&playerObj);
FileRecorder::DestroyFileRecorder(&recObj);
return res;
}
int VoEFileImpl::ConvertPCMToCompressed(InStream* streamIn,
OutStream* streamOut,
CodecInst* compression)
{
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"ConvertPCMToCompressed(streamIn, streamOut, compression)");
if ((streamIn == NULL) || (streamOut == NULL))
{
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1), "invalid stream handles");
return (-1);
}
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_shared->instance_id(), -1),
" compression: plname=%s, plfreq=%d, pacsize=%d",
compression->plname, compression->plfreq,
compression->pacsize);
// Create file player object
FilePlayer& playerObj(*FilePlayer::CreateFilePlayer(
-1, kFileFormatPcm16kHzFile));
int res = playerObj.StartPlayingFile(*streamIn,0,1.0,0,0,NULL);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertPCMToCompressed failed to create player object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
return -1;
}
// Create file recorder object
FileRecorder& recObj(*FileRecorder::CreateFileRecorder(
-1, kFileFormatCompressedFile));
res = recObj.StartRecordingAudioFile(*streamOut,*compression,0);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertPCMToCompressed failed to create recorder object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
recObj.StopRecording();
FileRecorder::DestroyFileRecorder(&recObj);
return -1;
}
// Run throught the file
AudioFrame audioFrame;
int16_t decodedData[160];
int decLength=0;
const uint32_t frequency = 16000;
while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency))
{
if(decLength!=frequency/100)
{
// This is an OK way to end
break;
}
audioFrame.UpdateFrame(-1, 0, decodedData,
(uint16_t)decLength,
frequency, AudioFrame::kNormalSpeech,
AudioFrame::kVadActive);
res=recObj.RecordAudioToFile(audioFrame);
if(res)
{
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"ConvertPCMToCompressed failed during conversion "
"(write frame)");
}
}
playerObj.StopPlayingFile();
recObj.StopRecording();
FilePlayer::DestroyFilePlayer(&playerObj);
FileRecorder::DestroyFileRecorder(&recObj);
return res;
}
int VoEFileImpl::ConvertCompressedToPCM(const char* fileNameInUTF8,
const char* fileNameOutUTF8)
{
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"ConvertCompressedToPCM(fileNameInUTF8=%s,"
" fileNameOutUTF8=%s)",
fileNameInUTF8, fileNameOutUTF8);
// Create file player object
FilePlayer& playerObj(*FilePlayer::CreateFilePlayer(
-1, kFileFormatCompressedFile));
int res = playerObj.StartPlayingFile(fileNameInUTF8,false,0,1.0,0,0,NULL);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertCompressedToPCM failed to create player object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
return -1;
}
// Create file recorder object
FileRecorder& recObj(*FileRecorder::CreateFileRecorder(
-1, kFileFormatPcm16kHzFile));
CodecInst codecInst;
strncpy(codecInst.plname,"L16",32);
codecInst.channels = 1;
codecInst.rate = 256000;
codecInst.plfreq = 16000;
codecInst.pltype = 94;
codecInst.pacsize = 160;
res = recObj.StartRecordingAudioFile(fileNameOutUTF8,codecInst,0);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertCompressedToPCM failed to create recorder object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
recObj.StopRecording();
FileRecorder::DestroyFileRecorder(&recObj);
return -1;
}
// Run throught the file
AudioFrame audioFrame;
int16_t decodedData[160];
int decLength=0;
const uint32_t frequency = 16000;
while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency))
{
if(decLength!=frequency/100)
{
// This is an OK way to end
break;
}
audioFrame.UpdateFrame(-1, 0, decodedData,
(uint16_t)decLength,
frequency,
AudioFrame::kNormalSpeech,
AudioFrame::kVadActive);
res=recObj.RecordAudioToFile(audioFrame);
if(res)
{
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"ConvertCompressedToPCM failed during conversion "
"(write frame)");
}
}
playerObj.StopPlayingFile();
recObj.StopRecording();
FilePlayer::DestroyFilePlayer(&playerObj);
FileRecorder::DestroyFileRecorder(&recObj);
return res;
}
int VoEFileImpl::ConvertCompressedToPCM(InStream* streamIn,
OutStream* streamOut)
{
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"ConvertCompressedToPCM(file, file);");
if ((streamIn == NULL) || (streamOut == NULL))
{
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1), "invalid stream handles");
return (-1);
}
// Create file player object
FilePlayer& playerObj(*FilePlayer::CreateFilePlayer(
-1, kFileFormatCompressedFile));
int res;
res = playerObj.StartPlayingFile(*streamIn,0,1.0,0,0,NULL);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertCompressedToPCM failed to create player object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
return -1;
}
// Create file recorder object
FileRecorder& recObj(*FileRecorder::CreateFileRecorder(
-1, kFileFormatPcm16kHzFile));
CodecInst codecInst;
strncpy(codecInst.plname,"L16",32);
codecInst.channels = 1;
codecInst.rate = 256000;
codecInst.plfreq = 16000;
codecInst.pltype = 94;
codecInst.pacsize = 160;
res = recObj.StartRecordingAudioFile(*streamOut,codecInst,0);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"ConvertCompressedToPCM failed to create recorder object");
playerObj.StopPlayingFile();
FilePlayer::DestroyFilePlayer(&playerObj);
recObj.StopRecording();
FileRecorder::DestroyFileRecorder(&recObj);
return -1;
}
// Run throught the file
AudioFrame audioFrame;
int16_t decodedData[160];
int decLength=0;
const uint32_t frequency = 16000;
while(!playerObj.Get10msAudioFromFile(decodedData,decLength,frequency))
{
if(decLength!=frequency/100)
{
// This is an OK way to end
break;
}
audioFrame.UpdateFrame(-1, 0, decodedData,
(uint16_t)decLength,
frequency,
AudioFrame::kNormalSpeech,
AudioFrame::kVadActive);
res=recObj.RecordAudioToFile(audioFrame);
if(res)
{
WEBRTC_TRACE(kTraceError, kTraceVoice,
VoEId(_shared->instance_id(), -1),
"ConvertCompressedToPCM failed during conversion "
"(write frame)");
}
}
playerObj.StopPlayingFile();
recObj.StopRecording();
FilePlayer::DestroyFilePlayer(&playerObj);
FileRecorder::DestroyFileRecorder(&recObj);
return res;
}
int VoEFileImpl::GetFileDuration(const char* fileNameUTF8,
int& durationMs,
FileFormats format)
{
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"GetFileDuration(fileNameUTF8=%s, format=%d)",
fileNameUTF8, format);
// Create a dummy file module for this
MediaFile * fileModule=MediaFile::CreateMediaFile(-1);
// Temp container of the right format
uint32_t duration;
int res=fileModule->FileDurationMs(fileNameUTF8,duration,format);
if (res)
{
_shared->SetLastError(VE_BAD_FILE, kTraceError,
"GetFileDuration() failed measure file duration");
return -1;
}
durationMs = duration;
MediaFile::DestroyMediaFile(fileModule);
fileModule = NULL;
return(res);
}
int VoEFileImpl::GetPlaybackPosition(int channel, int& positionMs)
{
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"GetPlaybackPosition(channel=%d)", channel);
voe::ChannelOwner ch = _shared->channel_manager().GetChannel(channel);
voe::Channel* channelPtr = ch.channel();
if (channelPtr == NULL)
{
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
"GetPlaybackPosition() failed to locate channel");
return -1;
}
return channelPtr->GetLocalPlayoutPosition(positionMs);
}
#endif // #ifdef WEBRTC_VOICE_ENGINE_FILE_API
} // namespace webrtc

View File

@ -41,8 +41,6 @@ public:
virtual int IsPlayingFileLocally(int channel);
virtual int ScaleLocalFilePlayout(int channel, float scale);
// Use file as microphone input
virtual int StartPlayingFileAsMicrophone(
@ -64,8 +62,6 @@ public:
virtual int IsPlayingFileAsMicrophone(int channel);
virtual int ScaleFileAsMicrophonePlayout(int channel, float scale);
// Record speaker signal to file
virtual int StartRecordingPlayout(int channel,
@ -90,43 +86,6 @@ public:
virtual int StopRecordingMicrophone();
// Conversion between different file formats
virtual int ConvertPCMToWAV(const char* fileNameInUTF8,
const char* fileNameOutUTF8);
virtual int ConvertPCMToWAV(InStream* streamIn,
OutStream* streamOut);
virtual int ConvertWAVToPCM(const char* fileNameInUTF8,
const char* fileNameOutUTF8);
virtual int ConvertWAVToPCM(InStream* streamIn,
OutStream* streamOut);
virtual int ConvertPCMToCompressed(const char* fileNameInUTF8,
const char* fileNameOutUTF8,
CodecInst* compression);
virtual int ConvertPCMToCompressed(InStream* streamIn,
OutStream* streamOut,
CodecInst* compression);
virtual int ConvertCompressedToPCM(const char* fileNameInUTF8,
const char* fileNameOutUTF8);
virtual int ConvertCompressedToPCM(InStream* streamIn,
OutStream* streamOut);
// Misc file functions
virtual int GetFileDuration(
const char* fileNameUTF8,
int& durationMs,
FileFormats format = kFileFormatPcm16kHzFile);
virtual int GetPlaybackPosition(int channel, int& positionMs);
protected:
VoEFileImpl(voe::SharedData* shared);
virtual ~VoEFileImpl();