1 /*
2  * Copyright (c) 2023-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 #include "track_factory.h"
17 
18 #include "basic_definitions.h"
19 #include "dp_log.h"
20 #include "media_format.h"
21 
22 namespace OHOS {
23 namespace CameraStandard {
24 namespace DeferredProcessing {
TrackFactory()25 TrackFactory::TrackFactory()
26 {
27     DP_DEBUG_LOG("entered.");
28 }
29 
~TrackFactory()30 TrackFactory::~TrackFactory()
31 {
32     DP_DEBUG_LOG("entered.");
33 }
34 
CreateTrack(const std::shared_ptr<AVSource> & source,int trackIndex)35 std::shared_ptr<Track> TrackFactory::CreateTrack(const std::shared_ptr<AVSource>& source, int trackIndex)
36 {
37     DP_DEBUG_LOG("entered.");
38     Format trackFormat;
39     int32_t trackType = -1;
40     DP_CHECK_ERROR_RETURN_RET_LOG(source == nullptr, nullptr, "source is nullptr.");
41     auto ret = source->GetTrackFormat(trackFormat, trackIndex);
42     DP_CHECK_ERROR_RETURN_RET_LOG(ret != static_cast<int32_t>(OK), nullptr, "get track format failed.");
43     DP_CHECK_ERROR_RETURN_RET_LOG(!trackFormat.GetIntValue(Media::Tag::MEDIA_TYPE, trackType),
44         nullptr, "get track type failed.");
45 
46     DP_INFO_LOG("CreateTrack type: %{public}d", trackType);
47     auto track = std::make_shared<Track>();
48     if (static_cast<TrackType>(trackType) == TrackType::AV_KEY_AUDIO_TYPE ||
49         static_cast<TrackType>(trackType) == TrackType::AV_KEY_VIDEO_TYPE) {
50         TrackFormat formatOfIndex;
51         formatOfIndex.format = std::make_shared<Format>(trackFormat);
52         formatOfIndex.trackId = trackIndex;
53         track->SetFormat(formatOfIndex, static_cast<TrackType>(trackType));
54     }
55     return track;
56 }
57 } // namespace DeferredProcessing
58 } // namespace CameraStandard
59 } // namespace OHOS
60