1 /*
2  * Copyright (C) 2024 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 "audio_sampleformat.h"
17 #include <map>
18 
19 namespace OHOS {
20 namespace Media {
21 namespace Pipeline {
22 const std::map<Plugins::AudioSampleFormat, int32_t> SAMPLEFORMAT_INFOS = {
23     {Plugins::SAMPLE_U8, 8},
24     {Plugins::SAMPLE_S16LE, 16},
25     {Plugins::SAMPLE_S24LE, 24},
26     {Plugins::SAMPLE_S32LE, 32},
27     {Plugins::SAMPLE_F32LE, 32},
28     {Plugins::SAMPLE_U8P, 8},
29     {Plugins::SAMPLE_S16P, 16},
30     {Plugins::SAMPLE_S24P, 24},
31     {Plugins::SAMPLE_S32P, 32},
32     {Plugins::SAMPLE_F32P, 32},
33     {Plugins::SAMPLE_S8, 8},
34     {Plugins::SAMPLE_S8P, 8},
35     {Plugins::SAMPLE_U16, 16},
36     {Plugins::SAMPLE_U16P, 16},
37     {Plugins::SAMPLE_U24, 24},
38     {Plugins::SAMPLE_U24P, 24},
39     {Plugins::SAMPLE_U32, 32},
40     {Plugins::SAMPLE_U32P, 32},
41     {Plugins::SAMPLE_S64, 64},
42     {Plugins::SAMPLE_U64, 64},
43     {Plugins::SAMPLE_S64P, 64},
44     {Plugins::SAMPLE_U64P, 64},
45     {Plugins::SAMPLE_F64, 64},
46     {Plugins::SAMPLE_F64P, 64},
47     {Plugins::INVALID_WIDTH, -1},
48 };
49 
AudioSampleFormatToBitDepth(Plugins::AudioSampleFormat sampleFormat)50 int32_t AudioSampleFormatToBitDepth(Plugins::AudioSampleFormat sampleFormat)
51 {
52     if (SAMPLEFORMAT_INFOS.count(sampleFormat) != 0) {
53         return SAMPLEFORMAT_INFOS.at(sampleFormat);
54     }
55     return -1;
56 }
57 } // namespace Pipeline
58 } // namespace Media
59 } // namespace OHOS