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