• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "media_log.h"
17 #include "data_center/impl/data_center_impl.h"
18 #include "data_center/asset/video_asset.h"
19 #include "data_center/asset/asset_factory.h"
20 #include "data_center/effect/effect_factory.h"
21 
22 namespace OHOS {
23 namespace Media {
24 
25 namespace {
26 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_VIDEOEDITOR, "DataCenter"};
27 }
28 
29 constexpr uint64_t INPUT_VIDEO_COUNT_THRESHOLD = 1;   // Currently, only one input video is supported.
30 
Create()31 std::shared_ptr<IDataCenter> IDataCenter::Create()
32 {
33     return std::make_shared<DataCenterImpl>();
34 }
35 
AppendVideo(int fileFd,const std::string & effectDescription)36 VEFError DataCenterImpl::AppendVideo(int fileFd, const std::string& effectDescription)
37 {
38     std::unique_lock<std::shared_mutex> lock(dataLock_);
39     if (assetList_.size() >= INPUT_VIDEO_COUNT_THRESHOLD) {
40         MEDIA_LOGE("create asset for video[%{public}d] failed", fileFd);
41         return VEFError::ERR_INPUT_VIDEO_COUNT_LIMITED;
42     }
43     auto asset = AssetFactory::CreateAsset(AssetType::VIDEO, fileFd);
44     if (asset == nullptr) {
45         MEDIA_LOGE("create asset for video[%{public}d] failed", fileFd);
46         return VEFError::ERR_INTERNAL_ERROR;
47     }
48     auto effect = EffectFactory::CreateEffect(effectDescription);
49     if (effect == nullptr) {
50         MEDIA_LOGE("create effect[%{public}s] failed.", effectDescription.c_str());
51         return VEFError::ERR_INTERNAL_ERROR;
52     }
53     if (asset->GetType() != AssetType::VIDEO) {
54         MEDIA_LOGE("asset[id = %{public}" PRIu64 "] is not video asset.", asset->GetId());
55         return VEFError::ERR_INTERNAL_ERROR;
56     }
57     auto videoAsset = std::static_pointer_cast<VideoAsset>(asset);
58     videoAsset->ApplyEffect(effect);
59     assetList_.push_back(asset);
60     MEDIA_LOGI("create asset for video[%{public}d] success.", fileFd);
61     return VEFError::ERR_OK;
62 }
63 
GetAssetList() const64 std::vector<const std::shared_ptr<Asset>> DataCenterImpl::GetAssetList() const
65 {
66     std::shared_lock<std::shared_mutex> lock(dataLock_);
67     std::vector<const std::shared_ptr<Asset>> result;
68     std::copy(assetList_.begin(), assetList_.end(), std::back_inserter(result));
69     return result;
70 }
71 
72 } // namespace Media
73 } // namespace OHOS
74