• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HISTREAMER_PLUGIN_TAG_VALUE_MAP_H
17 #define HISTREAMER_PLUGIN_TAG_VALUE_MAP_H
18 
19 #include "plugin_tags.h"
20 #include "plugin_types.h"
21 #include "plugin_source_tags.h"
22 #include "plugin_audio_tags.h"
23 #include "plugin_video_tags.h"
24 #if !defined(OHOS_LITE) && defined(VIDEO_SUPPORT)
25 #include "surface_allocator.h"
26 #endif
27 
28 namespace OHOS {
29 namespace Media {
30 namespace Plugin {
31 #define DEFINE_INSERT_GET_FUNC(condition, ValueType)             \
32         template<Tag tag>                                        \
33         inline typename std::enable_if<(condition), bool>::type  \
34         Insert(ValueType value)                                  \
35         {                                                        \
36             map_.insert(std::make_pair(tag, value));             \
37             return true;                                         \
38         }                                                        \
39         template<Tag tag>                                        \
40         inline typename std::enable_if<(condition), bool>::type  \
41         Get(ValueType& value)                                    \
42         {                                                        \
43             if (map_.count(tag) == 0) {                          \
44                 return false;                                    \
45             }                                                    \
46             Any& temp = map_.at(tag);                            \
47             if (!temp.SameTypeWith(typeid(ValueType))) {         \
48                 return false;                                    \
49             }                                                    \
50             value = AnyCast<ValueType>(map_.at(tag));            \
51             return true;                                         \
52         }
53 
54 
55 using MapIt = std::map<Tag, Any>::const_iterator;
56 class TagMap {
57 public:
58 #if !defined(OHOS_LITE) && defined(VIDEO_SUPPORT)
59     DEFINE_INSERT_GET_FUNC(tag == Tag::BUFFER_ALLOCATOR or tag == Tag::VIDEO_SURFACE,
60                            std::shared_ptr<SurfaceAllocator>);
61 #endif
62     DEFINE_INSERT_GET_FUNC(tag == Tag::SRC_INPUT_TYPE, SrcInputType);
63     DEFINE_INSERT_GET_FUNC(tag == Tag::MEDIA_CODEC_CONFIG, std::vector<uint8_t>);
64     DEFINE_INSERT_GET_FUNC(
65         tag == Tag::AUDIO_CHANNEL_LAYOUT or
66         tag == Tag::AUDIO_OUTPUT_CHANNEL_LAYOUT, AudioChannelLayout);
67     DEFINE_INSERT_GET_FUNC(tag == Tag::AUDIO_SAMPLE_FORMAT, AudioSampleFormat);
68     DEFINE_INSERT_GET_FUNC(tag == Tag::AUDIO_AAC_PROFILE, AudioAacProfile);
69     DEFINE_INSERT_GET_FUNC(tag == Tag::AUDIO_AAC_STREAM_FORMAT, AudioAacStreamFormat);
70     DEFINE_INSERT_GET_FUNC(tag == Tag::VIDEO_PIXEL_FORMAT, VideoPixelFormat);
71     DEFINE_INSERT_GET_FUNC(tag == Tag::MEDIA_SEEKABLE, Seekable);
72     DEFINE_INSERT_GET_FUNC(tag == Tag::MEDIA_TYPE, MediaType);
73     DEFINE_INSERT_GET_FUNC(tag == Tag::VIDEO_BIT_STREAM_FORMAT, std::vector<VideoBitStreamFormat>);
74     DEFINE_INSERT_GET_FUNC(
75         tag == Tag::TRACK_ID or
76         tag == Tag::REQUIRED_OUT_BUFFER_CNT or
77         tag == Tag::BUFFERING_SIZE or
78         tag == Tag::WATERLINE_HIGH or
79         tag == Tag::WATERLINE_LOW or
80         tag == Tag::AUDIO_CHANNELS or
81         tag == Tag::AUDIO_SAMPLE_RATE or
82         tag == Tag::AUDIO_SAMPLE_PER_FRAME or
83         tag == Tag::AUDIO_OUTPUT_CHANNELS or
84         tag == Tag::AUDIO_MPEG_VERSION or
85         tag == Tag::AUDIO_MPEG_LAYER or
86         tag == Tag::AUDIO_AAC_LEVEL or
87         tag == Tag::VIDEO_WIDTH or
88         tag == Tag::VIDEO_HEIGHT or
89         tag == Tag::VIDEO_FRAME_RATE or
90         tag == Tag::VIDEO_MAX_SURFACE_NUM or
91         tag == Tag::BITS_PER_CODED_SAMPLE, uint32_t);
92     DEFINE_INSERT_GET_FUNC(
93         tag == Tag::MEDIA_DURATION or
94         tag == Tag::MEDIA_FILE_SIZE or
95         tag == Tag::MEDIA_BITRATE or
96         tag == Tag::MEDIA_POSITION or
97         tag == Tag::MEDIA_START_TIME, int64_t);
98     DEFINE_INSERT_GET_FUNC(
99         tag == Tag::VIDEO_CAPTURE_RATE, double);
100     DEFINE_INSERT_GET_FUNC(
101         tag == Tag::MIME or
102         tag == Tag::MEDIA_FILE_EXTENSION or
103         tag == Tag::MEDIA_TITLE or
104         tag == Tag::MEDIA_ARTIST or
105         tag == Tag::MEDIA_LYRICIST or
106         tag == Tag::MEDIA_ALBUM or
107         tag == Tag::MEDIA_ALBUM_ARTIST or
108         tag == Tag::MEDIA_DATE or
109         tag == Tag::MEDIA_COMMENT or
110         tag == Tag::MEDIA_GENRE or
111         tag == Tag::MEDIA_COPYRIGHT or
112         tag == Tag::MEDIA_LANGUAGE or
113         tag == Tag::MEDIA_DESCRIPTION or
114         tag == Tag::MEDIA_LYRICS, std::string);
115 
116     ValueType& operator[](const Tag &tag)
117     {
118         return map_[tag];
119     }
120 
begin()121     MapIt begin() const // to support for (auto e : TagMap), must use begin/end name
122     {
123         return map_.cbegin();
124     }
125 
end()126     MapIt end() const
127     {
128         return map_.cend();
129     }
130 
Clear()131     void Clear()
132     {
133         map_.clear();
134     }
135 
Find(Tag tag)136     MapIt Find(Tag tag) const
137     {
138         return map_.find(tag);
139     }
140 private:
141     std::map<Tag, Any> map_;
142 };
143 } // namespace Plugin
144 } // namespace Media
145 } // namespace OHOS
146 #endif // HISTREAMER_PLUGIN_TAG_VALUE_MAP_H
147