Commit 3e0fe16b authored by mikhal's avatar mikhal Committed by Commit bot

Adding an ALAC enum to AudioDecoderConfig

This CL enables using the ALAC codec within the media pipeline.
This does not add ALAC support, as the ALAC codec is not part of the current build.

BUG=441343

Review URL: https://codereview.chromium.org/881603002

Cr-Commit-Position: refs/heads/master@{#313654}
parent 97bf67f3
......@@ -51,7 +51,8 @@ AudioBuffer::AudioBuffer(SampleFormat sample_format,
return;
if (sample_format == kSampleFormatPlanarF32 ||
sample_format == kSampleFormatPlanarS16) {
sample_format == kSampleFormatPlanarS16 ||
sample_format == kSampleFormatPlanarS32) {
// Planar data, so need to allocate buffer for each channel.
// Determine per channel data size, taking into account alignment.
int block_size_per_channel =
......@@ -254,6 +255,12 @@ static inline int32 ConvertF32ToS32(float value) {
: value * std::numeric_limits<int32>::max());
}
// No need for conversion. Return value as is. Keeping function to align with
// code structure.
static inline int32 ConvertS32ToS32(int32 value) {
return value;
}
template <class Target, typename Converter>
void InterleaveToS32(const std::vector<uint8*>& channel_data,
size_t frames_to_copy,
......@@ -322,6 +329,14 @@ void AudioBuffer::ReadFramesInterleavedS32(int frames_to_copy,
dest_data,
ConvertF32ToS32);
break;
case kSampleFormatPlanarS32:
// Format is planar signed 32 bit. Convert each value into int32 and
// insert into output channel data.
InterleaveToS32<int32>(channel_data_,
frames_to_copy,
trim_start_,
dest_data,
ConvertS32ToS32);
case kUnknownSampleFormat:
NOTREACHED();
break;
......@@ -365,6 +380,7 @@ void AudioBuffer::TrimRange(int start, int end) {
switch (sample_format_) {
case kSampleFormatPlanarS16:
case kSampleFormatPlanarF32:
case kSampleFormatPlanarS32:
// Planar data must be shifted per channel.
for (int ch = 0; ch < channel_count_; ++ch) {
memmove(channel_data_[ch] + (trim_start_ + start) * bytes_per_channel,
......
......@@ -488,6 +488,16 @@ static scoped_refptr<AudioBuffer> MakeReadFramesInterleavedTestBuffer(
65536.0f / std::numeric_limits<int32>::max(),
frames,
base::TimeDelta::FromSeconds(0));
case kSampleFormatPlanarS32:
return MakeAudioBuffer<int32>(
sample_format,
channel_layout,
channel_count,
sample_rate,
0.0f,
65536.0f / std::numeric_limits<int32>::max(),
frames,
base::TimeDelta::FromSeconds(0));
case kSampleFormatU8:
case kUnknownSampleFormat:
EXPECT_FALSE(true);
......
......@@ -150,6 +150,8 @@ std::string AudioDecoderConfig::GetHumanReadableCodecName() const {
return "pcm_mulaw";
case kCodecOpus:
return "opus";
case kCodecALAC:
return "alac";
}
NOTREACHED();
return "";
......
......@@ -36,13 +36,14 @@ enum AudioCodec {
kCodecOpus = 12,
// kCodecEAC3 = 13,
kCodecPCM_ALAW = 14,
kCodecALAC = 15,
// DO NOT ADD RANDOM AUDIO CODECS!
//
// The only acceptable time to add a new codec is if there is production code
// that uses said codec in the same CL.
// Must always be equal to the largest entry ever logged.
kAudioCodecMax = kCodecPCM_ALAW,
kAudioCodecMax = kCodecALAC,
};
// TODO(dalecurtis): FFmpeg API uses |bytes_per_channel| instead of
......
......@@ -20,6 +20,7 @@ int SampleFormatToBytesPerChannel(SampleFormat sample_format) {
case kSampleFormatS32:
case kSampleFormatF32:
case kSampleFormatPlanarF32:
case kSampleFormatPlanarS32:
return 4;
}
......@@ -43,6 +44,8 @@ const char* SampleFormatToString(SampleFormat sample_format) {
return "Signed 16-bit planar";
case kSampleFormatPlanarF32:
return "Float 32-bit planar";
case kSampleFormatPlanarS32:
return "Signed 32-bit planar";
}
NOTREACHED() << "Invalid sample format provided: " << sample_format;
return "";
......
......@@ -21,9 +21,10 @@ enum SampleFormat {
kSampleFormatF32, // Float 32-bit.
kSampleFormatPlanarS16, // Signed 16-bit planar.
kSampleFormatPlanarF32, // Float 32-bit planar.
kSampleFormatPlanarS32, // Signed 32-bit planar.
// Must always be equal to largest value ever logged.
kSampleFormatMax = kSampleFormatPlanarF32,
kSampleFormatMax = kSampleFormatPlanarS32,
};
// Returns the number of bytes used per channel for the specified
......
......@@ -92,6 +92,8 @@ static AudioCodec CodecIDToAudioCodec(AVCodecID codec_id) {
return kCodecPCM_MULAW;
case AV_CODEC_ID_OPUS:
return kCodecOpus;
case AV_CODEC_ID_ALAC:
return kCodecALAC;
default:
DVLOG(1) << "Unknown audio CodecID: " << codec_id;
}
......@@ -103,6 +105,8 @@ static AVCodecID AudioCodecToCodecID(AudioCodec audio_codec,
switch (audio_codec) {
case kCodecAAC:
return AV_CODEC_ID_AAC;
case kCodecALAC:
return AV_CODEC_ID_ALAC;
case kCodecMP3:
return AV_CODEC_ID_MP3;
case kCodecPCM:
......@@ -242,6 +246,8 @@ SampleFormat AVSampleFormatToSampleFormat(AVSampleFormat sample_format) {
return kSampleFormatF32;
case AV_SAMPLE_FMT_S16P:
return kSampleFormatPlanarS16;
case AV_SAMPLE_FMT_S32P:
return kSampleFormatPlanarS32;
case AV_SAMPLE_FMT_FLTP:
return kSampleFormatPlanarF32;
default:
......
......@@ -31,7 +31,8 @@ enum AudioCodec {
Opus = 12,
// EAC3 = 13,
PCM_ALAW = 14,
MAX = PCM_ALAW,
ALAC = 15,
MAX = ALAC,
};
// See media/base/channel_layout.h for descriptions.
......@@ -84,7 +85,8 @@ enum SampleFormat {
F32,
PlanarS16,
PlanarF32,
Max = PlanarF32,
PlanarS32,
Max = PlanarS32,
};
// See media/base/video_frame.h for descriptions.
......
......@@ -47,6 +47,7 @@ ASSERT_ENUM_EQ(AudioCodec, kCodec, AUDIO_CODEC_, PCM_S16BE);
ASSERT_ENUM_EQ(AudioCodec, kCodec, AUDIO_CODEC_, PCM_S24BE);
ASSERT_ENUM_EQ(AudioCodec, kCodec, AUDIO_CODEC_, Opus);
ASSERT_ENUM_EQ(AudioCodec, kCodec, AUDIO_CODEC_, PCM_ALAW);
ASSERT_ENUM_EQ(AudioCodec, kCodec, AUDIO_CODEC_, ALAC);
ASSERT_ENUM_EQ_RAW(AudioCodec, kAudioCodecMax, AUDIO_CODEC_MAX);
// ChannelLayout.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment