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_PLAYER_TRACK_PARSE_H 17 #define GST_PLAYER_TRACK_PARSE_H 18 19 #include <string> 20 #include <vector> 21 #include <gst/gst.h> 22 #include <gst/player/player.h> 23 #include "player.h" 24 25 namespace OHOS { 26 namespace Media { 27 class GstPlayerTrackParse { 28 public: 29 static std::shared_ptr<GstPlayerTrackParse> Create(); 30 int32_t GetVideoTrackInfo(std::vector<Format> &videoTrack); 31 int32_t GetAudioTrackInfo(std::vector<Format> &audioTrack); 32 void SetDemuxerElementFind(bool isFind); 33 bool GetDemuxerElementFind(); 34 static void OnPadAddedCb(const GstElement *element, const GstPad *pad, GstPlayerTrackParse *playerTrackInfo); GstPlayerTrackParse()35 GstPlayerTrackParse() {}; ~GstPlayerTrackParse()36 ~GstPlayerTrackParse() {}; 37 38 private: 39 static void ParseStreamStruc(const GstPad *pad, GstPlayerTrackParse *playerTrackInfo); 40 static void ParseSingleCapsStructure(const GstStructure *struc, const GstPad *pad, 41 std::vector<std::unordered_map<GstPad *, std::unordered_map<std::string, std::string>>> &trackInfoVec, 42 std::vector<std::string_view> expectedCapsFields, int32_t index); 43 static int32_t GetStrucFromPad(const GstPad *pad, GstStructure **struc); 44 static int32_t GetMimeFromStruc(const GstStructure *struc, std::string &mime); 45 static void AddProbeToPad(const GstPad *pad, GstPlayerTrackParse *playerTrackInfo); 46 static GstPadProbeReturn ProbeCallback(GstPad *pad, GstPadProbeInfo *info, gpointer usrdata); 47 static void ParseTagList(const GstPad *pad, const GstTagList *tagList, GstPlayerTrackParse *playerTrackInfo); 48 static std::unordered_map<std::string, std::string> *FindTrackInfoMap(const GstPad *pad, 49 std::vector<std::unordered_map<GstPad *, std::unordered_map<std::string, std::string>>> &trackInfoVec); 50 static void ParseTag(const GstTagList *tagList, guint tagIndex, std::vector<std::string_view> expectedTagFields, 51 std::unordered_map<std::string, std::string> *trackInfoMap); 52 static std::string GetSerializedValue(const GValue *value); 53 static void ParseTagAndSaveTrackInfo(const GstPad *pad, const GstTagList *tagList, 54 const std::vector<std::string_view> &expectedTagFields, 55 std::vector<std::unordered_map<GstPad *, std::unordered_map<std::string, std::string>>> &trackInfoVec); 56 int32_t trackIndex_ = 0; 57 bool demuxerElementFind_ = false; 58 std::vector<std::unordered_map<GstPad *, std::unordered_map<std::string, std::string>>> videoTrackInfo_; 59 std::vector<std::unordered_map<GstPad *, std::unordered_map<std::string, std::string>>> audioTrackInfo_; 60 std::unordered_map<GstPad *, gulong> padProbes_; 61 }; 62 } // namespace Media 63 } // namespace OHOS 64 #endif // GST_PLAYER_TRACK_PARSE_H 65