• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_encoder_engine.h"
18 #include "codec/video/encoder/video_encoder_engine_impl.h"
19 
20 namespace OHOS {
21 namespace Media {
22 
23 namespace {
24 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_VIDEOEDITOR, "VideoEditorEncode"};
25 }
26 
27 static std::atomic<uint64_t> g_encoderId { 1 };
Create(const VideoEncodeParam & encodeParam,VideoEncodeCallback * cb)28 std::shared_ptr<IVideoEncoderEngine> IVideoEncoderEngine::Create(const VideoEncodeParam& encodeParam,
29     VideoEncodeCallback* cb)
30 {
31     if (cb == nullptr) {
32         MEDIA_LOGE("create video encoder for video failed, the parameter cb is nullptr.");
33         return nullptr;
34     }
35 
36     // videoTrunkFormat cannot be empty, the video file must contain video tracks, but the audio track is optional
37     if (encodeParam.videoTrunkFormat == nullptr) {
38         MEDIA_LOGE("create encoder engine failed, videoTrunkFormat is nullptr.");
39         return nullptr;
40     }
41 
42     auto engine = std::make_shared<VideoEncoderEngineImpl>(g_encoderId.fetch_add(1), cb);
43     auto error = engine->Init(encodeParam);
44     if (error != VEFError::ERR_OK) {
45         MEDIA_LOGE("init video encoder[id = %{public}" PRIu64 "] failed, error: %{public}d.",
46             engine->GetId(), error);
47         return nullptr;
48     }
49     return engine;
50 }
51 
52 } // namespace Media
53 } // namespace OHOS
54