ActsVideoDecEncNdkTest.cpp 18.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * 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 "native_avcodec_videodecoder.h"
#include "native_avcodec_videoencoder.h"
#include "native_avcodec_base.h"
#include "native_avformat.h"
22
#include "VDecEncNdkSample.h"
L
liyiming 已提交
23
#include "syscap_ndk.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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
class ActsVideoDecEncNdkTest : public testing::Test {
public:
    static void SetUpTestCase();
    static void TearDownTestCase();
    void SetUp() override;
    void TearDown() override;
};

void ActsVideoDecEncNdkTest::SetUpTestCase() {}
void ActsVideoDecEncNdkTest::TearDownTestCase() {}
void ActsVideoDecEncNdkTest::SetUp() {}
void ActsVideoDecEncNdkTest::TearDown() {}
const string MIME_TYPE_AVC = "video/avc";
const string MIME_TYPE_MPEG4 = "video/mp4v-es";
constexpr uint32_t DEFAULT_WIDTH = 320;
constexpr uint32_t DEFAULT_HEIGHT = 240;
constexpr uint32_t DEFAULT_PIXELFORMAT = 2;
constexpr uint32_t DEFAULT_FRAMERATE = 60;
const char* READPATH = "/data/media/out_320_240_10s.h264";

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;
66
        }
67
        out = 0;
68
    }
69 70
    return true;
}
71

72 73 74 75 76 77 78 79 80
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;
81 82
        }
    }
83 84
    return true;
}
85

86 87 88 89 90 91 92
struct OH_AVFormat* createFormat()
{
    OH_AVFormat *DefaultFormat = OH_AVFormat_Create();
    OH_AVFormat_SetIntValue(DefaultFormat, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
    OH_AVFormat_SetIntValue(DefaultFormat, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
    OH_AVFormat_SetIntValue(DefaultFormat, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
    OH_AVFormat_SetIntValue(DefaultFormat, OH_MD_KEY_FRAME_RATE, DEFAULT_FRAMERATE);
93
    OH_AVFormat_SetStringValue(DefaultFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_VIDEO_AVC);
94 95
    return DefaultFormat;
}
L
liyiming 已提交
96 97 98 99 100 101 102

bool CanUseVideoCodec()
{
    return canIUse("SystemCapability.Multimedia.Media.CodecBase") &&
        canIUse("SystemCapability.Multimedia.Media.VideoDecoder") &&
        canIUse("SystemCapability.Multimedia.Media.VideoEncoder");
}
103 104 105
}

/**
106
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0100
107 108 109
 * @tc.name      : stop at end of stream
 * @tc.desc      : Basic function test
 */
110
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0100, TestSize.Level1)
111
{
L
liyiming 已提交
112 113 114 115
    if (!CanUseVideoCodec()) {
        cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0100 ignore" <<endl;
        return;
    }
116 117 118
    VDecEncNdkSample *vDecEncSample = new VDecEncNdkSample();
    struct OH_AVCodec* videoDec = vDecEncSample->CreateVideoDecoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoDec);
119

120 121 122
    struct OH_AVCodec* videoEnc = vDecEncSample->CreateVideoEncoderByMime(MIME_TYPE_MPEG4);
    ASSERT_NE(nullptr, videoEnc);
    vDecEncSample->SetReadPath(READPATH);
123
    vDecEncSample->SetSavePath("/data/media/video_001.h264");
124 125 126 127 128 129 130 131 132 133
    
    OH_AVFormat *VideoFormat = OH_AVFormat_Create();
    ASSERT_NE(nullptr, VideoFormat);
    map<string, int> VideoParam = {
        {OH_MD_KEY_WIDTH, DEFAULT_WIDTH},
        {OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT},
        {OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT},
        {OH_MD_KEY_FRAME_RATE, DEFAULT_FRAMERATE},
    };
    ASSERT_EQ(true, SetFormat(VideoFormat, VideoParam));
134 135
    OH_AVFormat_SetIntValue(VideoFormat, OH_MD_KEY_TRACK_TYPE, MEDIA_TYPE_VID);

136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureDec(VideoFormat));
    OH_AVFormat *OutDescDec = OH_VideoDecoder_GetOutputDescription(videoDec);
    ASSERT_NE(nullptr, OutDescDec);
    ASSERT_EQ(true, CheckDecDesc(VideoParam, OutDescDec));

    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureEnc(VideoFormat));
    OH_AVFormat *OutDescEnc = OH_VideoEncoder_GetOutputDescription(videoEnc);
    ASSERT_NE(nullptr, OutDescEnc);
    ASSERT_EQ(true, CheckDecDesc(VideoParam, OutDescEnc));

    ASSERT_EQ(AV_ERR_OK, vDecEncSample->GetSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->SetOutputSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartDec());

    while (!vDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StopDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StopEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseEnc());
    videoEnc = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseDec());
    videoDec = nullptr;
    OH_AVFormat_Destroy(VideoFormat);
    VideoFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->CalcuError());
}

