1 /* 2 * Copyright (C) 2021 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 GST_META_PARSER_H 17 #define GST_META_PARSER_H 18 19 #include <gst/gst.h> 20 #include <unordered_map> 21 #include <string> 22 #include "format.h" 23 24 namespace OHOS { 25 namespace Media { 26 // meta key, sorted by alphabetical order. 27 inline constexpr std::string_view INNER_META_KEY_ALBUM = "album"; 28 inline constexpr std::string_view INNER_META_KEY_ALBUM_ARTIST = "albumartist"; 29 inline constexpr std::string_view INNER_META_KEY_ARTIST = "artist"; 30 inline constexpr std::string_view INNER_META_KEY_AUTHOR = "author"; 31 inline constexpr std::string_view INNER_META_KEY_BITRATE = "bitrate"; 32 inline constexpr std::string_view INNER_META_KEY_CHANNEL_COUNT = "channel-count"; 33 inline constexpr std::string_view INNER_META_KEY_COMPOSER = "composer"; 34 inline constexpr std::string_view INNER_META_KEY_DATE_TIME = "datetime"; 35 inline constexpr std::string_view INNER_META_KEY_DURATION = "duration"; 36 inline constexpr std::string_view INNER_META_KEY_FRAMERATE = "frame-rate"; 37 inline constexpr std::string_view INNER_META_KEY_GENRE = "genre"; 38 inline constexpr std::string_view INNER_META_KEY_VIDEO_HEIGHT = "height"; 39 inline constexpr std::string_view INNER_META_KEY_IMAGE = "image"; 40 inline constexpr std::string_view INNER_META_KEY_LANGUAGE = "language"; 41 inline constexpr std::string_view INNER_META_KEY_VIDEO_ORIENTATION = "image-orientation"; 42 inline constexpr std::string_view INNER_META_KEY_MIME_TYPE = "mime"; 43 inline constexpr std::string_view INNER_META_KEY_SAMPLE_RATE = "samplerate"; 44 inline constexpr std::string_view INNER_META_KEY_TITLE = "title"; 45 inline constexpr std::string_view INNER_META_KEY_TRACK_INDEX = "track-index"; 46 inline constexpr std::string_view INNER_META_KEY_TRACK_TYPE = "track-type"; 47 inline constexpr std::string_view INNER_META_KEY_VIDEO_WIDTH = "width"; 48 inline constexpr std::string_view INNER_META_KEY_BANDWIDTH = "bandwidth"; 49 50 // video codec mime 51 inline constexpr std::string_view VIDEO_MIMETYPE_AVC = "video/avc"; 52 inline constexpr std::string_view VIDEO_MIMETYPE_MPEG4 = "video/mp4v-es"; 53 54 // audio codec mime 55 inline constexpr std::string_view AUDIO_MIMETYPE_AAC = "audio/mp4a-latm"; 56 inline constexpr std::string_view AUDIO_MIMETYPE_MPEG = "audio/mpeg"; 57 58 // subtitle codec mime 59 inline constexpr std::string_view SUBTITLE_MIMETYPE_SRT = "subtitle/srt"; 60 61 // container mime 62 inline constexpr std::string_view FILE_MIMETYPE_VIDEO_MP4 = "video/mp4"; 63 inline constexpr std::string_view FILE_MIMETYPE_AUDIO_MP4 = "audio/mp4"; 64 inline constexpr std::string_view FILE_MIMETYPE_VIDEO_MKV = "video/x-matroska"; 65 inline constexpr std::string_view FILE_MIMETYPE_AUDIO_MKV = "audio/x-matroska"; 66 inline constexpr std::string_view FILE_MIMETYPE_VIDEO_MPEGTS = "video/mp2ts"; 67 inline constexpr std::string_view FILE_MIMETYPE_VIDEO_WEBM = "video/webm"; 68 inline constexpr std::string_view FILE_MIMETYPE_AUDIO_WEBM = "audio/webm"; 69 inline constexpr std::string_view FILE_MIMETYPE_AUDIO_AAC = "audio/aac-adts"; 70 inline constexpr std::string_view FILE_MIMETYPE_AUDIO_OGG = "audio/ogg"; 71 inline constexpr std::string_view FILE_MIMETYPE_AUDIO_FLAC = "audio/flac"; 72 inline constexpr std::string_view FILE_MIMETYPE_AUDIO_WAV = "audio/wav"; 73 inline constexpr std::string_view FILE_MIMETYPE_AUDIO_MP3 = "audio/mpeg"; 74 75 // parse meta from GstTagList, GstCaps 76 class GstMetaParser { 77 public: 78 static void ParseTagList(const GstTagList &tagList, Format &metadata); 79 static void ParseStreamCaps(const GstCaps &caps, Format &metadata); 80 static void ParseFileMimeType(const GstCaps &caps, Format &metadata); 81 82 private: 83 GstMetaParser() = default; 84 ~GstMetaParser() = default; 85 }; 86 } // namespace Media 87 } // namespace OHOS 88 #endif // GST_META_PARSER_H