1 /*
2 * Copyright (c) 2023-2024 Shenzhen Kaihong Digital Industry Development 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 "codec_factory.h"
17 #include "audio_aac_codec.h"
18 #include "audio_avcodec_decoder.h"
19 #include "audio_g711_codec.h"
20 #include "audio_pcm_processor.h"
21 #include "sharing_log.h"
22
23 namespace OHOS {
24 namespace Sharing {
CreateAudioEncoder(CodecId format)25 std::shared_ptr<AudioEncoder> CodecFactory::CreateAudioEncoder(CodecId format)
26 {
27 SHARING_LOGD("trace.");
28 std::shared_ptr<AudioEncoder> encoder;
29
30 switch (format) {
31 case CODEC_G711A:
32 encoder.reset(new AudioG711Encoder(G711_TYPE::G711_ALAW));
33 break;
34 case CODEC_G711U:
35 encoder.reset(new AudioG711Encoder(G711_TYPE::G711_ULAW));
36 break;
37 case CODEC_AAC:
38 encoder.reset(new AudioAACEncoder());
39 break;
40 case CODEC_PCM:
41 encoder.reset(new AudioPcmProcessor());
42 break;
43 default:
44 SHARING_LOGE("unsupported codec format %{public}d.", (int32_t)format);
45 break;
46 }
47
48 return encoder;
49 }
50
CreateAudioDecoder(CodecId format)51 std::shared_ptr<AudioDecoder> CodecFactory::CreateAudioDecoder(CodecId format)
52 {
53 SHARING_LOGD("trace.");
54 std::shared_ptr<AudioDecoder> decoder;
55 switch (format) {
56 case CODEC_G711A:
57 decoder.reset(new AudioG711Decoder(G711_TYPE::G711_ALAW));
58 break;
59 case CODEC_G711U:
60 decoder.reset(new AudioG711Decoder(G711_TYPE::G711_ULAW));
61 break;
62 case CODEC_AAC:
63 decoder.reset(new AudioAvCodecDecoder());
64 break;
65 default:
66 SHARING_LOGE("unsupported codec format %{public}d.", (int32_t)format);
67 break;
68 }
69
70 return decoder;
71 }
72
CreateVideoEncoder(CodecId format)73 std::shared_ptr<VideoEncoder> CodecFactory::CreateVideoEncoder(CodecId format)
74 {
75 SHARING_LOGD("trace.");
76 std::shared_ptr<VideoEncoder> encoder;
77 switch (format) {
78 case CODEC_AAC:
79 SHARING_LOGE("unsupported codec format %{public}d.", (int32_t)format);
80 break;
81 case CODEC_G711U:
82 SHARING_LOGE("unsupported codec format %{public}d.", (int32_t)format);
83 break;
84 default:
85 SHARING_LOGE("unsupported codec format %{public}d.", (int32_t)format);
86 break;
87 }
88
89 return encoder;
90 }
91
CreateVideoDecoder(CodecId format)92 std::shared_ptr<VideoDecoder> CodecFactory::CreateVideoDecoder(CodecId format)
93 {
94 SHARING_LOGD("trace.");
95 std::shared_ptr<VideoDecoder> decoder;
96 switch (format) {
97 case CODEC_AAC:
98 SHARING_LOGE("unsupported codec format %{public}d.", (int32_t)format);
99 break;
100 case CODEC_G711U:
101 SHARING_LOGE("unsupported codec format %{public}d.", (int32_t)format);
102 break;
103 default:
104 SHARING_LOGE("unsupported codec format %{public}d.", (int32_t)format);
105 break;
106 }
107
108 return decoder;
109 }
110 } // namespace Sharing
111 } // namespace OHOS
112