• 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 MEDIA_SERVER_MANAGER_H
17 #define MEDIA_SERVER_MANAGER_H
18 
19 #include <memory>
20 #include <functional>
21 #include <map>
22 #include <list>
23 #include "iremote_object.h"
24 #include "ipc_skeleton.h"
25 #include "nocopyable.h"
26 
27 namespace OHOS {
28 namespace Media {
29 using DumperEntry = std::function<int32_t(int32_t)>;
30 struct Dumper {
31     pid_t pid_;
32     pid_t uid_;
33     DumperEntry entry_;
34     sptr<IRemoteObject> remoteObject_;
35 };
36 
37 class MediaServerManager : public NoCopyable {
38 public:
39     static MediaServerManager &GetInstance();
40     ~MediaServerManager();
41 
42     enum StubType {
43         RECORDER = 0,
44         PLAYER,
45         AVMETADATAHELPER,
46         AVCODECLIST,
47         AVCODEC,
48         RECORDERPROFILES,
49         MONITOR,
50         SCREEN_CAPTURE,
51     };
52     sptr<IRemoteObject> CreateStubObject(StubType type);
53     void DestroyStubObject(StubType type, sptr<IRemoteObject> object);
54     void DestroyStubObjectForPid(pid_t pid);
55     int32_t Dump(int32_t fd, const std::vector<std::u16string> &args);
56     void DestroyDumper(StubType type, sptr<IRemoteObject> object);
57     void DestroyDumperForPid(pid_t pid);
58 
59 private:
60     MediaServerManager();
61 #ifdef SUPPORT_PLAYER
62     sptr<IRemoteObject> CreatePlayerStubObject();
63 #endif
64 #ifdef SUPPORT_RECORDER
65     sptr<IRemoteObject> CreateRecorderStubObject();
66     sptr<IRemoteObject> CreateRecorderProfilesStubObject();
67 #endif
68 #ifdef SUPPORT_METADATA
69     sptr<IRemoteObject> CreateAVMetadataHelperStubObject();
70 #endif
71 #ifdef SUPPORT_CODEC
72     sptr<IRemoteObject> CreateAVCodecListStubObject();
73     sptr<IRemoteObject> CreateAVCodecStubObject();
74 #endif
75 #ifdef SUPPORT_SCREEN_CAPTURE
76     sptr<IRemoteObject> CreateScreenCaptureStubObject();
77 #endif
78     sptr<IRemoteObject> GetMonitorStubObject();
79 
80     class AsyncExecutor {
81     public:
82         AsyncExecutor() = default;
83         virtual ~AsyncExecutor() = default;
84         void Commit(sptr<IRemoteObject> obj);
85         void Clear();
86     private:
87         void HandleAsyncExecution();
88         std::list<sptr<IRemoteObject>> freeList_;
89         std::mutex listMutex_;
90     };
91     std::map<sptr<IRemoteObject>, pid_t> recorderStubMap_;
92     std::map<sptr<IRemoteObject>, pid_t> playerStubMap_;
93     std::map<sptr<IRemoteObject>, pid_t> avMetadataHelperStubMap_;
94     std::map<sptr<IRemoteObject>, pid_t> avCodecListStubMap_;
95     std::map<sptr<IRemoteObject>, pid_t> avCodecStubMap_;
96     std::map<sptr<IRemoteObject>, pid_t> recorderProfilesStubMap_;
97     std::map<sptr<IRemoteObject>, pid_t> screenCaptureStubMap_;
98     std::map<StubType, std::vector<Dumper>> dumperTbl_;
99     AsyncExecutor executor_;
100 
101     std::mutex mutex_;
102 };
103 } // namespace Media
104 } // namespace OHOS
105 #endif // MEDIA_SERVER_MANAGER_H