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 "AVMuxerDemo.h" 19 #include "avcodec_info.h" 20 #include "avcodec_errors.h" 21 #include "avcodec_common.h" 22 23 using namespace std; 24 using namespace testing::ext; 25 using namespace OHOS; 26 using namespace OHOS::MediaAVCodec; 27 28 29 namespace { 30 class InnerAVMuxerParamCheckTest : public testing::Test { 31 public: 32 static void SetUpTestCase(); 33 static void TearDownTestCase(); 34 void SetUp() override; 35 void TearDown() override; 36 }; 37 SetUpTestCase()38 void InnerAVMuxerParamCheckTest::SetUpTestCase() {} TearDownTestCase()39 void InnerAVMuxerParamCheckTest::TearDownTestCase() {} SetUp()40 void InnerAVMuxerParamCheckTest::SetUp() {} TearDown()41 void InnerAVMuxerParamCheckTest::TearDown() {} 42 } 43 44 45 /** 46 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_001 47 * @tc.name : InnerCreate - fd check 48 * @tc.desc : param check test 49 */ 50 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_001, TestSize.Level2) 51 { 52 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 53 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 54 int32_t fd = -1; 55 int32_t ret = muxerDemo->InnerCreate(fd, format); 56 ASSERT_EQ(AVCS_ERR_NO_MEMORY, ret); 57 muxerDemo->InnerDestroy(); 58 59 fd = muxerDemo->InnergetFdByMode(format); 60 ret = muxerDemo->InnerCreate(fd, format); 61 ASSERT_EQ(AVCS_ERR_OK, ret); 62 muxerDemo->InnerDestroy(); 63 delete muxerDemo; 64 } 65 66 67 /** 68 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_002 69 * @tc.name : InnerCreate - format check 70 * @tc.desc : param check test 71 */ 72 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_002, TestSize.Level2) 73 { 74 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 75 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 76 int32_t fd = muxerDemo->InnergetFdByMode(format); 77 int32_t ret = muxerDemo->InnerCreate(fd, format); 78 ASSERT_EQ(AVCS_ERR_OK, ret); 79 muxerDemo->InnerDestroy(); 80 81 format = OUTPUT_FORMAT_M4A; 82 fd = muxerDemo->InnergetFdByMode(format); 83 ret = muxerDemo->InnerCreate(fd, format); 84 ASSERT_EQ(AVCS_ERR_OK, ret); 85 86 muxerDemo->InnerDestroy(); 87 88 format = OUTPUT_FORMAT_DEFAULT; 89 fd = muxerDemo->InnergetFdByMode(format); 90 ret = muxerDemo->InnerCreate(fd, format); 91 ASSERT_EQ(AVCS_ERR_OK, ret); 92 93 muxerDemo->InnerDestroy(); 94 delete muxerDemo; 95 } 96 97 /** 98 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_003 99 * @tc.name : InnerSetRotation - rotation check 100 * @tc.desc : param check test 101 */ 102 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_003, TestSize.Level2) 103 { 104 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 105 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 106 int32_t fd = muxerDemo->InnergetFdByMode(format); 107 std::cout<<"fd "<< fd << endl; 108 int32_t ret = muxerDemo->InnerCreate(fd, format); 109 ASSERT_EQ(AVCS_ERR_OK, ret); 110 111 int32_t rotation; 112 113 rotation = 0; 114 ret = muxerDemo->InnerSetRotation(rotation); 115 ASSERT_EQ(AVCS_ERR_OK, ret); 116 117 rotation = 90; 118 ret = muxerDemo->InnerSetRotation(rotation); 119 ASSERT_EQ(AVCS_ERR_OK, ret); 120 121 rotation = 180; 122 ret = muxerDemo->InnerSetRotation(rotation); 123 ASSERT_EQ(AVCS_ERR_OK, ret); 124 125 rotation = 270; 126 ret = muxerDemo->InnerSetRotation(rotation); 127 ASSERT_EQ(AVCS_ERR_OK, ret); 128 129 rotation = -90; 130 ret = muxerDemo->InnerSetRotation(rotation); 131 ASSERT_EQ(AVCS_ERR_INVALID_VAL, ret); 132 133 rotation = 45; 134 ret = muxerDemo->InnerSetRotation(rotation); 135 ASSERT_EQ(AVCS_ERR_INVALID_VAL, ret); 136 137 muxerDemo->InnerDestroy(); 138 139 delete muxerDemo; 140 } 141 142 143 /** 144 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_004 145 * @tc.name : InnerAddTrack - (MediaDescriptionKey::MD_KEY_CODEC_MIME) check 146 * @tc.desc : param check test 147 */ 148 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_004, TestSize.Level2) 149 { 150 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 151 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 152 int32_t fd = muxerDemo->InnergetFdByMode(format); 153 std::cout<<"fd "<< fd << endl; 154 155 int32_t ret = muxerDemo->InnerCreate(fd, format); 156 ASSERT_EQ(AVCS_ERR_OK, ret); 157 158 MediaDescription audioParams; 159 uint8_t a[100]; 160 161 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC); 162 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, a, 100); 163 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 164 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 165 166 int trackIndex = 0; 167 int32_t trackId; 168 169 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 170 ASSERT_EQ(0, trackId); 171 172 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_MPEG); 173 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 174 ASSERT_EQ(0, trackId); 175 176 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_FLAC); 177 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 178 ASSERT_EQ(AVCS_ERR_UNSUPPORT_CONTAINER_TYPE, trackId); 179 180 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, "aaaaaa"); 181 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 182 ASSERT_EQ(AVCS_ERR_UNSUPPORT_CONTAINER_TYPE, trackId); 183 184 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, 0); 185 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 186 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 187 188 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, 0); 189 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 190 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 191 192 audioParams.PutFloatValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, 0.1); 193 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 194 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 195 196 audioParams.PutDoubleValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, 0.1); 197 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 198 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 199 200 uint8_t b[100]; 201 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_MIME, b, 100); 202 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 203 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 204 205 muxerDemo->InnerDestroy(); 206 207 delete muxerDemo; 208 } 209 210 211 /** 212 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_005 213 * @tc.name : InnerAddTrack - (MediaDescriptionKey::MD_KEY_CHANNEL_COUNT) check 214 * @tc.desc : param check test 215 */ 216 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_005, TestSize.Level2) 217 { 218 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 219 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 220 int32_t fd = muxerDemo->InnergetFdByMode(format); 221 int32_t ret = muxerDemo->InnerCreate(fd, format); 222 ASSERT_EQ(AVCS_ERR_OK, ret); 223 224 MediaDescription audioParams; 225 uint8_t a[100]; 226 227 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC); 228 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, a, 100); 229 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 230 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 231 232 int trackIndex = 0; 233 int32_t trackId; 234 235 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 236 ASSERT_EQ(0, trackId); 237 238 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, -1); 239 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 240 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 241 242 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, "aaaaaa"); 243 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 244 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 245 246 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 0); 247 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 248 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 249 250 audioParams.PutFloatValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 0.1); 251 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 252 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 253 254 audioParams.PutDoubleValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 0.1); 255 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 256 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 257 258 uint8_t b[100]; 259 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, b, 100); 260 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 261 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 262 263 muxerDemo->InnerDestroy(); 264 delete muxerDemo; 265 } 266 267 268 /** 269 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_006 270 * @tc.name : InnerAddTrack - (MediaDescriptionKey::MD_KEY_SAMPLE_RATE) check 271 * @tc.desc : param check test 272 */ 273 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_006, TestSize.Level2) 274 { 275 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 276 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 277 int32_t fd = muxerDemo->InnergetFdByMode(format); 278 int32_t ret = muxerDemo->InnerCreate(fd, format); 279 ASSERT_EQ(AVCS_ERR_OK, ret); 280 281 MediaDescription audioParams; 282 uint8_t a[100]; 283 284 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC); 285 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, a, 100); 286 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 287 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 288 289 int trackIndex = 0; 290 int32_t trackId; 291 292 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 293 ASSERT_EQ(0, trackId); 294 295 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, -1); 296 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 297 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 298 299 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, "aaaaaa"); 300 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 301 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 302 303 audioParams.PutLongValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 0); 304 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 305 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 306 307 audioParams.PutFloatValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 0.1); 308 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 309 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 310 311 audioParams.PutDoubleValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 0.1); 312 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 313 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 314 315 uint8_t b[100]; 316 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, b, 100); 317 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 318 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 319 320 muxerDemo->InnerDestroy(); 321 delete muxerDemo; 322 } 323 324 /** 325 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_007 326 * @tc.name : InnerAddTrack - video (MediaDescriptionKey::MD_KEY_CODEC_MIME) check 327 * @tc.desc : param check test 328 */ 329 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_007, TestSize.Level2) 330 { 331 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 332 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 333 int32_t fd = muxerDemo->InnergetFdByMode(format); 334 int32_t ret = muxerDemo->InnerCreate(fd, format); 335 ASSERT_EQ(AVCS_ERR_OK, ret); 336 337 MediaDescription videoParams; 338 uint8_t a[100]; 339 340 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4); 341 videoParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, a, 100); 342 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, 352); 343 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, 288); 344 345 int32_t trackId; 346 int trackIndex = 0; 347 348 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 349 ASSERT_EQ(0, trackId); 350 351 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_AVC); 352 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 353 ASSERT_EQ(0, trackId); 354 355 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::IMAGE_JPG); 356 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 357 ASSERT_EQ(0, trackId); 358 359 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::IMAGE_PNG); 360 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 361 ASSERT_EQ(0, trackId); 362 363 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::IMAGE_BMP); 364 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 365 ASSERT_EQ(0, trackId); 366 367 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, 0); 368 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 369 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 370 371 videoParams.PutLongValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, 0); 372 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 373 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 374 375 videoParams.PutFloatValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, 0.1); 376 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 377 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 378 379 videoParams.PutDoubleValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, 0.1); 380 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 381 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 382 383 uint8_t b[100]; 384 videoParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_MIME, b, 100); 385 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 386 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 387 388 muxerDemo->InnerDestroy(); 389 delete muxerDemo; 390 } 391 392 393 /** 394 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_008 395 * @tc.name : InnerAddTrack - video (MediaDescriptionKey::MD_KEY_WIDTH) check 396 * @tc.desc : param check test 397 */ 398 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_008, TestSize.Level2) 399 { 400 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 401 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 402 int32_t fd = muxerDemo->InnergetFdByMode(format); 403 int32_t ret = muxerDemo->InnerCreate(fd, format); 404 ASSERT_EQ(AVCS_ERR_OK, ret); 405 406 MediaDescription videoParams; 407 uint8_t a[100]; 408 409 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4); 410 videoParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, a, 100); 411 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, 352); 412 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, 288); 413 414 int trackIndex = 0; 415 int32_t trackId; 416 417 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 418 ASSERT_EQ(0, trackId); 419 420 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, -1); 421 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 422 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 423 424 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_WIDTH, "aaa"); 425 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 426 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 427 428 videoParams.PutLongValue(MediaDescriptionKey::MD_KEY_WIDTH, 0); 429 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 430 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 431 432 videoParams.PutFloatValue(MediaDescriptionKey::MD_KEY_WIDTH, 0.1); 433 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 434 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 435 436 videoParams.PutDoubleValue(MediaDescriptionKey::MD_KEY_WIDTH, 0.1); 437 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 438 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 439 440 uint8_t b[100]; 441 videoParams.PutBuffer(MediaDescriptionKey::MD_KEY_WIDTH, b, 100); 442 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 443 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 444 445 muxerDemo->InnerDestroy(); 446 delete muxerDemo; 447 } 448 449 450 /** 451 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_009 452 * @tc.name : InnerAddTrack - video (MediaDescriptionKey::MD_KEY_HEIGHT) check 453 * @tc.desc : param check test 454 */ 455 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_009, TestSize.Level2) 456 { 457 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 458 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 459 int32_t fd = muxerDemo->InnergetFdByMode(format); 460 int32_t ret = muxerDemo->InnerCreate(fd, format); 461 ASSERT_EQ(AVCS_ERR_OK, ret); 462 463 MediaDescription videoParams; 464 uint8_t a[100]; 465 466 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4); 467 videoParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, a, 100); 468 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, 352); 469 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, 288); 470 471 int trackIndex = 0; 472 int32_t trackId; 473 474 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 475 ASSERT_EQ(0, trackId); 476 477 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, -1); 478 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 479 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 480 481 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_HEIGHT, "aaa"); 482 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 483 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 484 485 videoParams.PutLongValue(MediaDescriptionKey::MD_KEY_HEIGHT, 0); 486 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 487 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 488 489 videoParams.PutFloatValue(MediaDescriptionKey::MD_KEY_HEIGHT, 0.1); 490 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 491 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 492 493 videoParams.PutDoubleValue(MediaDescriptionKey::MD_KEY_HEIGHT, 0.1); 494 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 495 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 496 497 uint8_t b[100]; 498 videoParams.PutBuffer(MediaDescriptionKey::MD_KEY_HEIGHT, b, 100); 499 trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams); 500 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 501 502 muxerDemo->InnerDestroy(); 503 delete muxerDemo; 504 } 505 506 507 /** 508 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_010 509 * @tc.name : InnerAddTrack - (any key) check 510 * @tc.desc : param check test 511 */ 512 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_010, TestSize.Level2) 513 { 514 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 515 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 516 int32_t fd = muxerDemo->InnergetFdByMode(format); 517 int32_t ret = muxerDemo->InnerCreate(fd, format); 518 ASSERT_EQ(AVCS_ERR_OK, ret); 519 520 MediaDescription audioParams; 521 audioParams.PutStringValue("aaaaa", "bbbbb"); 522 523 int trackIndex = 0; 524 int32_t trackId; 525 526 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 527 ASSERT_EQ(AVCS_ERR_INVALID_VAL, trackId); 528 529 muxerDemo->InnerDestroy(); 530 delete muxerDemo; 531 } 532 533 534 /** 535 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_011 536 * @tc.name : InnerWriteSample - info.trackIndex check 537 * @tc.desc : param check test 538 */ 539 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_011, TestSize.Level2) 540 { 541 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 542 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 543 int32_t fd = muxerDemo->InnergetFdByMode(format); 544 int32_t ret = muxerDemo->InnerCreate(fd, format); 545 ASSERT_EQ(AVCS_ERR_OK, ret); 546 547 MediaDescription audioParams; 548 uint8_t a[100]; 549 550 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC); 551 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, a, 100); 552 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 553 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 554 555 int trackIndex = 0; 556 int32_t trackId; 557 558 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 559 ASSERT_EQ(0, trackId); 560 561 562 ret = muxerDemo->InnerStart(); 563 ASSERT_EQ(AVCS_ERR_OK, ret); 564 565 uint8_t data[100]; 566 AVCodecBufferInfo info; 567 info.presentationTimeUs = 0; 568 info.size = 100; 569 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE; 570 info.offset = 0; 571 572 std::shared_ptr<AVSharedMemoryBase> avMemBuffer = std::make_shared<AVSharedMemoryBase> 573 (info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData"); 574 575 avMemBuffer->Init(); 576 (void)memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), data, info.size); 577 578 ret = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag); 579 ASSERT_EQ(AVCS_ERR_OK, ret); 580 581 trackIndex = -1; 582 ret = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag); 583 ASSERT_EQ(AVCS_ERR_INVALID_VAL, ret); 584 585 muxerDemo->InnerDestroy(); 586 delete muxerDemo; 587 } 588 589 590 /** 591 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_012 592 * @tc.name : InnerWriteSample - info.presentationTimeUs check 593 * @tc.desc : param check test 594 */ 595 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_012, TestSize.Level2) 596 { 597 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 598 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 599 int32_t fd = muxerDemo->InnergetFdByMode(format); 600 int32_t ret = muxerDemo->InnerCreate(fd, format); 601 ASSERT_EQ(AVCS_ERR_OK, ret); 602 603 MediaDescription audioParams; 604 uint8_t a[100]; 605 606 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC); 607 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, a, 100); 608 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 609 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 610 611 int trackIndex = 0; 612 613 ret = muxerDemo->InnerAddTrack(trackIndex, audioParams); 614 ASSERT_EQ(0, ret); 615 std::cout << "trackIndex: " << trackIndex << std::endl; 616 ret = muxerDemo->InnerStart(); 617 ASSERT_EQ(AVCS_ERR_OK, ret); 618 619 uint8_t data[100]; 620 AVCodecBufferInfo info; 621 info.presentationTimeUs = 0; 622 info.size = 100; 623 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE; 624 info.offset = 0; 625 626 std::shared_ptr<AVSharedMemoryBase> avMemBuffer = std::make_shared<AVSharedMemoryBase> 627 (info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData"); 628 avMemBuffer->Init(); 629 (void)memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), data, info.size); 630 std::cout << "avMemBuffer: " << avMemBuffer << std::endl; 631 ret = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag); 632 ASSERT_EQ(AVCS_ERR_OK, ret); 633 634 info.presentationTimeUs = -1; 635 ret = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag); 636 ASSERT_EQ(AVCS_ERR_OK, ret); 637 638 muxerDemo->InnerDestroy(); 639 delete muxerDemo; 640 } 641 642 643 /** 644 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_013 645 * @tc.name : InnerWriteSample - info.size check 646 * @tc.desc : param check test 647 */ 648 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_013, TestSize.Level2) 649 { 650 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 651 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 652 int32_t fd = muxerDemo->InnergetFdByMode(format); 653 int32_t ret = muxerDemo->InnerCreate(fd, format); 654 ASSERT_EQ(AVCS_ERR_OK, ret); 655 656 MediaDescription audioParams; 657 uint8_t a[100]; 658 659 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC); 660 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, a, 100); 661 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 662 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 663 664 int trackIndex = 0; 665 int32_t trackId; 666 667 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 668 ASSERT_EQ(0, trackId); 669 670 ret = muxerDemo->InnerStart(); 671 ASSERT_EQ(AVCS_ERR_OK, ret); 672 673 uint8_t data[100]; 674 AVCodecBufferInfo info; 675 info.presentationTimeUs = 0; 676 info.size = 100; 677 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE; 678 info.offset = 0; 679 680 std::shared_ptr<AVSharedMemoryBase> avMemBuffer = std::make_shared<AVSharedMemoryBase> 681 (info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData"); 682 avMemBuffer->Init(); 683 (void)memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), data, info.size); 684 ret = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag); 685 ASSERT_EQ(AVCS_ERR_OK, ret); 686 687 info.size = -1; 688 ret = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag); 689 ASSERT_EQ(AVCS_ERR_INVALID_VAL, ret); 690 691 muxerDemo->InnerDestroy(); 692 delete muxerDemo; 693 } 694 /** 695 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_014 696 * @tc.name : InnerWriteSample - info.offset check 697 * @tc.desc : param check test 698 */ 699 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_014, TestSize.Level2) 700 { 701 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 702 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 703 int32_t fd = muxerDemo->InnergetFdByMode(format); 704 int32_t ret = muxerDemo->InnerCreate(fd, format); 705 ASSERT_EQ(AVCS_ERR_OK, ret); 706 707 MediaDescription audioParams; 708 uint8_t a[100]; 709 710 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC); 711 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, a, 100); 712 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 713 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 714 715 int trackIndex = 0; 716 int32_t trackId; 717 718 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 719 ASSERT_EQ(0, trackId); 720 721 ret = muxerDemo->InnerStart(); 722 ASSERT_EQ(AVCS_ERR_OK, ret); 723 724 uint8_t data[100]; 725 AVCodecBufferInfo info; 726 info.presentationTimeUs = 0; 727 info.size = 100; 728 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE; 729 info.offset = 0; 730 731 std::shared_ptr<AVSharedMemoryBase> avMemBuffer = std::make_shared<AVSharedMemoryBase> 732 (info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData"); 733 avMemBuffer->Init(); 734 (void)memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), data, info.size); 735 ret = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag); 736 ASSERT_EQ(AVCS_ERR_OK, ret); 737 738 info.offset = -1; 739 ret = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag); 740 ASSERT_EQ(AVCS_ERR_INVALID_VAL, ret); 741 742 muxerDemo->InnerDestroy(); 743 delete muxerDemo; 744 } 745 746 747 /** 748 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_015 749 * @tc.name : InnerWriteSample - info.flags check 750 * @tc.desc : param check test 751 */ 752 HWTEST_F(InnerAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_015, TestSize.Level2) 753 { 754 AVMuxerDemo* muxerDemo = new AVMuxerDemo(); 755 OutputFormat format = OUTPUT_FORMAT_MPEG_4; 756 int32_t fd = muxerDemo->InnergetFdByMode(format); 757 int32_t ret = muxerDemo->InnerCreate(fd, format); 758 ASSERT_EQ(AVCS_ERR_OK, ret); 759 760 MediaDescription audioParams; 761 uint8_t a[100]; 762 763 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC); 764 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, a, 100); 765 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 766 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 767 768 int trackIndex = 0; 769 int32_t trackId; 770 771 trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams); 772 ASSERT_EQ(0, trackId); 773 774 ret = muxerDemo->InnerStart(); 775 ASSERT_EQ(AVCS_ERR_OK, ret); 776 777 uint8_t data[100]; 778 AVCodecBufferInfo info; 779 info.presentationTimeUs = 0; 780 info.size = 100; 781 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE; 782 info.offset = 0; 783 784 std::shared_ptr<AVSharedMemoryBase> avMemBuffer = 785 std::make_shared<AVSharedMemoryBase>(info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData"); 786 avMemBuffer->Init(); 787 (void)memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), data, info.size); 788 ret = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag); 789 ASSERT_EQ(AVCS_ERR_OK, ret); 790 791 muxerDemo->InnerDestroy(); 792 delete muxerDemo; 793 } 794