Commit 95e65f62 authored by ziyangch's avatar ziyangch Committed by Commit Bot

[Chromecast] Add channel count check in AudioDecoderAndroid.

Bug: internal b/140189221

Test: Cast from Youtube to Android TV.
      TTS on Android Things.

Change-Id: I285f06ce5f44d6d0875e43d5d7ed62328e7ece70
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1917342Reviewed-by: default avatarKenneth MacKay <kmackay@chromium.org>
Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Commit-Queue: Ziyang Cheng <ziyangch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715358}
parent c03c64b4
...@@ -53,6 +53,13 @@ const int64_t kInvalidTimestamp = std::numeric_limits<int64_t>::min(); ...@@ -53,6 +53,13 @@ const int64_t kInvalidTimestamp = std::numeric_limits<int64_t>::min();
const int64_t kNoPendingOutput = -1; const int64_t kNoPendingOutput = -1;
bool IsValidChannelNumber(int channel_number) {
// Currently, we only support following channel numbers.
return (channel_number == 1) || (channel_number == 2) ||
(channel_number == 4) || (channel_number == 6) ||
(channel_number == 8);
}
} // namespace } // namespace
AudioDecoderAndroid::RateShifterInfo::RateShifterInfo(float playback_rate) AudioDecoderAndroid::RateShifterInfo::RateShifterInfo(float playback_rate)
...@@ -119,6 +126,7 @@ bool AudioDecoderAndroid::Start(int64_t start_pts) { ...@@ -119,6 +126,7 @@ bool AudioDecoderAndroid::Start(int64_t start_pts) {
TRACE_FUNCTION_ENTRY0(); TRACE_FUNCTION_ENTRY0();
current_pts_ = start_pts; current_pts_ = start_pts;
DCHECK(IsValidConfig(config_)); DCHECK(IsValidConfig(config_));
DCHECK(IsValidChannelNumber(config_.channel_number));
sink_.Reset(this, config_.channel_number, config_.samples_per_second, sink_.Reset(this, config_.channel_number, config_.samples_per_second,
backend_->Primary(), backend_->DeviceId(), backend_->Primary(), backend_->DeviceId(),
backend_->ContentType()); backend_->ContentType());
...@@ -253,7 +261,7 @@ bool AudioDecoderAndroid::SetConfig(const AudioConfig& config) { ...@@ -253,7 +261,7 @@ bool AudioDecoderAndroid::SetConfig(const AudioConfig& config) {
TRACE_FUNCTION_ENTRY0(); TRACE_FUNCTION_ENTRY0();
DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(task_runner_->BelongsToCurrentThread());
if (!IsValidConfig(config)) { if (!IsValidConfig(config) || !IsValidChannelNumber(config.channel_number)) {
LOG(ERROR) << "Invalid audio config passed to SetConfig"; LOG(ERROR) << "Invalid audio config passed to SetConfig";
return false; return false;
} }
...@@ -296,6 +304,7 @@ void AudioDecoderAndroid::CreateDecoder() { ...@@ -296,6 +304,7 @@ void AudioDecoderAndroid::CreateDecoder() {
DCHECK(!decoder_); DCHECK(!decoder_);
DCHECK(IsValidConfig(config_)); DCHECK(IsValidConfig(config_));
DCHECK(IsValidChannelNumber(config_.channel_number));
// No need to create a decoder if the samples are already decoded. // No need to create a decoder if the samples are already decoded.
if (BypassDecoder()) { if (BypassDecoder()) {
...@@ -401,6 +410,11 @@ void AudioDecoderAndroid::OnBufferDecoded( ...@@ -401,6 +410,11 @@ void AudioDecoderAndroid::OnBufferDecoded(
delegate_->OnPushBufferComplete(MediaPipelineBackendAndroid::kBufferFailed); delegate_->OnPushBufferComplete(MediaPipelineBackendAndroid::kBufferFailed);
return; return;
} }
if (!IsValidChannelNumber(config.channel_number)) {
LOG(ERROR) << "Channel number changes to be invalid.";
delegate_->OnPushBufferComplete(MediaPipelineBackendAndroid::kBufferFailed);
return;
}
Statistics delta; Statistics delta;
delta.decoded_bytes = input_bytes; delta.decoded_bytes = input_bytes;
......
...@@ -246,6 +246,7 @@ class AudioSinkAudioTrackImpl { ...@@ -246,6 +246,7 @@ class AudioSinkAudioTrackImpl {
return AudioFormat.CHANNEL_OUT_7POINT1; return AudioFormat.CHANNEL_OUT_7POINT1;
} }
default: default:
Log.e(TAG, "Unsupported channel count: " + channelCount);
return AudioFormat.CHANNEL_OUT_DEFAULT; return AudioFormat.CHANNEL_OUT_DEFAULT;
} }
} }
......
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