• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <string>
17 #include "gtest/gtest.h"
18 #include "audio_info.h"
19 #include "native_avcodec_audiodecoder.h"
20 #include "native_avcodec_audioencoder.h"
21 #include "native_avcodec_base.h"
22 #include "native_avformat.h"
23 #include "ADecEncNdkSample.h"
24 #include "syscap_ndk.h"
25 
26 using namespace std;
27 using namespace testing::ext;
28 using namespace OHOS;
29 using namespace OHOS::Media;
30 
31 namespace {
32 class ActsAudioDecEncNdkTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38 };
39 
SetUpTestCase()40 void ActsAudioDecEncNdkTest::SetUpTestCase() {}
TearDownTestCase()41 void ActsAudioDecEncNdkTest::TearDownTestCase() {}
SetUp()42 void ActsAudioDecEncNdkTest::SetUp() {}
TearDown()43 void ActsAudioDecEncNdkTest::TearDown() {}
44 
45 uint32_t ES_AAC_48000_32_1[] = {
46     283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, 541,
47     540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, 401,
48     393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, 376,
49     381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, 385,
50     384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, 381,
51     369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, 385};
52 
53 constexpr uint32_t ES_AAC_48000_32_1_Length = sizeof(ES_AAC_48000_32_1) / sizeof(uint32_t);
54 const string MIME_TYPE_AAC = "audio/mp4a-latm";
55 const string DECODER_AAC = "avdec_aac";
56 const string ENCODER_AAC = "avenc_aac";
57 constexpr uint32_t DEFAULT_SAMPLE_RATE = 44100;
58 constexpr uint32_t DEFAULT_CHANNELS = 2;
59 const char* READPATH = "/data/media/AAC_48000_32_1.aac";
60 
CheckDecDesc(map<string,int> InDesc,OH_AVFormat * OutDesc)61 bool CheckDecDesc(map<string, int> InDesc, OH_AVFormat* OutDesc)
62 {
63     int32_t out ;
64     for (const auto& t: InDesc) {
65         bool res = OH_AVFormat_GetIntValue(OutDesc, t.first.c_str(), &out);
66         cout << "key: " << t.first << "; out: " << out <<endl;
67         if (!res) {
68             cout << "OH_AVFormat_GetIntValue Fail. key:" << t.first << endl;
69             return false;
70         }
71         if (out != t.second) {
72             cout << "OH_AVFormat_GetIntValue error. key: " << t.first
73             << "; expect: "<< t.second
74             << ", actual: "<< out << endl;
75             return false;
76         }
77         out = 0;
78     }
79     return true;
80 }
81 
SetFormat(struct OH_AVFormat * format,map<string,int> mediaDescription)82 bool SetFormat(struct OH_AVFormat *format, map<string, int> mediaDescription)
83 {
84     const char *key;
85     for (const auto& t: mediaDescription) {
86         key = t.first.c_str();
87         if (not OH_AVFormat_SetIntValue(format, key, t.second)) {
88             cout << "OH_AV_FormatPutIntValue Fail. format key: " << t.first
89             << ", value: "<< t.second << endl;
90             return false;
91         }
92     }
93     return true;
94 }
95 
CanUseAudioCodec()96 bool CanUseAudioCodec()
97 {
98     return canIUse("SystemCapability.Multimedia.Media.CodecBase") &&
99         canIUse("SystemCapability.Multimedia.Media.AudioDecoder") &&
100         canIUse("SystemCapability.Multimedia.Media.AudioEncoder");
101 }
102 }
103 
104 /**
105  * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0100
106  * @tc.name      : stop at end of stream
107  * @tc.desc      : Basic function test
108  */
109 HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0100, TestSize.Level1)
110 {
111     if (!CanUseAudioCodec()) {
112         cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0100 ignore" <<endl;
113         return;
114     }
115     ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();
116 
117     map<string, int> AudioParam = {
118             {OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS},
119             {OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE},
120             {OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE},
121     };
122     OH_AVFormat *AudioFormat = OH_AVFormat_Create();
123     ASSERT_NE(nullptr, AudioFormat);
124     ASSERT_EQ(true, SetFormat(AudioFormat, AudioParam));
125     OH_AVFormat_SetStringValue(AudioFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AAC);
126 
127     struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByName(DECODER_AAC);
128     ASSERT_NE(nullptr, audDec);
129     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
130     OH_AVFormat *OutDescDec = OH_AudioDecoder_GetOutputDescription(audDec);
131     ASSERT_NE(nullptr, OutDescDec);
132     ASSERT_EQ(true, CheckDecDesc(AudioParam, OutDescDec));
133     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());
134 
135     struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByName(ENCODER_AAC);
136     ASSERT_NE(nullptr, audEnc);
137     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
138     OH_AVFormat *OutDescEnc = OH_AudioEncoder_GetOutputDescription(audEnc);
139     ASSERT_NE(nullptr, OutDescEnc);
140     ASSERT_EQ(true, CheckDecDesc(AudioParam, OutDescEnc));
141     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
142 
143     aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
144     aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out1.aac");
145     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
146     ASSERT_EQ(AV_ERR_OK, aDecEncSample->SetParameterEnc(AudioFormat));
147     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
148     ASSERT_EQ(AV_ERR_OK, aDecEncSample->SetParameterDec(AudioFormat));
149 
150     while (!aDecEncSample->GetEncEosState()) {};
151     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StopDec());
152     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StopEnc());
153     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
154     audDec = nullptr;
155     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
156     audEnc = nullptr;
157     OH_AVFormat_Destroy(AudioFormat);
158     AudioFormat = nullptr;
159     ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
160 }
161 
162 /**
163  * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0200
164  * @tc.name      : reset at end of stream
165  * @tc.desc      : Basic function test
166  */
167 HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0200, TestSize.Level1)
168 {
169     if (!CanUseAudioCodec()) {
170         cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0200 ignore" <<endl;
171         return;
172     }
173     ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();
174 
175     struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByMime(MIME_TYPE_AAC);
176     ASSERT_NE(nullptr, audDec);
177     OH_AVFormat *AudioFormat = OH_AVFormat_Create();
178     ASSERT_NE(nullptr, AudioFormat);
179     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS);
180     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE);
181     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE);
182     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_TRACK_TYPE, MEDIA_TYPE_AUD);
183 
184     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
185     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());
186 
187     struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByMime(MIME_TYPE_AAC);
188     ASSERT_NE(nullptr, audEnc);
189     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
190     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
191     aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
192     aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out2.aac");
193 
194     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
195     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
196     while (!aDecEncSample->GetEncEosState()) {};
197     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ResetEnc());
198     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ResetDec());
199     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
200     audDec = nullptr;
201     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
202     audEnc = nullptr;
203     OH_AVFormat_Destroy(AudioFormat);
204     AudioFormat = nullptr;
205     ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
206 }
207 
208 /**
209  * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0300
210  * @tc.name      : release at end of stream
211  * @tc.desc      : Basic function test
212  */
213 HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0300, TestSize.Level1)
214 {
215     if (!CanUseAudioCodec()) {
216         cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0300 ignore" <<endl;
217         return;
218     }
219     ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();
220 
221     struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByMime(MIME_TYPE_AAC);
222     ASSERT_NE(nullptr, audDec);
223     OH_AVFormat *AudioFormat = OH_AVFormat_Create();
224     ASSERT_NE(nullptr, AudioFormat);
225     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS);
226     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE);
227     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE);
228     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_PROFILE, AAC_PROFILE_LC);
229 
230     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
231     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());
232 
233     struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByMime(MIME_TYPE_AAC);
234     ASSERT_NE(nullptr, audEnc);
235     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
236     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
237     aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
238     aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out3.aac");
239 
240     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
241     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
242     while (!aDecEncSample->GetEncEosState()) {};
243     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
244     audDec = nullptr;
245     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
246     audEnc = nullptr;
247     OH_AVFormat_Destroy(AudioFormat);
248     AudioFormat = nullptr;
249     ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
250 }
251 
252 /**
253  * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0400
254  * @tc.name      : flush at running
255  * @tc.desc      : Basic function test
256  */
257 HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0400, TestSize.Level1)
258 {
259     if (!CanUseAudioCodec()) {
260         cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0400 ignore" <<endl;
261         return;
262     }
263     ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();
264 
265     struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByMime(MIME_TYPE_AAC);
266     ASSERT_NE(nullptr, audDec);
267     OH_AVFormat *AudioFormat = OH_AVFormat_Create();
268     ASSERT_NE(nullptr, AudioFormat);
269     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS);
270     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE);
271     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE);
272     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
273     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());
274 
275     struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByMime(MIME_TYPE_AAC);
276     ASSERT_NE(nullptr, audEnc);
277     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
278     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
279     aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
280     aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out4.aac");
281     aDecEncSample->SetEosState(false);
282 
283     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
284     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
285     while (aDecEncSample->GetFrameCount() < 50) {};
286     ASSERT_EQ(AV_ERR_OK, aDecEncSample->FlushDec());
287     ASSERT_EQ(AV_ERR_OK, aDecEncSample->FlushEnc());
288     aDecEncSample->ReRead();
289     aDecEncSample->ResetDecParam();
290     aDecEncSample->ResetEncParam();
291     aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out4_2.aac");
292     aDecEncSample->SetEosState(true);
293     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
294     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
295 
296     while (!aDecEncSample->GetEncEosState()) {};
297     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
298     audDec = nullptr;
299     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
300     audEnc = nullptr;
301     OH_AVFormat_Destroy(AudioFormat);
302     AudioFormat = nullptr;
303     ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
304 }
305 
306 /**
307  * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0500
308  * @tc.name      : flush decoder at eos
309  * @tc.desc      : Basic function test
310  */
311 HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0500, TestSize.Level1)
312 {
313     if (!CanUseAudioCodec()) {
314         cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0500 ignore" <<endl;
315         return;
316     }
317     ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();
318 
319     struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByMime(MIME_TYPE_AAC);
320     ASSERT_NE(nullptr, audDec);
321     OH_AVFormat *AudioFormat = OH_AVFormat_Create();
322     ASSERT_NE(nullptr, AudioFormat);
323     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS);
324     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE);
325     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE);
326     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
327     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());
328 
329     struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByMime(MIME_TYPE_AAC);
330     ASSERT_NE(nullptr, audEnc);
331     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
332     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
333     aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
334     aDecEncSample->SetEosState(false);
335     aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out5.aac");
336 
337     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
338     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
339     while (!aDecEncSample->GetDecEosState()) {};
340     cout << "aDecEncSample->GetDecEosState() is " << aDecEncSample->GetDecEosState() << endl;
341     ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
342     ASSERT_EQ(AV_ERR_OK, aDecEncSample->FlushDec());
343     ASSERT_EQ(AV_ERR_OK, aDecEncSample->FlushEnc());
344     aDecEncSample->ReRead();
345     aDecEncSample->ResetDecParam();
346     aDecEncSample->ResetEncParam();
347     aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out5_2.aac");
348     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
349     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
350     aDecEncSample->SetEosState(true);
351 
352     while (!aDecEncSample->GetEncEosState()) {};
353     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
354     audDec = nullptr;
355     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
356     audEnc = nullptr;
357     OH_AVFormat_Destroy(AudioFormat);
358     AudioFormat = nullptr;
359     ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
360 }
361 
362 
363 /**
364  * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0600
365  * @tc.name      : stop at running and restart to eos
366  * @tc.desc      : Basic function test
367  */
368 HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0600, TestSize.Level1)
369 {
370     if (!CanUseAudioCodec()) {
371         cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0600 ignore" <<endl;
372         return;
373     }
374     ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();
375 
376     struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByMime(MIME_TYPE_AAC);
377     ASSERT_NE(nullptr, audDec);
378     OH_AVFormat *AudioFormat = OH_AVFormat_Create();
379     ASSERT_NE(nullptr, AudioFormat);
380     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS);
381     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE);
382     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE);
383     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
384     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());
385 
386     struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByMime(MIME_TYPE_AAC);
387     ASSERT_NE(nullptr, audEnc);
388     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
389     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
390     aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
391     aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out6.aac");
392     aDecEncSample->SetEosState(false);
393 
394     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
395     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
396     while (aDecEncSample->GetFrameCount() < 50) {};
397     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StopDec());
398     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StopEnc());
399     aDecEncSample->ReRead();
400     aDecEncSample->ResetDecParam();
401     aDecEncSample->ResetEncParam();
402     aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out6_2.aac");
403     aDecEncSample->SetEosState(true);
404     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
405     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
406     ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
407 
408     while (!aDecEncSample->GetEncEosState()) {};
409     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
410     audDec = nullptr;
411     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
412     audEnc = nullptr;
413     OH_AVFormat_Destroy(AudioFormat);
414     AudioFormat = nullptr;
415     ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
416 }
417 
418 
419 /**
420  * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0700
421  * @tc.name      : stop dec at eos and restart to eos
422  * @tc.desc      : Basic function test
423  */
424 HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0700, TestSize.Level1)
425 {
426     if (!CanUseAudioCodec()) {
427         cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0700 ignore" <<endl;
428         return;
429     }
430     ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();
431 
432     struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByMime(MIME_TYPE_AAC);
433     ASSERT_NE(nullptr, audDec);
434     OH_AVFormat *AudioFormat = OH_AVFormat_Create();
435     ASSERT_NE(nullptr, AudioFormat);
436     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS);
437     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE);
438     OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE);
439     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
440     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());
441 
442     struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByMime(MIME_TYPE_AAC);
443     ASSERT_NE(nullptr, audEnc);
444     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
445     ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
446     aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
447     aDecEncSample->SetEosState(false);
448     aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out7.aac");
449 
450     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
451     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
452     while (!aDecEncSample->GetDecEosState()) {};
453     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StopDec());
454     ASSERT_EQ(AV_ERR_OK, aDecEncSample->FlushEnc());
455     ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
456 
457     aDecEncSample->ReRead();
458     aDecEncSample->ResetDecParam();
459     aDecEncSample->ResetEncParam();
460     aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out7_2.aac");
461     aDecEncSample->SetEosState(true);
462     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
463     ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
464 
465     while (!aDecEncSample->GetEncEosState()) {};
466     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
467     audDec = nullptr;
468     ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
469     audEnc = nullptr;
470     OH_AVFormat_Destroy(AudioFormat);
471     AudioFormat = nullptr;
472     ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
473 }