180922886Sopenharmony_ci/* 280922886Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 480922886Sopenharmony_ci * you may not use this file except in compliance with the License. 580922886Sopenharmony_ci * You may obtain a copy of the License at 680922886Sopenharmony_ci * 780922886Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 880922886Sopenharmony_ci * 980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1280922886Sopenharmony_ci * See the License for the specific language governing permissions and 1380922886Sopenharmony_ci * limitations under the License. 1480922886Sopenharmony_ci */ 1580922886Sopenharmony_ci#include "OHAVMetadataBuilder.h" 1680922886Sopenharmony_ci#include "avsession_log.h" 1780922886Sopenharmony_ci 1880922886Sopenharmony_ciusing namespace OHOS::AVSession; 1980922886Sopenharmony_ci 2080922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetTitle(const std::string &title) 2180922886Sopenharmony_ci{ 2280922886Sopenharmony_ci title_ = title; 2380922886Sopenharmony_ci return AVMETADATA_SUCCESS; 2480922886Sopenharmony_ci} 2580922886Sopenharmony_ci 2680922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetArtist(const std::string &artist) 2780922886Sopenharmony_ci{ 2880922886Sopenharmony_ci artist_ = artist; 2980922886Sopenharmony_ci return AVMETADATA_SUCCESS; 3080922886Sopenharmony_ci} 3180922886Sopenharmony_ci 3280922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetAuthor(const std::string &author) 3380922886Sopenharmony_ci{ 3480922886Sopenharmony_ci author_ = author; 3580922886Sopenharmony_ci return AVMETADATA_SUCCESS; 3680922886Sopenharmony_ci} 3780922886Sopenharmony_ci 3880922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetAlbum(const std::string &album) 3980922886Sopenharmony_ci{ 4080922886Sopenharmony_ci album_ = album; 4180922886Sopenharmony_ci return AVMETADATA_SUCCESS; 4280922886Sopenharmony_ci} 4380922886Sopenharmony_ci 4480922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetWriter(const std::string &writer) 4580922886Sopenharmony_ci{ 4680922886Sopenharmony_ci writer_ = writer; 4780922886Sopenharmony_ci return AVMETADATA_SUCCESS; 4880922886Sopenharmony_ci} 4980922886Sopenharmony_ci 5080922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetComposer(const std::string &composer) 5180922886Sopenharmony_ci{ 5280922886Sopenharmony_ci composer_ = composer; 5380922886Sopenharmony_ci return AVMETADATA_SUCCESS; 5480922886Sopenharmony_ci} 5580922886Sopenharmony_ci 5680922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetDuration(int64_t duration) 5780922886Sopenharmony_ci{ 5880922886Sopenharmony_ci duration_ = duration; 5980922886Sopenharmony_ci return AVMETADATA_SUCCESS; 6080922886Sopenharmony_ci} 6180922886Sopenharmony_ci 6280922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetMediaImageUri(const std::string &mediaImageUri) 6380922886Sopenharmony_ci{ 6480922886Sopenharmony_ci mediaImageUri_ = mediaImageUri; 6580922886Sopenharmony_ci return AVMETADATA_SUCCESS; 6680922886Sopenharmony_ci} 6780922886Sopenharmony_ci 6880922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetSubtitle(const std::string &subtitle) 6980922886Sopenharmony_ci{ 7080922886Sopenharmony_ci subtitle_ = subtitle; 7180922886Sopenharmony_ci return AVMETADATA_SUCCESS; 7280922886Sopenharmony_ci} 7380922886Sopenharmony_ci 7480922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetDescription(const std::string &description) 7580922886Sopenharmony_ci{ 7680922886Sopenharmony_ci description_ = description; 7780922886Sopenharmony_ci return AVMETADATA_SUCCESS; 7880922886Sopenharmony_ci} 7980922886Sopenharmony_ci 8080922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetLyric(const std::string &lyric) 8180922886Sopenharmony_ci{ 8280922886Sopenharmony_ci lyric_ = lyric; 8380922886Sopenharmony_ci return AVMETADATA_SUCCESS; 8480922886Sopenharmony_ci} 8580922886Sopenharmony_ci 8680922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetAssetId(const std::string &assetId) 8780922886Sopenharmony_ci{ 8880922886Sopenharmony_ci assetId_ = assetId; 8980922886Sopenharmony_ci return AVMETADATA_SUCCESS; 9080922886Sopenharmony_ci} 9180922886Sopenharmony_ci 9280922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetSkipIntervals(AVMetadata_SkipIntervals intervals) 9380922886Sopenharmony_ci{ 9480922886Sopenharmony_ci switch (intervals) { 9580922886Sopenharmony_ci case SECONDS_10: 9680922886Sopenharmony_ci case SECONDS_15: 9780922886Sopenharmony_ci case SECONDS_30: 9880922886Sopenharmony_ci intervals_ = intervals; 9980922886Sopenharmony_ci return AVMETADATA_SUCCESS; 10080922886Sopenharmony_ci default: 10180922886Sopenharmony_ci SLOGE("Failed to set skip intervals: Invalid skip intervals value: %d", intervals); 10280922886Sopenharmony_ci return AVMETADATA_ERROR_INVALID_PARAM; 10380922886Sopenharmony_ci } 10480922886Sopenharmony_ci} 10580922886Sopenharmony_ci 10680922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::SetDisplayTags(int32_t tags) 10780922886Sopenharmony_ci{ 10880922886Sopenharmony_ci tags_ = tags; 10980922886Sopenharmony_ci return AVMETADATA_SUCCESS; 11080922886Sopenharmony_ci} 11180922886Sopenharmony_ci 11280922886Sopenharmony_cisize_t OHAVMetadataBuilder::WriteCallback(std::uint8_t *ptr, size_t size, size_t nmemb, 11380922886Sopenharmony_ci std::vector<std::uint8_t> *imgBuffer) 11480922886Sopenharmony_ci{ 11580922886Sopenharmony_ci size_t realsize = size * nmemb; 11680922886Sopenharmony_ci imgBuffer->reserve(realsize + imgBuffer->capacity()); 11780922886Sopenharmony_ci for (size_t i = 0; i < realsize; i++) { 11880922886Sopenharmony_ci imgBuffer->push_back(ptr[i]); 11980922886Sopenharmony_ci } 12080922886Sopenharmony_ci return realsize; 12180922886Sopenharmony_ci} 12280922886Sopenharmony_ci 12380922886Sopenharmony_cibool OHAVMetadataBuilder::CurlSetRequestOptions(std::vector<std::uint8_t>& imgBuffer, const std::string uri) 12480922886Sopenharmony_ci{ 12580922886Sopenharmony_ci CURL *easyHandle_ = curl_easy_init(); 12680922886Sopenharmony_ci if (easyHandle_) { 12780922886Sopenharmony_ci // set request options 12880922886Sopenharmony_ci curl_easy_setopt(easyHandle_, CURLOPT_URL, uri.c_str()); 12980922886Sopenharmony_ci curl_easy_setopt(easyHandle_, CURLOPT_CONNECTTIMEOUT, OHAVMetadataBuilder::TIME_OUT_SECOND); 13080922886Sopenharmony_ci curl_easy_setopt(easyHandle_, CURLOPT_SSL_VERIFYPEER, 0L); 13180922886Sopenharmony_ci curl_easy_setopt(easyHandle_, CURLOPT_SSL_VERIFYHOST, 0L); 13280922886Sopenharmony_ci curl_easy_setopt(easyHandle_, CURLOPT_CAINFO, "/etc/ssl/certs/" "cacert.pem"); 13380922886Sopenharmony_ci curl_easy_setopt(easyHandle_, CURLOPT_HTTPGET, 1L); 13480922886Sopenharmony_ci curl_easy_setopt(easyHandle_, CURLOPT_WRITEFUNCTION, OHAVMetadataBuilder::WriteCallback); 13580922886Sopenharmony_ci curl_easy_setopt(easyHandle_, CURLOPT_WRITEDATA, &imgBuffer); 13680922886Sopenharmony_ci 13780922886Sopenharmony_ci // perform request 13880922886Sopenharmony_ci CURLcode res = curl_easy_perform(easyHandle_); 13980922886Sopenharmony_ci if (res != CURLE_OK) { 14080922886Sopenharmony_ci SLOGI("DoDownload curl easy_perform failure: %{public}s\n", curl_easy_strerror(res)); 14180922886Sopenharmony_ci curl_easy_cleanup(easyHandle_); 14280922886Sopenharmony_ci easyHandle_ = nullptr; 14380922886Sopenharmony_ci return false; 14480922886Sopenharmony_ci } else { 14580922886Sopenharmony_ci int64_t httpCode = 0; 14680922886Sopenharmony_ci curl_easy_getinfo(easyHandle_, CURLINFO_RESPONSE_CODE, &httpCode); 14780922886Sopenharmony_ci SLOGI("DoDownload Http result " "%{public}" PRId64, httpCode); 14880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(httpCode < OHAVMetadataBuilder::HTTP_ERROR_CODE, false, "recv Http ERROR"); 14980922886Sopenharmony_ci curl_easy_cleanup(easyHandle_); 15080922886Sopenharmony_ci easyHandle_ = nullptr; 15180922886Sopenharmony_ci return true; 15280922886Sopenharmony_ci } 15380922886Sopenharmony_ci } 15480922886Sopenharmony_ci return false; 15580922886Sopenharmony_ci} 15680922886Sopenharmony_ci 15780922886Sopenharmony_cibool OHAVMetadataBuilder::DoDownloadInCommon(std::shared_ptr<Media::PixelMap>& pixelMap, const std::string uri) 15880922886Sopenharmony_ci{ 15980922886Sopenharmony_ci std::vector<std::uint8_t> imgBuffer(0); 16080922886Sopenharmony_ci if (CurlSetRequestOptions(imgBuffer, uri) == true) { 16180922886Sopenharmony_ci std::uint8_t* buffer = (std::uint8_t*) calloc(imgBuffer.size(), sizeof(uint8_t)); 16280922886Sopenharmony_ci if (buffer == nullptr) { 16380922886Sopenharmony_ci SLOGE("buffer malloc fail"); 16480922886Sopenharmony_ci free(buffer); 16580922886Sopenharmony_ci return false; 16680922886Sopenharmony_ci } 16780922886Sopenharmony_ci std::copy(imgBuffer.begin(), imgBuffer.end(), buffer); 16880922886Sopenharmony_ci uint32_t errorCode = 0; 16980922886Sopenharmony_ci Media::SourceOptions opts; 17080922886Sopenharmony_ci SLOGD("DoDownload get size %{public}d", static_cast<int>(imgBuffer.size())); 17180922886Sopenharmony_ci auto imageSource = Media::ImageSource::CreateImageSource(buffer, imgBuffer.size(), opts, errorCode); 17280922886Sopenharmony_ci free(buffer); 17380922886Sopenharmony_ci if (errorCode || !imageSource) { 17480922886Sopenharmony_ci SLOGE("DoDownload create imageSource fail: %{public}u", errorCode); 17580922886Sopenharmony_ci return false; 17680922886Sopenharmony_ci } 17780922886Sopenharmony_ci Media::DecodeOptions decodeOpts; 17880922886Sopenharmony_ci pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode); 17980922886Sopenharmony_ci if (errorCode || pixelMap == nullptr) { 18080922886Sopenharmony_ci SLOGE("DoDownload creatPix fail: %{public}u, %{public}d", errorCode, static_cast<int>(pixelMap != nullptr)); 18180922886Sopenharmony_ci return false; 18280922886Sopenharmony_ci } 18380922886Sopenharmony_ci return true; 18480922886Sopenharmony_ci } 18580922886Sopenharmony_ci return false; 18680922886Sopenharmony_ci} 18780922886Sopenharmony_ci 18880922886Sopenharmony_ciint32_t OHAVMetadataBuilder::DoDownload(AVMetaData& metadata, const std::string uri) 18980922886Sopenharmony_ci{ 19080922886Sopenharmony_ci std::shared_ptr<Media::PixelMap> pixelMap = nullptr; 19180922886Sopenharmony_ci bool ret = OHAVMetadataBuilder::DoDownloadInCommon(pixelMap, uri); 19280922886Sopenharmony_ci if (ret && pixelMap != nullptr) { 19380922886Sopenharmony_ci SLOGI("DoDownload success"); 19480922886Sopenharmony_ci metadata.SetMediaImage(AVSessionPixelMapAdapter::ConvertToInner(pixelMap)); 19580922886Sopenharmony_ci return AV_SESSION_ERR_SUCCESS; 19680922886Sopenharmony_ci } 19780922886Sopenharmony_ci 19880922886Sopenharmony_ci return AV_SESSION_ERR_SERVICE_EXCEPTION; 19980922886Sopenharmony_ci} 20080922886Sopenharmony_ci 20180922886Sopenharmony_ciAVMetadata_Result OHAVMetadataBuilder::GenerateAVMetadata(OH_AVMetadata** avMetadata) 20280922886Sopenharmony_ci{ 20380922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(avMetadata != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "avMetadata is null"); 20480922886Sopenharmony_ci 20580922886Sopenharmony_ci AVMetaData* metadata = new AVMetaData(); 20680922886Sopenharmony_ci if (metadata == nullptr) { 20780922886Sopenharmony_ci SLOGE("Failed to allocate memory for AVMetaData"); 20880922886Sopenharmony_ci *avMetadata = nullptr; 20980922886Sopenharmony_ci return AVMETADATA_ERROR_NO_MEMORY; 21080922886Sopenharmony_ci } 21180922886Sopenharmony_ci 21280922886Sopenharmony_ci switch (intervals_) { 21380922886Sopenharmony_ci case SECONDS_10: 21480922886Sopenharmony_ci metadata->SetSkipIntervals(AVMetaData::SECONDS_10); 21580922886Sopenharmony_ci break; 21680922886Sopenharmony_ci case SECONDS_15: 21780922886Sopenharmony_ci metadata->SetSkipIntervals(AVMetaData::SECONDS_15); 21880922886Sopenharmony_ci break; 21980922886Sopenharmony_ci case SECONDS_30: 22080922886Sopenharmony_ci metadata->SetSkipIntervals(AVMetaData::SECONDS_30); 22180922886Sopenharmony_ci break; 22280922886Sopenharmony_ci default: 22380922886Sopenharmony_ci SLOGE("Failed to generate avMetadata: Unsupported skip intervals: %d", intervals_); 22480922886Sopenharmony_ci delete metadata; 22580922886Sopenharmony_ci metadata = nullptr; 22680922886Sopenharmony_ci *avMetadata = nullptr; 22780922886Sopenharmony_ci return AVMETADATA_ERROR_INVALID_PARAM; 22880922886Sopenharmony_ci } 22980922886Sopenharmony_ci 23080922886Sopenharmony_ci metadata->SetTitle(title_); 23180922886Sopenharmony_ci metadata->SetArtist(artist_); 23280922886Sopenharmony_ci metadata->SetAuthor(author_); 23380922886Sopenharmony_ci metadata->SetAlbum(album_); 23480922886Sopenharmony_ci metadata->SetWriter(writer_); 23580922886Sopenharmony_ci metadata->SetComposer(composer_); 23680922886Sopenharmony_ci metadata->SetDuration(duration_); 23780922886Sopenharmony_ci metadata->SetMediaImageUri(mediaImageUri_); 23880922886Sopenharmony_ci metadata->SetSubTitle(subtitle_); 23980922886Sopenharmony_ci metadata->SetDescription(description_); 24080922886Sopenharmony_ci metadata->SetLyric(lyric_); 24180922886Sopenharmony_ci metadata->SetAssetId(assetId_); 24280922886Sopenharmony_ci metadata->SetDisplayTags(tags_); 24380922886Sopenharmony_ci 24480922886Sopenharmony_ci DoDownload(*metadata, mediaImageUri_); 24580922886Sopenharmony_ci 24680922886Sopenharmony_ci *avMetadata = reinterpret_cast<OH_AVMetadata*>(metadata); 24780922886Sopenharmony_ci 24880922886Sopenharmony_ci return AVMETADATA_SUCCESS; 24980922886Sopenharmony_ci} 25080922886Sopenharmony_ci 25180922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_Create(OH_AVMetadataBuilder** builder) 25280922886Sopenharmony_ci{ 25380922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 25480922886Sopenharmony_ci 25580922886Sopenharmony_ci OHAVMetadataBuilder* metadata = new OHAVMetadataBuilder(); 25680922886Sopenharmony_ci if (metadata == nullptr) { 25780922886Sopenharmony_ci SLOGE("Failed to allocate memory for OHAVMetadataBuilder"); 25880922886Sopenharmony_ci return AVMETADATA_ERROR_NO_MEMORY; 25980922886Sopenharmony_ci } 26080922886Sopenharmony_ci 26180922886Sopenharmony_ci *builder = reinterpret_cast<OH_AVMetadataBuilder*>(metadata); 26280922886Sopenharmony_ci return AVMETADATA_SUCCESS; 26380922886Sopenharmony_ci} 26480922886Sopenharmony_ci 26580922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_Destroy(OH_AVMetadataBuilder* builder) 26680922886Sopenharmony_ci{ 26780922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 26880922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 26980922886Sopenharmony_ci delete metadata; 27080922886Sopenharmony_ci metadata = nullptr; 27180922886Sopenharmony_ci return AVMETADATA_SUCCESS; 27280922886Sopenharmony_ci} 27380922886Sopenharmony_ci 27480922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetTitle(OH_AVMetadataBuilder* builder, const char* title) 27580922886Sopenharmony_ci{ 27680922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 27780922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(title != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "title is null"); 27880922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 27980922886Sopenharmony_ci return metadata->SetTitle(title); 28080922886Sopenharmony_ci} 28180922886Sopenharmony_ci 28280922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetArtist(OH_AVMetadataBuilder* builder, const char* artist) 28380922886Sopenharmony_ci{ 28480922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 28580922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(artist != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "artist is null"); 28680922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 28780922886Sopenharmony_ci return metadata->SetArtist(artist); 28880922886Sopenharmony_ci} 28980922886Sopenharmony_ci 29080922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetAuthor(OH_AVMetadataBuilder* builder, const char* author) 29180922886Sopenharmony_ci{ 29280922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 29380922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(author != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "author is null"); 29480922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 29580922886Sopenharmony_ci return metadata->SetAuthor(author); 29680922886Sopenharmony_ci} 29780922886Sopenharmony_ci 29880922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetAlbum(OH_AVMetadataBuilder* builder, const char* album) 29980922886Sopenharmony_ci{ 30080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 30180922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(album != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "album is null"); 30280922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 30380922886Sopenharmony_ci return metadata->SetAlbum(album); 30480922886Sopenharmony_ci} 30580922886Sopenharmony_ci 30680922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetWriter(OH_AVMetadataBuilder* builder, const char* writer) 30780922886Sopenharmony_ci{ 30880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 30980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(writer != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "writer is null"); 31080922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 31180922886Sopenharmony_ci return metadata->SetWriter(writer); 31280922886Sopenharmony_ci} 31380922886Sopenharmony_ci 31480922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetComposer(OH_AVMetadataBuilder* builder, const char* composer) 31580922886Sopenharmony_ci{ 31680922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 31780922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(composer != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "composer is null"); 31880922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 31980922886Sopenharmony_ci return metadata->SetComposer(composer); 32080922886Sopenharmony_ci} 32180922886Sopenharmony_ci 32280922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetDuration(OH_AVMetadataBuilder* builder, int64_t duration) 32380922886Sopenharmony_ci{ 32480922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 32580922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 32680922886Sopenharmony_ci return metadata->SetDuration(duration); 32780922886Sopenharmony_ci} 32880922886Sopenharmony_ci 32980922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetMediaImageUri(OH_AVMetadataBuilder* builder, const char* mediaImageUri) 33080922886Sopenharmony_ci{ 33180922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 33280922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(mediaImageUri != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "mediaImageUri is null"); 33380922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 33480922886Sopenharmony_ci return metadata->SetMediaImageUri(mediaImageUri); 33580922886Sopenharmony_ci} 33680922886Sopenharmony_ci 33780922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetSubtitle(OH_AVMetadataBuilder* builder, const char* subtitle) 33880922886Sopenharmony_ci{ 33980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 34080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(subtitle != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "subtitle is null"); 34180922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 34280922886Sopenharmony_ci return metadata->SetSubtitle(subtitle); 34380922886Sopenharmony_ci} 34480922886Sopenharmony_ci 34580922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetDescription(OH_AVMetadataBuilder* builder, const char* description) 34680922886Sopenharmony_ci{ 34780922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 34880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(description != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "description is null"); 34980922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 35080922886Sopenharmony_ci return metadata->SetDescription(description); 35180922886Sopenharmony_ci} 35280922886Sopenharmony_ci 35380922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetLyric(OH_AVMetadataBuilder* builder, const char* lyric) 35480922886Sopenharmony_ci{ 35580922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 35680922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(lyric != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "lyric is null"); 35780922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 35880922886Sopenharmony_ci return metadata->SetLyric(lyric); 35980922886Sopenharmony_ci} 36080922886Sopenharmony_ci 36180922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetAssetId(OH_AVMetadataBuilder* builder, const char* assetId) 36280922886Sopenharmony_ci{ 36380922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 36480922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(assetId != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "assetId is null"); 36580922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 36680922886Sopenharmony_ci return metadata->SetAssetId(assetId); 36780922886Sopenharmony_ci} 36880922886Sopenharmony_ci 36980922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetSkipIntervals(OH_AVMetadataBuilder* builder, 37080922886Sopenharmony_ci AVMetadata_SkipIntervals intervals) 37180922886Sopenharmony_ci{ 37280922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 37380922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 37480922886Sopenharmony_ci return metadata->SetSkipIntervals(intervals); 37580922886Sopenharmony_ci} 37680922886Sopenharmony_ci 37780922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_SetDisplayTags(OH_AVMetadataBuilder* builder, int32_t tags) 37880922886Sopenharmony_ci{ 37980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 38080922886Sopenharmony_ci if (tags != AVSESSION_DISPLAYTAG_AUDIO_VIVID) { 38180922886Sopenharmony_ci return AVMETADATA_ERROR_INVALID_PARAM; 38280922886Sopenharmony_ci } 38380922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 38480922886Sopenharmony_ci return metadata->SetDisplayTags(tags); 38580922886Sopenharmony_ci} 38680922886Sopenharmony_ci 38780922886Sopenharmony_ciAVMetadata_Result OH_AVMetadataBuilder_GenerateAVMetadata(OH_AVMetadataBuilder* builder, 38880922886Sopenharmony_ci OH_AVMetadata** avMetadata) 38980922886Sopenharmony_ci{ 39080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(builder != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "builder is null"); 39180922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(avMetadata != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "avMetadata is null"); 39280922886Sopenharmony_ci OHAVMetadataBuilder* metadata = reinterpret_cast<OHAVMetadataBuilder*>(builder); 39380922886Sopenharmony_ci return metadata->GenerateAVMetadata(avMetadata); 39480922886Sopenharmony_ci} 39580922886Sopenharmony_ci 39680922886Sopenharmony_ciAVMetadata_Result OH_AVMetadata_Destroy(OH_AVMetadata* avMetadata) 39780922886Sopenharmony_ci{ 39880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(avMetadata != nullptr, AVMETADATA_ERROR_INVALID_PARAM, "avMetadata is null"); 39980922886Sopenharmony_ci AVMetaData* metadata = reinterpret_cast<AVMetaData*>(avMetadata); 40080922886Sopenharmony_ci delete metadata; 40180922886Sopenharmony_ci metadata = nullptr; 40280922886Sopenharmony_ci return AVMETADATA_SUCCESS; 40380922886Sopenharmony_ci}