/**
166
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0200
167 168 169
 * @tc.name      : reset at end of stream
 * @tc.desc      : Basic function test
 */
170
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0200, TestSize.Level1)
171
{
L
liyiming 已提交
172 173 174 175
    if (!CanUseVideoCodec()) {
        cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0200 ignore" <<endl;
        return;
    }
176 177 178 179 180 181 182
    VDecEncNdkSample *vDecEncSample = new VDecEncNdkSample();

    struct OH_AVCodec* videoDec = vDecEncSample->CreateVideoDecoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoDec);
    struct OH_AVCodec* videoEnc = vDecEncSample->CreateVideoEncoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoEnc);
    vDecEncSample->SetReadPath(READPATH);
183
    vDecEncSample->SetSavePath("/data/media/video_002.h264");
184 185 186
    
    OH_AVFormat *VideoFormat = createFormat();
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureDec(VideoFormat));
187
    OH_AVFormat_SetIntValue(VideoFormat, OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CBR);
188 189 190 191 192 193
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureEnc(VideoFormat));
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->GetSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->SetOutputSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartEnc());
194
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->SetParameterDec(VideoFormat));
195
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartDec());
196
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->SetParameterEnc(VideoFormat));
197 198 199 200 201 202 203 204 205 206 207 208 209 210

    while (!vDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ResetDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ResetEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseEnc());
    videoEnc = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseDec());
    videoDec = nullptr;
    OH_AVFormat_Destroy(VideoFormat);
    VideoFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->CalcuError());
}

 /**
211
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0300
212 213 214
 * @tc.name      : release at end of stream
 * @tc.desc      : Basic function test
 */
215
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0300, TestSize.Level1)
216
{
L
liyiming 已提交
217 218 219 220
    if (!CanUseVideoCodec()) {
        cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0300 ignore" <<endl;
        return;
    }
221 222 223 224 225 226 227
    VDecEncNdkSample *vDecEncSample = new VDecEncNdkSample();

    struct OH_AVCodec* videoDec = vDecEncSample->CreateVideoDecoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoDec);
    struct OH_AVCodec* videoEnc = vDecEncSample->CreateVideoEncoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoEnc);
    vDecEncSample->SetReadPath(READPATH);
228
    vDecEncSample->SetSavePath("/data/media/video_003.h264");
229 230
    
    OH_AVFormat *VideoFormat = createFormat();
231 232
    OH_AVFormat_SetIntValue(VideoFormat, OH_MD_KEY_PROFILE, AVC_PROFILE_BASELINE);

233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureDec(VideoFormat));
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureEnc(VideoFormat));
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->GetSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->SetOutputSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartDec());

    while (!vDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseEnc());
    videoEnc = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseDec());
    videoDec = nullptr;
    OH_AVFormat_Destroy(VideoFormat);
    VideoFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->CalcuError());
}

/**
253
* @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0400
254 255 256
* @tc.name      : flush at running
* @tc.desc      : Basic function test
*/
257
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0400, TestSize.Level1)
258
{
L
liyiming 已提交
259 260 261 262
    if (!CanUseVideoCodec()) {
        cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0400 ignore" <<endl;
        return;
    }
263 264 265 266 267 268 269 270
    VDecEncNdkSample *vDecEncSample = new VDecEncNdkSample();

    struct OH_AVCodec* videoDec = vDecEncSample->CreateVideoDecoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoDec);
    struct OH_AVCodec* videoEnc = vDecEncSample->CreateVideoEncoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoEnc);
    vDecEncSample->SetReadPath(READPATH);
    vDecEncSample->SetEosState(false);
271
    vDecEncSample->SetSavePath("/data/media/video_004.h264");
272 273
    
    OH_AVFormat *VideoFormat = createFormat();
274 275
    OH_AVFormat_SetIntValue(VideoFormat, OH_MD_KEY_PROFILE, AVC_PROFILE_HIGH);

276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureDec(VideoFormat));
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureEnc(VideoFormat));
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->GetSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->SetOutputSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartDec());

    while (vDecEncSample->GetFrameCount() < 100) {};
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->FlushDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->FlushEnc());
    vDecEncSample->ReRead();
    vDecEncSample->ResetDecParam();
    vDecEncSample->ResetEncParam();
    vDecEncSample->SetEosState(true);
292
    vDecEncSample->SetSavePath("/data/media/video_004_2.h264");
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308

    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartDec());

    while (!vDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseEnc());
    videoEnc = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseDec());
    videoDec = nullptr;
    OH_AVFormat_Destroy(VideoFormat);
    VideoFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->CalcuError());
}


/**
309
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0500
310 311 312
 * @tc.name      : flush dec at eos and restart
 * @tc.desc      : Basic function test
 */
