1 /*
2 * Copyright (C) 2024 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 "gtest/gtest.h"
17
18 #include "native_avcodec_base.h"
19 #include "native_avdemuxer.h"
20 #include "native_avformat.h"
21 #include "native_avsource.h"
22 #include "native_avmemory.h"
23
24 #include <iostream>
25 #include <cstdio>
26 #include <string>
27 #include <fcntl.h>
28 #include <cmath>
29 #include <thread>
30
31 namespace OHOS {
32 namespace Media {
33 class DemuxerFormatNdkTest : public testing::Test {
34 public:
35 // SetUpTestCase: Called before all test cases
36 static void SetUpTestCase(void);
37 // TearDownTestCase: Called after all test case
38 static void TearDownTestCase(void);
39 // SetUp: Called before each test cases
40 void SetUp(void);
41 // TearDown: Called after each test cases
42 void TearDown(void);
43 };
44
45 static OH_AVMemory *memory = nullptr;
46 static OH_AVSource *source = nullptr;
47 static OH_AVDemuxer *demuxer = nullptr;
48 static OH_AVFormat *sourceFormat = nullptr;
49 static OH_AVFormat *trackFormat = nullptr;
50 static OH_AVBuffer *avBuffer = nullptr;
51 static OH_AVFormat *format = nullptr;
52
53 static int32_t g_trackCount;
54 static int32_t g_width = 3840;
55 static int32_t g_height = 2160;
56 constexpr uint64_t AVC_BITRATE = 2144994;
57 constexpr uint64_t ACTUAL_DURATION = 4120000;
58 constexpr uint32_t ACTUAL_AUDIOFORMAT = 9;
59 constexpr uint32_t ACTUAL_AUDIOCOUNT = 2;
60 constexpr uint64_t ACTUAL_LAYOUT = 3;
61 constexpr uint32_t ACTUAL_SAMPLERATE = 44100;
62 constexpr uint32_t ACTUAL_CODEDSAMPLE = 16;
63 constexpr uint32_t ACTUAL_CURRENTWIDTH = 1920;
64 constexpr uint32_t ACTUAL_CURRENTHEIGHT = 1080;
65 constexpr double ACTUAL_FRAMERATE = 25;
66 constexpr uint64_t HEVC_BITRATE = 4162669;
67 constexpr uint32_t ACTUAL_CHARACTERISTICS = 2;
68 constexpr uint32_t ACTUAL_COEFFICIENTS = 2;
69 constexpr uint32_t ACTUAL_PRIMARIES = 2;
70
SetUpTestCase()71 void DemuxerFormatNdkTest::SetUpTestCase() {}
TearDownTestCase()72 void DemuxerFormatNdkTest::TearDownTestCase() {}
SetUp()73 void DemuxerFormatNdkTest::SetUp()
74 {
75 memory = OH_AVMemory_Create(g_width * g_height);
76 g_trackCount = 0;
77 }
TearDown()78 void DemuxerFormatNdkTest::TearDown()
79 {
80 if (trackFormat != nullptr) {
81 OH_AVFormat_Destroy(trackFormat);
82 trackFormat = nullptr;
83 }
84
85 if (sourceFormat != nullptr) {
86 OH_AVFormat_Destroy(sourceFormat);
87 sourceFormat = nullptr;
88 }
89
90 if (memory != nullptr) {
91 OH_AVMemory_Destroy(memory);
92 memory = nullptr;
93 }
94 if (source != nullptr) {
95 OH_AVSource_Destroy(source);
96 source = nullptr;
97 }
98 if (demuxer != nullptr) {
99 OH_AVDemuxer_Destroy(demuxer);
100 demuxer = nullptr;
101 }
102 if (avBuffer != nullptr) {
103 OH_AVBuffer_Destroy(avBuffer);
104 avBuffer = nullptr;
105 }
106 if (format != nullptr) {
107 OH_AVFormat_Destroy(format);
108 format = nullptr;
109 }
110 }
111 } // namespace Media
112 } // namespace OHOS
113
114 using namespace std;
115 using namespace OHOS;
116 using namespace OHOS::Media;
117 using namespace testing::ext;
118
119 string g_vvc8bitPath = string("/data/test/media/vvc_8bit_3840_2160.mp4");
120 string g_vvc10bitPath = string("/data/test/media/vvc_aac_10bit_1920_1080.mp4");
121
GetFileSize(const char * fileName)122 static int64_t GetFileSize(const char *fileName)
123 {
124 int64_t fileSize = 0;
125 if (fileName != nullptr) {
126 struct stat fileStatus {};
127 if (stat(fileName, &fileStatus) == 0) {
128 fileSize = static_cast<int64_t>(fileStatus.st_size);
129 }
130 }
131 return fileSize;
132 }
133
SetAudioValue(OH_AVCodecBufferAttr attr,bool & audioIsEnd,int & audioFrame,int & aKeyCount)134 static void SetAudioValue(OH_AVCodecBufferAttr attr, bool &audioIsEnd, int &audioFrame, int &aKeyCount)
135 {
136 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
137 audioIsEnd = true;
138 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
139 } else {
140 audioFrame++;
141 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
142 aKeyCount++;
143 }
144 }
145 }
146
SetVideoValue(OH_AVCodecBufferAttr attr,bool & videoIsEnd,int & videoFrame,int & vKeyCount)147 static void SetVideoValue(OH_AVCodecBufferAttr attr, bool &videoIsEnd, int &videoFrame, int &vKeyCount)
148 {
149 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
150 videoIsEnd = true;
151 cout << videoFrame << " video is end !!!!!!!!!!!!!!!" << endl;
152 } else {
153 videoFrame++;
154 cout << "video track !!!!!" << endl;
155 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
156 vKeyCount++;
157 }
158 }
159 }
160
CheckVideoKey()161 static void CheckVideoKey()
162 {
163 uint8_t *codecConfig = nullptr;
164 size_t bufferSize;
165 int64_t bitrate = 0;
166 const char* mimeType = nullptr;
167 double frameRate;
168 int32_t currentWidth = 0;
169 int32_t currentHeight = 0;
170 const char* language = nullptr;
171 int32_t rotation;
172 ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &bitrate));
173 int bitrateResult = 1660852;
174 ASSERT_EQ(bitrateResult, bitrate);
175 ASSERT_TRUE(OH_AVFormat_GetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, &codecConfig, &bufferSize));
176 size_t bufferSizeResult = 255;
177 ASSERT_EQ(bufferSizeResult, bufferSize);
178 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
179 int expectNum = 0;
180 ASSERT_EQ(expectNum, strcmp(mimeType, OH_AVCODEC_MIMETYPE_VIDEO_VVC));
181 ASSERT_TRUE(OH_AVFormat_GetDoubleValue(trackFormat, OH_MD_KEY_FRAME_RATE, &frameRate));
182 int frameRateResult = 50.000000;
183 ASSERT_EQ(frameRateResult, frameRate);
184 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_HEIGHT, ¤tHeight));
185 int currentHeightResult = 1080;
186 ASSERT_EQ(currentHeightResult, currentHeight);
187 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_WIDTH, ¤tWidth));
188 int currentWidthResult = 1920;
189 ASSERT_EQ(currentWidthResult, currentWidth);
190 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_LANGUAGE, &language));
191 ASSERT_EQ(expectNum, strcmp(language, "und"));
192 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_ROTATION, &rotation));
193 int rotationResult = 0;
194 ASSERT_EQ(rotationResult, rotation);
195 }
196
CheckAudioKey()197 static void CheckAudioKey()
198 {
199 int32_t aacisAdts = 0;
200 int64_t channelLayout;
201 int32_t audioCount = 0;
202 int32_t sampleFormat;
203 int64_t bitrate = 0;
204 int32_t bitsPreCodedSample;
205 uint8_t *codecConfig = nullptr;
206 size_t bufferSize;
207 const char* mimeType = nullptr;
208 int32_t sampleRate = 0;
209 const char* language = nullptr;
210 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AAC_IS_ADTS, &aacisAdts));
211 int aacisAdtsResult = 1;
212 ASSERT_EQ(aacisAdtsResult, aacisAdts);
213 ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_CHANNEL_LAYOUT, &channelLayout));
214 int channelLayoutResult = 3;
215 ASSERT_EQ(channelLayoutResult, channelLayout);
216 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, &audioCount));
217 int audioCountResult = 2;
218 ASSERT_EQ(audioCountResult, audioCount);
219 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, &sampleFormat));
220 int sampleFormatResult = 0;
221 ASSERT_EQ(sampleFormatResult, sampleFormat);
222 ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &bitrate));
223 int bitrateResult = 127881;
224 ASSERT_EQ(bitrateResult, bitrate);
225 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_BITS_PER_CODED_SAMPLE, &bitsPreCodedSample));
226 int bitsPreCodedSampleResult = 16;
227 ASSERT_EQ(bitsPreCodedSampleResult, bitsPreCodedSample);
228 ASSERT_TRUE(OH_AVFormat_GetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, &codecConfig, &bufferSize));
229 int bufferSizeResult = 5;
230 ASSERT_EQ(bufferSizeResult, bufferSize);
231 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
232 int expectNum = 0;
233 ASSERT_EQ(expectNum, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_AAC));
234 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_LANGUAGE, &language));
235 ASSERT_EQ(expectNum, strcmp(language, "eng"));
236 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, &sampleRate));
237 int sampleRateResult = 48000;
238 ASSERT_EQ(sampleRateResult, sampleRate);
239 }
240
CheckAudioKeyVvc()241 static void CheckAudioKeyVvc()
242 {
243 uint8_t *codecConfig = nullptr;
244 size_t bufferSize;
245 const char* language = nullptr;
246 int64_t bitrate = 0;
247 double frameRate;
248 int32_t currentWidth = 0;
249 int32_t currentHeight = 0;
250 int tarckType = 0;
251 const char* mimeType = nullptr;
252 int32_t rotation;
253 ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &bitrate));
254 int bitrateResult = 10014008;
255 ASSERT_EQ(bitrateResult, bitrate);
256 ASSERT_TRUE(OH_AVFormat_GetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, &codecConfig, &bufferSize));
257 int bufferSizeResult = 247;
258 ASSERT_EQ(bufferSizeResult, bufferSize);
259 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
260 int expectNum = 0;
261 ASSERT_EQ(expectNum, strcmp(mimeType, OH_AVCODEC_MIMETYPE_VIDEO_VVC));
262 ASSERT_TRUE(OH_AVFormat_GetDoubleValue(trackFormat, OH_MD_KEY_FRAME_RATE, &frameRate));
263 int frameRateResult = 60.000000;
264 ASSERT_EQ(frameRateResult, frameRate);
265 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_HEIGHT, ¤tHeight));
266 int currentHeightResult = 2160;
267 ASSERT_EQ(currentHeightResult, currentHeight);
268 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_WIDTH, ¤tWidth));
269 int currentWidthResult = 3840;
270 ASSERT_EQ(currentWidthResult, currentWidth);
271 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_LANGUAGE, &language));
272 ASSERT_EQ(expectNum, strcmp(language, "und"));
273 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_ROTATION, &rotation));
274 int rotationResult = 0;
275 ASSERT_EQ(rotationResult, rotation);
276 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
277 int tarckTypeResult = 1;
278 ASSERT_EQ(tarckTypeResult, tarckType);
279 }
280
SetAllParam(OH_AVFormat * paramFormat)281 static void SetAllParam(OH_AVFormat *paramFormat)
282 {
283 int64_t duration = 0;
284 int64_t startTime = 0;
285 const char* artist = nullptr;
286 const char* album = nullptr;
287 const char* albumArtist = nullptr;
288 const char* date = nullptr;
289 const char* comment = nullptr;
290 const char* genre = nullptr;
291 const char* copyright = nullptr;
292 const char* language = nullptr;
293 const char* description = nullptr;
294 const char* lyrics = nullptr;
295 const char* title = nullptr;
296 ASSERT_TRUE(OH_AVFormat_GetLongValue(paramFormat, OH_MD_KEY_DURATION, &duration));
297 ASSERT_EQ(ACTUAL_DURATION, duration);
298 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_TITLE, &title));
299 ASSERT_EQ(0, strcmp(title, "title"));
300 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_ARTIST, &artist));
301 ASSERT_EQ(0, strcmp(artist, "artist"));
302 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_ALBUM, &album));
303 ASSERT_EQ(0, strcmp(album, "album"));
304 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_ALBUM_ARTIST, &albumArtist));
305 ASSERT_EQ(0, strcmp(albumArtist, "album artist"));
306 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_DATE, &date));
307 ASSERT_EQ(0, strcmp(date, "2023"));
308 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_COMMENT, &comment));
309 ASSERT_EQ(0, strcmp(comment, "comment"));
310 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_GENRE, &genre));
311 ASSERT_EQ(0, strcmp(genre, "genre"));
312 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_COPYRIGHT, ©right));
313 ASSERT_EQ(0, strcmp(copyright, "Copyright"));
314 ASSERT_FALSE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_LANGUAGE, &language));
315 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_DESCRIPTION, &description));
316 ASSERT_EQ(0, strcmp(description, "description"));
317 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_LYRICS, &lyrics));
318 ASSERT_EQ(0, strcmp(lyrics, "lyrics"));
319 ASSERT_TRUE(OH_AVFormat_GetLongValue(paramFormat, OH_MD_KEY_START_TIME, &startTime));
320 ASSERT_EQ(0, startTime);
321 }
322
SetAudioParam(OH_AVFormat * paramFormat)323 static void SetAudioParam(OH_AVFormat *paramFormat)
324 {
325 int32_t codedSample = 0;
326 int32_t audioFormat = 0;
327 int32_t audioCount = 0;
328 int32_t sampleRate = 0;
329 int32_t aacisAdts = 0;
330 int64_t layout = 0;
331 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, &audioFormat));
332 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, &audioCount));
333 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_AUD_SAMPLE_RATE, &sampleRate));
334 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_BITS_PER_CODED_SAMPLE, &codedSample));
335 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_AAC_IS_ADTS, &aacisAdts));
336 ASSERT_TRUE(OH_AVFormat_GetLongValue(paramFormat, OH_MD_KEY_CHANNEL_LAYOUT, &layout));
337 ASSERT_EQ(ACTUAL_AUDIOFORMAT, audioFormat);
338 ASSERT_EQ(ACTUAL_AUDIOCOUNT, audioCount);
339 ASSERT_EQ(ACTUAL_SAMPLERATE, sampleRate);
340 ASSERT_EQ(ACTUAL_CODEDSAMPLE, codedSample);
341 ASSERT_EQ(1, aacisAdts);
342 ASSERT_EQ(ACTUAL_LAYOUT, layout);
343 }
344
AvcVideoParam(OH_AVFormat * paramFormat)345 static void AvcVideoParam(OH_AVFormat *paramFormat)
346 {
347 int32_t currentWidth = 0;
348 int32_t currentHeight = 0;
349 int32_t rotation = 0;
350 double frameRate = 0.0;
351 int32_t profile = 0;
352 int32_t flag = 0;
353 int32_t characteristics = 0;
354 int32_t coefficients = 0;
355 int32_t mode = 0;
356 int64_t bitrate = 0;
357 int32_t primaries = 0;
358 int32_t videoIsHdrvivid = 0;
359 const char* mimeType = nullptr;
360 double sar = 0.0;
361 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_WIDTH, ¤tWidth));
362 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_HEIGHT, ¤tHeight));
363 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_ROTATION, &rotation));
364 ASSERT_TRUE(OH_AVFormat_GetDoubleValue(paramFormat, OH_MD_KEY_FRAME_RATE, &frameRate));
365 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_PROFILE, &profile));
366 ASSERT_TRUE(OH_AVFormat_GetLongValue(paramFormat, OH_MD_KEY_BITRATE, &bitrate));
367 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE, &mode));
368 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_RANGE_FLAG, &flag));
369 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_TRANSFER_CHARACTERISTICS, &characteristics));
370 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_MATRIX_COEFFICIENTS, &coefficients));
371 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_VIDEO_IS_HDR_VIVID, &videoIsHdrvivid));
372 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_COLOR_PRIMARIES, &primaries));
373 ASSERT_TRUE(OH_AVFormat_GetDoubleValue(paramFormat, OH_MD_KEY_VIDEO_SAR, &sar));
374 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
375 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_VIDEO_AVC));
376 ASSERT_EQ(ACTUAL_CURRENTWIDTH, currentWidth);
377 ASSERT_EQ(ACTUAL_CURRENTHEIGHT, currentHeight);
378 ASSERT_EQ(ACTUAL_FRAMERATE, frameRate);
379 ASSERT_EQ(AVC_BITRATE, bitrate);
380 ASSERT_EQ(1, sar);
381 }
382
HevcVideoParam(OH_AVFormat * paramFormat)383 static void HevcVideoParam(OH_AVFormat *paramFormat)
384 {
385 int32_t currentWidth = 0;
386 int32_t currentHeight = 0;
387 int32_t rotation = 0;
388 double frameRate = 0.0;
389 int32_t profile = 0;
390 int32_t flag = 0;
391 int32_t characteristics = 0;
392 int32_t coefficients = 0;
393 int32_t mode = 0;
394 int64_t bitrate = 0;
395 int32_t primaries = 0;
396 int32_t videoIsHdrvivid = 0;
397 const char* mimeType = nullptr;
398 double sar = 0.0;
399 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_WIDTH, ¤tWidth));
400 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_HEIGHT, ¤tHeight));
401 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_ROTATION, &rotation));
402 ASSERT_TRUE(OH_AVFormat_GetDoubleValue(paramFormat, OH_MD_KEY_FRAME_RATE, &frameRate));
403 ASSERT_TRUE(OH_AVFormat_GetLongValue(paramFormat, OH_MD_KEY_BITRATE, &bitrate));
404 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE, &mode));
405 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_RANGE_FLAG, &flag));
406 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_TRANSFER_CHARACTERISTICS, &characteristics));
407 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_MATRIX_COEFFICIENTS, &coefficients));
408 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_VIDEO_IS_HDR_VIVID, &videoIsHdrvivid));
409 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_COLOR_PRIMARIES, &primaries));
410 ASSERT_TRUE(OH_AVFormat_GetDoubleValue(paramFormat, OH_MD_KEY_VIDEO_SAR, &sar));
411 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
412 if (!access("/system/lib64/media/", 0)) {
413 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_PROFILE, &profile));
414 ASSERT_EQ(0, profile);
415 } else {
416 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_PROFILE, &profile));
417 }
418 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_VIDEO_HEVC));
419 ASSERT_EQ(ACTUAL_CURRENTWIDTH, currentWidth);
420 ASSERT_EQ(ACTUAL_CURRENTHEIGHT, currentHeight);
421 ASSERT_EQ(ACTUAL_FRAMERATE, frameRate);
422 ASSERT_EQ(HEVC_BITRATE, bitrate);
423 ASSERT_EQ(0, flag);
424 ASSERT_EQ(ACTUAL_CHARACTERISTICS, characteristics);
425 ASSERT_EQ(ACTUAL_COEFFICIENTS, coefficients);
426 ASSERT_EQ(ACTUAL_PRIMARIES, primaries);
427 ASSERT_EQ(1, sar);
428 }
429
SetOtherAllParam(OH_AVFormat * paramFormat)430 static void SetOtherAllParam(OH_AVFormat *paramFormat)
431 {
432 int64_t duration = 0;
433 int64_t startTime = 0;
434 const char* artist = nullptr;
435 const char* album = nullptr;
436 const char* albumArtist = nullptr;
437 const char* date = nullptr;
438 const char* comment = nullptr;
439 const char* genre = nullptr;
440 const char* copyright = nullptr;
441 const char* language = nullptr;
442 const char* description = nullptr;
443 const char* lyrics = nullptr;
444 const char* title = nullptr;
445 int32_t dur = 10800000;
446 ASSERT_TRUE(OH_AVFormat_GetLongValue(paramFormat, OH_MD_KEY_DURATION, &duration));
447 ASSERT_EQ(dur, duration);
448 ASSERT_FALSE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_TITLE, &title));
449 ASSERT_FALSE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_ARTIST, &artist));
450 ASSERT_FALSE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_ALBUM, &album));
451 ASSERT_FALSE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_ALBUM_ARTIST, &albumArtist));
452 ASSERT_FALSE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_DATE, &date));
453 ASSERT_FALSE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_COMMENT, &comment));
454 ASSERT_FALSE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_GENRE, &genre));
455 ASSERT_FALSE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_COPYRIGHT, ©right));
456 ASSERT_FALSE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_LANGUAGE, &language));
457 ASSERT_FALSE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_DESCRIPTION, &description));
458 ASSERT_FALSE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_LYRICS, &lyrics));
459 ASSERT_TRUE(OH_AVFormat_GetLongValue(paramFormat, OH_MD_KEY_START_TIME, &startTime));
460 ASSERT_EQ(0, startTime);
461 }
462
SetOtherAudioParam(OH_AVFormat * paramFormat)463 static void SetOtherAudioParam(OH_AVFormat *paramFormat)
464 {
465 int32_t codedSample = 0;
466 int32_t audioFormat = 0;
467 int32_t audioCount = 0;
468 int32_t sampleRate = 0;
469 int32_t aacisAdts = 0;
470 int64_t layout = 0;
471 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, &audioFormat));
472 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, &audioCount));
473 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_AUD_SAMPLE_RATE, &sampleRate));
474 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_BITS_PER_CODED_SAMPLE, &codedSample));
475 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_AAC_IS_ADTS, &aacisAdts));
476 ASSERT_TRUE(OH_AVFormat_GetLongValue(paramFormat, OH_MD_KEY_CHANNEL_LAYOUT, &layout));
477 ASSERT_EQ(ACTUAL_AUDIOFORMAT, audioFormat);
478 ASSERT_EQ(ACTUAL_AUDIOCOUNT, audioCount);
479 ASSERT_EQ(ACTUAL_SAMPLERATE, sampleRate);
480 ASSERT_EQ(ACTUAL_CODEDSAMPLE, codedSample);
481 ASSERT_EQ(1, aacisAdts);
482 ASSERT_EQ(ACTUAL_LAYOUT, layout);
483 }
484
OtherVideoParam(OH_AVFormat * paramFormat)485 static void OtherVideoParam(OH_AVFormat *paramFormat)
486 {
487 int32_t currentWidth = 0;
488 int32_t currentHeight = 0;
489 int32_t rotation = 0;
490 double frameRate = 0.0;
491 int32_t profile = 0;
492 int32_t flag = 0;
493 int32_t characteristics = 0;
494 int32_t coefficients = 0;
495 int32_t mode = 0;
496 int64_t bitrate = 0;
497 int32_t primaries = 0;
498 int32_t videoIsHdrvivid = 0;
499 const char* mimeType = nullptr;
500 double sar = 0.0;
501 int32_t width = 3840;
502 int32_t height = 2160;
503 int32_t framerateActual = 30;
504 int32_t bitrateActual = 24863756;
505 int32_t rotationActual = 180;
506 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_WIDTH, ¤tWidth));
507 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_HEIGHT, ¤tHeight));
508 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_ROTATION, &rotation));
509 ASSERT_TRUE(OH_AVFormat_GetDoubleValue(paramFormat, OH_MD_KEY_FRAME_RATE, &frameRate));
510 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_PROFILE, &profile));
511 ASSERT_TRUE(OH_AVFormat_GetLongValue(paramFormat, OH_MD_KEY_BITRATE, &bitrate));
512 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE, &mode));
513 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_RANGE_FLAG, &flag));
514 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_TRANSFER_CHARACTERISTICS, &characteristics));
515 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_MATRIX_COEFFICIENTS, &coefficients));
516 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_VIDEO_IS_HDR_VIVID, &videoIsHdrvivid));
517 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_COLOR_PRIMARIES, &primaries));
518 ASSERT_FALSE(OH_AVFormat_GetDoubleValue(paramFormat, OH_MD_KEY_VIDEO_SAR, &sar));
519 ASSERT_TRUE(OH_AVFormat_GetStringValue(paramFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
520 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_VIDEO_AVC));
521 ASSERT_EQ(width, currentWidth);
522 ASSERT_EQ(height, currentHeight);
523 ASSERT_EQ(framerateActual, frameRate);
524 ASSERT_EQ(bitrateActual, bitrate);
525 ASSERT_EQ(rotationActual, rotation);
526 }
527
528 /**
529 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_4400
530 * @tc.name : demux hevc ts video
531 * @tc.desc : function test
532 */
533 HWTEST_F(DemuxerFormatNdkTest, SUB_MEDIA_DEMUXER_PROCESS_4400, TestSize.Level0)
534 {
535 int tarckType = 0;
536 const char *file = "/data/test/media/test_265_B_Gop25_4sec.mp4";
537 int fd = open(file, O_RDONLY);
538 int64_t size = GetFileSize(file);
539 source = OH_AVSource_CreateWithFD(fd, 0, size);
540 ASSERT_NE(source, nullptr);
541 demuxer = OH_AVDemuxer_CreateWithSource(source);
542 ASSERT_NE(demuxer, nullptr);
543 sourceFormat = OH_AVSource_GetSourceFormat(source);
544 SetAllParam(sourceFormat);
545 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
546 ASSERT_EQ(2, g_trackCount);
547 const char* mimeType = nullptr;
548 for (int32_t index = 0; index < g_trackCount; index++) {
549 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
550 }
551 OH_AVCodecBufferAttr attr;
552 int vKeyCount = 0;
553 int aKeyCount = 0;
554 bool audioIsEnd = false;
555 bool videoIsEnd = false;
556 int audioFrame = 0;
557 int videoFrame = 0;
558 while (!audioIsEnd || !videoIsEnd) {
559 for (int32_t index = 0; index < g_trackCount; index++) {
560 trackFormat = OH_AVSource_GetTrackFormat(source, index);
561 ASSERT_NE(trackFormat, nullptr);
562 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
563 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD) && index == MEDIA_TYPE_AUD) ||
564 (videoIsEnd && (tarckType == MEDIA_TYPE_VID) && index == MEDIA_TYPE_VID)) {
565 continue;
566 }
567 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
568 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
569 if (tarckType == MEDIA_TYPE_AUD) {
570 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
571 SetAudioParam(trackFormat);
572 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_AAC));
573 } else if (tarckType == MEDIA_TYPE_VID) {
574 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
575 HevcVideoParam(trackFormat);
576 }
577 OH_AVFormat_Destroy(trackFormat);
578 trackFormat = nullptr;
579 }
580 }
581 close(fd);
582 fd = -1;
583 }
584
585 /**
586 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_4500
587 * @tc.name : demux avc ts video
588 * @tc.desc : function test
589 */
590 HWTEST_F(DemuxerFormatNdkTest, SUB_MEDIA_DEMUXER_PROCESS_4500, TestSize.Level0)
591 {
592 int tarckType = 0;
593 const char *file = "/data/test/media/test_264_B_Gop25_4sec.mp4";
594 int fd = open(file, O_RDONLY);
595 int64_t size = GetFileSize(file);
596 source = OH_AVSource_CreateWithFD(fd, 0, size);
597 ASSERT_NE(source, nullptr);
598 demuxer = OH_AVDemuxer_CreateWithSource(source);
599 ASSERT_NE(demuxer, nullptr);
600 sourceFormat = OH_AVSource_GetSourceFormat(source);
601 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
602 ASSERT_EQ(2, g_trackCount);
603 SetAllParam(sourceFormat);
604 const char* mimeType = nullptr;
605 for (int32_t index = 0; index < g_trackCount; index++) {
606 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
607 }
608 OH_AVCodecBufferAttr attr;
609 int vKeyCount = 0;
610 int aKeyCount = 0;
611 bool audioIsEnd = false;
612 bool videoIsEnd = false;
613 int audioFrame = 0;
614 int videoFrame = 0;
615 while (!audioIsEnd || !videoIsEnd) {
616 for (int32_t index = 0; index < g_trackCount; index++) {
617 trackFormat = OH_AVSource_GetTrackFormat(source, index);
618 ASSERT_NE(trackFormat, nullptr);
619 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
620 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD) && index == MEDIA_TYPE_AUD)
621 || (videoIsEnd && (tarckType == MEDIA_TYPE_VID) && index == MEDIA_TYPE_VID)) {
622 continue;
623 }
624 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
625 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
626 if (tarckType == MEDIA_TYPE_AUD) {
627 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
628 SetAudioParam(trackFormat);
629 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_AAC));
630 } else if (tarckType == MEDIA_TYPE_VID) {
631 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
632 AvcVideoParam(trackFormat);
633 }
634 OH_AVFormat_Destroy(trackFormat);
635 trackFormat = nullptr;
636 }
637 }
638 close(fd);
639 fd = -1;
640 }
641 /**
642 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_4510
643 * @tc.name : demux avc ios video, check key
644 * @tc.desc : function test
645 */
646 HWTEST_F(DemuxerFormatNdkTest, SUB_MEDIA_DEMUXER_PROCESS_4510, TestSize.Level0)
647 {
648 int tarckType = 0;
649 const char *file = "/data/test/media/record_from_ios.mp4";
650 int fd = open(file, O_RDONLY);
651 int64_t size = GetFileSize(file);
652 source = OH_AVSource_CreateWithFD(fd, 0, size);
653 ASSERT_NE(source, nullptr);
654 demuxer = OH_AVDemuxer_CreateWithSource(source);
655 ASSERT_NE(demuxer, nullptr);
656 sourceFormat = OH_AVSource_GetSourceFormat(source);
657 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
658 ASSERT_EQ(5, g_trackCount);
659 SetOtherAllParam(sourceFormat);
660 const char* mimeType = nullptr;
661 for (int32_t index = 0; index < 2; index++) {
662 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
663 }
664 OH_AVCodecBufferAttr attr;
665 int vKeyCount = 0;
666 int aKeyCount = 0;
667 bool audioIsEnd = false;
668 bool videoIsEnd = false;
669 int audioFrame = 0;
670 int videoFrame = 0;
671 while (!audioIsEnd || !videoIsEnd) {
672 for (int32_t index = 0; index < 2; index++) {
673 trackFormat = OH_AVSource_GetTrackFormat(source, index);
674 ASSERT_NE(trackFormat, nullptr);
675 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
676 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD) && index == MEDIA_TYPE_AUD)
677 || (videoIsEnd && (tarckType == MEDIA_TYPE_VID) && index == MEDIA_TYPE_VID)) {
678 continue;
679 }
680 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
681 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
682 if (tarckType == MEDIA_TYPE_AUD) {
683 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
684 SetOtherAudioParam(trackFormat);
685 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_AAC));
686 } else if (tarckType == MEDIA_TYPE_VID) {
687 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
688 OtherVideoParam(trackFormat);
689 }
690 OH_AVFormat_Destroy(trackFormat);
691 trackFormat = nullptr;
692 }
693 }
694 close(fd);
695 fd = -1;
696 }
697 /**
698 * @tc.number : VIDEO_DEMUXER_VVC_0500
699 * @tc.name : demuxer 8bit H266 MP4 file, check key
700 * @tc.desc : function test
701 */
702 HWTEST_F(DemuxerFormatNdkTest, VIDEO_DEMUXER_VVC_0500, TestSize.Level0)
703 {
704 if (access(g_vvc8bitPath.c_str(), F_OK) != 0) {
705 return;
706 }
707 int64_t duration = 0;
708 int64_t startTime;
709 int fd = open(g_vvc8bitPath.c_str(), O_RDONLY);
710 int64_t size = GetFileSize(g_vvc8bitPath.c_str());
711 cout << g_vvc8bitPath.c_str() << "---------" << fd << "----------" << size <<endl;
712 source = OH_AVSource_CreateWithFD(fd, 0, size);
713 ASSERT_NE(source, nullptr);
714 sourceFormat = OH_AVSource_GetSourceFormat(source);
715 ASSERT_NE(sourceFormat, nullptr);
716 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
717 ASSERT_NE(trackFormat, nullptr);
718 ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_DURATION, &duration));
719 ASSERT_EQ(10000000, duration);
720 ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_START_TIME, &startTime));
721 ASSERT_EQ(0, startTime);
722 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
723 ASSERT_EQ(1, g_trackCount);
724 CheckAudioKeyVvc();
725 close(fd);
726 fd = -1;
727 }
728
729 /**
730 * @tc.number : VIDEO_DEMUXER_VVC_0600
731 * @tc.name : demuxer 10bit H266 MP4 file, check key
732 * @tc.desc : function test
733 */
734 HWTEST_F(DemuxerFormatNdkTest, VIDEO_DEMUXER_VVC_0600, TestSize.Level0)
735 {
736 if (access(g_vvc10bitPath.c_str(), F_OK) != 0) {
737 return;
738 }
739 int64_t duration = 0;
740 int64_t startTime;
741 int tarckType = 0;
742 int fd = open(g_vvc10bitPath.c_str(), O_RDONLY);
743 int64_t size = GetFileSize(g_vvc10bitPath.c_str());
744 cout << g_vvc10bitPath.c_str() << "---------" << fd << "----------" << size <<endl;
745 source = OH_AVSource_CreateWithFD(fd, 0, size);
746 ASSERT_NE(source, nullptr);
747 sourceFormat = OH_AVSource_GetSourceFormat(source);
748 ASSERT_NE(sourceFormat, nullptr);
749 ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_DURATION, &duration));
750 ASSERT_EQ(60000000, duration);
751 ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_START_TIME, &startTime));
752 ASSERT_EQ(0, startTime);
753 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
754 ASSERT_EQ(2, g_trackCount);
755 for (int32_t index = 0; index < g_trackCount; index++) {
756 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
757 ASSERT_NE(trackFormat, nullptr);
758 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
759 OH_AVFormat_Destroy(trackFormat);
760 trackFormat = nullptr;
761 if (tarckType == MEDIA_TYPE_VID) {
762 CheckVideoKey();
763 } else if (tarckType == MEDIA_TYPE_AUD) {
764 CheckAudioKey();
765 }
766 }
767 close(fd);
768 fd = -1;
769 }
770
771 /**
772 * @tc.number : DEMUXER_GBK_0010
773 * @tc.name : demux mp3 file with gbk, check key
774 * @tc.desc : function test
775 */
776 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0010, TestSize.Level2)
777 {
778 const char* artist = nullptr;
779 const char* album = nullptr;
780 const char* title = nullptr;
781 const char *file = "/data/test/media/audio/gbk.mp3";
782 int fd = open(file, O_RDONLY);
783 int64_t size = GetFileSize(file);
784 cout << file << "----------------------" << fd << "---------" << size << endl;
785 source = OH_AVSource_CreateWithFD(fd, 0, size);
786 ASSERT_NE(source, nullptr);
787 demuxer = OH_AVDemuxer_CreateWithSource(source);
788 ASSERT_NE(demuxer, nullptr);
789 sourceFormat = OH_AVSource_GetSourceFormat(source);
790 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
791 ASSERT_EQ(0, strcmp(title, "bom"));
792 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
793 ASSERT_EQ(0, strcmp(artist, "张三"));
794 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
795 ASSERT_EQ(0, strcmp(album, "a"));
796 close(fd);
797 fd = -1;
798 }
799
800 /**
801 * @tc.number : DEMUXER_GBK_0020
802 * @tc.name : demux mp3 file with gb2312, check key
803 * @tc.desc : function test
804 */
805 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0020, TestSize.Level2)
806 {
807 const char* artist = nullptr;
808 const char* album = nullptr;
809 const char* title = nullptr;
810 const char *file = "/data/test/media/audio/gb2312.mp3";
811 int fd = open(file, O_RDONLY);
812 int64_t size = GetFileSize(file);
813 cout << file << "----------------------" << fd << "---------" << size << endl;
814 source = OH_AVSource_CreateWithFD(fd, 0, size);
815 ASSERT_NE(source, nullptr);
816 demuxer = OH_AVDemuxer_CreateWithSource(source);
817 ASSERT_NE(demuxer, nullptr);
818 sourceFormat = OH_AVSource_GetSourceFormat(source);
819 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
820 ASSERT_EQ(0, strcmp(title, "bom"));
821 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
822 ASSERT_EQ(0, strcmp(artist, "张三"));
823 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
824 ASSERT_EQ(0, strcmp(album, "a"));
825 close(fd);
826 fd = -1;
827 }
828
829 /**
830 * @tc.number : DEMUXER_GBK_0030
831 * @tc.name : demux mp3 file with gb18030, check key
832 * @tc.desc : function test
833 */
834 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0030, TestSize.Level2)
835 {
836 const char* artist = nullptr;
837 const char* album = nullptr;
838 const char* title = nullptr;
839 const char *file = "/data/test/media/audio/gb18030.mp3";
840 int fd = open(file, O_RDONLY);
841 int64_t size = GetFileSize(file);
842 cout << file << "----------------------" << fd << "---------" << size << endl;
843 source = OH_AVSource_CreateWithFD(fd, 0, size);
844 ASSERT_NE(source, nullptr);
845 demuxer = OH_AVDemuxer_CreateWithSource(source);
846 ASSERT_NE(demuxer, nullptr);
847 sourceFormat = OH_AVSource_GetSourceFormat(source);
848 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
849 ASSERT_EQ(0, strcmp(title, "bom"));
850 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
851 ASSERT_EQ(0, strcmp(artist, "张三"));
852 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
853 ASSERT_EQ(0, strcmp(album, "a"));
854 close(fd);
855 fd = -1;
856 }
857
858 /**
859 * @tc.number : DEMUXER_GBK_0040
860 * @tc.name : demux flac file with gbk, check key
861 * @tc.desc : function test
862 */
863 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0040, TestSize.Level2)
864 {
865 const char* artist = nullptr;
866 const char* album = nullptr;
867 const char* title = nullptr;
868 const char *file = "/data/test/media/audio/gbk.flac";
869 int fd = open(file, O_RDONLY);
870 int64_t size = GetFileSize(file);
871 cout << file << "----------------------" << fd << "---------" << size << endl;
872 source = OH_AVSource_CreateWithFD(fd, 0, size);
873 ASSERT_NE(source, nullptr);
874 demuxer = OH_AVDemuxer_CreateWithSource(source);
875 ASSERT_NE(demuxer, nullptr);
876 sourceFormat = OH_AVSource_GetSourceFormat(source);
877 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
878 ASSERT_EQ(0, strcmp(title, "音乐"));
879 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
880 ASSERT_EQ(0, strcmp(artist, "张三"));
881 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
882 ASSERT_EQ(0, strcmp(album, "风景"));
883 close(fd);
884 fd = -1;
885 }
886
887 /**
888 * @tc.number : DEMUXER_GBK_0050
889 * @tc.name : demux flac file with gb2312, check key
890 * @tc.desc : function test
891 */
892 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0050, TestSize.Level2)
893 {
894 const char* artist = nullptr;
895 const char* album = nullptr;
896 const char* title = nullptr;
897 const char *file = "/data/test/media/audio/gb2312.flac";
898 int fd = open(file, O_RDONLY);
899 int64_t size = GetFileSize(file);
900 cout << file << "----------------------" << fd << "---------" << size << endl;
901 source = OH_AVSource_CreateWithFD(fd, 0, size);
902 ASSERT_NE(source, nullptr);
903 demuxer = OH_AVDemuxer_CreateWithSource(source);
904 ASSERT_NE(demuxer, nullptr);
905 sourceFormat = OH_AVSource_GetSourceFormat(source);
906 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
907 ASSERT_EQ(0, strcmp(title, "音乐"));
908 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
909 ASSERT_EQ(0, strcmp(artist, "张三"));
910 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
911 ASSERT_EQ(0, strcmp(album, "风景"));
912 close(fd);
913 fd = -1;
914 }
915
916 /**
917 * @tc.number : DEMUXER_GBK_0060
918 * @tc.name : demux flac file with gb18030, check key
919 * @tc.desc : function test
920 */
921 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0060, TestSize.Level2)
922 {
923 const char* artist = nullptr;
924 const char* album = nullptr;
925 const char* title = nullptr;
926 const char *file = "/data/test/media/audio/gb18030.flac";
927 int fd = open(file, O_RDONLY);
928 int64_t size = GetFileSize(file);
929 cout << file << "----------------------" << fd << "---------" << size << endl;
930 source = OH_AVSource_CreateWithFD(fd, 0, size);
931 ASSERT_NE(source, nullptr);
932 demuxer = OH_AVDemuxer_CreateWithSource(source);
933 ASSERT_NE(demuxer, nullptr);
934 sourceFormat = OH_AVSource_GetSourceFormat(source);
935 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
936 ASSERT_EQ(0, strcmp(title, "音乐"));
937 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
938 ASSERT_EQ(0, strcmp(artist, "张三"));
939 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
940 ASSERT_EQ(0, strcmp(album, "风景"));
941 close(fd);
942 fd = -1;
943 }
944
945 /**
946 * @tc.number : DEMUXER_GBK_0070
947 * @tc.name : demux flv file with gbk, check key
948 * @tc.desc : function test
949 */
950 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0070, TestSize.Level2)
951 {
952 const char* title = nullptr;
953 const char *file = "/data/test/media/gbk.flv";
954 int fd = open(file, O_RDONLY);
955 int64_t size = GetFileSize(file);
956 cout << file << "----------------------" << fd << "---------" << size << endl;
957 source = OH_AVSource_CreateWithFD(fd, 0, size);
958 ASSERT_NE(source, nullptr);
959 demuxer = OH_AVDemuxer_CreateWithSource(source);
960 ASSERT_NE(demuxer, nullptr);
961 sourceFormat = OH_AVSource_GetSourceFormat(source);
962 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
963 ASSERT_EQ(0, strcmp(title, "张三"));
964 close(fd);
965 fd = -1;
966 }
967
968 /**
969 * @tc.number : DEMUXER_GBK_0080
970 * @tc.name : demux flv file with gb2312, check key
971 * @tc.desc : function test
972 */
973 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0080, TestSize.Level2)
974 {
975 const char* title = nullptr;
976 const char *file = "/data/test/media/gb2312.flv";
977 int fd = open(file, O_RDONLY);
978 int64_t size = GetFileSize(file);
979 cout << file << "----------------------" << fd << "---------" << size << endl;
980 source = OH_AVSource_CreateWithFD(fd, 0, size);
981 ASSERT_NE(source, nullptr);
982 demuxer = OH_AVDemuxer_CreateWithSource(source);
983 ASSERT_NE(demuxer, nullptr);
984 sourceFormat = OH_AVSource_GetSourceFormat(source);
985 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
986 ASSERT_EQ(0, strcmp(title, "张三"));
987 close(fd);
988 fd = -1;
989 }
990
991 /**
992 * @tc.number : DEMUXER_GBK_0090
993 * @tc.name : demux flv file with gb18030, check key
994 * @tc.desc : function test
995 */
996 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0090, TestSize.Level2)
997 {
998 const char* title = nullptr;
999 const char *file = "/data/test/media/gb18030.flv";
1000 int fd = open(file, O_RDONLY);
1001 int64_t size = GetFileSize(file);
1002 cout << file << "----------------------" << fd << "---------" << size << endl;
1003 source = OH_AVSource_CreateWithFD(fd, 0, size);
1004 ASSERT_NE(source, nullptr);
1005 demuxer = OH_AVDemuxer_CreateWithSource(source);
1006 ASSERT_NE(demuxer, nullptr);
1007 sourceFormat = OH_AVSource_GetSourceFormat(source);
1008 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1009 ASSERT_EQ(0, strcmp(title, "张三"));
1010 close(fd);
1011 fd = -1;
1012 }
1013
1014 /**
1015 * @tc.number : DEMUXER_GBK_0100
1016 * @tc.name : demux m4a file with gbk, check key
1017 * @tc.desc : function test
1018 */
1019 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0100, TestSize.Level2)
1020 {
1021 const char* artist = nullptr;
1022 const char* album = nullptr;
1023 const char* title = nullptr;
1024 const char *file = "/data/test/media/audio/gbk.m4a";
1025 int fd = open(file, O_RDONLY);
1026 int64_t size = GetFileSize(file);
1027 cout << file << "----------------------" << fd << "---------" << size << endl;
1028 source = OH_AVSource_CreateWithFD(fd, 0, size);
1029 ASSERT_NE(source, nullptr);
1030 demuxer = OH_AVDemuxer_CreateWithSource(source);
1031 ASSERT_NE(demuxer, nullptr);
1032 sourceFormat = OH_AVSource_GetSourceFormat(source);
1033 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1034 ASSERT_EQ(0, strcmp(title, "音乐"));
1035 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
1036 ASSERT_EQ(0, strcmp(artist, "张三"));
1037 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
1038 ASSERT_EQ(0, strcmp(album, "风景"));
1039 close(fd);
1040 fd = -1;
1041 }
1042
1043 /**
1044 * @tc.number : DEMUXER_GBK_0110
1045 * @tc.name : demux m4a file with gb2312, check key
1046 * @tc.desc : function test
1047 */
1048 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0110, TestSize.Level2)
1049 {
1050 const char* artist = nullptr;
1051 const char* album = nullptr;
1052 const char* title = nullptr;
1053 const char *file = "/data/test/media/audio/gb2312.m4a";
1054 int fd = open(file, O_RDONLY);
1055 int64_t size = GetFileSize(file);
1056 cout << file << "----------------------" << fd << "---------" << size << endl;
1057 source = OH_AVSource_CreateWithFD(fd, 0, size);
1058 ASSERT_NE(source, nullptr);
1059 demuxer = OH_AVDemuxer_CreateWithSource(source);
1060 ASSERT_NE(demuxer, nullptr);
1061 sourceFormat = OH_AVSource_GetSourceFormat(source);
1062 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1063 ASSERT_EQ(0, strcmp(title, "音乐"));
1064 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
1065 ASSERT_EQ(0, strcmp(artist, "张三"));
1066 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
1067 ASSERT_EQ(0, strcmp(album, "风景"));
1068 close(fd);
1069 fd = -1;
1070 }
1071
1072 /**
1073 * @tc.number : DEMUXER_GBK_0120
1074 * @tc.name : demux m4a file with gb18030, check key
1075 * @tc.desc : function test
1076 */
1077 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0120, TestSize.Level2)
1078 {
1079 const char* artist = nullptr;
1080 const char* album = nullptr;
1081 const char* title = nullptr;
1082 const char *file = "/data/test/media/audio/gb18030.m4a";
1083 int fd = open(file, O_RDONLY);
1084 int64_t size = GetFileSize(file);
1085 cout << file << "----------------------" << fd << "---------" << size << endl;
1086 source = OH_AVSource_CreateWithFD(fd, 0, size);
1087 ASSERT_NE(source, nullptr);
1088 demuxer = OH_AVDemuxer_CreateWithSource(source);
1089 ASSERT_NE(demuxer, nullptr);
1090 sourceFormat = OH_AVSource_GetSourceFormat(source);
1091 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1092 ASSERT_EQ(0, strcmp(title, "音乐"));
1093 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
1094 ASSERT_EQ(0, strcmp(artist, "张三"));
1095 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
1096 ASSERT_EQ(0, strcmp(album, "风景"));
1097 close(fd);
1098 fd = -1;
1099 }
1100
1101 /**
1102 * @tc.number : DEMUXER_GBK_0130
1103 * @tc.name : demux mkv file with gbk, check key
1104 * @tc.desc : function test
1105 */
1106 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0130, TestSize.Level2)
1107 {
1108 const char* title = nullptr;
1109 const char *file = "/data/test/media/gbk.mkv";
1110 int fd = open(file, O_RDONLY);
1111 int64_t size = GetFileSize(file);
1112 cout << file << "----------------------" << fd << "---------" << size << endl;
1113 source = OH_AVSource_CreateWithFD(fd, 0, size);
1114 ASSERT_NE(source, nullptr);
1115 demuxer = OH_AVDemuxer_CreateWithSource(source);
1116 ASSERT_NE(demuxer, nullptr);
1117 sourceFormat = OH_AVSource_GetSourceFormat(source);
1118 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1119 ASSERT_EQ(0, strcmp(title, "张三"));
1120 close(fd);
1121 fd = -1;
1122 }
1123
1124 /**
1125 * @tc.number : DEMUXER_GBK_0140
1126 * @tc.name : demux mkv file with gb2312, check key
1127 * @tc.desc : function test
1128 */
1129 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0140, TestSize.Level2)
1130 {
1131 const char* title = nullptr;
1132 const char *file = "/data/test/media/gb2312.mkv";
1133 int fd = open(file, O_RDONLY);
1134 int64_t size = GetFileSize(file);
1135 cout << file << "----------------------" << fd << "---------" << size << endl;
1136 source = OH_AVSource_CreateWithFD(fd, 0, size);
1137 ASSERT_NE(source, nullptr);
1138 demuxer = OH_AVDemuxer_CreateWithSource(source);
1139 ASSERT_NE(demuxer, nullptr);
1140 sourceFormat = OH_AVSource_GetSourceFormat(source);
1141 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1142 ASSERT_EQ(0, strcmp(title, "张三"));
1143 close(fd);
1144 fd = -1;
1145 }
1146
1147 /**
1148 * @tc.number : DEMUXER_GBK_0150
1149 * @tc.name : demux mkv file with gb18030, check key
1150 * @tc.desc : function test
1151 */
1152 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0150, TestSize.Level2)
1153 {
1154 const char* title = nullptr;
1155 const char *file = "/data/test/media/gb18030.mkv";
1156 int fd = open(file, O_RDONLY);
1157 int64_t size = GetFileSize(file);
1158 cout << file << "----------------------" << fd << "---------" << size << endl;
1159 source = OH_AVSource_CreateWithFD(fd, 0, size);
1160 ASSERT_NE(source, nullptr);
1161 demuxer = OH_AVDemuxer_CreateWithSource(source);
1162 ASSERT_NE(demuxer, nullptr);
1163 sourceFormat = OH_AVSource_GetSourceFormat(source);
1164 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1165 ASSERT_EQ(0, strcmp(title, "张三"));
1166 close(fd);
1167 fd = -1;
1168 }
1169
1170 /**
1171 * @tc.number : DEMUXER_GBK_0160
1172 * @tc.name : demux mov file with gbk, check key
1173 * @tc.desc : function test
1174 */
1175 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0160, TestSize.Level2)
1176 {
1177 const char* title = nullptr;
1178 const char *file = "/data/test/media/gbk.mov";
1179 int fd = open(file, O_RDONLY);
1180 int64_t size = GetFileSize(file);
1181 cout << file << "----------------------" << fd << "---------" << size << endl;
1182 source = OH_AVSource_CreateWithFD(fd, 0, size);
1183 ASSERT_NE(source, nullptr);
1184 demuxer = OH_AVDemuxer_CreateWithSource(source);
1185 ASSERT_NE(demuxer, nullptr);
1186 sourceFormat = OH_AVSource_GetSourceFormat(source);
1187 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1188 ASSERT_EQ(0, strcmp(title, "张三"));
1189 close(fd);
1190 fd = -1;
1191 }
1192
1193 /**
1194 * @tc.number : DEMUXER_GBK_0170
1195 * @tc.name : demux mov file with gb2312, check key
1196 * @tc.desc : function test
1197 */
1198 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0170, TestSize.Level2)
1199 {
1200 const char* title = nullptr;
1201 const char *file = "/data/test/media/gb2312.mov";
1202 int fd = open(file, O_RDONLY);
1203 int64_t size = GetFileSize(file);
1204 cout << file << "----------------------" << fd << "---------" << size << endl;
1205 source = OH_AVSource_CreateWithFD(fd, 0, size);
1206 ASSERT_NE(source, nullptr);
1207 demuxer = OH_AVDemuxer_CreateWithSource(source);
1208 ASSERT_NE(demuxer, nullptr);
1209 sourceFormat = OH_AVSource_GetSourceFormat(source);
1210 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1211 ASSERT_EQ(0, strcmp(title, "张三"));
1212 close(fd);
1213 fd = -1;
1214 }
1215
1216 /**
1217 * @tc.number : DEMUXER_GBK_0180
1218 * @tc.name : demux mov file with gb18030, check key
1219 * @tc.desc : function test
1220 */
1221 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0180, TestSize.Level2)
1222 {
1223 const char* title = nullptr;
1224 const char *file = "/data/test/media/gb18030.mov";
1225 int fd = open(file, O_RDONLY);
1226 int64_t size = GetFileSize(file);
1227 cout << file << "----------------------" << fd << "---------" << size << endl;
1228 source = OH_AVSource_CreateWithFD(fd, 0, size);
1229 ASSERT_NE(source, nullptr);
1230 demuxer = OH_AVDemuxer_CreateWithSource(source);
1231 ASSERT_NE(demuxer, nullptr);
1232 sourceFormat = OH_AVSource_GetSourceFormat(source);
1233 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1234 ASSERT_EQ(0, strcmp(title, "张三"));
1235 close(fd);
1236 fd = -1;
1237 }
1238
1239 /**
1240 * @tc.number : DEMUXER_GBK_0190
1241 * @tc.name : demux mp4 file with gbk, check key
1242 * @tc.desc : function test
1243 */
1244 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0190, TestSize.Level2)
1245 {
1246 const char* title = nullptr;
1247 const char *file = "/data/test/media/gbk.mp4";
1248 int fd = open(file, O_RDONLY);
1249 int64_t size = GetFileSize(file);
1250 cout << file << "----------------------" << fd << "---------" << size << endl;
1251 source = OH_AVSource_CreateWithFD(fd, 0, size);
1252 ASSERT_NE(source, nullptr);
1253 demuxer = OH_AVDemuxer_CreateWithSource(source);
1254 ASSERT_NE(demuxer, nullptr);
1255 sourceFormat = OH_AVSource_GetSourceFormat(source);
1256 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1257 ASSERT_EQ(0, strcmp(title, "张三"));
1258 close(fd);
1259 fd = -1;
1260 }
1261
1262 /**
1263 * @tc.number : DEMUXER_GBK_0200
1264 * @tc.name : demux mp4 file with gb2312, check key
1265 * @tc.desc : function test
1266 */
1267 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0200, TestSize.Level2)
1268 {
1269 const char* title = nullptr;
1270 const char *file = "/data/test/media/gb2312.mp4";
1271 int fd = open(file, O_RDONLY);
1272 int64_t size = GetFileSize(file);
1273 cout << file << "----------------------" << fd << "---------" << size << endl;
1274 source = OH_AVSource_CreateWithFD(fd, 0, size);
1275 ASSERT_NE(source, nullptr);
1276 demuxer = OH_AVDemuxer_CreateWithSource(source);
1277 ASSERT_NE(demuxer, nullptr);
1278 sourceFormat = OH_AVSource_GetSourceFormat(source);
1279 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1280 ASSERT_EQ(0, strcmp(title, "张三"));
1281 close(fd);
1282 fd = -1;
1283 }
1284
1285 /**
1286 * @tc.number : DEMUXER_GBK_0210
1287 * @tc.name : demux mp4 file with gb18030, check key
1288 * @tc.desc : function test
1289 */
1290 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0210, TestSize.Level2)
1291 {
1292 const char* title = nullptr;
1293 const char *file = "/data/test/media/gb18030.mp4";
1294 int fd = open(file, O_RDONLY);
1295 int64_t size = GetFileSize(file);
1296 cout << file << "----------------------" << fd << "---------" << size << endl;
1297 source = OH_AVSource_CreateWithFD(fd, 0, size);
1298 ASSERT_NE(source, nullptr);
1299 demuxer = OH_AVDemuxer_CreateWithSource(source);
1300 ASSERT_NE(demuxer, nullptr);
1301 sourceFormat = OH_AVSource_GetSourceFormat(source);
1302 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1303 ASSERT_EQ(0, strcmp(title, "张三"));
1304 close(fd);
1305 fd = -1;
1306 }
1307
1308 /**
1309 * @tc.number : DEMUXER_GBK_0220
1310 * @tc.name : demux wav file with gbk, check key
1311 * @tc.desc : function test
1312 */
1313 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0220, TestSize.Level2)
1314 {
1315 const char* artist = nullptr;
1316 const char* album = nullptr;
1317 const char* title = nullptr;
1318 const char *file = "/data/test/media/audio/gbk.wav";
1319 int fd = open(file, O_RDONLY);
1320 int64_t size = GetFileSize(file);
1321 cout << file << "----------------------" << fd << "---------" << size << endl;
1322 source = OH_AVSource_CreateWithFD(fd, 0, size);
1323 ASSERT_NE(source, nullptr);
1324 demuxer = OH_AVDemuxer_CreateWithSource(source);
1325 ASSERT_NE(demuxer, nullptr);
1326 sourceFormat = OH_AVSource_GetSourceFormat(source);
1327 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1328 ASSERT_EQ(0, strcmp(title, "音乐"));
1329 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
1330 ASSERT_EQ(0, strcmp(artist, "张三"));
1331 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
1332 ASSERT_EQ(0, strcmp(album, "风景"));
1333 close(fd);
1334 fd = -1;
1335 }
1336
1337 /**
1338 * @tc.number : DEMUXER_GBK_0230
1339 * @tc.name : demux wav file with gb2312, check key
1340 * @tc.desc : function test
1341 */
1342 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0230, TestSize.Level2)
1343 {
1344 const char* artist = nullptr;
1345 const char* album = nullptr;
1346 const char* title = nullptr;
1347 const char *file = "/data/test/media/audio/gb2312.wav";
1348 int fd = open(file, O_RDONLY);
1349 int64_t size = GetFileSize(file);
1350 cout << file << "----------------------" << fd << "---------" << size << endl;
1351 source = OH_AVSource_CreateWithFD(fd, 0, size);
1352 ASSERT_NE(source, nullptr);
1353 demuxer = OH_AVDemuxer_CreateWithSource(source);
1354 ASSERT_NE(demuxer, nullptr);
1355 sourceFormat = OH_AVSource_GetSourceFormat(source);
1356 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1357 ASSERT_EQ(0, strcmp(title, "音乐"));
1358 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
1359 ASSERT_EQ(0, strcmp(artist, "张三"));
1360 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
1361 ASSERT_EQ(0, strcmp(album, "风景"));
1362 close(fd);
1363 fd = -1;
1364 }
1365
1366 /**
1367 * @tc.number : DEMUXER_GBK_0240
1368 * @tc.name : demux wav file with gb18030, check key
1369 * @tc.desc : function test
1370 */
1371 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0240, TestSize.Level2)
1372 {
1373 const char* artist = nullptr;
1374 const char* album = nullptr;
1375 const char* title = nullptr;
1376 const char *file = "/data/test/media/audio/gb18030.wav";
1377 int fd = open(file, O_RDONLY);
1378 int64_t size = GetFileSize(file);
1379 cout << file << "----------------------" << fd << "---------" << size << endl;
1380 source = OH_AVSource_CreateWithFD(fd, 0, size);
1381 ASSERT_NE(source, nullptr);
1382 demuxer = OH_AVDemuxer_CreateWithSource(source);
1383 ASSERT_NE(demuxer, nullptr);
1384 sourceFormat = OH_AVSource_GetSourceFormat(source);
1385 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1386 ASSERT_EQ(0, strcmp(title, "音乐"));
1387 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
1388 ASSERT_EQ(0, strcmp(artist, "张三"));
1389 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
1390 ASSERT_EQ(0, strcmp(album, "风景"));
1391 close(fd);
1392 fd = -1;
1393 }