1 /*
2 * Copyright (c) 2022-2022 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 #define HST_LOG_TAG "CodecFilterFactory"
17
18 #include "codec_filter_factory.h"
19 #include "async_mode.h"
20 #include "codec_filter_base.h"
21 #include "codec/audio_decoder/audio_decoder_filter.h"
22 #include "codec/audio_encoder/audio_encoder_filter.h"
23 #include "codec/video_decoder/video_decoder_filter.h"
24 #include "factory/filter_factory.h"
25 #include "pipeline/core/filter_codec_mode.h"
26 #include "sync_mode.h"
27
28 namespace OHOS {
29 namespace Media {
30 namespace Pipeline {
31 #ifdef OHOS_LITE
32 static AutoRegisterFilter<AudioDecoderFilter> g_registerAudioDecoderFilter("builtin.player.audiodecoder",
__anonca7294970102(const std::string& name) 33 [](const std::string& name) { return CreateCodecFilter(name, FilterCodecMode::AUDIO_SYNC_DECODER); });
34 #ifdef VIDEO_SUPPORT
35 static AutoRegisterFilter<VideoDecoderFilter> g_registerVideoDecoderFilter("builtin.player.videodecoder",
__anonca7294970202(const std::string& name) 36 [](const std::string& name) { return CreateCodecFilter(name, FilterCodecMode::VIDEO_ASYNC_DECODER); });
37 #endif
38 #else
39 static AutoRegisterFilter<AudioDecoderFilter> g_registerAudioDecoderFilter("builtin.player.audiodecoder",
40 [](const std::string& name) { return CreateCodecFilter(name, FilterCodecMode::AUDIO_ASYNC_DECODER); });
41 #ifdef VIDEO_SUPPORT
42 static AutoRegisterFilter<VideoDecoderFilter> g_registerVideoDecoderFilter("builtin.player.videodecoder",
43 [](const std::string& name) { return CreateCodecFilter(name, FilterCodecMode::VIDEO_ASYNC_DECODER); });
44 #endif
45 #endif
46
CreateCodecFilter(const std::string & name,FilterCodecMode type)47 std::shared_ptr<CodecFilterBase> CreateCodecFilter(const std::string& name, FilterCodecMode type)
48 {
49 std::shared_ptr<CodecMode> codecMode {nullptr};
50 std::shared_ptr<CodecFilterBase> filter {nullptr};
51 switch (type) {
52 case FilterCodecMode::AUDIO_SYNC_DECODER:
53 codecMode = std::make_shared<SyncMode>("audioDec");
54 filter = std::make_shared<AudioDecoderFilter>(name, codecMode);
55 break;
56 case FilterCodecMode::AUDIO_ASYNC_DECODER:
57 codecMode = std::make_shared<AsyncMode>("audioDec");
58 filter = std::make_shared<AudioDecoderFilter>(name, codecMode);
59 break;
60 #ifdef VIDEO_SUPPORT
61 case FilterCodecMode::VIDEO_SYNC_DECODER:
62 codecMode = std::make_shared<SyncMode>("videoDec");
63 filter = std::make_shared<VideoDecoderFilter>(name, codecMode);
64 break;
65 case FilterCodecMode::VIDEO_ASYNC_DECODER:
66 codecMode = std::make_shared<AsyncMode>("videoDec");
67 filter = std::make_shared<VideoDecoderFilter>(name, codecMode);
68 break;
69 #endif
70 default:
71 break;
72 }
73 return filter;
74 }
75 } // Pipeline
76 } // Media
77 } // OHOS
78
79