Use UsbIds::GetVendorName to retrieve USB vendor name.
[chromium-blink-merge.git] / media / base / video_frame_metadata.cc
blobd14bbe9a318a613ce6e1042145f33cfeb427c01b
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
3 // found in the LICENSE file.
5 #include "base/logging.h"
6 #include "base/strings/string_number_conversions.h"
7 #include "media/base/video_frame_metadata.h"
9 namespace media {
11 namespace {
13 // Map enum key to internal std::string key used by base::DictionaryValue.
14 inline std::string ToInternalKey(VideoFrameMetadata::Key key) {
15 DCHECK_LT(key, VideoFrameMetadata::NUM_KEYS);
16 return base::IntToString(static_cast<int>(key));
19 } // namespace
21 VideoFrameMetadata::VideoFrameMetadata() {}
23 VideoFrameMetadata::~VideoFrameMetadata() {}
25 bool VideoFrameMetadata::HasKey(Key key) const {
26 return dictionary_.HasKey(ToInternalKey(key));
29 void VideoFrameMetadata::SetBoolean(Key key, bool value) {
30 dictionary_.SetBooleanWithoutPathExpansion(ToInternalKey(key), value);
33 void VideoFrameMetadata::SetInteger(Key key, int value) {
34 dictionary_.SetIntegerWithoutPathExpansion(ToInternalKey(key), value);
37 void VideoFrameMetadata::SetDouble(Key key, double value) {
38 dictionary_.SetDoubleWithoutPathExpansion(ToInternalKey(key), value);
41 void VideoFrameMetadata::SetString(Key key, const std::string& value) {
42 dictionary_.SetWithoutPathExpansion(
43 ToInternalKey(key),
44 // Using BinaryValue since we don't want the |value| interpreted as having
45 // any particular character encoding (e.g., UTF-8) by
46 // base::DictionaryValue.
47 base::BinaryValue::CreateWithCopiedBuffer(value.data(), value.size()));
50 void VideoFrameMetadata::SetTimeTicks(Key key, const base::TimeTicks& value) {
51 const int64 internal_value = value.ToInternalValue();
52 dictionary_.SetWithoutPathExpansion(
53 ToInternalKey(key),
54 base::BinaryValue::CreateWithCopiedBuffer(
55 reinterpret_cast<const char*>(&internal_value),
56 sizeof(internal_value)));
59 void VideoFrameMetadata::SetValue(Key key, scoped_ptr<base::Value> value) {
60 dictionary_.SetWithoutPathExpansion(ToInternalKey(key), value.Pass());
63 bool VideoFrameMetadata::GetBoolean(Key key, bool* value) const {
64 DCHECK(value);
65 return dictionary_.GetBooleanWithoutPathExpansion(ToInternalKey(key), value);
68 bool VideoFrameMetadata::GetInteger(Key key, int* value) const {
69 DCHECK(value);
70 return dictionary_.GetIntegerWithoutPathExpansion(ToInternalKey(key), value);
73 bool VideoFrameMetadata::GetDouble(Key key, double* value) const {
74 DCHECK(value);
75 return dictionary_.GetDoubleWithoutPathExpansion(ToInternalKey(key), value);
78 bool VideoFrameMetadata::GetString(Key key, std::string* value) const {
79 DCHECK(value);
80 const base::BinaryValue* const binary_value = GetBinaryValue(key);
81 if (binary_value)
82 value->assign(binary_value->GetBuffer(), binary_value->GetSize());
83 return !!binary_value;
86 bool VideoFrameMetadata::GetTimeTicks(Key key, base::TimeTicks* value) const {
87 DCHECK(value);
88 const base::BinaryValue* const binary_value = GetBinaryValue(key);
89 if (binary_value && binary_value->GetSize() == sizeof(int64)) {
90 int64 internal_value;
91 memcpy(&internal_value, binary_value->GetBuffer(), sizeof(internal_value));
92 *value = base::TimeTicks::FromInternalValue(internal_value);
93 return true;
95 return false;
98 const base::Value* VideoFrameMetadata::GetValue(Key key) const {
99 const base::Value* result = nullptr;
100 if (!dictionary_.GetWithoutPathExpansion(ToInternalKey(key), &result))
101 return nullptr;
102 return result;
105 void VideoFrameMetadata::MergeInternalValuesInto(
106 base::DictionaryValue* out) const {
107 out->MergeDictionary(&dictionary_);
110 void VideoFrameMetadata::MergeInternalValuesFrom(
111 const base::DictionaryValue& in) {
112 dictionary_.MergeDictionary(&in);
115 const base::BinaryValue* VideoFrameMetadata::GetBinaryValue(Key key) const {
116 const base::Value* internal_value = nullptr;
117 if (dictionary_.GetWithoutPathExpansion(ToInternalKey(key),
118 &internal_value) &&
119 internal_value->GetType() == base::Value::TYPE_BINARY) {
120 return static_cast<const base::BinaryValue*>(internal_value);
122 return nullptr;
125 } // namespace media