Skip to content

Commit

Permalink
Reland "Supporting 48kHz PCM file."
Browse files Browse the repository at this point in the history
This was first reviewed in https://codereview.webrtc.org/2790493004/.

It got reverted in https://codereview.webrtc.org/2791453004/ due to
upstreaming error.

Bug: None
TBR: [email protected]
Change-Id: Ia5e9bf86e004258b2aa7822bd489d357fcb8f906
Reviewed-on: https://chromium-review.googlesource.com/645634
Reviewed-by: Minyue Li (BackIn2018March) <[email protected]>
Commit-Queue: Minyue Li (BackIn2018March) <[email protected]>
Cr-Commit-Position: refs/heads/master@{#19642}
  • Loading branch information
minyuel authored and Commit Bot committed Sep 1, 2017
1 parent 084c55a commit 85a3b6b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 17 deletions.
3 changes: 2 additions & 1 deletion webrtc/common_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ enum FileFormats {
kFileFormatPreencodedFile = 4,
kFileFormatPcm16kHzFile = 7,
kFileFormatPcm8kHzFile = 8,
kFileFormatPcm32kHzFile = 9
kFileFormatPcm32kHzFile = 9,
kFileFormatPcm48kHzFile = 10
};

enum FrameType {
Expand Down
15 changes: 11 additions & 4 deletions webrtc/modules/media_file/media_file_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ int32_t MediaFileImpl::PlayoutAudioData(int8_t* buffer,

switch(_fileFormat)
{
case kFileFormatPcm48kHzFile:
case kFileFormatPcm32kHzFile:
case kFileFormatPcm16kHzFile:
case kFileFormatPcm8kHzFile:
Expand Down Expand Up @@ -450,6 +451,7 @@ int32_t MediaFileImpl::StartPlayingStream(
case kFileFormatPcm8kHzFile:
case kFileFormatPcm16kHzFile:
case kFileFormatPcm32kHzFile:
case kFileFormatPcm48kHzFile:
{
// ValidFileFormat() called in the beginneing of this function
// prevents codecInst from being NULL here.
Expand Down Expand Up @@ -593,6 +595,7 @@ int32_t MediaFileImpl::IncomingAudioData(
case kFileFormatPcm8kHzFile:
case kFileFormatPcm16kHzFile:
case kFileFormatPcm32kHzFile:
case kFileFormatPcm48kHzFile:
bytesWritten = _ptrFileUtilityObj->WritePCMData(
*_ptrOutStream,
buffer,
Expand Down Expand Up @@ -795,12 +798,14 @@ int32_t MediaFileImpl::StartRecordingAudioStream(
}
case kFileFormatPcm8kHzFile:
case kFileFormatPcm16kHzFile:
case kFileFormatPcm32kHzFile:
case kFileFormatPcm48kHzFile:
{
if(!ValidFrequency(codecInst.plfreq) ||
_ptrFileUtilityObj->InitPCMWriting(stream, codecInst.plfreq) ==
-1)
{
LOG(LS_ERROR) << "Failed to initialize 8 or 16KHz PCM file!";
LOG(LS_ERROR) << "Failed to initialize PCM file!";
delete _ptrFileUtilityObj;
_ptrFileUtilityObj = NULL;
return -1;
Expand Down Expand Up @@ -1010,7 +1015,8 @@ bool MediaFileImpl::ValidFileFormat(const FileFormats format,
if(format == kFileFormatPreencodedFile ||
format == kFileFormatPcm8kHzFile ||
format == kFileFormatPcm16kHzFile ||
format == kFileFormatPcm32kHzFile)
format == kFileFormatPcm32kHzFile ||
format == kFileFormatPcm48kHzFile)
{
LOG(LS_ERROR) << "Codec info required for file format specified!";
return false;
Expand Down Expand Up @@ -1052,11 +1058,12 @@ bool MediaFileImpl::ValidFilePositions(const uint32_t startPointMs,

bool MediaFileImpl::ValidFrequency(const uint32_t frequency)
{
if((frequency == 8000) || (frequency == 16000)|| (frequency == 32000))
if((frequency == 8000) || (frequency == 16000)|| (frequency == 32000) ||
(frequency == 48000))
{
return true;
}
LOG(LS_ERROR) << "Frequency should be 8000, 16000 or 32000 (Hz)";
LOG(LS_ERROR) << "Frequency should be 8000, 16000, 32000, or 48000 (Hz)";
return false;
}
} // namespace webrtc
30 changes: 28 additions & 2 deletions webrtc/modules/media_file/media_file_utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,16 @@ int32_t ModuleFileUtility::InitPCMReading(InStream& pcm,
codec_info_.rate = 512000;
_codecId = kCodecL16_32Khz;
}
else if(freq == 48000)
{
strcpy(codec_info_.plname, "L16");
codec_info_.pltype = -1;
codec_info_.plfreq = 48000;
codec_info_.pacsize = 480;
codec_info_.channels = 1;
codec_info_.rate = 768000;
_codecId = kCodecL16_48Khz;
}

// Readsize for 10ms of audio data (2 bytes per sample).
_readSizeBytes = 2 * codec_info_. plfreq / 100;
Expand Down Expand Up @@ -1261,11 +1271,23 @@ int32_t ModuleFileUtility::InitPCMWriting(OutStream& out, uint32_t freq)

_codecId = kCodecL16_32Khz;
}
else if(freq == 48000)
{
strcpy(codec_info_.plname, "L16");
codec_info_.pltype = -1;
codec_info_.plfreq = 48000;
codec_info_.pacsize = 480;
codec_info_.channels = 1;
codec_info_.rate = 768000;

_codecId = kCodecL16_48Khz;
}
if((_codecId != kCodecL16_8Khz) &&
(_codecId != kCodecL16_16kHz) &&
(_codecId != kCodecL16_32Khz))
(_codecId != kCodecL16_32Khz) &&
(_codecId != kCodecL16_48Khz))
{
LOG(LS_ERROR) << "CodecInst is not 8KHz PCM or 16KHz PCM!";
LOG(LS_ERROR) << "CodecInst is not 8KHz, 16KHz, 32kHz or 48kHz PCM!";
return -1;
}
_writing = true;
Expand Down Expand Up @@ -1335,6 +1357,10 @@ int32_t ModuleFileUtility::set_codec_info(const CodecInst& codecInst)
{
_codecId = kCodecL16_32Khz;
}
else if(codecInst.plfreq == 48000)
{
_codecId = kCodecL16_48Khz;
}
}
#ifdef WEBRTC_CODEC_ILBC
else if(STR_CASE_CMP(codecInst.plname, "ilbc") == 0)
Expand Down
1 change: 1 addition & 0 deletions webrtc/modules/media_file/media_file_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class ModuleFileUtility
kCodecL16_8Khz,
kCodecL16_16kHz,
kCodecL16_32Khz,
kCodecL16_48Khz,
kCodecPcmu,
kCodecPcma,
kCodecIlbc20Ms,
Expand Down
22 changes: 14 additions & 8 deletions webrtc/voice_engine/file_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int32_t FilePlayerImpl::Frequency() const {
} else if (_codec.plfreq == 44000) {
return 32000;
} else if (_codec.plfreq == 48000) {
return 32000;
return 48000;
} else {
return _codec.plfreq;
}
Expand Down Expand Up @@ -220,16 +220,18 @@ int32_t FilePlayerImpl::StartPlayingFile(const char* fileName,
codecInstL16.rate = 128000;
codecInstL16.plfreq = 8000;
codecInstL16.pacsize = 80;

} else if (_fileFormat == kFileFormatPcm16kHzFile) {
codecInstL16.rate = 256000;
codecInstL16.plfreq = 16000;
codecInstL16.pacsize = 160;

} else if (_fileFormat == kFileFormatPcm32kHzFile) {
codecInstL16.rate = 512000;
codecInstL16.plfreq = 32000;
codecInstL16.pacsize = 160;
codecInstL16.pacsize = 320;
} else if (_fileFormat == kFileFormatPcm48kHzFile) {
codecInstL16.rate = 768000;
codecInstL16.plfreq = 48000;
codecInstL16.pacsize = 480;
} else {
LOG(LS_ERROR) << "StartPlayingFile() sample frequency not "
<< "supported for PCM format.";
Expand Down Expand Up @@ -277,7 +279,8 @@ int32_t FilePlayerImpl::StartPlayingFile(InStream* sourceStream,
const CodecInst* codecInst) {
if (_fileFormat == kFileFormatPcm16kHzFile ||
_fileFormat == kFileFormatPcm32kHzFile ||
_fileFormat == kFileFormatPcm8kHzFile) {
_fileFormat == kFileFormatPcm8kHzFile ||
_fileFormat == kFileFormatPcm48kHzFile) {
CodecInst codecInstL16;
strncpy(codecInstL16.plname, "L16", 32);
codecInstL16.pltype = 93;
Expand All @@ -287,16 +290,18 @@ int32_t FilePlayerImpl::StartPlayingFile(InStream* sourceStream,
codecInstL16.rate = 128000;
codecInstL16.plfreq = 8000;
codecInstL16.pacsize = 80;

} else if (_fileFormat == kFileFormatPcm16kHzFile) {
codecInstL16.rate = 256000;
codecInstL16.plfreq = 16000;
codecInstL16.pacsize = 160;

} else if (_fileFormat == kFileFormatPcm32kHzFile) {
codecInstL16.rate = 512000;
codecInstL16.plfreq = 32000;
codecInstL16.pacsize = 160;
codecInstL16.pacsize = 320;
} else if (_fileFormat == kFileFormatPcm48kHzFile) {
codecInstL16.rate = 768000;
codecInstL16.plfreq = 48000;
codecInstL16.pacsize = 480;
} else {
LOG(LS_ERROR) << "StartPlayingFile() sample frequency not "
<< "supported for PCM format.";
Expand Down Expand Up @@ -379,6 +384,7 @@ std::unique_ptr<FilePlayer> FilePlayer::CreateFilePlayer(
case kFileFormatPcm16kHzFile:
case kFileFormatPcm8kHzFile:
case kFileFormatPcm32kHzFile:
case kFileFormatPcm48kHzFile:
// audio formats
return std::unique_ptr<FilePlayer>(
new FilePlayerImpl(instanceID, fileFormat));
Expand Down
4 changes: 2 additions & 2 deletions webrtc/voice_engine/file_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class FileCallback;

class FilePlayer {
public:
// The largest decoded frame size in samples (60ms with 32kHz sample rate).
enum { MAX_AUDIO_BUFFER_IN_SAMPLES = 60 * 32 };
// The largest decoded frame size in samples (60ms with 48kHz sample rate).
enum { MAX_AUDIO_BUFFER_IN_SAMPLES = 60 * 48 };
enum { MAX_AUDIO_BUFFER_IN_BYTES = MAX_AUDIO_BUFFER_IN_SAMPLES * 2 };

// Note: will return NULL for unsupported formats.
Expand Down

0 comments on commit 85a3b6b

Please sign in to comment.