ActsAudioDecEncNdkTest.cpp 18.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <string>
#include "gtest/gtest.h"
#include "audio_info.h"
#include "native_avcodec_audiodecoder.h"
#include "native_avcodec_audioencoder.h"
#include "native_avcodec_base.h"
#include "native_avformat.h"
23
#include "ADecEncNdkSample.h"
24 25 26 27 28 29 30

using namespace std;
using namespace testing::ext;
using namespace OHOS;
using namespace OHOS::Media;

namespace {
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
class ActsAudioDecEncNdkTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp() override;
    void TearDown() override;
};

void ActsAudioDecEncNdkTest::SetUpTestCase() {}
void ActsAudioDecEncNdkTest::TearDownTestCase() {}
void ActsAudioDecEncNdkTest::SetUp() {}
void ActsAudioDecEncNdkTest::TearDown() {}

uint32_t ES_AAC_48000_32_1[] = {
    283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, 541, 
    540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, 401, 
    393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, 376, 
    381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, 385, 
    384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, 381, 
    369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, 385};
51

52 53
constexpr uint32_t ES_AAC_48000_32_1_Length = sizeof(ES_AAC_48000_32_1) / sizeof(uint32_t);
const string MIME_TYPE_AAC = "audio/mp4a-latm";
54 55
const string DECODER_AAC = "avdec_aac";
const string ENCODER_AAC = "avenc_aac";
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
constexpr uint32_t DEFAULT_SAMPLE_RATE = 44100;
constexpr uint32_t DEFAULT_CHANNELS = 2;
const char* READPATH = "/data/media/AAC_48000_32_1.aac";

bool CheckDecDesc(map<string, int> InDesc, OH_AVFormat* OutDesc)
{
    int32_t out ;
    for (const auto& t: InDesc) {
        bool res = OH_AVFormat_GetIntValue(OutDesc, t.first.c_str(), &out);
        cout << "key: " << t.first << "; out: " << out <<endl;
        if (!res) {
            cout << "OH_AVFormat_GetIntValue Fail. key:" << t.first << endl;
            return false;
        }
        if (out != t.second) {
            cout << "OH_AVFormat_GetIntValue error. key: " << t.first
            << "; expect: "<< t.second
            << ", actual: "<< out << endl;
            return false;
75
        }
76
        out = 0;
77
    }
78 79
    return true;
}
80

81 82 83 84 85 86 87 88 89
bool SetFormat(struct OH_AVFormat *format, map<string, int> mediaDescription)
{
    const char *key;
    for (const auto& t: mediaDescription) {
        key = t.first.c_str();
        if (not OH_AVFormat_SetIntValue(format, key, t.second)) {
            cout << "OH_AV_FormatPutIntValue Fail. format key: " << t.first
            << ", value: "<< t.second << endl;
            return false;
90 91
        }
    }
92 93
    return true;
}
94 95 96
}

/**
97
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0100
98 99 100
 * @tc.name      : stop at end of stream
 * @tc.desc      : Basic function test
 */
101
HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0100, TestSize.Level1)
102 103 104 105 106 107 108 109 110 111 112
{
    ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();

    map<string, int> AudioParam = {
            {OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS},
            {OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE},
            {OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE},
    };
    OH_AVFormat *AudioFormat = OH_AVFormat_Create();
    ASSERT_NE(nullptr, AudioFormat);
    ASSERT_EQ(true, SetFormat(AudioFormat, AudioParam));
113
    OH_AVFormat_SetStringValue(AudioFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AAC);
114

115
    struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByName(DECODER_AAC);
116 117 118 119 120 121 122
    ASSERT_NE(nullptr, audDec);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
    OH_AVFormat *OutDescDec = OH_AudioDecoder_GetOutputDescription(audDec);
    ASSERT_NE(nullptr, OutDescDec);
    ASSERT_EQ(true, CheckDecDesc(AudioParam, OutDescDec));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());

123
    struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByName(ENCODER_AAC);
