1 /*
2  * Copyright (c) 2021-2021 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 "common/media_source.h"
17 #include "common/log.h"
18 #include <type_traits>
19 
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_FOUNDATION, "MediaSource" };
22 }
23 
24 namespace OHOS {
25 namespace Media {
26 namespace Plugins {
MediaSource(std::string uri)27 MediaSource::MediaSource(std::string uri)
28     : uri_(std::move(uri)), type_(SourceType::SOURCE_TYPE_URI)
29 {
30 }
31 
32 #ifndef OHOS_LITE
MediaSource(std::shared_ptr<IMediaDataSource> dataSrc)33 MediaSource::MediaSource(std::shared_ptr<IMediaDataSource> dataSrc)
34     :type_(SourceType::SOURCE_TYPE_STREAM), dataSrc_(std::move(dataSrc))
35 {
36     MEDIA_LOG_I("MediaSource ctor called dataSrc");
37 }
38 #endif
39 
MediaSource(std::string uri,std::map<std::string,std::string> header)40 MediaSource::MediaSource(std::string uri, std::map<std::string, std::string> header)
41     : uri_(std::move(uri)), header_(std::move(header))
42 {
43     MEDIA_LOG_I("MediaSource ctor called header");
44 }
45 
GetSourceType() const46 SourceType MediaSource::GetSourceType() const
47 {
48     return type_;
49 }
50 
GetSourceUri() const51 const std::string &MediaSource::GetSourceUri() const
52 {
53     return uri_;
54 }
55 
GetSourceHeader() const56 const std::map<std::string, std::string> &MediaSource::GetSourceHeader() const
57 {
58     return header_;
59 }
60 
SetPlayStrategy(const std::shared_ptr<PlayStrategy> & playStrategy)61 void MediaSource::SetPlayStrategy(const std::shared_ptr<PlayStrategy>& playStrategy)
62 {
63     MEDIA_LOG_I("SetPlayStrategy width: %{public}d, height: %{public}d, duration: %{public}d, preferHDR: %{public}d",
64         playStrategy->width, playStrategy->height, playStrategy->duration, playStrategy->preferHDR);
65     playStrategy_ = playStrategy;
66 }
67 
GetPlayStrategy() const68 std::shared_ptr<PlayStrategy> MediaSource::GetPlayStrategy() const
69 {
70     return playStrategy_;
71 }
72 
SetAppUid(int32_t appUid)73 void MediaSource::SetAppUid(int32_t appUid)
74 {
75     appUid_ = appUid;
76 }
77 
GetAppUid()78 int32_t MediaSource::GetAppUid()
79 {
80     return appUid_;
81 }
82 
SetMimeType(const std::string & mimeType)83 void MediaSource::SetMimeType(const std::string& mimeType)
84 {
85     mimeType_ = mimeType;
86 }
87 
GetMimeType() const88 std::string MediaSource::GetMimeType() const
89 {
90     return mimeType_;
91 }
92 
93 #ifndef OHOS_LITE
GetDataSrc() const94 std::shared_ptr<IMediaDataSource> MediaSource::GetDataSrc() const
95 {
96     return dataSrc_;
97 }
98 #endif
99 } // namespace Plugins
100 } // namespace Media
101 } // namespace OHOS
102 
103