summaryrefslogtreecommitdiffstats
path: root/chromecast
diff options
context:
space:
mode:
authorjyw <jyw@chromium.org>2016-03-08 17:46:05 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-09 01:50:53 +0000
commitb92b0b2ccec55e07d667315283ba06006bba42db (patch)
tree8f7d386494987f79668d6d6e3f1d0348c44fa2fe /chromecast
parentc13b8c096cf27d06582d9528be8b9b46a11df529 (diff)
downloadchromium_src-b92b0b2ccec55e07d667315283ba06006bba42db.zip
chromium_src-b92b0b2ccec55e07d667315283ba06006bba42db.tar.gz
chromium_src-b92b0b2ccec55e07d667315283ba06006bba42db.tar.bz2
[chromecast] Add cast_shell --accept-resource-provider switch and a utility function, GetSwitchValueBoolean.
Also has the cast_shell flag --accept-resource-provider imply --alsa-check-close-timeout=0 unless the close timeout is explicitly overridden. BUG=internal b/26091363 TEST=pepperoni build cast_base_unittests --gtest_filter=ChromecastSwitchesTest.* Review URL: https://codereview.chromium.org/1767603003 Cr-Commit-Position: refs/heads/master@{#380024}
Diffstat (limited to 'chromecast')
-rw-r--r--chromecast/base/BUILD.gn1
-rw-r--r--chromecast/base/chromecast_switches.cc40
-rw-r--r--chromecast/base/chromecast_switches.h21
-rw-r--r--chromecast/base/chromecast_switches_unittest.cc61
-rw-r--r--chromecast/chromecast_tests.gypi1
-rw-r--r--chromecast/media/cma/backend/alsa/stream_mixer_alsa.cc8
6 files changed, 129 insertions, 3 deletions
diff --git a/chromecast/base/BUILD.gn b/chromecast/base/BUILD.gn
index fec43ac..c5a5445 100644
--- a/chromecast/base/BUILD.gn
+++ b/chromecast/base/BUILD.gn
@@ -91,6 +91,7 @@ source_set("test_support") {
test("cast_base_unittests") {
sources = [
"bind_to_task_runner_unittest.cc",
+ "chromecast_switches_unittest.cc",
"device_capabilities_impl_unittest.cc",
"error_codes_unittest.cc",
"path_utils_unittest.cc",
diff --git a/chromecast/base/chromecast_switches.cc b/chromecast/base/chromecast_switches.cc
index 469768c..baaf447 100644
--- a/chromecast/base/chromecast_switches.cc
+++ b/chromecast/base/chromecast_switches.cc
@@ -4,8 +4,16 @@
#include "chromecast/base/chromecast_switches.h"
+#include "base/command_line.h"
+
namespace switches {
+// Value indicating whether flag from command line switch is true.
+const char kSwitchValueTrue[] = "true";
+
+// Value indicating whether flag from command line switch is false.
+const char kSwitchValueFalse[] = "false";
+
// Enable the CMA media pipeline.
const char kEnableCmaMediaPipeline[] = "enable-cma-media-pipeline";
@@ -32,6 +40,11 @@ const char kLastLaunchedApp[] = "last-launched-app";
// started.
const char kPreviousApp[] = "previous-app";
+// Flag indicating that a resource provider must be set up to provide cast
+// receiver with resources. Apps cannot start until provided resources.
+// This flag implies --alsa-check-close-timeout=0.
+const char kAcceptResourceProvider[] = "accept-resource-provider";
+
// Size of the ALSA output buffer in frames. This directly sets the latency of
// the output device. Latency can be calculated by multiplying the sample rate
// by the output buffer size.
@@ -48,7 +61,7 @@ const char kAlsaOutputStartThreshold[] = "alsa-output-start-threshold";
const char kAlsaOutputAvailMin[] = "alsa-output-avail-min";
// Time in ms to wait before closing the PCM handle when no more mixer inputs
-// remain.
+// remain. Assumed to be 0 if --accept-resource-provider is present.
const char kAlsaCheckCloseTimeout[] = "alsa-check-close-timeout";
// Number of channels on the alsa output device that the stream mixer uses.
@@ -56,3 +69,28 @@ const char kAlsaCheckCloseTimeout[] = "alsa-check-close-timeout";
const char kAlsaNumOutputChannels[] = "alsa-num-output-channels";
} // namespace switches
+
+namespace chromecast {
+
+bool GetSwitchValueBoolean(const std::string& switch_string,
+ const bool default_value) {
+ const base::CommandLine* command_line =
+ base::CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(switch_string)) {
+ if (command_line->GetSwitchValueASCII(switch_string) !=
+ switches::kSwitchValueTrue &&
+ command_line->GetSwitchValueASCII(switch_string) !=
+ switches::kSwitchValueFalse &&
+ command_line->GetSwitchValueASCII(switch_string) != "") {
+ LOG(WARNING) << "Invalid switch value " << switch_string << "="
+ << command_line->GetSwitchValueASCII(switch_string)
+ << "; assuming default value of " << default_value;
+ return default_value;
+ }
+ return command_line->GetSwitchValueASCII(switch_string) !=
+ switches::kSwitchValueFalse;
+ }
+ return default_value;
+}
+
+} // namespace chromecast
diff --git a/chromecast/base/chromecast_switches.h b/chromecast/base/chromecast_switches.h
index 0d3094a..eecff02 100644
--- a/chromecast/base/chromecast_switches.h
+++ b/chromecast/base/chromecast_switches.h
@@ -5,10 +5,16 @@
#ifndef CHROMECAST_BASE_CHROMECAST_SWITCHES_H_
#define CHROMECAST_BASE_CHROMECAST_SWITCHES_H_
+#include <string>
+
#include "build/build_config.h"
namespace switches {
+// Switch values
+extern const char kSwitchValueTrue[];
+extern const char kSwitchValueFalse[];
+
// Media switches
extern const char kEnableCmaMediaPipeline[];
extern const char kHdmiSinkSupportedCodecs[];
@@ -29,6 +35,9 @@ extern const char kAllowHiddenMediaPlayback[];
extern const char kLastLaunchedApp[];
extern const char kPreviousApp[];
+// Cast Receiver switches
+extern const char kAcceptResourceProvider[];
+
// ALSA-based CMA switches. (Only valid for audio products.)
extern const char kAlsaOutputBufferSize[];
extern const char kAlsaOutputPeriodSize[];
@@ -39,4 +48,16 @@ extern const char kAlsaNumOutputChannels[];
} // namespace switches
+namespace chromecast {
+
+// Gets boolean value from switch |switch_string|.
+// --|switch_string| -> true
+// --|switch_string|="true" -> true
+// --|switch_string|="false" -> false
+// no switch named |switch_string| -> |default_value|
+bool GetSwitchValueBoolean(const std::string& switch_string,
+ const bool default_value);
+
+} // namespace chromecast
+
#endif // CHROMECAST_BASE_CHROMECAST_SWITCHES_H_
diff --git a/chromecast/base/chromecast_switches_unittest.cc b/chromecast/base/chromecast_switches_unittest.cc
new file mode 100644
index 0000000..465456e
--- /dev/null
+++ b/chromecast/base/chromecast_switches_unittest.cc
@@ -0,0 +1,61 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "chromecast/base/chromecast_switches.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromecast {
+
+TEST(ChromecastSwitchesTest, NoSwitch) {
+ if (base::CommandLine::CommandLine::InitializedForCurrentProcess())
+ base::CommandLine::Reset();
+ base::CommandLine::Init(0, nullptr);
+ EXPECT_TRUE(GetSwitchValueBoolean(switches::kEnableCmaMediaPipeline, true));
+ EXPECT_FALSE(GetSwitchValueBoolean(switches::kEnableCmaMediaPipeline, false));
+}
+
+TEST(ChromecastSwitchesTest, NoSwitchValue) {
+ if (base::CommandLine::CommandLine::InitializedForCurrentProcess())
+ base::CommandLine::Reset();
+ base::CommandLine::Init(0, nullptr);
+ base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
+ cl->AppendSwitch(switches::kEnableCmaMediaPipeline);
+ EXPECT_TRUE(GetSwitchValueBoolean(switches::kEnableCmaMediaPipeline, true));
+ EXPECT_TRUE(GetSwitchValueBoolean(switches::kEnableCmaMediaPipeline, false));
+}
+
+TEST(ChromecastSwitchesTest, SwitchValueTrue) {
+ if (base::CommandLine::CommandLine::InitializedForCurrentProcess())
+ base::CommandLine::Reset();
+ base::CommandLine::Init(0, nullptr);
+ base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
+ cl->AppendSwitchASCII(switches::kEnableCmaMediaPipeline,
+ switches::kSwitchValueTrue);
+ EXPECT_TRUE(GetSwitchValueBoolean(switches::kEnableCmaMediaPipeline, true));
+ EXPECT_TRUE(GetSwitchValueBoolean(switches::kEnableCmaMediaPipeline, false));
+}
+
+TEST(ChromecastSwitchesTest, SwitchValueFalse) {
+ if (base::CommandLine::CommandLine::InitializedForCurrentProcess())
+ base::CommandLine::Reset();
+ base::CommandLine::Init(0, nullptr);
+ base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
+ cl->AppendSwitchASCII(switches::kEnableCmaMediaPipeline,
+ switches::kSwitchValueFalse);
+ EXPECT_FALSE(GetSwitchValueBoolean(switches::kEnableCmaMediaPipeline, true));
+ EXPECT_FALSE(GetSwitchValueBoolean(switches::kEnableCmaMediaPipeline, false));
+}
+
+TEST(ChromecastSwitchesTest, SwitchValueNonsense) {
+ if (base::CommandLine::CommandLine::InitializedForCurrentProcess())
+ base::CommandLine::Reset();
+ base::CommandLine::Init(0, nullptr);
+ base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
+ cl->AppendSwitchASCII(switches::kEnableCmaMediaPipeline, "silverware");
+ EXPECT_TRUE(GetSwitchValueBoolean(switches::kEnableCmaMediaPipeline, true));
+ EXPECT_FALSE(GetSwitchValueBoolean(switches::kEnableCmaMediaPipeline, false));
+}
+
+} // namespace chromecast
diff --git a/chromecast/chromecast_tests.gypi b/chromecast/chromecast_tests.gypi
index a5794038..88dfba9 100644
--- a/chromecast/chromecast_tests.gypi
+++ b/chromecast/chromecast_tests.gypi
@@ -21,6 +21,7 @@
],
'sources': [
'base/bind_to_task_runner_unittest.cc',
+ 'base/chromecast_switches_unittest.cc',
'base/component/component_unittest.cc',
'base/device_capabilities_impl_unittest.cc',
'base/error_codes_unittest.cc',
diff --git a/chromecast/media/cma/backend/alsa/stream_mixer_alsa.cc b/chromecast/media/cma/backend/alsa/stream_mixer_alsa.cc
index 2f1afc7..5e5e17b 100644
--- a/chromecast/media/cma/backend/alsa/stream_mixer_alsa.cc
+++ b/chromecast/media/cma/backend/alsa/stream_mixer_alsa.cc
@@ -256,9 +256,13 @@ void StreamMixerAlsa::DefineAlsaParameters() {
}
alsa_avail_min_ = avail_min;
+ // --accept-resource-provider should imply a check close timeout of 0.
+ int default_close_timeout = chromecast::GetSwitchValueBoolean(
+ switches::kAcceptResourceProvider, false)
+ ? 0
+ : kDefaultCheckCloseTimeoutMs;
GetSwitchValueAsNonNegativeInt(switches::kAlsaCheckCloseTimeout,
- kDefaultCheckCloseTimeoutMs,
- &check_close_timeout_);
+ default_close_timeout, &check_close_timeout_);
}
int StreamMixerAlsa::SetAlsaPlaybackParams() {