• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SERVER_H
17 #define AVMETADATAHELPER_SERVICE_SERVER_H
18 
19 #include <mutex>
20 #include "i_avmetadatahelper_service.h"
21 #include "i_avmetadatahelper_engine.h"
22 #include "nocopyable.h"
23 #include "uri_helper.h"
24 #include "task_queue.h"
25 
26 namespace OHOS {
27 namespace Media {
28 class AVMetadataHelperServer : public IAVMetadataHelperService, public NoCopyable {
29 public:
30     static std::shared_ptr<IAVMetadataHelperService> Create();
31     AVMetadataHelperServer();
32     virtual ~AVMetadataHelperServer();
33 
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     std::shared_ptr<AVBuffer> FetchFrameYuv(int64_t timeUs,
44         int32_t option, const OutputConfiguration &param) override;
45     void Release() override;
46     int32_t SetHelperCallback(const std::shared_ptr<HelperCallback> &callback) override;
47     int32_t GetTimeByFrameIndex(uint32_t index, uint64_t &time) override;
48     int32_t GetFrameIndexByTime(uint64_t time, uint32_t &index) override;
49 
50 private:
51     const std::string &GetStatusDescription(int32_t status);
52     void ChangeState(const HelperStates state);
53     void NotifyErrorCallback(int32_t code, const std::string msg);
54     void NotifyInfoCallback(HelperOnInfoType type, int32_t extra);
55     int32_t InitEngine(const std::string &uri);
56 
57     int32_t appUid_;
58     std::shared_ptr<IAVMetadataHelperEngine> avMetadataHelperEngine_ = nullptr;
59     std::mutex mutex_;
60     std::unique_ptr<UriHelper> uriHelper_;
61     TaskQueue taskQue_;
62     std::shared_ptr<IMediaDataSource> dataSrc_ = nullptr;
63     bool isLiveStream_ = false;
64     struct ConfigInfo {
65         std::atomic<bool> looping = false;
66         float leftVolume = INVALID_VALUE;
67         float rightVolume = INVALID_VALUE;
68         std::string url;
69     } config_;
70     static constexpr float INVALID_VALUE = 2.0f;
71 
72     std::shared_ptr<HelperCallback> helperCb_ = nullptr;
73     HelperStates currState_ = HelperStates::HELPER_IDLE;
74     std::mutex mutexCb_;
75 };
76 } // namespace Media
77 } // namespace OHOS
78 #endif // AVMETADATAHELPER_SERVICE_SERVER_H
79