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 
40 #ifdef SUPPORT_CODEC
41     int32_t CreateCodecService(std::shared_ptr<ICodecService> &codecClient) override;
42     int32_t DestroyCodecService(std::shared_ptr<ICodecService> codecClient) override;
43 #endif
44 
45 #ifdef SUPPORT_CODECLIST
46     std::shared_ptr<ICodecListService> CreateCodecListService() override;
47     int32_t DestroyCodecListService(std::shared_ptr<ICodecListService> codecListClient) override;
48 #endif
49 
50 private:
51     sptr<IStandardAVCodecService> GetAVCodecProxy();
52     bool IsAlived();
53     static void AVCodecServerDied(pid_t pid);
54     void DoAVCodecServerDied();
55 
56     sptr<IStandardAVCodecService> avCodecProxy_ = nullptr;
57     sptr<AVCodecListenerStub> listenerStub_ = nullptr;
58     sptr<AVCodecDeathRecipient> deathRecipient_ = nullptr;
59 
60 #ifdef SUPPORT_CODEC
61     std::list<std::shared_ptr<ICodecService>> codecClientList_;
62 #endif
63 #ifdef SUPPORT_CODECLIST
64     std::list<std::shared_ptr<ICodecListService>> codecListClientList_;
65 #endif
66 
67     std::mutex mutex_;
68 };
69 } // namespace MediaAVCodec
70 } // namespace OHOS
71 #endif // AVCODEC_CLIENT_H
72