1da853ecaSopenharmony_ci/* 2da853ecaSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3da853ecaSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4da853ecaSopenharmony_ci * you may not use this file except in compliance with the License. 5da853ecaSopenharmony_ci * You may obtain a copy of the License at 6da853ecaSopenharmony_ci * 7da853ecaSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8da853ecaSopenharmony_ci * 9da853ecaSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10da853ecaSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11da853ecaSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12da853ecaSopenharmony_ci * See the License for the specific language governing permissions and 13da853ecaSopenharmony_ci * limitations under the License. 14da853ecaSopenharmony_ci */ 15da853ecaSopenharmony_ci 16da853ecaSopenharmony_ci#include <string> 17da853ecaSopenharmony_ci#include "gtest/gtest.h" 18da853ecaSopenharmony_ci#include "AudioEncoderDemoCommon.h" 19da853ecaSopenharmony_ci 20da853ecaSopenharmony_ciusing namespace std; 21da853ecaSopenharmony_ciusing namespace testing::ext; 22da853ecaSopenharmony_ciusing namespace OHOS; 23da853ecaSopenharmony_ciusing namespace OHOS::MediaAVCodec; 24da853ecaSopenharmony_ci 25da853ecaSopenharmony_cinamespace { 26da853ecaSopenharmony_ciclass NativeParamCheckTest : public testing::Test { 27da853ecaSopenharmony_cipublic: 28da853ecaSopenharmony_ci static void SetUpTestCase(); 29da853ecaSopenharmony_ci static void TearDownTestCase(); 30da853ecaSopenharmony_ci void SetUp() override; 31da853ecaSopenharmony_ci void TearDown() override; 32da853ecaSopenharmony_ci}; 33da853ecaSopenharmony_ci 34da853ecaSopenharmony_civoid NativeParamCheckTest::SetUpTestCase() {} 35da853ecaSopenharmony_civoid NativeParamCheckTest::TearDownTestCase() {} 36da853ecaSopenharmony_civoid NativeParamCheckTest::SetUp() {} 37da853ecaSopenharmony_civoid NativeParamCheckTest::TearDown() {} 38da853ecaSopenharmony_ci 39da853ecaSopenharmony_ciconstexpr int32_t CHANNEL_COUNT_FLAC = 2; 40da853ecaSopenharmony_ciconstexpr int32_t SAMPLE_RATE_FLAC = 48000; 41da853ecaSopenharmony_ciconstexpr int64_t BITS_RATE_FLAC = 128000; 42da853ecaSopenharmony_ci} // namespace 43da853ecaSopenharmony_ci 44da853ecaSopenharmony_ci/** 45da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_001 46da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_CreateByMime - mime check 47da853ecaSopenharmony_ci * @tc.desc : param check test 48da853ecaSopenharmony_ci */ 49da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_001, TestSize.Level2) 50da853ecaSopenharmony_ci{ 51da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 52da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByMime("aaa"); 53da853ecaSopenharmony_ci ASSERT_EQ(nullptr, handle); 54da853ecaSopenharmony_ci 55da853ecaSopenharmony_ci handle = encoderDemo->NativeCreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC); 56da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 57da853ecaSopenharmony_ci 58da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 59da853ecaSopenharmony_ci handle = nullptr; 60da853ecaSopenharmony_ci handle = encoderDemo->NativeCreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_FLAC); 61da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 62da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 63da853ecaSopenharmony_ci delete encoderDemo; 64da853ecaSopenharmony_ci} 65da853ecaSopenharmony_ci 66da853ecaSopenharmony_ci/** 67da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_002 68da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_CreateByName - name check 69da853ecaSopenharmony_ci * @tc.desc : param check test 70da853ecaSopenharmony_ci */ 71da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_002, TestSize.Level2) 72da853ecaSopenharmony_ci{ 73da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 74da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByName("aaa"); 75da853ecaSopenharmony_ci ASSERT_EQ(nullptr, handle); 76da853ecaSopenharmony_ci 77da853ecaSopenharmony_ci handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 78da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 79da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 80da853ecaSopenharmony_ci handle = nullptr; 81da853ecaSopenharmony_ci 82da853ecaSopenharmony_ci handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.Flac"); 83da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 84da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 85da853ecaSopenharmony_ci handle = nullptr; 86da853ecaSopenharmony_ci delete encoderDemo; 87da853ecaSopenharmony_ci} 88da853ecaSopenharmony_ci 89da853ecaSopenharmony_ci/** 90da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_003 91da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_Configure - format(MD_KEY_BITRATE) check 92da853ecaSopenharmony_ci * @tc.desc : param check test 93da853ecaSopenharmony_ci */ 94da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_003, TestSize.Level2) 95da853ecaSopenharmony_ci{ 96da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 97da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 98da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 99da853ecaSopenharmony_ci 100da853ecaSopenharmony_ci OH_AVFormat *format = OH_AVFormat_Create(); 101da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 102da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 103da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 104da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 105da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 106da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, 1); 107da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 108da853ecaSopenharmony_ci 109da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeConfigure(handle, format); 110da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 111da853ecaSopenharmony_ci 112da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 113da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, -1); 114da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 115da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 116da853ecaSopenharmony_ci 117da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 118da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, 1); 119da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 120da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 121da853ecaSopenharmony_ci 122da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 123da853ecaSopenharmony_ci OH_AVFormat_SetStringValue(format, OH_MD_KEY_BITRATE, "aaa"); 124da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 125da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 126da853ecaSopenharmony_ci 127da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 128da853ecaSopenharmony_ci OH_AVFormat_SetFloatValue(format, OH_MD_KEY_BITRATE, 0.1); 129da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 130da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 131da853ecaSopenharmony_ci 132da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 133da853ecaSopenharmony_ci OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_BITRATE, 0.1); 134da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 135da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 136da853ecaSopenharmony_ci 137da853ecaSopenharmony_ci uint8_t a[100]; 138da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 139da853ecaSopenharmony_ci OH_AVFormat_SetBuffer(format, OH_MD_KEY_BITRATE, a, 100); 140da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 141da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 142da853ecaSopenharmony_ci 143da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 144da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 145da853ecaSopenharmony_ci delete encoderDemo; 146da853ecaSopenharmony_ci} 147da853ecaSopenharmony_ci 148da853ecaSopenharmony_ci/** 149da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_004 150da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_Configure - format(OH_MD_KEY_AUD_CHANNEL_COUNT) check 151da853ecaSopenharmony_ci * @tc.desc : param check test 152da853ecaSopenharmony_ci */ 153da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_004, TestSize.Level2) 154da853ecaSopenharmony_ci{ 155da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 156da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 157da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 158da853ecaSopenharmony_ci 159da853ecaSopenharmony_ci OH_AVFormat *format = OH_AVFormat_Create(); 160da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 161da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 162da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 163da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 164da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 165da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, 1); 166da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 167da853ecaSopenharmony_ci 168da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeConfigure(handle, format); 169da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 170da853ecaSopenharmony_ci 171da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 172da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, -1); 173da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 174da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 175da853ecaSopenharmony_ci 176da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 177da853ecaSopenharmony_ci OH_AVFormat_SetStringValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, "aaa"); 178da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 179da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 180da853ecaSopenharmony_ci 181da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 182da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0); 183da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 184da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 185da853ecaSopenharmony_ci 186da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 187da853ecaSopenharmony_ci OH_AVFormat_SetFloatValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0.1); 188da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 189da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 190da853ecaSopenharmony_ci 191da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 192da853ecaSopenharmony_ci OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0.1); 193da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 194da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 195da853ecaSopenharmony_ci 196da853ecaSopenharmony_ci uint8_t a[100]; 197da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 198da853ecaSopenharmony_ci OH_AVFormat_SetBuffer(format, OH_MD_KEY_AUD_CHANNEL_COUNT, a, 100); 199da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 200da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 201da853ecaSopenharmony_ci 202da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 203da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 204da853ecaSopenharmony_ci delete encoderDemo; 205da853ecaSopenharmony_ci} 206da853ecaSopenharmony_ci 207da853ecaSopenharmony_ci/** 208da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_005 209da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_Configure - format(OH_MD_KEY_AUD_SAMPLE_RATE) check 210da853ecaSopenharmony_ci * @tc.desc : param check test 211da853ecaSopenharmony_ci */ 212da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_005, TestSize.Level2) 213da853ecaSopenharmony_ci{ 214da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 215da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 216da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 217da853ecaSopenharmony_ci 218da853ecaSopenharmony_ci OH_AVFormat *format = OH_AVFormat_Create(); 219da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 220da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 221da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 222da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 223da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 224da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, 1); 225da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 226da853ecaSopenharmony_ci 227da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeConfigure(handle, format); 228da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 229da853ecaSopenharmony_ci 230da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 231da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, -1); 232da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 233da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 234da853ecaSopenharmony_ci 235da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 236da853ecaSopenharmony_ci OH_AVFormat_SetStringValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, "aaa"); 237da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 238da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 239da853ecaSopenharmony_ci 240da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 241da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0); 242da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 243da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 244da853ecaSopenharmony_ci 245da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 246da853ecaSopenharmony_ci OH_AVFormat_SetFloatValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0.1); 247da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 248da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 249da853ecaSopenharmony_ci 250da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 251da853ecaSopenharmony_ci OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0.1); 252da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 253da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 254da853ecaSopenharmony_ci 255da853ecaSopenharmony_ci uint8_t a[100]; 256da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 257da853ecaSopenharmony_ci OH_AVFormat_SetBuffer(format, OH_MD_KEY_AUD_SAMPLE_RATE, a, 100); 258da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 259da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 260da853ecaSopenharmony_ci 261da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 262da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 263da853ecaSopenharmony_ci delete encoderDemo; 264da853ecaSopenharmony_ci} 265da853ecaSopenharmony_ci 266da853ecaSopenharmony_ci/** 267da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_006 268da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_SetParameter - format(MD_KEY_BITRATE) check 269da853ecaSopenharmony_ci * @tc.desc : param check test 270da853ecaSopenharmony_ci */ 271da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_006, TestSize.Level2) 272da853ecaSopenharmony_ci{ 273da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 274da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 275da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 276da853ecaSopenharmony_ci 277da853ecaSopenharmony_ci OH_AVFormat *format = OH_AVFormat_Create(); 278da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 279da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 280da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 281da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 282da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 283da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, 1); 284da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 285da853ecaSopenharmony_ci 286da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeConfigure(handle, format); 287da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 288da853ecaSopenharmony_ci 289da853ecaSopenharmony_ci ret = encoderDemo->NativePrepare(handle); 290da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 291da853ecaSopenharmony_ci ret = encoderDemo->NativeStart(handle); 292da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 293da853ecaSopenharmony_ci 294da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 295da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 296da853ecaSopenharmony_ci 297da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, -1); 298da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 299da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 300da853ecaSopenharmony_ci 301da853ecaSopenharmony_ci OH_AVFormat_SetStringValue(format, OH_MD_KEY_BITRATE, "aaa"); 302da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 303da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 304da853ecaSopenharmony_ci 305da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, 0); 306da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 307da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 308da853ecaSopenharmony_ci 309da853ecaSopenharmony_ci OH_AVFormat_SetFloatValue(format, OH_MD_KEY_BITRATE, 0.1); 310da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 311da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 312da853ecaSopenharmony_ci 313da853ecaSopenharmony_ci OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_BITRATE, 0.1); 314da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 315da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 316da853ecaSopenharmony_ci 317da853ecaSopenharmony_ci uint8_t a[100]; 318da853ecaSopenharmony_ci OH_AVFormat_SetBuffer(format, OH_MD_KEY_AUD_SAMPLE_RATE, a, 100); 319da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 320da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 321da853ecaSopenharmony_ci 322da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 323da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 324da853ecaSopenharmony_ci delete encoderDemo; 325da853ecaSopenharmony_ci} 326da853ecaSopenharmony_ci 327da853ecaSopenharmony_ci/** 328da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_007 329da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_SetParameter - format(OH_MD_KEY_AUD_CHANNEL_COUNT) check 330da853ecaSopenharmony_ci * @tc.desc : param check test 331da853ecaSopenharmony_ci */ 332da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_007, TestSize.Level2) 333da853ecaSopenharmony_ci{ 334da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 335da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 336da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 337da853ecaSopenharmony_ci 338da853ecaSopenharmony_ci OH_AVFormat *format = OH_AVFormat_Create(); 339da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 340da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 341da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 342da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 343da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 344da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, 1); 345da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 346da853ecaSopenharmony_ci 347da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeConfigure(handle, format); 348da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 349da853ecaSopenharmony_ci 350da853ecaSopenharmony_ci ret = encoderDemo->NativePrepare(handle); 351da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 352da853ecaSopenharmony_ci ret = encoderDemo->NativeStart(handle); 353da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 354da853ecaSopenharmony_ci 355da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 356da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 357da853ecaSopenharmony_ci 358da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, -1); 359da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 360da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 361da853ecaSopenharmony_ci 362da853ecaSopenharmony_ci OH_AVFormat_SetStringValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, "aaa"); 363da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 364da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 365da853ecaSopenharmony_ci 366da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0); 367da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 368da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 369da853ecaSopenharmony_ci 370da853ecaSopenharmony_ci OH_AVFormat_SetFloatValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0.1); 371da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 372da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 373da853ecaSopenharmony_ci 374da853ecaSopenharmony_ci OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0.1); 375da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 376da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 377da853ecaSopenharmony_ci 378da853ecaSopenharmony_ci uint8_t a[100]; 379da853ecaSopenharmony_ci OH_AVFormat_SetBuffer(format, OH_MD_KEY_AUD_CHANNEL_COUNT, a, 100); 380da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 381da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 382da853ecaSopenharmony_ci 383da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 384da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 385da853ecaSopenharmony_ci delete encoderDemo; 386da853ecaSopenharmony_ci} 387da853ecaSopenharmony_ci 388da853ecaSopenharmony_ci/** 389da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_008 390da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_SetParameter - format(OH_MD_KEY_AUD_SAMPLE_RATE) check 391da853ecaSopenharmony_ci * @tc.desc : param check test 392da853ecaSopenharmony_ci */ 393da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_008, TestSize.Level2) 394da853ecaSopenharmony_ci{ 395da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 396da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 397da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 398da853ecaSopenharmony_ci 399da853ecaSopenharmony_ci OH_AVFormat *format = OH_AVFormat_Create(); 400da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 401da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 402da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 403da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 404da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 405da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, 1); 406da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 407da853ecaSopenharmony_ci 408da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeConfigure(handle, format); 409da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 410da853ecaSopenharmony_ci 411da853ecaSopenharmony_ci ret = encoderDemo->NativePrepare(handle); 412da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 413da853ecaSopenharmony_ci ret = encoderDemo->NativeStart(handle); 414da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 415da853ecaSopenharmony_ci 416da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 417da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 418da853ecaSopenharmony_ci 419da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, -1); 420da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 421da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 422da853ecaSopenharmony_ci 423da853ecaSopenharmony_ci OH_AVFormat_SetStringValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, "aaa"); 424da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 425da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 426da853ecaSopenharmony_ci 427da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0); 428da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 429da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 430da853ecaSopenharmony_ci 431da853ecaSopenharmony_ci OH_AVFormat_SetFloatValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0.1); 432da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 433da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 434da853ecaSopenharmony_ci 435da853ecaSopenharmony_ci OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0.1); 436da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 437da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 438da853ecaSopenharmony_ci 439da853ecaSopenharmony_ci uint8_t a[100]; 440da853ecaSopenharmony_ci OH_AVFormat_SetBuffer(format, OH_MD_KEY_AUD_SAMPLE_RATE, a, 100); 441da853ecaSopenharmony_ci ret = encoderDemo->NativeSetParameter(handle, format); 442da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 443da853ecaSopenharmony_ci 444da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 445da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 446da853ecaSopenharmony_ci delete encoderDemo; 447da853ecaSopenharmony_ci} 448da853ecaSopenharmony_ci 449da853ecaSopenharmony_ci/** 450da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_009 451da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_PushInputData - index check 452da853ecaSopenharmony_ci * @tc.desc : param check test 453da853ecaSopenharmony_ci */ 454da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_009, TestSize.Level2) 455da853ecaSopenharmony_ci{ 456da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 457da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 458da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 459da853ecaSopenharmony_ci 460da853ecaSopenharmony_ci OH_AVFormat *format = OH_AVFormat_Create(); 461da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 462da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 463da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 464da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 465da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 466da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, 1); 467da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 468da853ecaSopenharmony_ci 469da853ecaSopenharmony_ci struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 470da853ecaSopenharmony_ci &OnOutputBufferAvailable}; 471da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeSetCallback(handle, cb); 472da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 473da853ecaSopenharmony_ci 474da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 475da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 476da853ecaSopenharmony_ci 477da853ecaSopenharmony_ci ret = encoderDemo->NativePrepare(handle); 478da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 479da853ecaSopenharmony_ci ret = encoderDemo->NativeStart(handle); 480da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 481da853ecaSopenharmony_ci 482da853ecaSopenharmony_ci OH_AVCodecBufferAttr info; 483da853ecaSopenharmony_ci info.size = 100; 484da853ecaSopenharmony_ci info.offset = 0; 485da853ecaSopenharmony_ci info.pts = 0; 486da853ecaSopenharmony_ci info.flags = AVCODEC_BUFFER_FLAGS_NONE; 487da853ecaSopenharmony_ci 488da853ecaSopenharmony_ci uint32_t index = encoderDemo->NativeGetInputIndex(); 489da853ecaSopenharmony_ci ret = encoderDemo->NativePushInputData(handle, index, info); 490da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 491da853ecaSopenharmony_ci 492da853ecaSopenharmony_ci ret = encoderDemo->NativePushInputData(handle, -1, info); 493da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_NO_MEMORY, ret); 494da853ecaSopenharmony_ci 495da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 496da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 497da853ecaSopenharmony_ci delete encoderDemo; 498da853ecaSopenharmony_ci} 499da853ecaSopenharmony_ci 500da853ecaSopenharmony_ci/** 501da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_010 502da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_PushInputData - info.size check 503da853ecaSopenharmony_ci * @tc.desc : param check test 504da853ecaSopenharmony_ci */ 505da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_010, TestSize.Level2) 506da853ecaSopenharmony_ci{ 507da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 508da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 509da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 510da853ecaSopenharmony_ci 511da853ecaSopenharmony_ci OH_AVFormat *format = OH_AVFormat_Create(); 512da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 513da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 514da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 515da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 516da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 517da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, 1); 518da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 519da853ecaSopenharmony_ci 520da853ecaSopenharmony_ci struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 521da853ecaSopenharmony_ci &OnOutputBufferAvailable}; 522da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeSetCallback(handle, cb); 523da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 524da853ecaSopenharmony_ci 525da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 526da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 527da853ecaSopenharmony_ci 528da853ecaSopenharmony_ci ret = encoderDemo->NativePrepare(handle); 529da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 530da853ecaSopenharmony_ci ret = encoderDemo->NativeStart(handle); 531da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 532da853ecaSopenharmony_ci 533da853ecaSopenharmony_ci OH_AVCodecBufferAttr info; 534da853ecaSopenharmony_ci info.size = 100; 535da853ecaSopenharmony_ci info.offset = 0; 536da853ecaSopenharmony_ci info.pts = 0; 537da853ecaSopenharmony_ci info.flags = AVCODEC_BUFFER_FLAGS_NONE; 538da853ecaSopenharmony_ci 539da853ecaSopenharmony_ci uint32_t index = encoderDemo->NativeGetInputIndex(); 540da853ecaSopenharmony_ci ret = encoderDemo->NativePushInputData(handle, index, info); 541da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 542da853ecaSopenharmony_ci 543da853ecaSopenharmony_ci index = encoderDemo->NativeGetInputIndex(); 544da853ecaSopenharmony_ci info.size = -1; 545da853ecaSopenharmony_ci ret = encoderDemo->NativePushInputData(handle, index, info); 546da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 547da853ecaSopenharmony_ci 548da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 549da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 550da853ecaSopenharmony_ci delete encoderDemo; 551da853ecaSopenharmony_ci} 552da853ecaSopenharmony_ci 553da853ecaSopenharmony_ci/** 554da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_011 555da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_PushInputData - info.offset check 556da853ecaSopenharmony_ci * @tc.desc : param check test 557da853ecaSopenharmony_ci */ 558da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_011, TestSize.Level2) 559da853ecaSopenharmony_ci{ 560da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 561da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 562da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 563da853ecaSopenharmony_ci 564da853ecaSopenharmony_ci OH_AVFormat *format = OH_AVFormat_Create(); 565da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 566da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 567da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 568da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 569da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 570da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, 1); 571da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 572da853ecaSopenharmony_ci 573da853ecaSopenharmony_ci struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 574da853ecaSopenharmony_ci &OnOutputBufferAvailable}; 575da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeSetCallback(handle, cb); 576da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 577da853ecaSopenharmony_ci 578da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 579da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 580da853ecaSopenharmony_ci 581da853ecaSopenharmony_ci ret = encoderDemo->NativePrepare(handle); 582da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 583da853ecaSopenharmony_ci ret = encoderDemo->NativeStart(handle); 584da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 585da853ecaSopenharmony_ci 586da853ecaSopenharmony_ci OH_AVCodecBufferAttr info; 587da853ecaSopenharmony_ci info.size = 100; 588da853ecaSopenharmony_ci info.offset = 0; 589da853ecaSopenharmony_ci info.pts = 0; 590da853ecaSopenharmony_ci info.flags = AVCODEC_BUFFER_FLAGS_NONE; 591da853ecaSopenharmony_ci 592da853ecaSopenharmony_ci uint32_t index = encoderDemo->NativeGetInputIndex(); 593da853ecaSopenharmony_ci ret = encoderDemo->NativePushInputData(handle, index, info); 594da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 595da853ecaSopenharmony_ci 596da853ecaSopenharmony_ci index = encoderDemo->NativeGetInputIndex(); 597da853ecaSopenharmony_ci info.offset = -1; 598da853ecaSopenharmony_ci ret = encoderDemo->NativePushInputData(handle, index, info); 599da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 600da853ecaSopenharmony_ci 601da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 602da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 603da853ecaSopenharmony_ci delete encoderDemo; 604da853ecaSopenharmony_ci} 605da853ecaSopenharmony_ci 606da853ecaSopenharmony_ci/** 607da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_012 608da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_PushInputData - info.pts check 609da853ecaSopenharmony_ci * @tc.desc : param check test 610da853ecaSopenharmony_ci */ 611da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_012, TestSize.Level2) 612da853ecaSopenharmony_ci{ 613da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 614da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 615da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 616da853ecaSopenharmony_ci 617da853ecaSopenharmony_ci OH_AVFormat *format = OH_AVFormat_Create(); 618da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 619da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 620da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 621da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 622da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 623da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, 1); 624da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 625da853ecaSopenharmony_ci 626da853ecaSopenharmony_ci struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 627da853ecaSopenharmony_ci &OnOutputBufferAvailable}; 628da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeSetCallback(handle, cb); 629da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 630da853ecaSopenharmony_ci 631da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 632da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 633da853ecaSopenharmony_ci 634da853ecaSopenharmony_ci ret = encoderDemo->NativePrepare(handle); 635da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 636da853ecaSopenharmony_ci ret = encoderDemo->NativeStart(handle); 637da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 638da853ecaSopenharmony_ci 639da853ecaSopenharmony_ci OH_AVCodecBufferAttr info; 640da853ecaSopenharmony_ci info.size = 100; 641da853ecaSopenharmony_ci info.offset = 0; 642da853ecaSopenharmony_ci info.pts = 0; 643da853ecaSopenharmony_ci info.flags = AVCODEC_BUFFER_FLAGS_NONE; 644da853ecaSopenharmony_ci 645da853ecaSopenharmony_ci uint32_t index = encoderDemo->NativeGetInputIndex(); 646da853ecaSopenharmony_ci ret = encoderDemo->NativePushInputData(handle, index, info); 647da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 648da853ecaSopenharmony_ci 649da853ecaSopenharmony_ci index = encoderDemo->NativeGetInputIndex(); 650da853ecaSopenharmony_ci info.pts = -1; 651da853ecaSopenharmony_ci ret = encoderDemo->NativePushInputData(handle, index, info); 652da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 653da853ecaSopenharmony_ci 654da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 655da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 656da853ecaSopenharmony_ci delete encoderDemo; 657da853ecaSopenharmony_ci} 658da853ecaSopenharmony_ci 659da853ecaSopenharmony_ci/** 660da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_013 661da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_FreeOutputData - index check 662da853ecaSopenharmony_ci * @tc.desc : param check test 663da853ecaSopenharmony_ci */ 664da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_013, TestSize.Level2) 665da853ecaSopenharmony_ci{ 666da853ecaSopenharmony_ci AudioEncoderDemo *encoderDemo = new AudioEncoderDemo(); 667da853ecaSopenharmony_ci OH_AVCodec *handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 668da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 669da853ecaSopenharmony_ci 670da853ecaSopenharmony_ci OH_AVFormat *format = OH_AVFormat_Create(); 671da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 672da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 673da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 674da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 675da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 676da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, 1); 677da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 678da853ecaSopenharmony_ci 679da853ecaSopenharmony_ci struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 680da853ecaSopenharmony_ci &OnOutputBufferAvailable}; 681da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeSetCallback(handle, cb); 682da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 683da853ecaSopenharmony_ci 684da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 685da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 686da853ecaSopenharmony_ci 687da853ecaSopenharmony_ci ret = encoderDemo->NativePrepare(handle); 688da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 689da853ecaSopenharmony_ci ret = encoderDemo->NativeStart(handle); 690da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 691da853ecaSopenharmony_ci 692da853ecaSopenharmony_ci ret = encoderDemo->NativeFreeOutputData(handle, -1); 693da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_NO_MEMORY, ret); 694da853ecaSopenharmony_ci 695da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 696da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 697da853ecaSopenharmony_ci delete encoderDemo; 698da853ecaSopenharmony_ci} 699da853ecaSopenharmony_ci 700da853ecaSopenharmony_ci 701da853ecaSopenharmony_ci/** 702da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_014 703da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_Configure - format(FLAC MD_KEY_BITRATE) check 704da853ecaSopenharmony_ci * @tc.desc : param check test 705da853ecaSopenharmony_ci */ 706da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_014, TestSize.Level2) 707da853ecaSopenharmony_ci{ 708da853ecaSopenharmony_ci AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 709da853ecaSopenharmony_ci OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.Flac"); 710da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 711da853ecaSopenharmony_ci 712da853ecaSopenharmony_ci OH_AVFormat* format = OH_AVFormat_Create(); 713da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT_FLAC); 714da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE_FLAC); 715da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_S16LE); 716da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_S16LE); 717da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 718da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, BITS_RATE_FLAC); 719da853ecaSopenharmony_ci 720da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeConfigure(handle, format); 721da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 722da853ecaSopenharmony_ci 723da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 724da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, -1); 725da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 726da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 727da853ecaSopenharmony_ci 728da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 729da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, 1); 730da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 731da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 732da853ecaSopenharmony_ci 733da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 734da853ecaSopenharmony_ci OH_AVFormat_SetStringValue(format, OH_MD_KEY_BITRATE, "aaa"); 735da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 736da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 737da853ecaSopenharmony_ci 738da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 739da853ecaSopenharmony_ci OH_AVFormat_SetFloatValue(format, OH_MD_KEY_BITRATE, 0.1); 740da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 741da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 742da853ecaSopenharmony_ci 743da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 744da853ecaSopenharmony_ci OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_BITRATE, 0.1); 745da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 746da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 747da853ecaSopenharmony_ci 748da853ecaSopenharmony_ci uint8_t a[100]; 749da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 750da853ecaSopenharmony_ci OH_AVFormat_SetBuffer(format, OH_MD_KEY_BITRATE, a, 100); 751da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 752da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 753da853ecaSopenharmony_ci 754da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 755da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 756da853ecaSopenharmony_ci delete encoderDemo; 757da853ecaSopenharmony_ci} 758da853ecaSopenharmony_ci 759da853ecaSopenharmony_ci 760da853ecaSopenharmony_ci/** 761da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_015 762da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_SetParameter - format(FLAC OH_MD_KEY_AUD_CHANNEL_COUNT) check 763da853ecaSopenharmony_ci * @tc.desc : param check test 764da853ecaSopenharmony_ci */ 765da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_015, TestSize.Level2) 766da853ecaSopenharmony_ci{ 767da853ecaSopenharmony_ci AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 768da853ecaSopenharmony_ci OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.Flac"); 769da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 770da853ecaSopenharmony_ci 771da853ecaSopenharmony_ci OH_AVFormat* format = OH_AVFormat_Create(); 772da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT_FLAC); 773da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE_FLAC); 774da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_S16LE); 775da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_S16LE); 776da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 777da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, BITS_RATE_FLAC); 778da853ecaSopenharmony_ci 779da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeConfigure(handle, format); 780da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 781da853ecaSopenharmony_ci 782da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 783da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, -1); 784da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 785da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 786da853ecaSopenharmony_ci 787da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 788da853ecaSopenharmony_ci OH_AVFormat_SetStringValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, "aaa"); 789da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 790da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 791da853ecaSopenharmony_ci 792da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 793da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0); 794da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 795da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 796da853ecaSopenharmony_ci 797da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 798da853ecaSopenharmony_ci OH_AVFormat_SetFloatValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0.1); 799da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 800da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 801da853ecaSopenharmony_ci 802da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 803da853ecaSopenharmony_ci OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 0.1); 804da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 805da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 806da853ecaSopenharmony_ci 807da853ecaSopenharmony_ci uint8_t a[100]; 808da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 809da853ecaSopenharmony_ci OH_AVFormat_SetBuffer(format, OH_MD_KEY_AUD_CHANNEL_COUNT, a, 100); 810da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 811da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 812da853ecaSopenharmony_ci 813da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 814da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 815da853ecaSopenharmony_ci delete encoderDemo; 816da853ecaSopenharmony_ci} 817da853ecaSopenharmony_ci 818da853ecaSopenharmony_ci/** 819da853ecaSopenharmony_ci * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_016 820da853ecaSopenharmony_ci * @tc.name : OH_AudioEncoder_SetParameter - format(FLAC OH_MD_KEY_AUD_SAMPLE_RATE) check 821da853ecaSopenharmony_ci * @tc.desc : param check test 822da853ecaSopenharmony_ci */ 823da853ecaSopenharmony_ciHWTEST_F(NativeParamCheckTest, SUB_MULTIMEDIA_AUDIO_ENCODER_PARAM_CHECK_016, TestSize.Level2) 824da853ecaSopenharmony_ci{ 825da853ecaSopenharmony_ci AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 826da853ecaSopenharmony_ci OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.Flac"); 827da853ecaSopenharmony_ci ASSERT_NE(nullptr, handle); 828da853ecaSopenharmony_ci 829da853ecaSopenharmony_ci OH_AVFormat* format = OH_AVFormat_Create(); 830da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT_FLAC); 831da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE_FLAC); 832da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_S16LE); 833da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_S16LE); 834da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 835da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, BITS_RATE_FLAC); 836da853ecaSopenharmony_ci 837da853ecaSopenharmony_ci OH_AVErrCode ret = encoderDemo->NativeConfigure(handle, format); 838da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_OK, ret); 839da853ecaSopenharmony_ci 840da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 841da853ecaSopenharmony_ci OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, -1); 842da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 843da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 844da853ecaSopenharmony_ci 845da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 846da853ecaSopenharmony_ci OH_AVFormat_SetStringValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, "aaa"); 847da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 848da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 849da853ecaSopenharmony_ci 850da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 851da853ecaSopenharmony_ci OH_AVFormat_SetLongValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0); 852da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 853da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 854da853ecaSopenharmony_ci 855da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 856da853ecaSopenharmony_ci OH_AVFormat_SetFloatValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0.1); 857da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 858da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 859da853ecaSopenharmony_ci 860da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 861da853ecaSopenharmony_ci OH_AVFormat_SetDoubleValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 0.1); 862da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 863da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 864da853ecaSopenharmony_ci 865da853ecaSopenharmony_ci uint8_t a[100]; 866da853ecaSopenharmony_ci encoderDemo->NativeReset(handle); 867da853ecaSopenharmony_ci OH_AVFormat_SetBuffer(format, OH_MD_KEY_AUD_SAMPLE_RATE, a, 100); 868da853ecaSopenharmony_ci ret = encoderDemo->NativeConfigure(handle, format); 869da853ecaSopenharmony_ci ASSERT_EQ(AV_ERR_UNSUPPORT, ret); 870da853ecaSopenharmony_ci 871da853ecaSopenharmony_ci OH_AVFormat_Destroy(format); 872da853ecaSopenharmony_ci encoderDemo->NativeDestroy(handle); 873da853ecaSopenharmony_ci delete encoderDemo; 874da853ecaSopenharmony_ci}