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 AVMETADATAHELPER_SERVICE_CLIENT_H
17 #define AVMETADATAHELPER_SERVICE_CLIENT_H
18 
19 #include "i_avmetadatahelper_service.h"
20 #include "i_standard_avmetadatahelper_service.h"
21 #include "media_data_source_stub.h"
22 #include "helper_listener_stub.h"
23 
24 namespace OHOS {
25 namespace Media {
26 class AVMetadataHelperClient : public IAVMetadataHelperService, public NoCopyable {
27 public:
28     static std::shared_ptr<AVMetadataHelperClient> Create(const sptr<IStandardAVMetadataHelperService> &ipcProxy);
29     explicit AVMetadataHelperClient(const sptr<IStandardAVMetadataHelperService> &ipcProxy);
30     ~AVMetadataHelperClient();
31 
32     // IAVMetadataHelperService override
33     int32_t SetHelperCallback(const std::shared_ptr<HelperCallback> &callback) override;
34     int32_t SetSource(const std::string &uri, int32_t usage) override;
35     int32_t SetSource(int32_t fd, int64_t offset, int64_t size, int32_t usage) override;
36     int32_t SetSource(const std::shared_ptr<IMediaDataSource> &dataSrc) override;
37     std::string ResolveMetadata(int32_t key) override;
38     std::unordered_map<int32_t, std::string> ResolveMetadata() override;
39     std::shared_ptr<Meta> GetAVMetadata() override;
40     std::shared_ptr<AVSharedMemory> FetchArtPicture() override;
41     std::shared_ptr<AVSharedMemory> FetchFrameAtTime(int64_t timeUs,
42         int32_t option, const OutputConfiguration &param) override;
43     int32_t GetTimeByFrameIndex(uint32_t index, uint64_t &time) override;
44     int32_t GetFrameIndexByTime(uint64_t time, uint32_t &index) override;
45     std::shared_ptr<AVBuffer> FetchFrameYuv(int64_t timeUs,
46         int32_t option, const OutputConfiguration &param) override;
47     void Release() override;
48 
49     // AVMetadataHelperClient
50     void MediaServerDied();
51 private:
52     int32_t CreateListenerObject();
53 
54     sptr<IStandardAVMetadataHelperService> avMetadataHelperProxy_ = nullptr;
55     std::mutex mutex_;
56     std::shared_ptr<HelperCallback> callback_ = nullptr;
57     sptr<MediaDataSourceStub> dataSrcStub_ = nullptr;
58     sptr<HelperListenerStub> listenerStub_ = nullptr;
59 };
60 } // namespace Media
61 } // namespace OHOS
62 #endif // AVMETADATAHELPER_SERVICE_CLIENT_H
63