124 125 126 127 128 129 130 131 132 133
    ASSERT_NE(nullptr, audEnc);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
    OH_AVFormat *OutDescEnc = OH_AudioEncoder_GetOutputDescription(audEnc);
    ASSERT_NE(nullptr, OutDescEnc);
    ASSERT_EQ(true, CheckDecDesc(AudioParam, OutDescEnc));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());

    aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
    aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out1.aac");
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
134
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->SetParameterEnc(AudioFormat));
135
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
136
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->SetParameterDec(AudioFormat));
137 138 139 140 141 142 143 144 145 146 147 148 149 150

    while (!aDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StopDec());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StopEnc());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
    audDec = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
    audEnc = nullptr;
    OH_AVFormat_Destroy(AudioFormat);
    AudioFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
}

/**
151
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0200
152 153 154
 * @tc.name      : reset at end of stream
 * @tc.desc      : Basic function test
 */
155
HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0200, TestSize.Level1)
156 157 158
{
    ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();

159
    struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByMime(MIME_TYPE_AAC);
160 161 162 163 164 165
    ASSERT_NE(nullptr, audDec);
    OH_AVFormat *AudioFormat = OH_AVFormat_Create();
    ASSERT_NE(nullptr, AudioFormat);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE);
166 167
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_TRACK_TYPE, MEDIA_TYPE_AUD);

168 169 170
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());

171
    struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByMime(MIME_TYPE_AAC);
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
    ASSERT_NE(nullptr, audEnc);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
    aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
    aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out2.aac");

    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
    while (!aDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ResetEnc());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ResetDec());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
    audDec = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
    audEnc = nullptr;
    OH_AVFormat_Destroy(AudioFormat);
    AudioFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
}

/**
193
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0300
194 195 196
 * @tc.name      : release at end of stream
 * @tc.desc      : Basic function test
 */
197
HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0300, TestSize.Level1)
198 199 200
{
    ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();

201
    struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByMime(MIME_TYPE_AAC);
202 203 204 205 206 207
    ASSERT_NE(nullptr, audDec);
    OH_AVFormat *AudioFormat = OH_AVFormat_Create();
    ASSERT_NE(nullptr, AudioFormat);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE);
208 209
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_PROFILE, AAC_PROFILE_LC);

210 211 212
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());

213
    struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByMime(MIME_TYPE_AAC);
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
    ASSERT_NE(nullptr, audEnc);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
    aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
    aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out3.aac");

    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
    while (!aDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
    audDec = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
    audEnc = nullptr;
    OH_AVFormat_Destroy(AudioFormat);
    AudioFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
}

/**
233
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0400
234 235 236
 * @tc.name      : flush at running
 * @tc.desc      : Basic function test
 */
237
HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0400, TestSize.Level1)
238 239 240
{
    ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();

241
    struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByMime(MIME_TYPE_AAC);
242 243 244 245 246 247 248 249 250
    ASSERT_NE(nullptr, audDec);
    OH_AVFormat *AudioFormat = OH_AVFormat_Create();
    ASSERT_NE(nullptr, AudioFormat);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());

251
    struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByMime(MIME_TYPE_AAC);
252 253 254 255 256
    ASSERT_NE(nullptr, audEnc);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
    aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
    aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out4.aac");
257
    aDecEncSample->SetEosState(false);
258 259 260

    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
261
    while (aDecEncSample->GetFrameCount() < 50) {};
262
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->FlushDec());
263 264 265 266 267 268 269
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->FlushEnc());
    aDecEncSample->ReRead();
    aDecEncSample->ResetDecParam();
    aDecEncSample->ResetEncParam();
    aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out4_2.aac");
    aDecEncSample->SetEosState(true);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
270 271 272 273 274 275 276 277 278 279 280 281 282
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());

    while (!aDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
    audDec = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
    audEnc = nullptr;
    OH_AVFormat_Destroy(AudioFormat);
    AudioFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
}

/**
283
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0500
284 285 286
 * @tc.name      : flush decoder at eos
 * @tc.desc      : Basic function test
 */
287
HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0500, TestSize.Level1)
288 289 290
{
    ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();

291
    struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByMime(MIME_TYPE_AAC);
292 293 294 295 296 297 298 299 300
    ASSERT_NE(nullptr, audDec);
    OH_AVFormat *AudioFormat = OH_AVFormat_Create();
    ASSERT_NE(nullptr, AudioFormat);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());

