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