Import Cobalt 20.master.0.220857
diff --git a/src/cobalt/audio/audio.gyp b/src/cobalt/audio/audio.gyp
index b2cadf3..c0488c2 100644
--- a/src/cobalt/audio/audio.gyp
+++ b/src/cobalt/audio/audio.gyp
@@ -14,6 +14,7 @@
{
'variables': {
+ 'optimize_target_for_speed': 1,
'sb_pedantic_warnings': 1,
},
'targets': [
diff --git a/src/cobalt/browser/application.cc b/src/cobalt/browser/application.cc
index 277a0e3..cb3cc35 100644
--- a/src/cobalt/browser/application.cc
+++ b/src/cobalt/browser/application.cc
@@ -386,6 +386,15 @@
// accessed.
base::LazyInstance<NonTrivialStaticFields>::DestructorAtExit
non_trivial_static_fields = LAZY_INSTANCE_INITIALIZER;
+
+#if defined(ENABLE_DEBUGGER) && defined(STARBOARD_ALLOWS_MEMORY_TRACKING)
+const char kMemoryTrackerCommand[] = "memory_tracker";
+const char kMemoryTrackerCommandShortHelp[] = "Create a memory tracker.";
+const char kMemoryTrackerCommandLongHelp[] =
+ "Create a memory tracker of the given type. Use an empty string to see the "
+ "available trackers.";
+#endif // defined(ENABLE_DEBUGGER) && defined(STARBOARD_ALLOWS_MEMORY_TRACKING)
+
} // namespace
// Static user logs
@@ -405,7 +414,17 @@
int Application::network_disconnect_count_ = 0;
Application::Application(const base::Closure& quit_closure, bool should_preload)
- : message_loop_(base::MessageLoop::current()), quit_closure_(quit_closure) {
+ : message_loop_(base::MessageLoop::current()),
+ quit_closure_(quit_closure)
+#if defined(ENABLE_DEBUGGER) && defined(STARBOARD_ALLOWS_MEMORY_TRACKING)
+ ,
+ ALLOW_THIS_IN_INITIALIZER_LIST(memory_tracker_command_handler_(
+ kMemoryTrackerCommand,
+ base::Bind(&Application::OnMemoryTrackerCommand,
+ base::Unretained(this)),
+ kMemoryTrackerCommandShortHelp, kMemoryTrackerCommandLongHelp))
+#endif // defined(ENABLE_DEBUGGER) && defined(STARBOARD_ALLOWS_MEMORY_TRACKING)
+{
DCHECK(!quit_closure_.is_null());
// Check to see if a timed_trace has been set, indicating that we should
// begin a timed trace upon startup.
@@ -583,11 +602,13 @@
EnableUsingStubImageDecoderIfRequired();
+#if defined(ENABLE_DEBUGGER) && defined(STARBOARD_ALLOWS_MEMORY_TRACKING)
if (command_line->HasSwitch(switches::kMemoryTracker)) {
std::string command_arg =
command_line->GetSwitchValueASCII(switches::kMemoryTracker);
memory_tracker_tool_ = memory_tracker::CreateMemoryTrackerTool(command_arg);
}
+#endif // defined(ENABLE_DEBUGGER) && defined(STARBOARD_ALLOWS_MEMORY_TRACKING)
if (command_line->HasSwitch(switches::kDisableImageAnimations)) {
options.web_module_options.enable_image_animations = false;
@@ -724,7 +745,9 @@
// and involves a thread join. If this were to hang the app then having
// the destruction at this point gives a real file-line number and a place
// for the debugger to land.
+#if defined(ENABLE_DEBUGGER) && defined(STARBOARD_ALLOWS_MEMORY_TRACKING)
memory_tracker_tool_.reset(NULL);
+#endif // defined(ENABLE_DEBUGGER) && defined(STARBOARD_ALLOWS_MEMORY_TRACKING)
// Unregister event callbacks.
event_dispatcher_.RemoveEventCallback(base::DeepLinkEvent::TypeId(),
@@ -1105,5 +1128,23 @@
event_dispatcher_.DispatchEvent(std::unique_ptr<base::Event>(event));
}
+#if defined(ENABLE_DEBUGGER) && defined(STARBOARD_ALLOWS_MEMORY_TRACKING)
+void Application::OnMemoryTrackerCommand(const std::string& message) {
+ if (base::MessageLoop::current() != message_loop_) {
+ message_loop_->task_runner()->PostTask(
+ FROM_HERE, base::Bind(&Application::OnMemoryTrackerCommand,
+ base::Unretained(this), message));
+ return;
+ }
+
+ if (memory_tracker_tool_) {
+ LOG(ERROR) << "Can not create a memory tracker when one is already active.";
+ return;
+ }
+ LOG(WARNING) << "Creating \"" << message << "\" memory tracker.";
+ memory_tracker_tool_ = memory_tracker::CreateMemoryTrackerTool(message);
+}
+#endif // defined(ENABLE_DEBUGGER) && defined(STARBOARD_ALLOWS_MEMORY_TRACKING)
+
} // namespace browser
} // namespace cobalt
diff --git a/src/cobalt/browser/application.h b/src/cobalt/browser/application.h
index 8486ea0..66ff3c7 100644
--- a/src/cobalt/browser/application.h
+++ b/src/cobalt/browser/application.h
@@ -16,9 +16,11 @@
#define COBALT_BROWSER_APPLICATION_H_
#include <memory>
+#include <string>
#include "base/callback.h"
#include "base/command_line.h"
+#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/thread_checker.h"
#include "cobalt/account/account_manager.h"
@@ -33,8 +35,9 @@
#endif
#if defined(ENABLE_DEBUGGER)
+#include "cobalt/debug/console/command_manager.h"
#include "cobalt/debug/remote/debug_web_server.h"
-#endif
+#endif // ENABLE_DEBUGGER
namespace cobalt {
namespace browser {
@@ -56,13 +59,6 @@
protected:
base::MessageLoop* message_loop() { return message_loop_; }
- private:
- // The message loop that will handle UI events.
- base::MessageLoop* message_loop_;
-
- const base::Closure quit_closure_;
-
- protected:
// Called to handle a network event.
void OnNetworkEvent(const base::Event* event);
@@ -179,6 +175,11 @@
void UpdatePeriodicStats();
void DispatchEventInternal(base::Event* event);
+ // The message loop that will handle UI events.
+ base::MessageLoop* message_loop_;
+
+ const base::Closure quit_closure_;
+
static ssize_t available_memory_;
static int64 lifetime_in_ms_;
@@ -196,7 +197,18 @@
base::RepeatingTimer stats_update_timer_;
+#if defined(ENABLE_DEBUGGER) && defined(STARBOARD_ALLOWS_MEMORY_TRACKING)
std::unique_ptr<memory_tracker::Tool> memory_tracker_tool_;
+
+ // Command handler object for creating a memory tracker.
+ debug::console::ConsoleCommandManager::CommandHandler
+ memory_tracker_command_handler_;
+
+ // Create a memory tracker with the given message
+ void OnMemoryTrackerCommand(const std::string& message);
+#endif // defined(ENABLE_DEBUGGER) && defined(STARBOARD_ALLOWS_MEMORY_TRACKING)
+
+ DISALLOW_COPY_AND_ASSIGN(Application);
};
} // namespace browser
diff --git a/src/cobalt/browser/memory_tracker/tool.cc b/src/cobalt/browser/memory_tracker/tool.cc
index ee9c2d7..2a627e5 100644
--- a/src/cobalt/browser/memory_tracker/tool.cc
+++ b/src/cobalt/browser/memory_tracker/tool.cc
@@ -34,7 +34,9 @@
#include "cobalt/browser/memory_tracker/tool/tool_thread.h"
#include "nb/analytics/memory_tracker_helpers.h"
#include "starboard/common/log.h"
+#include "starboard/configuration.h"
#include "starboard/double.h"
+#include "starboard/file.h"
namespace cobalt {
namespace browser {
@@ -87,25 +89,93 @@
class SbLogger : public AbstractLogger {
public:
- void Output(const char* str) override { SbLogRaw(str); }
+ void Output(const char* str) override { LOG(INFO) << str; }
void Flush() override { SbLogFlush(); }
};
+class FileLogger : public AbstractLogger {
+ public:
+ explicit FileLogger(const std::string& filename);
+ ~FileLogger();
+ void Output(const char* str) override {
+ if (SbFileIsValid(log_file_)) {
+ SbFileWrite(log_file_, str, static_cast<int>(strlen(str)));
+ SbFileFlush(log_file_);
+ } else {
+ LOG(INFO) << str;
+ }
+ }
+ void Flush() override { SbLogFlush(); }
+
+ private:
+ SbFile log_file_;
+};
+
+FileLogger::FileLogger(const std::string& filename)
+ : log_file_(kSbFileInvalid) {
+ char file_name_buff[2048] = {};
+ SbSystemGetPath(kSbSystemPathDebugOutputDirectory, file_name_buff,
+ arraysize(file_name_buff));
+ std::string path(file_name_buff);
+ if (!path.empty()) { // Protect against a dangling "/" at end.
+ const int back_idx_signed = static_cast<int>(path.length()) - 1;
+ if (back_idx_signed >= 0) {
+ const size_t idx = back_idx_signed;
+ if (path[idx] == SB_FILE_SEP_CHAR) {
+ path.erase(idx);
+ }
+ }
+ }
+ path.push_back(SB_FILE_SEP_CHAR);
+ path.append(filename);
+ int flags = kSbFileCreateAlways | kSbFileWrite;
+ bool created_ok = false;
+ SbFileError error_code = kSbFileOk;
+ log_file_ = SbFileOpen(path.c_str(), flags, &created_ok, &error_code);
+ if (log_file_ == kSbFileInvalid || !created_ok) {
+ LOG(ERROR) << "Error creating log file";
+ return;
+ } else {
+ LOG(INFO) << "Logging to file: " << path;
+ }
+}
+
+FileLogger::~FileLogger() {
+ SbFileClose(log_file_);
+ log_file_ = kSbFileInvalid;
+} // namespace
+
// Parses out the toolname for a tool command.
// Example:
-// INPUT: "tool_name(arg)"
+// INPUT: "tool_name(arg):filename"
// OUTPUT: "tool_name"
std::string ParseToolName(const std::string& command_arg) {
const size_t first_open_paren_idx = command_arg.find('(');
if (first_open_paren_idx == std::string::npos) {
- return command_arg;
+ const size_t first_colon_idx = command_arg.find(':');
+ if (first_colon_idx == std::string::npos) {
+ return command_arg;
+ }
+ return command_arg.substr(0, first_colon_idx);
}
return command_arg.substr(0, first_open_paren_idx);
}
+// Parses out the output filename for a tool command.
+// Example:
+// INPUT: "tool_name(arg):filename"
+// OUTPUT: "filename"
+std::string ParseFileName(const std::string& command_arg) {
+ const size_t first_colon_idx = command_arg.find(':');
+ if (first_colon_idx == std::string::npos) {
+ return "";
+ }
+ return command_arg.substr(1 + first_colon_idx);
+}
+
// Parses out the arguments for a tool.
// Example:
-// INPUT: "tool_name(arg)"
+// INPUT: "tool_name(arg):filename"
// OUTPUT: "arg"
std::string ParseToolArg(const std::string& command_arg) {
const size_t first_open_paren_idx = command_arg.find('(');
@@ -250,6 +320,7 @@
std::string tool_name = ParseToolName(command_arg);
std::string tool_arg = ParseToolArg(command_arg);
+ std::string filename = ParseFileName(command_arg);
// FAST OUT - is a thread type not selected? Then print out a help menu
// and request that the app should shut down.
@@ -263,13 +334,13 @@
it != switch_map.end(); ++it) {
const std::string& name = it->first;
const SwitchVal& val = it->second;
- ss << " memory_tracker=" << name << " "
- << "\"" << val.help_msg << "\"\n";
+ ss << " memory_tracker=" << name << " \n" << val.help_msg;
}
- ss << "\n";
- SbLogRaw(ss.str().c_str());
+ ss << "\nIf the string has a colon, then the name after the colon is used\n"
+ "as the filename for output.\n"
+ "For example: \"leak_tracer:leaks.csv\"\n";
+ LOG(INFO) << ss.str();
ss.str(""); // Clears the contents of stringstream.
- SbLogFlush();
// Try and turn off all logging so that the stdout is less likely to be
// polluted by interleaving output.
@@ -282,9 +353,6 @@
found_it = switch_map.find(continuous_printer_tool.tool_name);
- ss << "Defaulting to tool: " << found_it->first << "\n";
- SbLogRaw(ss.str().c_str());
- SbLogFlush();
// One more help message and 1-second pause. Then continue on with the
// execution as normal.
const SbTime one_second = 1000 * kSbTimeMillisecond;
@@ -423,9 +491,15 @@
if (tool_ptr.get()) {
DisableMemoryTrackerInScope disable_in_scope(memory_tracker);
- base::SimpleThread* thread =
- new ToolThread(memory_tracker, // May be NULL.
- tool_ptr.release(), new SbLogger);
+ AbstractLogger* logger = NULL;
+ if (!filename.empty()) {
+ logger = new FileLogger(filename);
+ }
+ if (!logger) {
+ logger = new SbLogger;
+ }
+ base::SimpleThread* thread = new ToolThread(memory_tracker, // May be NULL.
+ tool_ptr.release(), logger);
return std::unique_ptr<Tool>(new MemoryTrackerThreadImpl(thread));
} else {
return std::unique_ptr<Tool>();
diff --git a/src/cobalt/browser/memory_tracker/tool/log_writer_tool.cc b/src/cobalt/browser/memory_tracker/tool/log_writer_tool.cc
index 032f5c4..0e58e29 100644
--- a/src/cobalt/browser/memory_tracker/tool/log_writer_tool.cc
+++ b/src/cobalt/browser/memory_tracker/tool/log_writer_tool.cc
@@ -21,6 +21,7 @@
#include "cobalt/browser/memory_tracker/tool/params.h"
#include "starboard/client_porting/poem/string_poem.h"
#include "starboard/common/string.h"
+#include "starboard/configuration.h"
#include "starboard/types.h"
namespace cobalt {
@@ -134,12 +135,13 @@
const int back_idx_signed = static_cast<int>(path.length()) - 1;
if (back_idx_signed >= 0) {
const size_t idx = back_idx_signed;
- if (path[idx] == '/') {
+ if (path[idx] == SB_FILE_SEP_CHAR) {
path.erase(idx);
}
}
}
- path.append("/memory_log.txt");
+ path.push_back(SB_FILE_SEP_CHAR);
+ path.append("memory_log.txt");
return path;
}
diff --git a/src/cobalt/browser/memory_tracker/tool/log_writer_tool.h b/src/cobalt/browser/memory_tracker/tool/log_writer_tool.h
index 1a47078..6c10ad8 100644
--- a/src/cobalt/browser/memory_tracker/tool/log_writer_tool.h
+++ b/src/cobalt/browser/memory_tracker/tool/log_writer_tool.h
@@ -20,6 +20,7 @@
#include "base/compiler_specific.h"
#include "base/time/time.h"
+#include "cobalt/browser/memory_tracker/tool/buffered_file_writer.h"
#include "cobalt/browser/memory_tracker/tool/params.h"
#include "cobalt/browser/memory_tracker/tool/tool_impl.h"
#include "starboard/memory_reporter.h"
diff --git a/src/cobalt/build/build.id b/src/cobalt/build/build.id
index 45fb3e0..eb09812 100644
--- a/src/cobalt/build/build.id
+++ b/src/cobalt/build/build.id
@@ -1 +1 @@
-220639
\ No newline at end of file
+220857
\ No newline at end of file
diff --git a/src/cobalt/dom/eme/media_key_system_access.cc b/src/cobalt/dom/eme/media_key_system_access.cc
index 32830f2..602069c 100644
--- a/src/cobalt/dom/eme/media_key_system_access.cc
+++ b/src/cobalt/dom/eme/media_key_system_access.cc
@@ -14,7 +14,11 @@
#include "cobalt/dom/eme/media_key_system_access.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_refptr.h"
+#include "cobalt/dom/dom_exception.h"
#include "cobalt/dom/eme/media_keys.h"
+#include "cobalt/media/base/drm_system.h"
#include "cobalt/script/script_value_factory.h"
namespace cobalt {
@@ -37,9 +41,25 @@
script::Handle<MediaKeySystemAccess::InterfacePromise> promise =
script_value_factory_->CreateInterfacePromise<scoped_refptr<MediaKeys>>();
+ // 2.5. Let instance be a new instance of the Key System implementation
+ // represented by this object's cdm implementation value.
+ scoped_refptr<media::DrmSystem> drm_system(
+ new media::DrmSystem(key_system_.c_str()));
+
+ // 2.9. If any of the preceding steps failed, reject promise with a new
+ // DOMException whose name is the appropriate error name.
+ if (!drm_system->is_valid()) {
+ drm_system.reset();
+ promise->Reject(new DOMException(
+ DOMException::kNotSupportedErr,
+ "Failed to load and initialize the Key System implementation."));
+ return promise;
+ }
+
// 2.10. Let media keys be a new MediaKeys object.
+ // 2.10.5. Let the cdm instance value be instance.
scoped_refptr<MediaKeys> media_keys(
- new MediaKeys(key_system_, script_value_factory_));
+ new MediaKeys(drm_system, script_value_factory_));
// 2.11. Resolve promise with media keys.
promise->Resolve(media_keys);
diff --git a/src/cobalt/dom/eme/media_keys.cc b/src/cobalt/dom/eme/media_keys.cc
index 2d46e09..b7c94d6 100644
--- a/src/cobalt/dom/eme/media_keys.cc
+++ b/src/cobalt/dom/eme/media_keys.cc
@@ -23,10 +23,11 @@
namespace dom {
namespace eme {
-MediaKeys::MediaKeys(const std::string& key_system,
+MediaKeys::MediaKeys(const scoped_refptr<media::DrmSystem>& drm_system,
script::ScriptValueFactory* script_value_factory)
- : script_value_factory_(script_value_factory),
- drm_system_(new media::DrmSystem(key_system.c_str())) {}
+ : script_value_factory_(script_value_factory), drm_system_(drm_system) {
+ SB_DCHECK(drm_system_->is_valid()) << "DrmSystem provided on initialization is invalid.";
+}
// See https://www.w3.org/TR/encrypted-media/#dom-mediakeys-createsession.
scoped_refptr<MediaKeySession> MediaKeys::CreateSession(
diff --git a/src/cobalt/dom/eme/media_keys.h b/src/cobalt/dom/eme/media_keys.h
index 1c5fd52..d276af7 100644
--- a/src/cobalt/dom/eme/media_keys.h
+++ b/src/cobalt/dom/eme/media_keys.h
@@ -42,7 +42,7 @@
typedef script::Handle<script::Promise<bool>> BoolPromiseHandle;
typedef script::ScriptValue<script::Promise<bool>> BoolPromiseValue;
- MediaKeys(const std::string& key_system,
+ MediaKeys(const scoped_refptr<media::DrmSystem>& drm_system,
script::ScriptValueFactory* script_value_factory);
scoped_refptr<media::DrmSystem> drm_system() const { return drm_system_; }
diff --git a/src/cobalt/layout/layout.gyp b/src/cobalt/layout/layout.gyp
index 884553b..bef1686 100644
--- a/src/cobalt/layout/layout.gyp
+++ b/src/cobalt/layout/layout.gyp
@@ -14,6 +14,7 @@
{
'variables': {
+ 'optimize_target_for_speed': 1,
'sb_pedantic_warnings': 1,
},
'targets': [
diff --git a/src/cobalt/loader/loader.gyp b/src/cobalt/loader/loader.gyp
index 2465d3a..912678a 100644
--- a/src/cobalt/loader/loader.gyp
+++ b/src/cobalt/loader/loader.gyp
@@ -14,6 +14,7 @@
{
'variables': {
+ 'optimize_target_for_speed': 1,
'sb_pedantic_warnings': 1,
},
'targets': [
diff --git a/src/cobalt/media/base/drm_system.cc b/src/cobalt/media/base/drm_system.cc
index 3e46a77..ab0cedd 100644
--- a/src/cobalt/media/base/drm_system.cc
+++ b/src/cobalt/media/base/drm_system.cc
@@ -102,7 +102,9 @@
message_loop_(base::MessageLoop::current()->task_runner()),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
weak_this_(weak_ptr_factory_.GetWeakPtr()) {
- DCHECK_NE(kSbDrmSystemInvalid, wrapped_drm_system_);
+ if (!is_valid()) {
+ SB_LOG(ERROR) << "Failed to initialize the underlying wrapped DrmSystem.";
+ }
}
DrmSystem::~DrmSystem() { SbDrmDestroySystem(wrapped_drm_system_); }
diff --git a/src/cobalt/media/base/drm_system.h b/src/cobalt/media/base/drm_system.h
index 819d9c9..d4290f8 100644
--- a/src/cobalt/media/base/drm_system.h
+++ b/src/cobalt/media/base/drm_system.h
@@ -142,6 +142,8 @@
SbDrmSystem wrapped_drm_system() { return wrapped_drm_system_; }
+ bool is_valid() const { return SbDrmSystemIsValid(wrapped_drm_system_); }
+
std::unique_ptr<Session> CreateSession(
SessionUpdateKeyStatusesCallback session_update_key_statuses_callback
#if SB_HAS(DRM_SESSION_CLOSED)
diff --git a/src/cobalt/media/media.gyp b/src/cobalt/media/media.gyp
index 820b34d..7cd8793 100644
--- a/src/cobalt/media/media.gyp
+++ b/src/cobalt/media/media.gyp
@@ -3,6 +3,9 @@
# found in the LICENSE file.
{
+ 'variables': {
+ 'optimize_target_for_speed': 1,
+ },
'targets': [
{
'target_name': 'media',
diff --git a/src/cobalt/network/url_request_context.h b/src/cobalt/network/url_request_context.h
index 56852a9..dfa77fb 100644
--- a/src/cobalt/network/url_request_context.h
+++ b/src/cobalt/network/url_request_context.h
@@ -17,6 +17,7 @@
#include <string>
+#include "base/macros.h"
#include "net/cookies/cookie_monster.h"
#include "net/log/net_log.h"
#include "net/url_request/url_request_context.h"
diff --git a/src/cobalt/render_tree/render_tree.gyp b/src/cobalt/render_tree/render_tree.gyp
index 31fba5d..c7c0ec9 100644
--- a/src/cobalt/render_tree/render_tree.gyp
+++ b/src/cobalt/render_tree/render_tree.gyp
@@ -14,6 +14,7 @@
{
'variables': {
+ 'optimize_target_for_speed': 1,
'sb_pedantic_warnings': 1,
},
diff --git a/src/cobalt/renderer/rasterizer/rasterizer.gyp b/src/cobalt/renderer/rasterizer/rasterizer.gyp
index 78ff2dc..03c32ea 100644
--- a/src/cobalt/renderer/rasterizer/rasterizer.gyp
+++ b/src/cobalt/renderer/rasterizer/rasterizer.gyp
@@ -13,6 +13,9 @@
# limitations under the License.
{
+ 'variables': {
+ 'optimize_target_for_speed': 1,
+ },
'targets': [
{
'target_name': 'rasterizer',
diff --git a/src/cobalt/renderer/rasterizer/skia/skia/skia.gyp b/src/cobalt/renderer/rasterizer/skia/skia/skia.gyp
index 091f7bd..8dd1a1e 100644
--- a/src/cobalt/renderer/rasterizer/skia/skia/skia.gyp
+++ b/src/cobalt/renderer/rasterizer/skia/skia/skia.gyp
@@ -3,6 +3,9 @@
# found in the LICENSE file.
{
+ 'variables': {
+ 'optimize_target_for_speed': 1,
+ },
'targets': [
{
# This is the target that all Cobalt modules should depend on if they
diff --git a/src/cobalt/renderer/renderer.gyp b/src/cobalt/renderer/renderer.gyp
index d45ce2f..89d6804 100644
--- a/src/cobalt/renderer/renderer.gyp
+++ b/src/cobalt/renderer/renderer.gyp
@@ -13,6 +13,9 @@
# limitations under the License.
{
+ 'variables': {
+ 'optimize_target_for_speed': 1,
+ },
'targets': [
{
# This target conveniently aggregates all sub-modules required to declare
diff --git a/src/cobalt/renderer/test/png_utils/png_utils.gyp b/src/cobalt/renderer/test/png_utils/png_utils.gyp
index e5334f0..dbea190 100644
--- a/src/cobalt/renderer/test/png_utils/png_utils.gyp
+++ b/src/cobalt/renderer/test/png_utils/png_utils.gyp
@@ -13,6 +13,9 @@
# limitations under the License.
{
+ 'variables': {
+ 'optimize_target_for_speed': 1,
+ },
'targets': [
{
# This target provides (not production suitable) utility code for decoding
diff --git a/src/nb/analytics/memory_tracker_impl.cc b/src/nb/analytics/memory_tracker_impl.cc
index edc7c8b..58eab36 100644
--- a/src/nb/analytics/memory_tracker_impl.cc
+++ b/src/nb/analytics/memory_tracker_impl.cc
@@ -38,7 +38,7 @@
// This class allows std containers to bypass memory reporting.
template <typename T>
class RawAllocator : public std::allocator<T> {
-public:
+ public:
typedef typename std::allocator<T>::pointer pointer;
typedef typename std::allocator<T>::const_pointer const_pointer;
typedef typename std::allocator<T>::reference reference;
@@ -54,7 +54,7 @@
RawAllocator(const RawAllocator<U>& x) {}
pointer allocate(size_type n,
- std::allocator<void>::const_pointer hint = NULL) {
+ std::allocator<void>::const_pointer hint = NULL) {
void* ptr = SbMemoryAllocateNoReport(n * sizeof(value_type));
return static_cast<pointer>(ptr);
}
@@ -89,7 +89,6 @@
return false;
}
return entry.Value();
-
}
private:
@@ -101,15 +100,12 @@
using VectorPair = std::vector<PairType, RawAllocator<PairType>>;
// The InnerMap is backed by the vector. The FlatMap transforms the vector
// into a map interface.
- using InnerMap = starboard::FlatMap<SbThreadId, bool,
- std::less<SbThreadId>,
- VectorPair>;
+ using InnerMap =
+ starboard::FlatMap<SbThreadId, bool, std::less<SbThreadId>, VectorPair>;
// Concurrent map uses distributed locking to achieve a highly concurrent
// unsorted map.
- using ThreadMap = ConcurrentMap<SbThreadId,
- bool,
- std::hash<SbThreadId>,
- InnerMap>;
+ using ThreadMap =
+ ConcurrentMap<SbThreadId, bool, std::hash<SbThreadId>, InnerMap>;
ThreadMap thread_map_;
};
@@ -147,8 +143,7 @@
AllocationGroup* MemoryTrackerImpl::PeekAllocationGroup() {
DisableMemoryTrackingInScope no_tracking(this);
- AllocationGroup* out =
- allocation_group_stack_tls_.GetOrCreate()->Peek();
+ AllocationGroup* out = allocation_group_stack_tls_.GetOrCreate()->Peek();
if (out == NULL) {
out = alloc_group_map_.GetDefaultUnaccounted();
}
@@ -157,7 +152,10 @@
void MemoryTrackerImpl::PopAllocationGroup() {
DisableMemoryTrackingInScope no_tracking(this);
- AllocationGroupStack* alloc_tls = allocation_group_stack_tls_.GetOrCreate();
+ AllocationGroupStack* alloc_tls = allocation_group_stack_tls_.GetIfExists();
+ if (!alloc_tls) {
+ return;
+ }
alloc_tls->Pop();
AllocationGroup* group = alloc_tls->Peek();
// We don't allow null, so if this is encountered then push the
@@ -286,8 +284,7 @@
NbMemoryScopeReporter* memory_scope_reporter) {
SbMemoryReporter mem_reporter = {
MemoryTrackerImpl::OnMalloc, MemoryTrackerImpl::OnDealloc,
- MemoryTrackerImpl::OnMapMem, MemoryTrackerImpl::OnUnMapMem,
- this};
+ MemoryTrackerImpl::OnMapMem, MemoryTrackerImpl::OnUnMapMem, this};
NbMemoryScopeReporter mem_scope_reporter = {
MemoryTrackerImpl::OnPushAllocationGroup,
@@ -363,8 +360,7 @@
// End all memory tracking in subsequent data structures.
DisableMemoryTrackingInScope no_memory_tracking(this);
- AllocationGroupStack* alloc_stack =
- allocation_group_stack_tls_.GetOrCreate();
+ AllocationGroupStack* alloc_stack = allocation_group_stack_tls_.GetOrCreate();
AllocationGroup* group = alloc_stack->Peek();
if (!group) {
group = alloc_group_map_.GetDefaultUnaccounted();
diff --git a/src/starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java b/src/starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java
index bee6e6d..49b37c0 100644
--- a/src/starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java
+++ b/src/starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java
@@ -421,9 +421,10 @@
String title,
String artist,
String album,
- MediaImage[] artwork) {
+ MediaImage[] artwork,
+ long duration) {
cobaltMediaSession.updateMediaSession(
- playbackState, actions, positionMs, speed, title, artist, album, artwork);
+ playbackState, actions, positionMs, speed, title, artist, album, artwork, duration);
}
/** Returns string for kSbSystemPropertyUserAgentAuxField */
diff --git a/src/starboard/android/apk/app/src/main/java/dev/cobalt/media/CobaltMediaSession.java b/src/starboard/android/apk/app/src/main/java/dev/cobalt/media/CobaltMediaSession.java
index a0e687b..fcc31b1 100644
--- a/src/starboard/android/apk/app/src/main/java/dev/cobalt/media/CobaltMediaSession.java
+++ b/src/starboard/android/apk/app/src/main/java/dev/cobalt/media/CobaltMediaSession.java
@@ -359,13 +359,14 @@
final String title,
final String artist,
final String album,
- final MediaImage[] artwork) {
+ final MediaImage[] artwork,
+ final long duration) {
mainHandler.post(
new Runnable() {
@Override
public void run() {
updateMediaSessionInternal(
- playbackState, actions, positionMs, speed, title, artist, album, artwork);
+ playbackState, actions, positionMs, speed, title, artist, album, artwork, duration);
}
});
}
@@ -379,7 +380,8 @@
String title,
String artist,
String album,
- MediaImage[] artwork) {
+ MediaImage[] artwork,
+ final long duration) {
checkMainLooperThread();
// Always keep track of what the HTML5 app thinks the playback state is so we can configure the
@@ -420,7 +422,8 @@
Log.i(
TAG,
String.format(
- "MediaSession state: %s, position: %d ms, speed: %f x", stateName, positionMs, speed));
+ "MediaSession state: %s, position: %d ms, speed: %f x, duration: %d ms",
+ stateName, positionMs, speed, duration));
playbackStateBuilder =
new PlaybackStateCompat.Builder()
@@ -435,7 +438,8 @@
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist)
.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, album)
.putBitmap(
- MediaMetadataCompat.METADATA_KEY_ALBUM_ART, artworkLoader.getOrLoadArtwork(artwork));
+ MediaMetadataCompat.METADATA_KEY_ALBUM_ART, artworkLoader.getOrLoadArtwork(artwork))
+ .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration);
// Update the metadata as soon as we can - even before artwork is loaded.
mediaSession.setMetadata(metadataBuilder.build());
}
diff --git a/src/starboard/android/apk/build.id b/src/starboard/android/apk/build.id
deleted file mode 100644
index 4c97ae0..0000000
--- a/src/starboard/android/apk/build.id
+++ /dev/null
@@ -1 +0,0 @@
-220597
\ No newline at end of file
diff --git a/src/starboard/android/shared/cobalt/android_media_session_client.cc b/src/starboard/android/shared/cobalt/android_media_session_client.cc
index 0b4b5c1..1861af9 100644
--- a/src/starboard/android/shared/cobalt/android_media_session_client.cc
+++ b/src/starboard/android/shared/cobalt/android_media_session_client.cc
@@ -289,14 +289,23 @@
}
}
+ jlong duration = session_state.duration();
+ // Set duration to negative if duration is unknown or infinite, as with live
+ // playback.
+ // https://developer.android.com/reference/android/support/v4/media/MediaMetadataCompat#METADATA_KEY_DURATION
+ if (duration == kSbTimeMax) {
+ duration = -1;
+ }
+
env->CallStarboardVoidMethodOrAbort(
"updateMediaSession",
"(IJJFLjava/lang/String;Ljava/lang/String;Ljava/lang/String;"
- "[Ldev/cobalt/media/MediaImage;)V",
+ "[Ldev/cobalt/media/MediaImage;J)V",
playback_state, playback_state_actions,
session_state.current_playback_position() / kSbTimeMillisecond,
static_cast<jfloat>(session_state.actual_playback_rate()),
- j_title.Get(), j_artist.Get(), j_album.Get(), j_artwork.Get());
+ j_title.Get(), j_artist.Get(), j_album.Get(), j_artwork.Get(),
+ duration);
}
};
diff --git a/src/starboard/build/base_configuration.gypi b/src/starboard/build/base_configuration.gypi
index a1c2a1d..1d405d5 100644
--- a/src/starboard/build/base_configuration.gypi
+++ b/src/starboard/build/base_configuration.gypi
@@ -118,6 +118,10 @@
# Used to indicate that the player is filter based.
'sb_filter_based_player%': 1,
+ # This variable dictates whether a given gyp target should be compiled with
+ # optimization flags for size vs. speed.
+ 'optimize_target_for_speed%': 0,
+
# Compiler configuration.
# The following variables are used to specify compiler and linker
@@ -142,15 +146,35 @@
'linker_flags_devel%': [],
'defines_devel%': [],
+ # For qa and gold configs, different compiler flags may be specified for
+ # gyp targets that should be built for size than for speed. Targets which
+ # specify 'optimize_target_for_speed == 1', will compile with flags:
+ # ['compiler_flags_*<config>', 'compiler_flags_*<config>_speed'].
+ # Otherwise, targets will use compiler flags:
+ # ['compiler_flags_*<config>', 'compiler_flags_*<config>_size'].
+ # Platforms may decide to use the same optimization flags for both
+ # target types by leaving the '*_size' and '*_speed' variables empty.
'compiler_flags_qa%': [],
+ 'compiler_flags_qa_size%': [],
+ 'compiler_flags_qa_speed%': [],
'compiler_flags_c_qa%': [],
+ 'compiler_flags_c_qa_size%': [],
+ 'compiler_flags_c_qa_speed%': [],
'compiler_flags_cc_qa%': [],
+ 'compiler_flags_cc_qa_size%': [],
+ 'compiler_flags_cc_qa_speed%': [],
'linker_flags_qa%': [],
'defines_qa%': [],
'compiler_flags_gold%': [],
+ 'compiler_flags_gold_size%': [],
+ 'compiler_flags_gold_speed%': [],
'compiler_flags_c_gold%': [],
+ 'compiler_flags_c_gold_size%': [],
+ 'compiler_flags_c_gold_speed%': [],
'compiler_flags_cc_gold%': [],
+ 'compiler_flags_cc_gold_size%': [],
+ 'compiler_flags_cc_gold_speed%': [],
'linker_flags_gold%': [],
'defines_gold%': [],
@@ -208,6 +232,11 @@
# value it has during early variable expansion. That's enough to make
# it available during target conditional processing.
'sb_pedantic_warnings%': '<(sb_pedantic_warnings)',
+
+ # This workaround is used to surface the default setting for the variable
+ # 'optimize_target_for_speed' if the gyp target does not explicitly set
+ # it.
+ 'optimize_target_for_speed%': '<(optimize_target_for_speed)',
},
'cflags': [ '<@(compiler_flags)' ],
'ldflags': [ '<@(linker_flags)' ],
@@ -286,9 +315,35 @@
'qa_base': {
'abstract': 1,
# optimize:
- 'cflags': [ '<@(compiler_flags_qa)' ],
- 'cflags_c': [ '<@(compiler_flags_c_qa)' ],
- 'cflags_cc': [ '<@(compiler_flags_cc_qa)' ],
+ 'target_conditions': [
+ ['optimize_target_for_speed==1', {
+ 'cflags': [
+ '<@(compiler_flags_qa)',
+ '<@(compiler_flags_qa_speed)',
+ ],
+ 'cflags_c': [
+ '<@(compiler_flags_c_qa)',
+ '<@(compiler_flags_c_qa_speed)',
+ ],
+ 'cflags_cc': [
+ '<@(compiler_flags_cc_qa)',
+ '<@(compiler_flags_cc_qa_speed)',
+ ],
+ }, {
+ 'cflags': [
+ '<@(compiler_flags_qa)',
+ '<@(compiler_flags_qa_size)',
+ ],
+ 'cflags_c': [
+ '<@(compiler_flags_c_qa)',
+ '<@(compiler_flags_c_qa_size)',
+ ],
+ 'cflags_cc': [
+ '<@(compiler_flags_cc_qa)',
+ '<@(compiler_flags_cc_qa_size)',
+ ],
+ }]
+ ],
'ldflags': [ '<@(linker_flags_qa)' ],
'defines': [
'<@(defines_qa)',
@@ -299,9 +354,35 @@
'gold_base': {
'abstract': 1,
# optimize:
- 'cflags': [ '<@(compiler_flags_gold)' ],
- 'cflags_c': [ '<@(compiler_flags_c_gold)' ],
- 'cflags_cc': [ '<@(compiler_flags_cc_gold)' ],
+ 'target_conditions': [
+ ['optimize_target_for_speed==1', {
+ 'cflags': [
+ '<@(compiler_flags_gold)',
+ '<@(compiler_flags_gold_speed)',
+ ],
+ 'cflags_c': [
+ '<@(compiler_flags_c_gold)',
+ '<@(compiler_flags_c_gold_speed)',
+ ],
+ 'cflags_cc': [
+ '<@(compiler_flags_cc_gold)',
+ '<@(compiler_flags_cc_gold_speed)',
+ ],
+ }, {
+ 'cflags': [
+ '<@(compiler_flags_gold)',
+ '<@(compiler_flags_gold_size)',
+ ],
+ 'cflags_c': [
+ '<@(compiler_flags_c_gold)',
+ '<@(compiler_flags_c_gold_size)',
+ ],
+ 'cflags_cc': [
+ '<@(compiler_flags_cc_gold)',
+ '<@(compiler_flags_cc_gold_size)',
+ ],
+ }]
+ ],
'ldflags': [ '<@(linker_flags_gold)' ],
'defines': [
'<@(defines_gold)',
diff --git a/src/starboard/raspi/0/gyp_configuration.py b/src/starboard/raspi/0/gyp_configuration.py
index b247085..72f4437 100644
--- a/src/starboard/raspi/0/gyp_configuration.py
+++ b/src/starboard/raspi/0/gyp_configuration.py
@@ -44,8 +44,8 @@
# Temporarily disable most of the tests until we can narrow it down to the
# minimum number of cases that are real test failures.
'player_filter_tests': [
- 'AudioDecoderTest.*',
- ],
+ 'VideoDecoderTests/VideoDecoderTest.DecodeFullGOP/0'
+ ]
}
diff --git a/src/starboard/shared/starboard/player/filter/testing/audio_decoder_test.cc b/src/starboard/shared/starboard/player/filter/testing/audio_decoder_test.cc
index 737c399..4f348d8 100644
--- a/src/starboard/shared/starboard/player/filter/testing/audio_decoder_test.cc
+++ b/src/starboard/shared/starboard/player/filter/testing/audio_decoder_test.cc
@@ -179,11 +179,15 @@
*decoded_audio = local_decoded_audio;
return;
}
- if (last_decoded_audio_) {
+ // TODO: Adaptive audio decoder outputs may don't have timestamp info.
+ // Currently, we skip timestamp check if the outputs don't have timestamp
+ // info. Enable it after we fix timestamp issues.
+ if (local_decoded_audio->timestamp() && last_decoded_audio_) {
ASSERT_LT(last_decoded_audio_->timestamp(),
local_decoded_audio->timestamp());
}
last_decoded_audio_ = local_decoded_audio;
+ num_of_output_frames_ += last_decoded_audio_->frames();
*decoded_audio = local_decoded_audio;
}
@@ -356,6 +360,15 @@
output_samples_per_second <= 480000);
}
+ void AssertExpectedAndOutputFramesMatch(int expected_output_frames) {
+ if (using_stub_decoder_) {
+ // The number of output frames is not applicable in the case of the
+ // StubAudioDecoder, because it is not actually doing any decoding work.
+ return;
+ }
+ ASSERT_LE(abs(expected_output_frames - num_of_output_frames_), 1);
+ }
+
Mutex event_queue_mutex_;
std::deque<Event> event_queue_;
@@ -378,6 +391,8 @@
bool eos_written_ = false;
std::map<size_t, uint8_t> invalid_inputs_;
+
+ int num_of_output_frames_ = 0;
};
TEST_P(AudioDecoderTest, ThreeMoreDecoders) {
@@ -423,12 +438,14 @@
ASSERT_NO_FATAL_FAILURE(DrainOutputs());
ASSERT_TRUE(last_decoded_audio_);
ASSERT_NO_FATAL_FAILURE(AssertInvalidOutputFormat());
- if (last_decoded_audio_->frames() == kAacFrameSize) {
- return;
- }
- auto sample_info = dmp_reader_.audio_sample_info();
- ASSERT_EQ(sample_info.samples_per_second * 2,
- audio_decoder_->GetSamplesPerSecond());
+
+ int input_sample_rate =
+ last_input_buffer_->audio_sample_info().samples_per_second;
+ int output_sample_rate = audio_decoder_->GetSamplesPerSecond();
+ ASSERT_NE(0, output_sample_rate);
+ int expected_output_frames =
+ kAacFrameSize * output_sample_rate / input_sample_rate;
+ AssertExpectedAndOutputFramesMatch(expected_output_frames);
}
TEST_P(AudioDecoderTest, SingleInvalidInput) {
diff --git a/src/starboard/shared/widevine/widevine3.gyp b/src/starboard/shared/widevine/widevine3.gyp
index 70ffb64..3575419 100644
--- a/src/starboard/shared/widevine/widevine3.gyp
+++ b/src/starboard/shared/widevine/widevine3.gyp
@@ -20,6 +20,7 @@
],
'variables': {
'oemcrypto_target': 'oemcrypto',
+ 'optimize_target_for_speed': 1,
# Use the protoc supplied in src/tools as precompiled executable.
'protoc_dir': '<(DEPTH)/tools',
diff --git a/src/third_party/boringssl/boringssl.gyp b/src/third_party/boringssl/boringssl.gyp
index 692b6c7..abc2afe 100644
--- a/src/third_party/boringssl/boringssl.gyp
+++ b/src/third_party/boringssl/boringssl.gyp
@@ -3,6 +3,7 @@
'variables': {
'asm_target_arch%': '<(target_arch)',
'boringssl_root%': '<(DEPTH)/third_party/boringssl/src',
+ 'optimize_target_for_speed': 1,
},
'target_defaults': {
@@ -278,8 +279,8 @@
# For |target_os=="win"| an ASM rule uses ml.exe (aka MS Macro Assembler)
# which we can't use with GNU format. As soon as ASM rule will be fixed
- # for using GNU Assembler, to accelerate "crypto" with assembler
- # implementations just remove target_os=="win" from abowe condition
+ # for using GNU Assembler, to accelerate "crypto" with assembler
+ # implementations just remove target_os=="win" from abowe condition
# |'asm_target_arch=="none" or target_os=="win"'| which currently
# sets OPENSSL_NO_ASM for "win" too
diff --git a/src/third_party/dlmalloc/dlmalloc.gyp b/src/third_party/dlmalloc/dlmalloc.gyp
index 64c0743..ac5b394 100644
--- a/src/third_party/dlmalloc/dlmalloc.gyp
+++ b/src/third_party/dlmalloc/dlmalloc.gyp
@@ -3,6 +3,9 @@
# found in the LICENSE file.
{
+ 'variables': {
+ 'optimize_target_for_speed': 1,
+ },
'targets': [
{
'target_name': 'dlmalloc',
diff --git a/src/third_party/icu/README.cobalt b/src/third_party/icu/README.cobalt
index cf85b3f..67ee1c1 100644
--- a/src/third_party/icu/README.cobalt
+++ b/src/third_party/icu/README.cobalt
@@ -99,4 +99,4 @@
Note that at the time of this writing, the final resulting contents had a size
of 6.9MB, from running the command
-`du -sh $COBALT_SRC_ROOT/src/cobalt/content/icu/icudt56l`.
+`du -sh $COBALT_SRC_ROOT/src/cobalt/content/icu/icudt56l`.
\ No newline at end of file
diff --git a/src/third_party/libjpeg-turbo/libjpeg.gyp b/src/third_party/libjpeg-turbo/libjpeg.gyp
index 17cdb1f..7225beb 100644
--- a/src/third_party/libjpeg-turbo/libjpeg.gyp
+++ b/src/third_party/libjpeg-turbo/libjpeg.gyp
@@ -3,6 +3,9 @@
# found in the LICENSE file.
{
+ 'variables': {
+ 'optimize_target_for_speed': 1,
+ },
'targets': [
{
'target_name': 'libjpeg',
diff --git a/src/third_party/libjpeg/libjpeg.gyp b/src/third_party/libjpeg/libjpeg.gyp
index 604782c..4907052 100644
--- a/src/third_party/libjpeg/libjpeg.gyp
+++ b/src/third_party/libjpeg/libjpeg.gyp
@@ -5,6 +5,9 @@
{
# This file handles building both with our local libjpeg and with the system
# libjpeg.
+ 'variables': {
+ 'optimize_target_for_speed': 1,
+ },
'conditions': [
['use_system_libjpeg==0', {
'targets': [
diff --git a/src/third_party/libpng/libpng.gyp b/src/third_party/libpng/libpng.gyp
index e2bf5b7..8cc5624 100644
--- a/src/third_party/libpng/libpng.gyp
+++ b/src/third_party/libpng/libpng.gyp
@@ -4,6 +4,7 @@
{
'variables': {
+ 'optimize_target_for_speed': 1,
'conditions': [
[ 'os_posix == 1 and OS != "mac" and OS != "android"', {
# Maybe link to system .so once the security concerns are thought
@@ -87,7 +88,7 @@
'defines': [
'PNG_USE_DLL',
],
- },
+ },
}],
['OS=="android"', {
'toolsets': ['target', 'host'],
diff --git a/src/third_party/libwebp/libwebp.gyp b/src/third_party/libwebp/libwebp.gyp
index 26b8d6d..9c77f08 100644
--- a/src/third_party/libwebp/libwebp.gyp
+++ b/src/third_party/libwebp/libwebp.gyp
@@ -2,6 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
{
+ 'variables': {
+ 'optimize_target_for_speed': 1,
+ },
'includes': [
'libwebp.gypi'
],
diff --git a/src/third_party/zlib/zlib.gyp b/src/third_party/zlib/zlib.gyp
index 1b373ca..1136faa 100644
--- a/src/third_party/zlib/zlib.gyp
+++ b/src/third_party/zlib/zlib.gyp
@@ -4,6 +4,7 @@
{
'variables': {
+ 'optimize_target_for_speed': 1,
'conditions': [
[ 'OS == "none"', {
# Because we have a patched zlib, we cannot use the system libz.
diff --git a/src/v8/src/v8.gyp b/src/v8/src/v8.gyp
index b40af6c..2209b6d 100644
--- a/src/v8/src/v8.gyp
+++ b/src/v8/src/v8.gyp
@@ -27,6 +27,7 @@
{
'variables': {
+ 'optimize_target_for_speed': 1,
'v8_code': 1,
'v8_random_seed%': 314159265,
'v8_vector_stores%': 0,
@@ -2739,4 +2740,4 @@
],
},
],
-}
\ No newline at end of file
+}