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 "codec/video_decoder_engine.h"
18 #include "codec/video/decoder/video_decoder_engine_impl.h"
19
20 namespace OHOS {
21 namespace Media {
22
23 namespace {
24 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_VIDEOEDITOR, "VideoEditorDecode"};
25 }
26
27 static std::atomic<uint64_t> g_decoderId { 1 };
Create(int fd,VideoDecodeCallback * cb)28 std::shared_ptr<IVideoDecoderEngine> IVideoDecoderEngine::Create(int fd, VideoDecodeCallback* cb)
29 {
30 if (cb == nullptr) {
31 MEDIA_LOGE("create video decoder for video [%{public}d] failed, the parameter cb is nullptr.", fd);
32 return nullptr;
33 }
34
35 auto engine = std::make_shared<VideoDecoderEngineImpl>(g_decoderId.fetch_add(1), fd, cb);
36 auto error = engine->Init();
37 if (error != VEFError::ERR_OK) {
38 MEDIA_LOGE("init video decoder[id = %{public}" PRIu64 "] failed, error: %{public}d.", engine->GetId(), error);
39 return nullptr;
40 }
41 return engine;
42 }
43
44 } // namespace Media
45 } // namespace OHOS
46