• 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 "codec_listener_stub.h"
21 #include "i_codec_service.h"
22 #include "i_standard_codec_service.h"
23 
24 namespace OHOS {
25 namespace MediaAVCodec {
26 class CodecClientCallback;
27 class CodecClient : public MediaCodecCallback,
28                     public AVCodecCallback,
29                     public ICodecService,
30                     public std::enable_shared_from_this<CodecClient> {
31 public:
32     static std::shared_ptr<CodecClient> Create(const sptr<IStandardCodecService> &ipcProxy);
33     explicit CodecClient(const sptr<IStandardCodecService> &ipcProxy);
34     ~CodecClient();
35     // 业务
36     int32_t Init(AVCodecType type, bool isMimeType, const std::string &name,
37                  API_VERSION apiVersion = API_VERSION::API_VERSION_10) override;
38     int32_t Configure(const Format &format) override;
39     int32_t Start() override;
40     int32_t Stop() override;
41     int32_t Flush() override;
42     int32_t Reset() override;
43     int32_t Release() override;
44     int32_t NotifyEos() override;
45     sptr<Surface> CreateInputSurface() override;
46     int32_t SetOutputSurface(sptr<Surface> surface) override;
47     int32_t QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag) override;
48     int32_t QueueInputBuffer(uint32_t index) override;
49     int32_t GetOutputFormat(Format &format) override;
50     int32_t ReleaseOutputBuffer(uint32_t index, bool render) override;
51     int32_t SetParameter(const Format &format) override;
52     int32_t SetCallback(const std::shared_ptr<AVCodecCallback> &callback) override;
53     int32_t SetCallback(const std::shared_ptr<MediaCodecCallback> &callback) override;
54     int32_t GetInputFormat(Format &format) override;
55 #ifdef SUPPORT_DRM
56     int32_t SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession, const bool svpFlag) override;
57 #endif
58 
59     void AVCodecServerDied();
60 
61     void OnError(AVCodecErrorType errorType, int32_t errorCode) override;
62     void OnOutputFormatChanged(const Format &format) override;
63     void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVSharedMemory> buffer) override;
64     void OnOutputBufferAvailable(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag,
65                                  std::shared_ptr<AVSharedMemory> buffer) override;
66     void OnInputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override;
67     void OnOutputBufferAvailable(uint32_t index, std::shared_ptr<AVBuffer> buffer) override;
68 
69 private:
70     int32_t CreateListenerObject();
71     void UpdateGeneration();
72     void WaitCallbackDone();
73 
74     sptr<IStandardCodecService> codecProxy_ = nullptr;
75     sptr<CodecListenerStub> listenerStub_ = nullptr;
76     std::shared_ptr<AVCodecCallback> callback_ = nullptr;
77     std::shared_ptr<MediaCodecCallback> videoCallback_ = nullptr;
78     std::shared_mutex mutex_;
79     std::atomic<bool> needUpdateGeneration = true;
80 };
81 } // namespace MediaAVCodec
82 } // namespace OHOS
83 #endif // CODEC_CLIENT_H
84