Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Unified Diff: media/base/video_frame_metadata.cc

Issue 1146723002: New FRAME_DURATION VideoFrameMetadata, with Cast Streaming use case. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Expanded comments for VideoFrameMetadata::FRAME_DURATION. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/video_frame_metadata.h ('k') | media/base/video_frame_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/video_frame_metadata.cc
diff --git a/media/base/video_frame_metadata.cc b/media/base/video_frame_metadata.cc
index d14bbe9a318a613ce6e1042145f33cfeb427c01b..d6636123b5ca0c52ff3d16e6348c201f316c89b2 100644
--- a/media/base/video_frame_metadata.cc
+++ b/media/base/video_frame_metadata.cc
@@ -47,14 +47,27 @@ void VideoFrameMetadata::SetString(Key key, const std::string& value) {
base::BinaryValue::CreateWithCopiedBuffer(value.data(), value.size()));
}
-void VideoFrameMetadata::SetTimeTicks(Key key, const base::TimeTicks& value) {
+namespace {
+template<class TimeType>
+void SetTimeValue(VideoFrameMetadata::Key key,
+ const TimeType& value,
+ base::DictionaryValue* dictionary) {
const int64 internal_value = value.ToInternalValue();
- dictionary_.SetWithoutPathExpansion(
+ dictionary->SetWithoutPathExpansion(
ToInternalKey(key),
base::BinaryValue::CreateWithCopiedBuffer(
reinterpret_cast<const char*>(&internal_value),
sizeof(internal_value)));
}
+} // namespace
+
+void VideoFrameMetadata::SetTimeDelta(Key key, const base::TimeDelta& value) {
+ SetTimeValue(key, value, &dictionary_);
+}
+
+void VideoFrameMetadata::SetTimeTicks(Key key, const base::TimeTicks& value) {
+ SetTimeValue(key, value, &dictionary_);
+}
void VideoFrameMetadata::SetValue(Key key, scoped_ptr<base::Value> value) {
dictionary_.SetWithoutPathExpansion(ToInternalKey(key), value.Pass());
@@ -83,16 +96,27 @@ bool VideoFrameMetadata::GetString(Key key, std::string* value) const {
return !!binary_value;
}
-bool VideoFrameMetadata::GetTimeTicks(Key key, base::TimeTicks* value) const {
+namespace {
+template<class TimeType>
+bool ToTimeValue(const base::BinaryValue& binary_value, TimeType* value) {
DCHECK(value);
+ int64 internal_value;
+ if (binary_value.GetSize() != sizeof(internal_value))
+ return false;
+ memcpy(&internal_value, binary_value.GetBuffer(), sizeof(internal_value));
+ *value = TimeType::FromInternalValue(internal_value);
+ return true;
+}
+} // namespace
+
+bool VideoFrameMetadata::GetTimeDelta(Key key, base::TimeDelta* value) const {
const base::BinaryValue* const binary_value = GetBinaryValue(key);
- if (binary_value && binary_value->GetSize() == sizeof(int64)) {
- int64 internal_value;
- memcpy(&internal_value, binary_value->GetBuffer(), sizeof(internal_value));
- *value = base::TimeTicks::FromInternalValue(internal_value);
- return true;
- }
- return false;
+ return binary_value && ToTimeValue(*binary_value, value);
+}
+
+bool VideoFrameMetadata::GetTimeTicks(Key key, base::TimeTicks* value) const {
+ const base::BinaryValue* const binary_value = GetBinaryValue(key);
+ return binary_value && ToTimeValue(*binary_value, value);
}
const base::Value* VideoFrameMetadata::GetValue(Key key) const {
« no previous file with comments | « media/base/video_frame_metadata.h ('k') | media/base/video_frame_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698