ActsVideoDecEncNdkTest.cpp 17.4 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"
23 24 25 26 27 28 29

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

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

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

85 86 87 88 89 90 91
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);
92
    OH_AVFormat_SetStringValue(DefaultFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_VIDEO_AVC);
93 94
    return DefaultFormat;
}
95 96 97
}

/**
98
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0100
99 100 101
 * @tc.name      : stop at end of stream
 * @tc.desc      : Basic function test
 */
102
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0100, TestSize.Level1)
103 104 105 106
{
    VDecEncNdkSample *vDecEncSample = new VDecEncNdkSample();
    struct OH_AVCodec* videoDec = vDecEncSample->CreateVideoDecoderByMime(MIME_TYPE_AVC);
    ASSERT_NE(nullptr, videoDec);
107

108 109 110
    struct OH_AVCodec* videoEnc = vDecEncSample->CreateVideoEncoderByMime(MIME_TYPE_MPEG4);
    ASSERT_NE(nullptr, videoEnc);
    vDecEncSample->SetReadPath(READPATH);
111
    vDecEncSample->SetSavePath("/data/media/video_001.h264");
112 113 114 115 116 117 118 119 120 121
    
    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));
122 123
    OH_AVFormat_SetIntValue(VideoFormat, OH_MD_KEY_TRACK_TYPE, MEDIA_TYPE_VID);

124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    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());
}

/**
154
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0200
155 156 157
 * @tc.name      : reset at end of stream
 * @tc.desc      : Basic function test
 */
158
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0200, TestSize.Level1)
159 160 161 162 163 164 165 166
{
    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);
167
    vDecEncSample->SetSavePath("/data/media/video_002.h264");
168 169 170
    
    OH_AVFormat *VideoFormat = createFormat();
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->ConfigureDec(VideoFormat));
171
    OH_AVFormat_SetIntValue(VideoFormat, OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CBR);
172 173 174 175 176 177
    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());
178
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->SetParameterDec(VideoFormat));
179
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->StartDec());
180
    ASSERT_EQ(AV_ERR_OK, vDecEncSample->SetParameterEnc(VideoFormat));
181 182 183 184 185 186 187 188 189 190 191 192 193 194

    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());
}

 /**
195
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0300
196 197 198
 * @tc.name      : release at end of stream
 * @tc.desc      : Basic function test
 */
199
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0300, TestSize.Level1)
200 201 202 203 204 205 206 207
{
    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);
208
    vDecEncSample->SetSavePath("/data/media/video_003.h264");
209 210
    
    OH_AVFormat *VideoFormat = createFormat();
211 212
    OH_AVFormat_SetIntValue(VideoFormat, OH_MD_KEY_PROFILE, AVC_PROFILE_BASELINE);

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
    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());
}

/**
233
* @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0400
234 235 236
* @tc.name      : flush at running
* @tc.desc      : Basic function test
*/
237
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0400, TestSize.Level1)
238 239 240 241 242 243 244 245 246
{
    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);
247
    vDecEncSample->SetSavePath("/data/media/video_004.h264");
248 249
    
    OH_AVFormat *VideoFormat = createFormat();
250 251
    OH_AVFormat_SetIntValue(VideoFormat, OH_MD_KEY_PROFILE, AVC_PROFILE_HIGH);

252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
    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);
268
    vDecEncSample->SetSavePath("/data/media/video_004_2.h264");
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284

    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());
}


/**
285
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0500
286 287 288
 * @tc.name      : flush dec at eos and restart
 * @tc.desc      : Basic function test
 */
289
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0500, TestSize.Level1)
290 291 292 293 294 295 296 297 298
{
    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);
299
    vDecEncSample->SetSavePath("/data/media/video_005.h264");
300 301
    
    OH_AVFormat *VideoFormat = createFormat();
302 303
    OH_AVFormat_SetIntValue(VideoFormat, OH_MD_KEY_PROFILE, AVC_PROFILE_MAIN);

304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
    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();
320
    vDecEncSample->SetSavePath("/data/media/video_005_2.h264");
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
    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());
}


/**
338
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0600
339 340 341
 * @tc.name      : stop at running and restart to eos
 * @tc.desc      : Basic function test
 */
342
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0600, TestSize.Level1)
343 344 345 346 347 348 349 350 351
{
    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);
352
    vDecEncSample->SetSavePath("/data/media/video_006.h264");
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
    
    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);
371
    vDecEncSample->SetSavePath("/data/media/video_006_2.h264");
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
    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());
}


/**
389
 * @tc.number    : SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0700
390 391 392
 * @tc.name      : stop dec at eos and restart to eos
 * @tc.desc      : Basic function test
 */
393
HWTEST_F(ActsVideoDecEncNdkTest, SUB_MULTIMEDIA_MEDIA_VIDEO_DEC_ENC_FUNCTION_0700, TestSize.Level1)
394 395 396 397 398 399 400 401 402
{
    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);
403
    vDecEncSample->SetSavePath("/data/media/video_007.h264");
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
    
    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();
422
    vDecEncSample->SetSavePath("/data/media/video_007_2.h264");
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
    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());
}