Commit 5ce784de authored by Ted Meyer's avatar Ted Meyer Committed by Commit Bot

Create MediaLogMessages and MediaLogEvents

Share some of the helper macros from MediaLogProperties with these two
new types in the media_log_type_enforcement.h file, which replaces
media_log_properties_helper.h

Bug: 794255
Change-Id: I7c709c5ac881b3bf03ba327d850e0c58824cec57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2006130
Commit-Queue: Ted Meyer <tmathmeyer@chromium.org>
Reviewed-by: default avatarFrank Liberato <liberato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732672}
parent 38d493f7
...@@ -179,10 +179,14 @@ jumbo_source_set("base") { ...@@ -179,10 +179,14 @@ jumbo_source_set("base") {
"media_export.h", "media_export.h",
"media_log.cc", "media_log.cc",
"media_log.h", "media_log.h",
"media_log_events.cc",
"media_log_events.h",
"media_log_message_levels.cc",
"media_log_message_levels.h",
"media_log_properties.cc", "media_log_properties.cc",
"media_log_properties.h", "media_log_properties.h",
"media_log_properties_helper.h",
"media_log_record.h", "media_log_record.h",
"media_log_type_enforcement.h",
"media_observer.cc", "media_observer.cc",
"media_observer.h", "media_observer.h",
"media_permission.cc", "media_permission.cc",
......
// Copyright 2019 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 "media/base/media_log_events.h"
#include <string>
#include "base/logging.h"
namespace media {
std::string MediaLogEventToString(MediaLogEvent level) {
switch (level) {
case MediaLogEvent::kPlay:
return "PLAY";
case MediaLogEvent::kPause:
return "PAUSE";
case MediaLogEvent::kSeek:
return "SEEK";
case MediaLogEvent::kPipelineStateChange:
return "PIPELINE_STATE_CHANGED";
case MediaLogEvent::kWebMediaPlayerCreated:
return "WEBMEDIAPLAYER_CREATED";
case MediaLogEvent::kWebMediaPlayerDestroyed:
return "WEBMEDIAPLAYER_DESTROYED";
case MediaLogEvent::kLoad:
return "LOAD";
case MediaLogEvent::kVideoSizeChanged:
return "VIDEO_SIZE_SET";
case MediaLogEvent::kDurationChanged:
return "DURATION_SET";
case MediaLogEvent::kEnded:
return "ENDED";
case MediaLogEvent::kBufferingStateChanged:
return "BUFFERING_STATE_CHANGE";
case MediaLogEvent::kSuspended:
return "SUSPENDED";
}
NOTREACHED();
return "";
}
} // namespace media
\ No newline at end of file
// Copyright 2019 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.
#ifndef MEDIA_BASE_MEDIA_LOG_EVENTS_H_
#define MEDIA_BASE_MEDIA_LOG_EVENTS_H_
#include <string>
#include "media/base/media_export.h"
#include "media/base/media_log_type_enforcement.h"
#include "ui/gfx/geometry/size.h"
namespace media {
enum class MediaLogEvent {
// The media player has started playing.
kPlay,
// The media player has entered a paused state.
kPause,
// The media player has _started_ a seek operation.
kSeek,
// The pipeline state has changed - see PipelineStatus in
// media/base/pipeline_status.h
kPipelineStateChange,
// The media stack implementation of the blink media player has been created
// but may not be fully initialized.
kWebMediaPlayerCreated,
// The media player has been destroyed and the log will soon die. No events
// can come after receiving this one.
kWebMediaPlayerDestroyed,
// A web request has finished and the pipeline will start iminently.
kLoad,
// The video size has changed.
// TODO(tmathmeyer) This is already a property, it might be useless to have it
// be an event too. consider removing it.
kVideoSizeChanged,
// The runtime of the video was changed by the demuxer.
kDurationChanged,
// There is no more content to consume.
kEnded,
// There was a change to the buffering state of the video. This can be caused
// by either network slowness or decoding slowness. See the comments in
// media/base/buffering_state.h for more information.
kBufferingStateChanged,
// The player has been suspended to save resources.
kSuspended,
};
// This has to be declared before the macros use it - Some infra code relies on
// the enum names to be UPPER_CASE, so this will convert them manually
// instead of using macro stringification.
MEDIA_EXPORT std::string MediaLogEventToString(MediaLogEvent level);
// These events can be triggered with no extra associated data.
MEDIA_LOG_EVENT_TYPELESS(kPlay);
MEDIA_LOG_EVENT_TYPELESS(kPause);
MEDIA_LOG_EVENT_TYPELESS(kWebMediaPlayerDestroyed);
MEDIA_LOG_EVENT_TYPELESS(kEnded);
MEDIA_LOG_EVENT_TYPELESS(kSuspended);
MEDIA_LOG_EVENT_TYPELESS(kWebMediaPlayerCreated);
// These events can be triggered with the extra data / names as defined here.
// Note that some events can be defined multiple times.
MEDIA_LOG_EVENT_NAMED_DATA(kLoad, std::string, "url");
MEDIA_LOG_EVENT_NAMED_DATA(kSeek, double, "seek_target");
MEDIA_LOG_EVENT_NAMED_DATA(kVideoSizeChanged, gfx::Size, "dimensions");
MEDIA_LOG_EVENT_NAMED_DATA(kDurationChanged, base::TimeDelta, "duration");
MEDIA_LOG_EVENT_NAMED_DATA(kWebMediaPlayerCreated, std::string, "origin_url");
MEDIA_LOG_EVENT_NAMED_DATA(kPipelineStateChange, std::string, "pipeline_state");
// Each type of buffering state gets a different name.
MEDIA_LOG_EVENT_NAMED_DATA(
kBufferingStateChanged,
SerializableBufferingState<SerializableBufferingStateType::kVideo>,
"video_buffering_state");
MEDIA_LOG_EVENT_NAMED_DATA(
kBufferingStateChanged,
SerializableBufferingState<SerializableBufferingStateType::kAudio>,
"audio_buffering_state");
MEDIA_LOG_EVENT_NAMED_DATA(
kBufferingStateChanged,
SerializableBufferingState<SerializableBufferingStateType::kPipeline>,
"pipeline_buffering_state");
} // namespace media
#endif // MEDIA_BASE_MEDIA_LOG_EVENTS_H_
// Copyright 2019 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 "media/base/media_log_message_levels.h"
#include <string>
#include "base/logging.h"
namespace media {
std::string MediaLogMessageLevelToString(MediaLogMessageLevel level) {
switch (level) {
case MediaLogMessageLevel::kERROR:
return "error";
case MediaLogMessageLevel::kWARNING:
return "warning";
case MediaLogMessageLevel::kINFO:
return "info";
case MediaLogMessageLevel::kDEBUG:
return "debug";
}
NOTREACHED();
return "";
}
} // namespace media
\ No newline at end of file
// Copyright 2019 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.
#ifndef MEDIA_BASE_MEDIA_LOG_MESSAGE_LEVELS_H_
#define MEDIA_BASE_MEDIA_LOG_MESSAGE_LEVELS_H_
#include <string>
#include "media/base/media_export.h"
namespace media {
// TODO(tmathmeyer) Find a nice way to make this use the kCamelCase style, while
// still preserving the "MEDIA_LOG(ERROR, ...)" syntax. macros are bad :(
enum class MediaLogMessageLevel {
kERROR,
kWARNING,
kINFO,
kDEBUG,
};
MEDIA_EXPORT std::string MediaLogMessageLevelToString(
MediaLogMessageLevel level);
} // namespace media
#endif // MEDIA_BASE_MEDIA_LOG_MESSAGE_LEVELS_H_
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "media/base/audio_decoder_config.h" #include "media/base/audio_decoder_config.h"
#include "media/base/media_export.h" #include "media/base/media_export.h"
#include "media/base/media_log_properties_helper.h" #include "media/base/media_log_type_enforcement.h"
#include "media/base/video_decoder_config.h" #include "media/base/video_decoder_config.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
......
...@@ -2,25 +2,31 @@ ...@@ -2,25 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef MEDIA_BASE_MEDIA_LOG_PROPERTIES_HELPER_H_ #ifndef MEDIA_BASE_MEDIA_LOG_TYPE_ENFORCEMENT_H_
#define MEDIA_BASE_MEDIA_LOG_PROPERTIES_HELPER_H_ #define MEDIA_BASE_MEDIA_LOG_TYPE_ENFORCEMENT_H_
#include <string>
#include <vector>
#include "base/values.h"
#include "media/base/media_serializers.h" #include "media/base/media_serializers.h"
#include "ui/gfx/geometry/size.h"
namespace media { namespace media {
// Forward declare the enum. namespace internal {
enum class UnmatchableType {};
} // namespace internal
// Forward declare the enums.
enum class MediaLogProperty; enum class MediaLogProperty;
enum class MediaLogEvent;
// Allow only specific types for an individual property. // Allow only specific types for an individual property.
template <MediaLogProperty PROP, typename T> template <MediaLogProperty PROP, typename T>
struct MediaLogPropertyTypeSupport {}; struct MediaLogPropertyTypeSupport {};
// Allow only specific types for an individual event.
// However unlike Property, T is not required, so we default it to some
// unmatchable type that will never be passed as an argument accidentally.
template <MediaLogEvent EVENT, typename T = internal::UnmatchableType>
struct MediaLogEventTypeSupport {};
// Lets us define the supported type in a single line in media_log_properties.h. // Lets us define the supported type in a single line in media_log_properties.h.
#define MEDIA_LOG_PROPERTY_SUPPORTS_TYPE(PROPERTY, TYPE) \ #define MEDIA_LOG_PROPERTY_SUPPORTS_TYPE(PROPERTY, TYPE) \
template <> \ template <> \
...@@ -30,6 +36,24 @@ struct MediaLogPropertyTypeSupport {}; ...@@ -30,6 +36,24 @@ struct MediaLogPropertyTypeSupport {};
} \ } \
} }
#define MEDIA_LOG_EVENT_NAMED_DATA(EVENT, TYPE, DISPLAY) \
template <> \
struct MediaLogEventTypeSupport<MediaLogEvent::EVENT, TYPE> { \
static void AddExtraData(base::Value* params, const TYPE& t) { \
DCHECK(params); \
params->SetKey(DISPLAY, MediaSerialize<TYPE>(t)); \
} \
static std::string TypeName() { return #EVENT; } \
}
// Specifically do not create the Convert or DisplayName methods
#define MEDIA_LOG_EVENT_TYPELESS(EVENT) \
template <> \
struct MediaLogEventTypeSupport<MediaLogEvent::EVENT> { \
static std::string TypeName() { return #EVENT; } \
static void AddExtraData(base::Value* params) {} \
}
} // namespace media } // namespace media
#endif // MEDIA_BASE_MEDIA_LOG_PROPERTIES_HELPER_H_ #endif // MEDIA_BASE_MEDIA_LOG_TYPE_ENFORCEMENT_H_
\ No newline at end of file
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