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

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

Issue 955253002: Add metadata to media::VideoFrame and plumb it through IPC/MediaStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Metadata keys centralized, enums only. Created 5 years, 9 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
OLDNEW
(Empty)
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.
4
5 #include "base/logging.h"
6 #include "media/base/video_frame_metadata.h"
7
8 namespace media {
9
10 namespace {
11
12 // Map enum key to internal std::string key used by base::DictionaryValue.
13 inline std::string ToInternalKey(VideoFrameMetadata::Key key) {
14 DCHECK_LT(key, VideoFrameMetadata::NUM_KEYS);
15 return std::string(reinterpret_cast<char*>(&key), sizeof(key));
DaleCurtis 2015/03/02 23:23:28 Hmm, this creates an std::string() with 0x00 and 0
miu 2015/03/03 04:31:05 I accounted for that by using the Get/SetXXXWithou
16 }
17
18 } // namespace
19
20 VideoFrameMetadata::VideoFrameMetadata() {}
21
22 VideoFrameMetadata::~VideoFrameMetadata() {}
23
24 bool VideoFrameMetadata::HasKey(Key key) const {
25 return dictionary_.HasKey(ToInternalKey(key));
26 }
27
28 void VideoFrameMetadata::SetBoolean(Key key, bool value) {
29 dictionary_.SetBooleanWithoutPathExpansion(ToInternalKey(key), value);
30 }
31
32 void VideoFrameMetadata::SetInteger(Key key, int value) {
33 dictionary_.SetIntegerWithoutPathExpansion(ToInternalKey(key), value);
34 }
35
36 void VideoFrameMetadata::SetDouble(Key key, double value) {
37 dictionary_.SetDoubleWithoutPathExpansion(ToInternalKey(key), value);
38 }
39
40 void VideoFrameMetadata::SetString(Key key, const std::string& value) {
41 dictionary_.SetWithoutPathExpansion(
42 ToInternalKey(key),
43 // Using BinaryValue since we don't want the |value| interpreted as having
44 // any particular character encoding (e.g., UTF-8) by
45 // base::DictionaryValue.
46 base::BinaryValue::CreateWithCopiedBuffer(value.data(), value.size()));
47 }
48
49 void VideoFrameMetadata::SetTimeTicks(Key key, const base::TimeTicks& value) {
50 const int64 internal_value = value.ToInternalValue();
51 dictionary_.SetWithoutPathExpansion(
52 ToInternalKey(key),
53 base::BinaryValue::CreateWithCopiedBuffer(
54 reinterpret_cast<const char*>(&internal_value),
55 sizeof(internal_value)));
56 }
57
58 void VideoFrameMetadata::SetValue(Key key, scoped_ptr<base::Value> value) {
59 dictionary_.SetWithoutPathExpansion(ToInternalKey(key), value.Pass());
60 }
61
62 bool VideoFrameMetadata::GetBoolean(Key key, bool* value) const {
63 DCHECK(value);
64 return dictionary_.GetBooleanWithoutPathExpansion(ToInternalKey(key), value);
65 }
66
67 bool VideoFrameMetadata::GetInteger(Key key, int* value) const {
68 DCHECK(value);
69 return dictionary_.GetIntegerWithoutPathExpansion(ToInternalKey(key), value);
70 }
71
72 bool VideoFrameMetadata::GetDouble(Key key, double* value) const {
73 DCHECK(value);
74 return dictionary_.GetDoubleWithoutPathExpansion(ToInternalKey(key), value);
75 }
76
77 bool VideoFrameMetadata::GetString(Key key, std::string* value) const {
78 DCHECK(value);
79 const base::BinaryValue* const binary_value = GetBinaryValue(key);
80 if (binary_value)
81 value->assign(binary_value->GetBuffer(), binary_value->GetSize());
82 return !!binary_value;
83 }
84
85 bool VideoFrameMetadata::GetTimeTicks(Key key, base::TimeTicks* value) const {
86 DCHECK(value);
87 const base::BinaryValue* const binary_value = GetBinaryValue(key);
88 if (binary_value && binary_value->GetSize() == sizeof(int64)) {
89 int64 internal_value;
90 memcpy(&internal_value, binary_value->GetBuffer(), sizeof(internal_value));
91 *value = base::TimeTicks::FromInternalValue(internal_value);
92 return true;
93 }
94 return false;
95 }
96
97 const base::Value* VideoFrameMetadata::GetValue(Key key) const {
98 const base::Value* result = nullptr;
99 if (!dictionary_.GetWithoutPathExpansion(ToInternalKey(key), &result))
100 return nullptr;
101 return result;
102 }
103
104 void VideoFrameMetadata::MergeInternalValuesInto(
105 base::DictionaryValue* out) const {
106 out->MergeDictionary(&dictionary_);
107 }
108
109 void VideoFrameMetadata::MergeInternalValuesFrom(
110 const base::DictionaryValue& in) {
111 dictionary_.MergeDictionary(&in);
112 }
113
114 const base::BinaryValue* VideoFrameMetadata::GetBinaryValue(Key key) const {
115 const base::Value* internal_value = nullptr;
116 if (dictionary_.GetWithoutPathExpansion(ToInternalKey(key),
117 &internal_value) &&
118 internal_value->GetType() == base::Value::TYPE_BINARY) {
119 return static_cast<const base::BinaryValue*>(internal_value);
120 }
121 return nullptr;
122 }
123
124 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698