• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 AUDIO_SERVICE_DUMP_H
17 #define AUDIO_SERVICE_DUMP_H
18 
19 #include <pulse/pulseaudio.h>
20 #include <audio_info.h>
21 #include <audio_timer.h>
22 #include <audio_errors.h>
23 #include <vector>
24 #include <pwd.h>
25 #include <map>
26 #include "securec.h"
27 #include "audio_log.h"
28 #include "nocopyable.h"
29 
30 namespace OHOS {
31 namespace AudioStandard {
32 
33 static const int32_t AUDIO_DUMP_SUCCESS = 0;
34 static const int32_t AUDIO_DUMP_INIT_ERR = -1;
35 
36 typedef struct {
37     DeviceType deviceType;
38     DeviceRole deviceRole;
39     ConnectType conneceType;
40 } DevicesInfo;
41 
42 typedef struct {
43     std::string name;
44     pa_sample_spec sampleSpec;
45 } SinkSourceInfo;
46 
47 typedef struct {
48     uint32_t userId;
49     uint32_t corked;                   // status
50     std::string sessionId;
51     std::string sessionStartTime;
52     std::string applicationName;
53     std::string processId;
54     pa_sample_spec sampleSpec;
55 }InputOutputInfo;
56 
57 typedef struct {
58     std::vector<SinkSourceInfo> sinkDevices;
59     std::vector<SinkSourceInfo> sourceDevices;
60     std::vector<InputOutputInfo> sinkInputs;
61     std::vector<InputOutputInfo> sourceOutputs;
62 } StreamData;
63 
64 typedef struct {
65     ConnectType type;
66     std::string groupName;
67     std::int32_t groupId;
68 } GroupInfo;
69 
70 typedef struct {
71     std::vector<DevicesInfo> inputDevices;
72     std::vector<DevicesInfo> outputDevices;
73     std::map<AudioStreamType, int32_t> streamVolumes;
74     AudioRingerMode ringerMode;
75     AudioScene callStatus;
76     AudioInterrupt audioFocusInfo;
77     std::vector<GroupInfo> groupInfos;
78 } PolicyData;
79 
80 typedef struct {
81     StreamData streamData;
82     PolicyData policyData;
83 } AudioData;
84 
85 class AudioServiceDump : public AudioTimer {
86 public:
87     DISALLOW_COPY_AND_MOVE(AudioServiceDump);
88 
89     AudioServiceDump();
90     ~AudioServiceDump();
91     int32_t Initialize();
92     void AudioDataDump(PolicyData &policyData, std::string &dumpString);
93     static bool IsStreamSupported(AudioStreamType streamType);
94     virtual void OnTimeOut();
95 
96 private:
97     pa_threaded_mainloop *mainLoop;
98     pa_mainloop_api *api;
99     pa_context *context;
100     std::mutex ctrlMutex;
101 
102     bool isMainLoopStarted;
103     bool isContextConnected;
104     AudioData audioData_ = {};
105 
106     int32_t ConnectStreamToPA();
107     void ResetPAAudioDump();
108 
109     void PlaybackStreamDump(std::string &dumpString);
110     void RecordStreamDump(std::string &dumpString);
111     void HDFModulesDump(std::string &dumpString);
112     void CallStatusDump(std::string &dumpString);
113     void RingerModeDump(std::string &dumpString);
114     void StreamVolumesDump(std::string &dumpString);
115     void DevicesInfoDump(std::string &dumpString);
116     void AudioFocusInfoDump(std::string &dumpString);
117     void GroupInfoDump(std::string& dumpString);
118     void DataDump(std::string &dumpString);
119     static const std::string GetStreamName(AudioStreamType audioType);
120     static const std::string GetStreamUsgaeName(StreamUsage streamUsage);
121     static const std::string GetContentTypeName(ContentType contentType);
122     static const std::string GetDeviceTypeName(DeviceType deviceType);
123     static const std::string GetConnectTypeName(ConnectType connectType);
124     static bool IsEndWith(const std::string &mainStr, const std::string &toMatch);
125     static bool IsValidModule (const std::string moduleName);
126 
127     // Callbacks
128     static void PAContextStateCb(pa_context *context, void *userdata);
129     static void PASinkInfoCallback(pa_context *c, const pa_sink_info *i, int eol, void *userdata);
130     static void PASinkInputInfoCallback(pa_context *c, const pa_sink_input_info *i, int eol, void *userdata);
131     static void PASourceInfoCallback(pa_context *c, const pa_source_info *i, int eol, void *userdata);
132     static void PASourceOutputInfoCallback(pa_context *c, const pa_source_output_info *i, int eol, void *userdata);
133 };
134 } // namespace AudioStandard
135 } // namespace OHOS
136 #endif // AUDIO_SERVICE_DUMP_H
137