1 /*
2 * Copyright (c) 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 "image_source_ohos.h"
17
18 #include "image_source.h"
19 #include "media_errors.h"
20
21 namespace OHOS::Ace {
Create(int32_t fd)22 RefPtr<ImageSource> ImageSource::Create(int32_t fd)
23 {
24 uint32_t errorCode;
25 Media::SourceOptions options;
26 auto src = Media::ImageSource::CreateImageSource(fd, options, errorCode);
27 if (errorCode != Media::SUCCESS) {
28 LOGE("create image source failed, errorCode = %{public}u", errorCode);
29 return nullptr;
30 }
31 return MakeRefPtr<ImageSourceOhos>(std::move(src));
32 }
33
GetProperty(const std::string & key)34 std::string ImageSourceOhos::GetProperty(const std::string& key)
35 {
36 std::string value;
37 uint32_t res = imageSource_->GetImagePropertyString(0, key, value);
38 if (res != Media::SUCCESS) {
39 LOGE("Get ImageSource property %{public}s failed, errorCode = %{public}u", key.c_str(), res);
40 }
41 return value;
42 }
43 } // namespace OHOS::Ace
44