• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 "track_factory.h"
17 
18 #include "basic_definitions.h"
19 #include "dp_log.h"
20 
21 namespace OHOS {
22 namespace CameraStandard {
23 namespace DeferredProcessing {
24 namespace {
25     static const std::unordered_set<Media::Plugins::MediaType> TRACK_TYPES = {
26         Media::Plugins::MediaType::AUDIO,
27         Media::Plugins::MediaType::VIDEO,
28         Media::Plugins::MediaType::TIMEDMETA
29     };
30 }
31 
TrackFactory()32 TrackFactory::TrackFactory()
33 {
34     DP_DEBUG_LOG("entered.");
35 }
36 
~TrackFactory()37 TrackFactory::~TrackFactory()
38 {
39     DP_DEBUG_LOG("entered.");
40 }
41 
CreateTrack(const std::shared_ptr<AVSource> & source,int32_t trackIndex)42 std::shared_ptr<Track> TrackFactory::CreateTrack(const std::shared_ptr<AVSource>& source, int32_t trackIndex)
43 {
44     DP_CHECK_ERROR_RETURN_RET_LOG(source == nullptr, nullptr, "AVSource is nullptr.");
45     Format trackFormat;
46     int32_t trackType = -1;
47     auto ret = source->GetTrackFormat(trackFormat, trackIndex);
48     DP_CHECK_ERROR_RETURN_RET_LOG(ret != static_cast<int32_t>(OK), nullptr, "Get track format failed.");
49     DP_CHECK_ERROR_RETURN_RET_LOG(!trackFormat.GetIntValue(Media::Tag::MEDIA_TYPE, trackType),
50         nullptr, "Get track type failed.");
51 
52     DP_INFO_LOG("CreateTrack data: %{public}s", trackFormat.Stringify().c_str());
53     auto type = static_cast<Media::Plugins::MediaType>(trackType);
54     DP_CHECK_ERROR_RETURN_RET_LOG(!CheckTrackFormat(type), nullptr, "Track type: %{public}d is not supported.", type);
55 
56     auto track = std::make_shared<Track>();
57     TrackFormat formatOfIndex;
58     formatOfIndex.format = std::make_shared<Format>(trackFormat);
59     formatOfIndex.trackId = trackIndex;
60     track->SetFormat(formatOfIndex, type);
61     return track;
62 }
63 
CheckTrackFormat(Media::Plugins::MediaType type)64 bool TrackFactory::CheckTrackFormat(Media::Plugins::MediaType type)
65 {
66     return TRACK_TYPES.find(type) != TRACK_TYPES.end();
67 }
68 } // namespace DeferredProcessing
69 } // namespace CameraStandard
70 } // namespace OHOS
71