• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 "avcodec_engine_factory.h"
17 #include <cstdlib>
18 #include "format_processor/processor_adec_impl.h"
19 #include "format_processor/processor_aenc_impl.h"
20 #include "format_processor/processor_vdec_impl.h"
21 #include "format_processor/processor_venc_impl.h"
22 #include "sink_wrapper/sink_bytebuffer_impl.h"
23 #include "sink_wrapper/sink_surface_impl.h"
24 #include "src_wrapper/src_bytebuffer_impl.h"
25 #include "src_wrapper/src_surface_impl.h"
26 #include "media_log.h"
27 
28 namespace {
29     constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVCodecEngineFactory"};
30 }
31 
32 namespace OHOS {
33 namespace Media {
CreateProcessor(AVCodecType type)34 std::unique_ptr<ProcessorBase> AVCodecEngineFactory::CreateProcessor(AVCodecType type)
35 {
36     std::unique_ptr<ProcessorBase> processor;
37     switch (type) {
38         case AVCODEC_TYPE_VIDEO_ENCODER:
39             processor = std::make_unique<ProcessorVencImpl>();
40             break;
41         case AVCODEC_TYPE_VIDEO_DECODER:
42             processor = std::make_unique<ProcessorVdecImpl>();
43             break;
44         case AVCODEC_TYPE_AUDIO_ENCODER:
45             processor = std::make_unique<ProcessorAencImpl>();
46             break;
47         case AVCODEC_TYPE_AUDIO_DECODER:
48             processor = std::make_unique<ProcessorAdecImpl>();
49             break;
50         default:
51             MEDIA_LOGE("Unknown type");
52             break;
53     }
54     return processor;
55 }
56 
CreateSink(SinkType type)57 std::unique_ptr<SinkBase> AVCodecEngineFactory::CreateSink(SinkType type)
58 {
59     std::unique_ptr<SinkBase> sink;
60     switch (type) {
61         case SINK_TYPE_BYTEBUFFER:
62             sink = std::make_unique<SinkBytebufferImpl>();
63             break;
64         case SINK_TYPE_SURFACE:
65             sink = std::make_unique<SinkSurfaceImpl>();
66             break;
67         default:
68             MEDIA_LOGE("Unknown type");
69             break;
70     }
71     return sink;
72 }
73 
CreateSrc(SrcType type)74 std::unique_ptr<SrcBase> AVCodecEngineFactory::CreateSrc(SrcType type)
75 {
76     std::unique_ptr<SrcBase> src;
77     switch (type) {
78         case SRC_TYPE_BYTEBUFFER:
79             src = std::make_unique<SrcBytebufferImpl>();
80             break;
81         case SRC_TYPE_SURFACE:
82             src = std::make_unique<SrcSurfaceImpl>();
83             break;
84         default:
85             MEDIA_LOGE("Unknown type");
86             break;
87     }
88     return src;
89 }
90 } // namespace Media
91 } // namespace OHOS
92