• 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 
16 #ifndef CODEC_CLIENT_H
17 #define CODEC_CLIENT_H
18 
19 #include <shared_mutex>
20 #include "i_codec_service.h"
21 #include "i_standard_codec_service.h"
22 #include "codec_listener_stub.h"
23 
24 namespace OHOS {
25 namespace MediaAVCodec {
26 class CodecClient : public ICodecService {
27 public:
28     static std::shared_ptr<CodecClient> Create(const sptr<IStandardCodecService> &ipcProxy);
29     explicit CodecClient(const sptr<IStandardCodecService> &ipcProxy);
30     ~CodecClient();
31     // 业务
32     int32_t Init(AVCodecType type, bool isMimeType, const std::string &name) override;
33     int32_t Configure(const Format &format) override;
34     int32_t Start() override;
35     int32_t Stop() override;
36     int32_t Flush() override;
37     int32_t Reset() override;
38     int32_t Release() override;
39     int32_t NotifyEos() override;
40     sptr<Surface> CreateInputSurface() override;
41     int32_t SetOutputSurface(sptr<Surface> surface) override;
42     int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override;
43     int32_t GetOutputFormat(Format &format) override;
44     int32_t ReleaseOutputBuffer(uint32_t index, bool render) override;
45     int32_t SetParameter(const Format &format) override;
46     int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) override;
47     int32_t GetInputFormat(Format &format) override;
48 
49     void AVCodecServerDied();
50 
51 private:
52     int32_t CreateListenerObject();
53     void UpdateGeneration();
54     void WaitCallbackDone();
55 
56     sptr<IStandardCodecService> codecProxy_ = nullptr;
57     sptr<CodecListenerStub> listenerStub_ = nullptr;
58     std::shared_ptr<AVCodecCallback> callback_ = nullptr;
59     std::shared_mutex mutex_;
60     std::atomic<bool> needUpdateGeneration = true;
61 };
62 } // namespace MediaAVCodec
63 } // namespace OHOS
64 #endif // CODEC_CLIENT_H
65