• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #ifndef AVCODEC_CLIENT_H
16 #define AVCODEC_CLIENT_H
17 
18 #include "i_avcodec_service.h"
19 #include "avcodec_death_recipient.h"
20 #include "avcodec_listener_stub.h"
21 #include "i_standard_avcodec_service.h"
22 
23 #ifdef SUPPORT_CODEC
24 #include "codec_client.h"
25 #endif
26 
27 #ifdef SUPPORT_CODECLIST
28 #include "codeclist_client.h"
29 #endif
30 
31 #include "nocopyable.h"
32 
33 namespace OHOS {
34 namespace MediaAVCodec {
35 class AVCodecClient : public IAVCodecService, public NoCopyable {
36 public:
37     AVCodecClient() noexcept;
38     ~AVCodecClient();
39     int32_t SuspendFreeze(const std::vector<pid_t> &pidList) override;
40     int32_t SuspendActive(const std::vector<pid_t> &pidList) override;
41     int32_t SuspendActiveAll() override;
42 
43 #ifdef SUPPORT_CODEC
44     int32_t CreateCodecService(std::shared_ptr<ICodecService> &codecClient) override;
45     int32_t DestroyCodecService(std::shared_ptr<ICodecService> codecClient) override;
46 #endif
47 
48 #ifdef SUPPORT_CODECLIST
49     std::shared_ptr<ICodecListService> CreateCodecListService() override;
50     int32_t DestroyCodecListService(std::shared_ptr<ICodecListService> codecListClient) override;
51 #endif
52 
53 private:
54     int32_t CreateInstanceAndTryInTimes(IStandardAVCodecService::AVCodecSystemAbility subSystemId,
55                                         sptr<IRemoteObject> &object,
56                                         uint32_t tryTimes = 3);
57     sptr<IStandardAVCodecService> GetAVCodecProxy();
58     sptr<IStandardAVCodecService> GetTemporaryAVCodecProxy();
59     bool IsAlived();
60     static void AVCodecServerDied(pid_t pid);
61     void DoAVCodecServerDied();
62 
63     sptr<IStandardAVCodecService> avCodecProxy_ = nullptr;
64     sptr<AVCodecListenerStub> listenerStub_ = nullptr;
65     sptr<AVCodecDeathRecipient> deathRecipient_ = nullptr;
66 
67 #ifdef SUPPORT_CODEC
68     std::list<std::shared_ptr<ICodecService>> codecClientList_;
69 #endif
70 #ifdef SUPPORT_CODECLIST
71     std::list<std::shared_ptr<ICodecListService>> codecListClientList_;
72 #endif
73 
74     std::mutex mutex_;
75 };
76 } // namespace MediaAVCodec
77 } // namespace OHOS
78 #endif // AVCODEC_CLIENT_H
79