1 /*
2 * Copyright (C) 2023 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 <iostream>
17 #include "native_avmagic.h"
18 #include "codeclist_demo.h"
19 #include "native_avcodec_base.h"
20
21 namespace OHOS {
22 namespace MediaAVCodec {
23
SelectAudioType()24 OH_AVCapability* SelectAudioType()
25 {
26 std::cout << "Please select audio type(default AAC): " << std::endl;
27 std::cout << "0:AAC" << std::endl;
28 std::cout << "1:Flac" << std::endl;
29 std::cout << "2:Vorbis" << std::endl;
30 std::cout << "3:MPEG" << std::endl;
31 std::cout << "4:G711mu" << std::endl;
32 std::cout << "5:AMR-nb" << std::endl;
33 std::cout << "6:AMR-wb" << std::endl;
34 std::cout << "7:APE" << std::endl;
35 std::string mode;
36 OH_AVCapability *avCap = nullptr;
37 (void)getline(std::cin, mode);
38 if (mode == "0" || mode == "") {
39 avCap = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_AAC, false);
40 } else if (mode == "1") {
41 avCap = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_FLAC, false);
42 } else if (mode == "2") {
43 avCap = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_VORBIS, false);
44 } else if (mode == "3") {
45 avCap = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_MPEG, false);
46 } else if (mode == "4") {
47 avCap = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_G711MU, false);
48 } else if (mode == "5") {
49 avCap = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_AMR_NB, false);
50 } else if (mode == "6") {
51 avCap = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_AMR_WB, false);
52 } else if (mode == "7") {
53 avCap = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_AUDIO_APE, false);
54 }
55 return avCap;
56 }
57
NativeSelectSampleRateRanges()58 void NativeSelectSampleRateRanges()
59 {
60 OH_AVCapability *avCapability = SelectAudioType();
61 if (avCapability == nullptr) {
62 std::cout << "not support decode" << std::endl;
63 return;
64 }
65 OH_AVRange *sampleRateRanges = nullptr;
66 uint32_t rangesNum = 0;
67 std::string codecName = avCapability->capabilityData_->codecName;
68 OH_AVErrCode ret = OH_AVCapability_GetAudioSupportedSampleRateRanges(avCapability, &sampleRateRanges, &rangesNum);
69 if (ret == AV_ERR_OK) {
70 std::cout << codecName << " support sample rate range number:" << rangesNum << std::endl;
71 for (uint32_t i = 0; i < rangesNum; i++) {
72 std::cout << codecName << " support sample rate range[" << i << "]:" << sampleRateRanges[i].minVal
73 << "~" << sampleRateRanges[i].maxVal << std::endl;
74 }
75 } else {
76 std::cout << "get " << codecName << " sample rate ranges fail" << std::endl;
77 }
78 }
79
NativeSelectSampleRate()80 void NativeSelectSampleRate()
81 {
82 OH_AVCapability *avCapability = SelectAudioType();
83 if (avCapability == nullptr) {
84 std::cout << "not support decode" << std::endl;
85 return;
86 }
87 const int32_t *sampleRate = nullptr;
88 uint32_t rangesNum = 0;
89 std::string codecName = avCapability->capabilityData_->codecName;
90 OH_AVErrCode ret = OH_AVCapability_GetAudioSupportedSampleRates(avCapability, &sampleRate, &rangesNum);
91 if (ret == AV_ERR_OK) {
92 std::cout << codecName << " support sample rate number:" << rangesNum << std::endl;
93 std::cout << codecName << " support sample rate:" << std::endl;
94 for (uint32_t i = 0; i < rangesNum; i++) {
95 std::cout << sampleRate[i];
96 if (i == rangesNum - 1) {
97 std::cout << std::endl;
98 } else {
99 std::cout << ", ";
100 }
101 }
102 } else {
103 std::cout << "get " << codecName << " sample rate fail" << std::endl;
104 }
105 }
106
RunCase()107 void CodecListDemo::RunCase()
108 {
109 std::cout << "===== ============== ======" << std::endl;
110 const char *mime = "video/avc";
111 OH_AVCapability *cap = OH_AVCodec_GetCapability(mime, false);
112 const char *name = OH_AVCapability_GetName(cap);
113 std::cout << name << std::endl;
114 std::cout << "get caps successful" << std::endl;
115
116 std::cout << "===== ============== ======" << std::endl;
117 std::cout << "Please select a capability test(default 0)" << std::endl;
118 std::cout << "0:get audio supported sample rate ranges" << std::endl;
119 std::cout << "1:get audio supported sample rate" << std::endl;
120 std::string mode;
121 (void)getline(std::cin, mode);
122 if (mode == "0" || mode == "") {
123 (void)NativeSelectSampleRateRanges();
124 } else {
125 (void)NativeSelectSampleRate();
126 }
127 }
128 } // namespace MediaAVCodec
129 } // namespace OHOS