313
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0500, TestSize.Level1)
314
{
L
liyiming 已提交
315 316 317 318
    if (!CanUseVideoCodec()) {
        cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0500 ignore" <<endl;
        return;
    }
319 320 321 322 323 324 325 326
    VDecEncNdkSample *vDecEncSample = new VDecEncNdkSample();

    struct OH_AVCodec* videoDec = vDecEncSample->CreateVideoDecoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoDec);
    struct OH_AVCodec* videoEnc = vDecEncSample->CreateVideoEncoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoEnc);
    vDecEncSample->SetReadPath(READPATH);
    vDecEncSample->SetEosState(false);
327
    vDecEncSample->SetSavePath("/data/media/video_005.h264");
328 329
    
    OH_AVFormat *VideoFormat = createFormat();
330 331
    OH_AVFormat_SetIntValue(VideoFormat, OH_MD_KEY_PROFILE, AVC_PROFILE_MAIN);

332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureDec(VideoFormat));
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureEnc(VideoFormat));
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->GetSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->SetOutputSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartDec());

    while (!vDecEncSample->GetDecEosState()) {};
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->CalcuError());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->FlushDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->FlushEnc());
    vDecEncSample->ReRead();
    vDecEncSample->ResetDecParam();
    vDecEncSample->ResetEncParam();
348
    vDecEncSample->SetSavePath("/data/media/video_005_2.h264");
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
    vDecEncSample->SetEosState(true);
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->CalcuError());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartDec());

    while (!vDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseEnc());
    videoEnc = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseDec());
    videoDec = nullptr;
    OH_AVFormat_Destroy(VideoFormat);
    VideoFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->CalcuError());
}


/**
366
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0600
367 368 369
 * @tc.name      : stop at running and restart to eos
 * @tc.desc      : Basic function test
 */
370
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0600, TestSize.Level1)
371
{
L
liyiming 已提交
372 373 374 375
    if (!CanUseVideoCodec()) {
        cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0600 ignore" <<endl;
        return;
    }
376 377 378 379 380 381 382 383
    VDecEncNdkSample *vDecEncSample = new VDecEncNdkSample();

    struct OH_AVCodec* videoDec = vDecEncSample->CreateVideoDecoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoDec);
    struct OH_AVCodec* videoEnc = vDecEncSample->CreateVideoEncoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoEnc);
    vDecEncSample->SetReadPath(READPATH);
    vDecEncSample->SetEosState(false);
384
    vDecEncSample->SetSavePath("/data/media/video_006.h264");
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
    
    OH_AVFormat *VideoFormat = createFormat();
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureDec(VideoFormat));
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureEnc(VideoFormat));
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->GetSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->SetOutputSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartDec());

    while (vDecEncSample->GetFrameCount() < 100) {};
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StopDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StopEnc());
    vDecEncSample->ReRead();
    vDecEncSample->ResetDecParam();
    vDecEncSample->ResetEncParam();
    vDecEncSample->SetEosState(true);
403
    vDecEncSample->SetSavePath("/data/media/video_006_2.h264");
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartDec());

    while (!vDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StopDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StopEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseEnc());
    videoEnc = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseDec());
    videoDec = nullptr;
    OH_AVFormat_Destroy(VideoFormat);
    VideoFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->CalcuError());
}


/**
421
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0700
422 423 424
 * @tc.name      : stop dec at eos and restart to eos
 * @tc.desc      : Basic function test
 */
425
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0700, TestSize.Level1)
426
{
L
liyiming 已提交
427 428 429 430
    if (!CanUseVideoCodec()) {
        cout << "codec not support, ignore SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0700 ignore" <<endl;
        return;
    }
431 432 433 434 435 436 437 438
    VDecEncNdkSample *vDecEncSample = new VDecEncNdkSample();

    struct OH_AVCodec* videoDec = vDecEncSample->CreateVideoDecoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoDec);
    struct OH_AVCodec* videoEnc = vDecEncSample->CreateVideoEncoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoEnc);
    vDecEncSample->SetReadPath(READPATH);
    vDecEncSample->SetEosState(false);
439
    vDecEncSample->SetSavePath("/data/media/video_007.h264");
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
    
    OH_AVFormat *VideoFormat = createFormat();
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureDec(VideoFormat));
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureEnc(VideoFormat));
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->GetSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->SetOutputSurface());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->PrepareDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartDec());

    while (!vDecEncSample->GetDecEosState()) {};
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StopDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->FlushEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->CalcuError());
    vDecEncSample->ReRead();
    vDecEncSample->ResetDecParam();
    vDecEncSample->ResetEncParam();
458
    vDecEncSample->SetSavePath("/data/media/video_007_2.h264");
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
    vDecEncSample->SetEosState(true);
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartDec());

    while (!vDecEncSample->GetEncEosState()) {};
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StopDec());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StopEnc());
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseEnc());
    videoEnc = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ReleaseDec());
    videoDec = nullptr;
    OH_AVFormat_Destroy(VideoFormat);
    VideoFormat = nullptr;
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->CalcuError());
}