• 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 AVMETADATAHELPER_HST_IMPL_H
17 #define AVMETADATAHELPER_HST_IMPL_H
18 
19 #include <condition_variable>
20 #include <mutex>
21 
22 #include "avmetadata_collector.h"
23 #include "av_thumbnail_generator.h"
24 #include "buffer/avsharedmemorybase.h"
25 #include "common/status.h"
26 #include "i_avmetadatahelper_engine.h"
27 #include "i_avmetadatahelper_service.h"
28 #include "media_demuxer.h"
29 #include "nocopyable.h"
30 #include "interrupt_monitor.h"
31 
32 namespace OHOS {
33 namespace Media {
34 class TimeAndIndexConversion;
35 class AVMetadataHelperImpl : public IAVMetadataHelperEngine,
36                              public std::enable_shared_from_this<AVMetadataHelperImpl>,
37                              public NoCopyable {
38 public:
39     AVMetadataHelperImpl(int32_t appUid, int32_t appPid, uint32_t appTokenId, std::string appName);
40     ~AVMetadataHelperImpl();
41 
42     void OnError(MediaAVCodec::AVCodecErrorType errorType, int32_t errorCode);
43     int32_t SetSource(const std::string &uri, int32_t usage) override;
44     int32_t SetSource(const std::shared_ptr<IMediaDataSource> &dataSrc) override;
45     int32_t SetAVMetadataCaller(AVMetadataCaller caller) override;
46     int32_t SetUrlSource(const std::string &uri, const std::map<std::string, std::string> &header) override;
47     std::string ResolveMetadata(int32_t key) override;
48     std::unordered_map<int32_t, std::string> ResolveMetadata() override;
49     std::shared_ptr<Meta> GetAVMetadata() override;
50     std::shared_ptr<AVSharedMemory> FetchFrameAtTime(
51         int64_t timeUs, int32_t option, const OutputConfiguration &param) override;
52     std::shared_ptr<AVBuffer> FetchFrameYuv(
53         int64_t timeUs, int32_t option, const OutputConfiguration &param) override;
54     std::shared_ptr<AVSharedMemory> FetchArtPicture() override;
55     int32_t GetTimeByFrameIndex(uint32_t index, uint64_t &time) override;
56     int32_t GetFrameIndexByTime(uint64_t time, uint32_t &index) override;
57     void SetInterruptState(bool isInterruptNeeded) override;
58 
59 private:
60     std::shared_ptr<OHOS::Media::MediaDemuxer> mediaDemuxer_;
61     std::shared_ptr<AVMetaDataCollector> metadataCollector_;
62     std::shared_ptr<AVThumbnailGenerator> thumbnailGenerator_;
63     std::unordered_map<int32_t, std::string> collectedMeta_;
64     std::shared_ptr<AVSharedMemory> collectedArtPicture_;
65     std::shared_ptr<AVSharedMemoryBase> fetchedFrameAtTime_;
66     std::shared_ptr<OHOS::Media::TimeAndIndexConversion> conversion_ { nullptr };
67     std::shared_ptr<InterruptMonitor> interruptMonitor_ {nullptr};
68     std::atomic_bool stopProcessing_{ false };
69     std::atomic_bool isForFrameConvert_{ false };
70 
71     Status SetSourceInternel(const std::string &uri, bool isForFrameConvert);
72     Status SetSourceInternel(const std::shared_ptr<IMediaDataSource> &dataSrc);
73     Status SetSourceInternel(const std::string &uri, const std::map<std::string, std::string> &header);
74     Status SetSourceForFrameConvert(const std::string &uri);
75     Status InitMetadataCollector();
76     Status InitThumbnailGenerator();
77     int32_t GetTimeForFrameConvert(uint32_t index, uint64_t &time);
78     int32_t GetIndexForFrameConvert(uint64_t time, uint32_t &index);
79     int64_t GetDurationMs();
80 
81     void Reset();
82     void Destroy();
83     std::string groupId_;
84     std::atomic<bool> isInterruptNeeded_ = false;
85     int32_t appUid_{0};
86     int32_t appPid_{0};
87     uint32_t appTokenId_{0};
88     std::string appName_;
89     AVMetadataCaller metadataCaller_ = AVMetadataCaller::AV_META_DATA_DEFAULT;
90 };
91 }  // namespace Media
92 }  // namespace OHOS
93 #endif  // AVMETADATAHELPER_HST_IMPL_H