• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Note: ported from Chromium commit head: 19cd1babcaff
5 // Note: only functions related to END_OF_STREAM are ported.
6 
7 #include "video_frame_metadata.h"
8 
9 #include <stdint.h>
10 #include <utility>
11 
12 #include "base/logging.h"
13 #include "base/strings/string_number_conversions.h"
14 
15 namespace media {
16 
17 namespace {
18 
19 // Map enum key to internal std::string key used by base::DictionaryValue.
ToInternalKey(VideoFrameMetadata::Key key)20 inline std::string ToInternalKey(VideoFrameMetadata::Key key) {
21   DCHECK_LT(key, VideoFrameMetadata::NUM_KEYS);
22   return base::NumberToString(static_cast<int>(key));
23 }
24 
25 }  // namespace
26 
27 VideoFrameMetadata::VideoFrameMetadata() = default;
28 
29 VideoFrameMetadata::~VideoFrameMetadata() = default;
30 
HasKey(Key key) const31 bool VideoFrameMetadata::HasKey(Key key) const {
32   return dictionary_.HasKey(ToInternalKey(key));
33 }
34 
SetBoolean(Key key,bool value)35 void VideoFrameMetadata::SetBoolean(Key key, bool value) {
36   dictionary_.SetKey(ToInternalKey(key), base::Value(value));
37 }
38 
GetBoolean(Key key,bool * value) const39 bool VideoFrameMetadata::GetBoolean(Key key, bool* value) const {
40   DCHECK(value);
41   return dictionary_.GetBooleanWithoutPathExpansion(ToInternalKey(key), value);
42 }
43 
IsTrue(Key key) const44 bool VideoFrameMetadata::IsTrue(Key key) const {
45   bool value = false;
46   return GetBoolean(key, &value) && value;
47 }
48 
49 }  // namespace media
50