301
    struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByMime(MIME_TYPE_AAC);
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
    ASSERT_NE(nullptr, audEnc);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
    aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
    aDecEncSample->SetEosState(false);
    aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out5.aac");

    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
    while (!aDecEncSample->GetDecEosState()) {};
    cout << "aDecEncSample->GetDecEosState() is " << aDecEncSample->GetDecEosState() << endl;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->FlushDec());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->FlushEnc());
    aDecEncSample->ReRead();
    aDecEncSample->ResetDecParam();
    aDecEncSample->ResetEncParam();
    aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out5_2.aac");
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
    aDecEncSample->SetEosState(true);

    while (!aDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
    audDec = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
    audEnc = nullptr;
    OH_AVFormat_Destroy(AudioFormat);
    AudioFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
}


/**
336
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0600
337 338 339
 * @tc.name      : stop at running and restart to eos
 * @tc.desc      : Basic function test
 */
340
HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0600, TestSize.Level1)
341 342 343
{
    ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();

344
    struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByMime(MIME_TYPE_AAC);
345 346 347 348 349 350 351 352 353
    ASSERT_NE(nullptr, audDec);
    OH_AVFormat *AudioFormat = OH_AVFormat_Create();
    ASSERT_NE(nullptr, AudioFormat);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());

354
    struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByMime(MIME_TYPE_AAC);
355 356 357 358 359
    ASSERT_NE(nullptr, audEnc);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
    aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
    aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out6.aac");
360
    aDecEncSample->SetEosState(false);
361 362 363

    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
364
    while (aDecEncSample->GetFrameCount() < 50) {};
365
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StopDec());
366 367 368 369 370 371 372
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StopEnc());
    aDecEncSample->ReRead();
    aDecEncSample->ResetDecParam();
    aDecEncSample->ResetEncParam();
    aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out6_2.aac");
    aDecEncSample->SetEosState(true);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());

    while (!aDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
    audDec = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
    audEnc = nullptr;
    OH_AVFormat_Destroy(AudioFormat);
    AudioFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
}


/**
388
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0700
389 390 391
 * @tc.name      : stop dec at eos and restart to eos
 * @tc.desc      : Basic function test
 */
392
HWTEST_F(ActsAudioDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_AUDIO_DEC_ENC_FUNCTION_0700, TestSize.Level1)
393 394 395
{
    ADecEncNdkSample *aDecEncSample = new ADecEncNdkSample();

396
    struct OH_AVCodec* audDec = aDecEncSample->CreateAudioDecoderByMime(MIME_TYPE_AAC);
397 398 399 400 401 402 403 404 405
    ASSERT_NE(nullptr, audDec);
    OH_AVFormat *AudioFormat = OH_AVFormat_Create();
    ASSERT_NE(nullptr, AudioFormat);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, DEFAULT_CHANNELS);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUD_SAMPLE_RATE, DEFAULT_SAMPLE_RATE);
    OH_AVFormat_SetIntValue(AudioFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AudioStandard::SAMPLE_S16LE);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureDec(AudioFormat));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareDec());

406
    struct OH_AVCodec* audEnc = aDecEncSample->CreateAudioEncoderByMime(MIME_TYPE_AAC);
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
    ASSERT_NE(nullptr, audEnc);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ConfigureEnc(AudioFormat));
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->PrepareEnc());
    aDecEncSample->SetReadPath(READPATH, ES_AAC_48000_32_1, ES_AAC_48000_32_1_Length);
    aDecEncSample->SetEosState(false);
    aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out7.aac");

    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());
    while (!aDecEncSample->GetDecEosState()) {};
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StopDec());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->FlushEnc());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());

    aDecEncSample->ReRead();
    aDecEncSample->ResetDecParam();
    aDecEncSample->ResetEncParam();
    aDecEncSample->SetSavePath("/data/media/AAC_48000_32_1_out7_2.aac");
    aDecEncSample->SetEosState(true);
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->StartDec());

    while (!aDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseDec());
    audDec = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->ReleaseEnc());
    audEnc = nullptr;
    OH_AVFormat_Destroy(AudioFormat);
    AudioFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, aDecEncSample->CalcuError());
}