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

Side by Side Diff: media/base/video_frame_metadata.cc

Issue 2799093006: Remove base::BinaryValue (Closed)
Patch Set: Rebase Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « media/base/video_frame_metadata.h ('k') | mojo/common/common_custom_types_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/video_frame_metadata.h" 5 #include "media/base/video_frame_metadata.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 DCHECK_EQ(ROTATION, key); 46 DCHECK_EQ(ROTATION, key);
47 dictionary_.SetIntegerWithoutPathExpansion(ToInternalKey(key), value); 47 dictionary_.SetIntegerWithoutPathExpansion(ToInternalKey(key), value);
48 } 48 }
49 49
50 void VideoFrameMetadata::SetString(Key key, const std::string& value) { 50 void VideoFrameMetadata::SetString(Key key, const std::string& value) {
51 dictionary_.SetWithoutPathExpansion( 51 dictionary_.SetWithoutPathExpansion(
52 ToInternalKey(key), 52 ToInternalKey(key),
53 // Using BinaryValue since we don't want the |value| interpreted as having 53 // Using BinaryValue since we don't want the |value| interpreted as having
54 // any particular character encoding (e.g., UTF-8) by 54 // any particular character encoding (e.g., UTF-8) by
55 // base::DictionaryValue. 55 // base::DictionaryValue.
56 base::BinaryValue::CreateWithCopiedBuffer(value.data(), value.size())); 56 base::Value::CreateWithCopiedBuffer(value.data(), value.size()));
57 } 57 }
58 58
59 namespace { 59 namespace {
60 template<class TimeType> 60 template<class TimeType>
61 void SetTimeValue(VideoFrameMetadata::Key key, 61 void SetTimeValue(VideoFrameMetadata::Key key,
62 const TimeType& value, 62 const TimeType& value,
63 base::DictionaryValue* dictionary) { 63 base::DictionaryValue* dictionary) {
64 const int64_t internal_value = value.ToInternalValue(); 64 const int64_t internal_value = value.ToInternalValue();
65 dictionary->SetWithoutPathExpansion( 65 dictionary->SetWithoutPathExpansion(
66 ToInternalKey(key), 66 ToInternalKey(key), base::Value::CreateWithCopiedBuffer(
67 base::BinaryValue::CreateWithCopiedBuffer( 67 reinterpret_cast<const char*>(&internal_value),
68 reinterpret_cast<const char*>(&internal_value), 68 sizeof(internal_value)));
69 sizeof(internal_value)));
70 } 69 }
71 } // namespace 70 } // namespace
72 71
73 void VideoFrameMetadata::SetTimeDelta(Key key, const base::TimeDelta& value) { 72 void VideoFrameMetadata::SetTimeDelta(Key key, const base::TimeDelta& value) {
74 SetTimeValue(key, value, &dictionary_); 73 SetTimeValue(key, value, &dictionary_);
75 } 74 }
76 75
77 void VideoFrameMetadata::SetTimeTicks(Key key, const base::TimeTicks& value) { 76 void VideoFrameMetadata::SetTimeTicks(Key key, const base::TimeTicks& value) {
78 SetTimeValue(key, value, &dictionary_); 77 SetTimeValue(key, value, &dictionary_);
79 } 78 }
(...skipping 23 matching lines...) Expand all
103 int int_value; 102 int int_value;
104 const bool rv = dictionary_.GetIntegerWithoutPathExpansion(ToInternalKey(key), 103 const bool rv = dictionary_.GetIntegerWithoutPathExpansion(ToInternalKey(key),
105 &int_value); 104 &int_value);
106 if (rv) 105 if (rv)
107 *value = static_cast<VideoRotation>(int_value); 106 *value = static_cast<VideoRotation>(int_value);
108 return rv; 107 return rv;
109 } 108 }
110 109
111 bool VideoFrameMetadata::GetString(Key key, std::string* value) const { 110 bool VideoFrameMetadata::GetString(Key key, std::string* value) const {
112 DCHECK(value); 111 DCHECK(value);
113 const base::BinaryValue* const binary_value = GetBinaryValue(key); 112 const base::Value* const binary_value = GetBinaryValue(key);
114 if (binary_value) 113 if (binary_value)
115 value->assign(binary_value->GetBuffer(), binary_value->GetSize()); 114 value->assign(binary_value->GetBuffer(), binary_value->GetSize());
116 return !!binary_value; 115 return !!binary_value;
117 } 116 }
118 117
119 namespace { 118 namespace {
120 template<class TimeType> 119 template <class TimeType>
121 bool ToTimeValue(const base::BinaryValue& binary_value, TimeType* value) { 120 bool ToTimeValue(const base::Value& binary_value, TimeType* value) {
122 DCHECK(value); 121 DCHECK(value);
123 int64_t internal_value; 122 int64_t internal_value;
124 if (binary_value.GetSize() != sizeof(internal_value)) 123 if (binary_value.GetSize() != sizeof(internal_value))
125 return false; 124 return false;
126 memcpy(&internal_value, binary_value.GetBuffer(), sizeof(internal_value)); 125 memcpy(&internal_value, binary_value.GetBuffer(), sizeof(internal_value));
127 *value = TimeType::FromInternalValue(internal_value); 126 *value = TimeType::FromInternalValue(internal_value);
128 return true; 127 return true;
129 } 128 }
130 } // namespace 129 } // namespace
131 130
132 bool VideoFrameMetadata::GetTimeDelta(Key key, base::TimeDelta* value) const { 131 bool VideoFrameMetadata::GetTimeDelta(Key key, base::TimeDelta* value) const {
133 const base::BinaryValue* const binary_value = GetBinaryValue(key); 132 const base::Value* const binary_value = GetBinaryValue(key);
134 return binary_value && ToTimeValue(*binary_value, value); 133 return binary_value && ToTimeValue(*binary_value, value);
135 } 134 }
136 135
137 bool VideoFrameMetadata::GetTimeTicks(Key key, base::TimeTicks* value) const { 136 bool VideoFrameMetadata::GetTimeTicks(Key key, base::TimeTicks* value) const {
138 const base::BinaryValue* const binary_value = GetBinaryValue(key); 137 const base::Value* const binary_value = GetBinaryValue(key);
139 return binary_value && ToTimeValue(*binary_value, value); 138 return binary_value && ToTimeValue(*binary_value, value);
140 } 139 }
141 140
142 const base::Value* VideoFrameMetadata::GetValue(Key key) const { 141 const base::Value* VideoFrameMetadata::GetValue(Key key) const {
143 const base::Value* result = nullptr; 142 const base::Value* result = nullptr;
144 if (!dictionary_.GetWithoutPathExpansion(ToInternalKey(key), &result)) 143 if (!dictionary_.GetWithoutPathExpansion(ToInternalKey(key), &result))
145 return nullptr; 144 return nullptr;
146 return result; 145 return result;
147 } 146 }
148 147
(...skipping 10 matching lines...) Expand all
159 void VideoFrameMetadata::MergeInternalValuesFrom( 158 void VideoFrameMetadata::MergeInternalValuesFrom(
160 const base::DictionaryValue& in) { 159 const base::DictionaryValue& in) {
161 dictionary_.MergeDictionary(&in); 160 dictionary_.MergeDictionary(&in);
162 } 161 }
163 162
164 void VideoFrameMetadata::MergeMetadataFrom( 163 void VideoFrameMetadata::MergeMetadataFrom(
165 const VideoFrameMetadata* metadata_source) { 164 const VideoFrameMetadata* metadata_source) {
166 dictionary_.MergeDictionary(&metadata_source->dictionary_); 165 dictionary_.MergeDictionary(&metadata_source->dictionary_);
167 } 166 }
168 167
169 const base::BinaryValue* VideoFrameMetadata::GetBinaryValue(Key key) const { 168 const base::Value* VideoFrameMetadata::GetBinaryValue(Key key) const {
170 const base::Value* internal_value = nullptr; 169 const base::Value* internal_value = nullptr;
171 if (dictionary_.GetWithoutPathExpansion(ToInternalKey(key), 170 if (dictionary_.GetWithoutPathExpansion(ToInternalKey(key),
172 &internal_value) && 171 &internal_value) &&
173 internal_value->GetType() == base::Value::Type::BINARY) { 172 internal_value->GetType() == base::Value::Type::BINARY) {
174 return internal_value; 173 return internal_value;
175 } 174 }
176 return nullptr; 175 return nullptr;
177 } 176 }
178 177
179 } // namespace media 178 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_frame_metadata.h ('k') | mojo/common/common_custom_types_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698