• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PLAYER_TRACK_PARSE_H
17 #define PLAYER_TRACK_PARSE_H
18 
19 #include <mutex>
20 #include <vector>
21 #include <unordered_map>
22 #include <gst/gst.h>
23 #include <gst/player/player.h>
24 #include "format.h"
25 
26 namespace OHOS {
27 namespace Media {
28 class PlayerTrackParse {
29 public:
30     static std::shared_ptr<PlayerTrackParse> Create();
31     int32_t GetVideoTrackInfo(std::vector<Format> &videoTrack);
32     int32_t GetAudioTrackInfo(std::vector<Format> &audioTrack);
33     void SetDemuxerElementFind(bool isFind);
34     bool GetDemuxerElementFind() const;
35     void SetUpDemuxerElementCb(GstElement &elem);
36     void SetUpParseElementCb(GstElement &elem);
37     void Stop();
38     static void OnPadAddedCb(const GstElement *element, GstPad *pad, gpointer userData);
39     PlayerTrackParse();
40     ~PlayerTrackParse();
41 
42 private:
43     GstPadProbeReturn GetTrackParse(GstPad *pad, GstPadProbeInfo *info);
44     void ConvertToPlayerKeys(const Format &innerMeta, Format &outMeta) const;
45     bool AddProbeToPad(const GstElement *element, GstPad *pad);
46     bool AddProbeToPadList(const GstElement *element, GList &list);
47     static GstPadProbeReturn ProbeCallback(GstPad *pad, GstPadProbeInfo *info, gpointer userData);
48     bool demuxerElementFind_ = false;
49     std::unordered_map<GstPad *, Format> trackInfos_;
50     int32_t trackcount_ = 0;
51     struct SignalInfo {
52         GstElement *element;
53         gulong signalId;
54     };
55     std::vector<SignalInfo> signalIds_;
56     struct PadInfo {
57         GstPad *pad;
58         gulong probeId;
59     };
60     std::unordered_map<GstPad *, gulong> padProbes_;
61     std::mutex signalIdMutex_;
62     std::mutex padProbeMutex_;
63     std::mutex trackInfoMutex_;
64 };
65 }
66 }
67 #endif
68