1 /* 2 * Copyright (c) 2024 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 #ifndef OHOS_OHAVSESSION_METADATA_H 16 #define OHOS_OHAVSESSION_METADATA_H 17 18 #include <string> 19 #include "native_avmetadata.h" 20 #include "native_avsession_errors.h" 21 #include "avsession_pixel_map_adapter.h" 22 #include "avmeta_data.h" 23 #include "curl/curl.h" 24 #include "image_source.h" 25 #include "pixel_map.h" 26 27 namespace OHOS::AVSession { 28 class OHAVMetadataBuilder { 29 public: 30 AVMetadata_Result SetTitle(const std::string &title); 31 AVMetadata_Result SetArtist(const std::string &artist); 32 AVMetadata_Result SetAuthor(const std::string &author); 33 AVMetadata_Result SetAlbum(const std::string &album); 34 AVMetadata_Result SetWriter(const std::string &writer); 35 AVMetadata_Result SetComposer(const std::string &composer); 36 AVMetadata_Result SetDuration(int64_t duration); 37 AVMetadata_Result SetMediaImageUri(const std::string &mediaImageUri); 38 AVMetadata_Result SetSubtitle(const std::string &subtitle); 39 AVMetadata_Result SetDescription(const std::string &description); 40 AVMetadata_Result SetLyric(const std::string &lyric); 41 AVMetadata_Result SetAssetId(const std::string &assetId); 42 AVMetadata_Result SetSkipIntervals(AVMetadata_SkipIntervals intervals); 43 AVMetadata_Result SetDisplayTags(int32_t tags); 44 AVMetadata_Result GenerateAVMetadata(OH_AVMetadata** avMetadata); 45 46 private: 47 static bool CurlSetRequestOptions(std::vector<std::uint8_t>& imgBuffer, const std::string uri); 48 static bool DoDownloadInCommon(std::shared_ptr<Media::PixelMap>& pixelMap, const std::string uri); 49 static int32_t DoDownload(AVMetaData& meta, const std::string uri); 50 static size_t WriteCallback(std::uint8_t *ptr, size_t size, size_t nmemb, std::vector<std::uint8_t> *imgBuffer); 51 std::string title_ = ""; 52 std::string artist_ = ""; 53 std::string author_ = ""; 54 std::string album_ = ""; 55 std::string writer_ = ""; 56 std::string composer_ = ""; 57 int64_t duration_ = 0; 58 std::string mediaImageUri_ = ""; 59 std::string subtitle_ = ""; 60 std::string description_ = ""; 61 std::string lyric_ = ""; 62 std::string assetId_ = ""; 63 AVMetadata_SkipIntervals intervals_ = SECONDS_15; 64 int32_t tags_ = 0; 65 static constexpr size_t TIME_OUT_SECOND = 5; 66 static constexpr int HTTP_ERROR_CODE = 400; 67 }; 68 } 69 70 #endif // OHOS_OHAVSESSION_METADATA_H