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_STUB_H
17 #define AVMETADATAHELPER_SERVICE_STUB_H
18 
19 #include <map>
20 #include "i_standard_avmetadatahelper_service.h"
21 #include "media_death_recipient.h"
22 #include "avmetadatahelper_server.h"
23 #include "i_standard_helper_listener.h"
24 #include "helper_listener_proxy.h"
25 
26 namespace OHOS {
27 namespace Media {
28 using AVMetadataHelperStubFunc = std::function<int32_t(MessageParcel &, MessageParcel &)>;
29 class AVMetadataHelperServiceStub : public IRemoteStub<IStandardAVMetadataHelperService>, public NoCopyable {
30 public:
31     static sptr<AVMetadataHelperServiceStub> Create();
32     virtual ~AVMetadataHelperServiceStub();
33 
34     int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
35     int32_t SetSource(const std::string &uri, int32_t usage) override;
36     int32_t SetSource(int32_t fd, int64_t offset, int64_t size, int32_t usage) override;
37     int32_t SetSource(const sptr<IRemoteObject> &object) override;
38     std::string ResolveMetadata(int32_t key) override;
39     std::unordered_map<int32_t, std::string> ResolveMetadataMap() override;
40     std::shared_ptr<Meta> GetAVMetadata() override;
41     std::shared_ptr<AVSharedMemory> FetchArtPicture() override;
42     std::shared_ptr<AVSharedMemory> FetchFrameAtTime(int64_t timeUs,
43         int32_t option, const OutputConfiguration &param) override;
44     std::shared_ptr<AVBuffer> FetchFrameYuv(int64_t timeUs,
45         int32_t option, const OutputConfiguration &param) override;
46     void Release() override;
47     int32_t DestroyStub() override;
48     int32_t SetHelperCallback() override;
49     int32_t SetListenerObject(const sptr<IRemoteObject> &object) override;
50     int32_t GetTimeByFrameIndex(uint32_t index, uint64_t &time) override;
51     int32_t GetFrameIndexByTime(uint64_t time, uint32_t &index) override;
52 private:
53     AVMetadataHelperServiceStub();
54     int32_t Init();
55     int32_t SetUriSource(MessageParcel &data, MessageParcel &reply);
56     int32_t SetFdSource(MessageParcel &data, MessageParcel &reply);
57     int32_t SetMediaDataSource(MessageParcel &data, MessageParcel &reply);
58     int32_t ResolveMetadata(MessageParcel &data, MessageParcel &reply);
59     int32_t ResolveMetadataMap(MessageParcel &data, MessageParcel &reply);
60     int32_t GetAVMetadata(MessageParcel &data, MessageParcel &reply);
61     int32_t FetchArtPicture(MessageParcel &data, MessageParcel &reply);
62     int32_t FetchFrameAtTime(MessageParcel &data, MessageParcel &reply);
63     int32_t FetchFrameYuv(MessageParcel &data, MessageParcel &reply);
64     int32_t Release(MessageParcel &data, MessageParcel &reply);
65     int32_t DestroyStub(MessageParcel &data, MessageParcel &reply);
66     int32_t SetHelperCallback(MessageParcel &data, MessageParcel &reply);
67     int32_t SetListenerObject(MessageParcel &data, MessageParcel &reply);
68     int32_t GetTimeByFrameIndex(MessageParcel &data, MessageParcel &reply);
69     int32_t GetFrameIndexByTime(MessageParcel &data, MessageParcel &reply);
70 
71     std::mutex mutex_;
72     std::shared_ptr<IAVMetadataHelperService> avMetadateHelperServer_ = nullptr;
73     std::map<uint32_t, AVMetadataHelperStubFunc> avMetadataHelperFuncs_;
74     std::shared_ptr<HelperCallback> helperCallback_ = nullptr;
75 };
76 } // namespace Media
77 } // namespace OHOS
78 #endif // AVMETADATAHELPER_SERVICE_STUB_H
79