Commit b4231423 authored by Ted Meyer's avatar Ted Meyer Committed by Commit Bot

Add BufferingState to Serializers file

This just helps out the next CL in line which adds the new types for
media log and needs to serialize some of the buffering state types.

Bug: 794255
Change-Id: Id83d79108edc0021316fc362a222eadab7d3f032
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2005818Reviewed-by: default avatarFrank Liberato <liberato@chromium.org>
Commit-Queue: Ted Meyer <tmathmeyer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732663}
parent f4914fbf
...@@ -85,6 +85,7 @@ jumbo_source_set("base") { ...@@ -85,6 +85,7 @@ jumbo_source_set("base") {
"bit_reader_core.h", "bit_reader_core.h",
"bitstream_buffer.cc", "bitstream_buffer.cc",
"bitstream_buffer.h", "bitstream_buffer.h",
"buffering_state.cc",
"buffering_state.h", "buffering_state.h",
"byte_queue.cc", "byte_queue.cc",
"byte_queue.h", "byte_queue.h",
......
// Copyright 2020 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/buffering_state.h"
#include <string>
#include "base/logging.h"
namespace media {
std::string BufferingStateToString(BufferingState state,
BufferingStateChangeReason reason) {
DCHECK(state == BUFFERING_HAVE_NOTHING || state == BUFFERING_HAVE_ENOUGH);
DCHECK(reason == BUFFERING_CHANGE_REASON_UNKNOWN ||
reason == DEMUXER_UNDERFLOW || reason == DECODER_UNDERFLOW ||
reason == REMOTING_NETWORK_CONGESTION);
std::string state_string = state == BUFFERING_HAVE_NOTHING
? "BUFFERING_HAVE_NOTHING"
: "BUFFERING_HAVE_ENOUGH";
std::vector<std::string> flag_strings;
if (reason == DEMUXER_UNDERFLOW)
state_string += " (DEMUXER_UNDERFLOW)";
else if (reason == DECODER_UNDERFLOW)
state_string += " (DECODER_UNDERFLOW)";
else if (reason == REMOTING_NETWORK_CONGESTION)
state_string += " (REMOTING_NETWORK_CONGESTION)";
return state_string;
}
} // namespace media
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef MEDIA_BASE_BUFFERING_STATE_H_ #ifndef MEDIA_BASE_BUFFERING_STATE_H_
#define MEDIA_BASE_BUFFERING_STATE_H_ #define MEDIA_BASE_BUFFERING_STATE_H_
#include <string>
#include "base/callback_forward.h" #include "base/callback_forward.h"
namespace media { namespace media {
...@@ -48,10 +50,29 @@ enum BufferingStateChangeReason { ...@@ -48,10 +50,29 @@ enum BufferingStateChangeReason {
BUFFERING_STATE_CHANGE_REASON_MAX = REMOTING_NETWORK_CONGESTION, BUFFERING_STATE_CHANGE_REASON_MAX = REMOTING_NETWORK_CONGESTION,
}; };
enum class SerializableBufferingStateType {
kPipeline,
kVideo,
kAudio,
};
// A serializable combo of the state, type, and reason.
template <SerializableBufferingStateType T>
struct SerializableBufferingState {
BufferingState state;
BufferingStateChangeReason reason;
// Only included in the serialized state if |type == kPipeline|
bool suspended_start = false;
};
// Used to indicate changes in buffering state; // Used to indicate changes in buffering state;
typedef base::Callback<void(BufferingState, BufferingStateChangeReason)> typedef base::Callback<void(BufferingState, BufferingStateChangeReason)>
BufferingStateCB; BufferingStateCB;
std::string BufferingStateToString(
BufferingState state,
BufferingStateChangeReason reason = BUFFERING_CHANGE_REASON_UNKNOWN);
} // namespace media } // namespace media
#endif // MEDIA_BASE_BUFFERING_STATE_H_ #endif // MEDIA_BASE_BUFFERING_STATE_H_
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "media/base/audio_decoder_config.h" #include "media/base/audio_decoder_config.h"
#include "media/base/buffering_state.h"
#include "media/base/media_serializers_base.h" #include "media/base/media_serializers_base.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"
...@@ -118,6 +119,14 @@ struct MediaSerializer<gfx::Rect> { ...@@ -118,6 +119,14 @@ struct MediaSerializer<gfx::Rect> {
} }
}; };
// enum (simple)
template <>
struct MediaSerializer<base::TimeDelta> {
static inline base::Value Serialize(const base::TimeDelta value) {
return MediaSerializer<double>::Serialize(value.InSecondsF());
}
};
// Enum (simple) // Enum (simple)
template <> template <>
struct MediaSerializer<media::AudioCodec> { struct MediaSerializer<media::AudioCodec> {
...@@ -272,6 +281,60 @@ struct MediaSerializer<media::VideoDecoderConfig> { ...@@ -272,6 +281,60 @@ struct MediaSerializer<media::VideoDecoderConfig> {
} }
}; };
// enum (simple)
template <>
struct MediaSerializer<media::BufferingState> {
static inline base::Value Serialize(const media::BufferingState value) {
return base::Value(value == media::BufferingState::BUFFERING_HAVE_ENOUGH
? "BUFFERING_HAVE_ENOUGH"
: "BUFFERING_HAVE_NOTHING");
}
};
// enum (complex)
template <>
struct MediaSerializer<media::BufferingStateChangeReason> {
static base::Value Serialize(const media::BufferingStateChangeReason value) {
switch (value) {
case DEMUXER_UNDERFLOW:
return base::Value("DEMUXER_UNDERFLOW");
case DECODER_UNDERFLOW:
return base::Value("DECODER_UNDERFLOW");
case REMOTING_NETWORK_CONGESTION:
return base::Value("REMOTING_NETWORK_CONGESTION");
case BUFFERING_CHANGE_REASON_UNKNOWN:
return base::Value("BUFFERING_CHANGE_REASON_UNKNOWN");
}
}
};
// Class (complex)
template <media::SerializableBufferingStateType T>
struct MediaSerializer<media::SerializableBufferingState<T>> {
static base::Value Serialize(
const media::SerializableBufferingState<T>& value) {
base::Value result(base::Value::Type::DICTIONARY);
FIELD_SERIALIZE("state", value.state);
switch (value.reason) {
case DEMUXER_UNDERFLOW:
case DECODER_UNDERFLOW:
case REMOTING_NETWORK_CONGESTION:
FIELD_SERIALIZE("reason", value.reason);
break;
// Don't write anything here if the reason is unknown.
case BUFFERING_CHANGE_REASON_UNKNOWN:
break;
}
if (T == SerializableBufferingStateType::kPipeline)
result.SetBoolKey("for_suspended_start", value.suspended_start);
return result;
}
};
#undef FIELD_SERIALIZE #undef FIELD_SERIALIZE
} // namespace internal } // namespace internal
......
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