• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, &currentHeight));
185     int currentHeightResult = 1080;
186     ASSERT_EQ(currentHeightResult, currentHeight);
187     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_WIDTH, &currentWidth));
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, &currentHeight));
266     int currentHeightResult = 2160;
267     ASSERT_EQ(currentHeightResult, currentHeight);
268     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_WIDTH, &currentWidth));
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, &copyright));
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, &currentWidth));
362     ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_HEIGHT, &currentHeight));
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, &currentWidth));
400     ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_HEIGHT, &currentHeight));
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, &copyright));
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, &currentWidth));
507     ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_HEIGHT, &currentHeight));
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     cout << file << "----------------------" << fd << "---------" << size << endl;
540     source = OH_AVSource_CreateWithFD(fd, 0, size);
541     ASSERT_NE(source, nullptr);
542     demuxer = OH_AVDemuxer_CreateWithSource(source);
543     ASSERT_NE(demuxer, nullptr);
544     sourceFormat = OH_AVSource_GetSourceFormat(source);
545     SetAllParam(sourceFormat);
546     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
547     ASSERT_EQ(2, g_trackCount);
548     const char* mimeType = nullptr;
549     for (int32_t index = 0; index < g_trackCount; index++) {
550         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
551     }
552     OH_AVCodecBufferAttr attr;
553     int vKeyCount = 0;
554     int aKeyCount = 0;
555     bool audioIsEnd = false;
556     bool videoIsEnd = false;
557     int audioFrame = 0;
558     int videoFrame = 0;
559     while (!audioIsEnd || !videoIsEnd) {
560         for (int32_t index = 0; index < g_trackCount; index++) {
561             trackFormat = OH_AVSource_GetTrackFormat(source, index);
562             ASSERT_NE(trackFormat, nullptr);
563             ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
564             if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD) && index == MEDIA_TYPE_AUD) ||
565              (videoIsEnd && (tarckType == MEDIA_TYPE_VID) && index == MEDIA_TYPE_VID)) {
566                 continue;
567             }
568             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
569             ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
570             if (tarckType == MEDIA_TYPE_AUD) {
571                 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
572                 SetAudioParam(trackFormat);
573                 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_AAC));
574             } else if (tarckType == MEDIA_TYPE_VID) {
575                 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
576                 HevcVideoParam(trackFormat);
577             }
578             OH_AVFormat_Destroy(trackFormat);
579             trackFormat = nullptr;
580         }
581     }
582     close(fd);
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     cout << file << "----------------------" << fd << "---------" << size << endl;
597     source = OH_AVSource_CreateWithFD(fd, 0, size);
598     ASSERT_NE(source, nullptr);
599     demuxer = OH_AVDemuxer_CreateWithSource(source);
600     ASSERT_NE(demuxer, nullptr);
601     sourceFormat = OH_AVSource_GetSourceFormat(source);
602     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
603     ASSERT_EQ(2, g_trackCount);
604     SetAllParam(sourceFormat);
605     const char* mimeType = nullptr;
606     for (int32_t index = 0; index < g_trackCount; index++) {
607         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
608     }
609     OH_AVCodecBufferAttr attr;
610     int vKeyCount = 0;
611     int aKeyCount = 0;
612     bool audioIsEnd = false;
613     bool videoIsEnd = false;
614     int audioFrame = 0;
615     int videoFrame = 0;
616     while (!audioIsEnd || !videoIsEnd) {
617         for (int32_t index = 0; index < g_trackCount; index++) {
618             trackFormat = OH_AVSource_GetTrackFormat(source, index);
619             ASSERT_NE(trackFormat, nullptr);
620             ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
621             if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD) && index == MEDIA_TYPE_AUD)
622              || (videoIsEnd && (tarckType == MEDIA_TYPE_VID) && index == MEDIA_TYPE_VID)) {
623                 continue;
624             }
625             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
626             ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
627             if (tarckType == MEDIA_TYPE_AUD) {
628                 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
629                 SetAudioParam(trackFormat);
630                 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_AAC));
631             } else if (tarckType == MEDIA_TYPE_VID) {
632                 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
633                 AvcVideoParam(trackFormat);
634             }
635             OH_AVFormat_Destroy(trackFormat);
636             trackFormat = nullptr;
637         }
638     }
639     close(fd);
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     cout << file << "----------------------" << fd << "---------" << size << endl;
653     source = OH_AVSource_CreateWithFD(fd, 0, size);
654     ASSERT_NE(source, nullptr);
655     demuxer = OH_AVDemuxer_CreateWithSource(source);
656     ASSERT_NE(demuxer, nullptr);
657     sourceFormat = OH_AVSource_GetSourceFormat(source);
658     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
659     ASSERT_EQ(5, g_trackCount);
660     SetOtherAllParam(sourceFormat);
661     const char* mimeType = nullptr;
662     for (int32_t index = 0; index < 2; index++) {
663         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
664     }
665     OH_AVCodecBufferAttr attr;
666     int vKeyCount = 0;
667     int aKeyCount = 0;
668     bool audioIsEnd = false;
669     bool videoIsEnd = false;
670     int audioFrame = 0;
671     int videoFrame = 0;
672     while (!audioIsEnd || !videoIsEnd) {
673         for (int32_t index = 0; index < 2; index++) {
674             trackFormat = OH_AVSource_GetTrackFormat(source, index);
675             ASSERT_NE(trackFormat, nullptr);
676             ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
677             if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD) && index == MEDIA_TYPE_AUD)
678              || (videoIsEnd && (tarckType == MEDIA_TYPE_VID) && index == MEDIA_TYPE_VID)) {
679                 continue;
680             }
681             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
682             ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
683             if (tarckType == MEDIA_TYPE_AUD) {
684                 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
685                 SetOtherAudioParam(trackFormat);
686                 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_AAC));
687             } else if (tarckType == MEDIA_TYPE_VID) {
688                 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
689                 OtherVideoParam(trackFormat);
690             }
691             OH_AVFormat_Destroy(trackFormat);
692             trackFormat = nullptr;
693         }
694     }
695     close(fd);
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 }
727 
728 /**
729  * @tc.number    : VIDEO_DEMUXER_VVC_0600
730  * @tc.name      : demuxer 10bit H266 MP4 file, check key
731  * @tc.desc      : function test
732  */
733 HWTEST_F(DemuxerFormatNdkTest, VIDEO_DEMUXER_VVC_0600, TestSize.Level0)
734 {
735     if (access(g_vvc10bitPath.c_str(), F_OK) != 0) {
736         return;
737     }
738     int64_t duration = 0;
739     int64_t startTime;
740     int tarckType = 0;
741     int fd = open(g_vvc10bitPath.c_str(), O_RDONLY);
742     int64_t size = GetFileSize(g_vvc10bitPath.c_str());
743     cout << g_vvc10bitPath.c_str() << "---------" << fd << "----------" << size <<endl;
744     source = OH_AVSource_CreateWithFD(fd, 0, size);
745     ASSERT_NE(source, nullptr);
746     sourceFormat = OH_AVSource_GetSourceFormat(source);
747     ASSERT_NE(sourceFormat, nullptr);
748     ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_DURATION, &duration));
749     ASSERT_EQ(60000000, duration);
750     ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_START_TIME, &startTime));
751     ASSERT_EQ(0, startTime);
752     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
753     ASSERT_EQ(2, g_trackCount);
754     for (int32_t index = 0; index < g_trackCount; index++) {
755         trackFormat = OH_AVSource_GetTrackFormat(source, 0);
756         ASSERT_NE(trackFormat, nullptr);
757         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
758         OH_AVFormat_Destroy(trackFormat);
759         trackFormat = nullptr;
760         if (tarckType == MEDIA_TYPE_VID) {
761             CheckVideoKey();
762         } else if (tarckType == MEDIA_TYPE_AUD) {
763             CheckAudioKey();
764         }
765     }
766     close(fd);
767 }
768 
769 /**
770  * @tc.number    : DEMUXER_GBK_0010
771  * @tc.name      : demux mp3 file with gbk, check key
772  * @tc.desc      : function test
773  */
774 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0010, TestSize.Level2)
775 {
776     const char* artist = nullptr;
777     const char* album = nullptr;
778     const char* title = nullptr;
779     const char *file = "/data/test/media/audio/gbk.mp3";
780     int fd = open(file, O_RDONLY);
781     int64_t size = GetFileSize(file);
782     cout << file << "----------------------" << fd << "---------" << size << endl;
783     source = OH_AVSource_CreateWithFD(fd, 0, size);
784     ASSERT_NE(source, nullptr);
785     demuxer = OH_AVDemuxer_CreateWithSource(source);
786     ASSERT_NE(demuxer, nullptr);
787     sourceFormat = OH_AVSource_GetSourceFormat(source);
788     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
789     ASSERT_EQ(0, strcmp(title, "bom"));
790     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
791     ASSERT_EQ(0, strcmp(artist, "张三"));
792     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
793     ASSERT_EQ(0, strcmp(album, "a"));
794     close(fd);
795 }
796 
797 /**
798  * @tc.number    : DEMUXER_GBK_0020
799  * @tc.name      : demux mp3 file with gb2312, check key
800  * @tc.desc      : function test
801  */
802 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0020, TestSize.Level2)
803 {
804     const char* artist = nullptr;
805     const char* album = nullptr;
806     const char* title = nullptr;
807     const char *file = "/data/test/media/audio/gb2312.mp3";
808     int fd = open(file, O_RDONLY);
809     int64_t size = GetFileSize(file);
810     cout << file << "----------------------" << fd << "---------" << size << endl;
811     source = OH_AVSource_CreateWithFD(fd, 0, size);
812     ASSERT_NE(source, nullptr);
813     demuxer = OH_AVDemuxer_CreateWithSource(source);
814     ASSERT_NE(demuxer, nullptr);
815     sourceFormat = OH_AVSource_GetSourceFormat(source);
816     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
817     ASSERT_EQ(0, strcmp(title, "bom"));
818     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
819     ASSERT_EQ(0, strcmp(artist, "张三"));
820     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
821     ASSERT_EQ(0, strcmp(album, "a"));
822     close(fd);
823 }
824 
825 /**
826  * @tc.number    : DEMUXER_GBK_0030
827  * @tc.name      : demux mp3 file with gb18030, check key
828  * @tc.desc      : function test
829  */
830 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0030, TestSize.Level2)
831 {
832     const char* artist = nullptr;
833     const char* album = nullptr;
834     const char* title = nullptr;
835     const char *file = "/data/test/media/audio/gb18030.mp3";
836     int fd = open(file, O_RDONLY);
837     int64_t size = GetFileSize(file);
838     cout << file << "----------------------" << fd << "---------" << size << endl;
839     source = OH_AVSource_CreateWithFD(fd, 0, size);
840     ASSERT_NE(source, nullptr);
841     demuxer = OH_AVDemuxer_CreateWithSource(source);
842     ASSERT_NE(demuxer, nullptr);
843     sourceFormat = OH_AVSource_GetSourceFormat(source);
844     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
845     ASSERT_EQ(0, strcmp(title, "bom"));
846     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
847     ASSERT_EQ(0, strcmp(artist, "张三"));
848     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
849     ASSERT_EQ(0, strcmp(album, "a"));
850     close(fd);
851 }
852 
853 /**
854  * @tc.number    : DEMUXER_GBK_0040
855  * @tc.name      : demux flac file with gbk, check key
856  * @tc.desc      : function test
857  */
858 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0040, TestSize.Level2)
859 {
860     const char* artist = nullptr;
861     const char* album = nullptr;
862     const char* title = nullptr;
863     const char *file = "/data/test/media/audio/gbk.flac";
864     int fd = open(file, O_RDONLY);
865     int64_t size = GetFileSize(file);
866     cout << file << "----------------------" << fd << "---------" << size << endl;
867     source = OH_AVSource_CreateWithFD(fd, 0, size);
868     ASSERT_NE(source, nullptr);
869     demuxer = OH_AVDemuxer_CreateWithSource(source);
870     ASSERT_NE(demuxer, nullptr);
871     sourceFormat = OH_AVSource_GetSourceFormat(source);
872     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
873     ASSERT_EQ(0, strcmp(title, "音乐"));
874     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
875     ASSERT_EQ(0, strcmp(artist, "张三"));
876     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
877     ASSERT_EQ(0, strcmp(album, "风景"));
878     close(fd);
879 }
880 
881 /**
882  * @tc.number    : DEMUXER_GBK_0050
883  * @tc.name      : demux flac file with gb2312, check key
884  * @tc.desc      : function test
885  */
886 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0050, TestSize.Level2)
887 {
888     const char* artist = nullptr;
889     const char* album = nullptr;
890     const char* title = nullptr;
891     const char *file = "/data/test/media/audio/gb2312.flac";
892     int fd = open(file, O_RDONLY);
893     int64_t size = GetFileSize(file);
894     cout << file << "----------------------" << fd << "---------" << size << endl;
895     source = OH_AVSource_CreateWithFD(fd, 0, size);
896     ASSERT_NE(source, nullptr);
897     demuxer = OH_AVDemuxer_CreateWithSource(source);
898     ASSERT_NE(demuxer, nullptr);
899     sourceFormat = OH_AVSource_GetSourceFormat(source);
900     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
901     ASSERT_EQ(0, strcmp(title, "音乐"));
902     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
903     ASSERT_EQ(0, strcmp(artist, "张三"));
904     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
905     ASSERT_EQ(0, strcmp(album, "风景"));
906     close(fd);
907 }
908 
909 /**
910  * @tc.number    : DEMUXER_GBK_0060
911  * @tc.name      : demux flac file with gb18030, check key
912  * @tc.desc      : function test
913  */
914 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0060, TestSize.Level2)
915 {
916     const char* artist = nullptr;
917     const char* album = nullptr;
918     const char* title = nullptr;
919     const char *file = "/data/test/media/audio/gb18030.flac";
920     int fd = open(file, O_RDONLY);
921     int64_t size = GetFileSize(file);
922     cout << file << "----------------------" << fd << "---------" << size << endl;
923     source = OH_AVSource_CreateWithFD(fd, 0, size);
924     ASSERT_NE(source, nullptr);
925     demuxer = OH_AVDemuxer_CreateWithSource(source);
926     ASSERT_NE(demuxer, nullptr);
927     sourceFormat = OH_AVSource_GetSourceFormat(source);
928     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
929     ASSERT_EQ(0, strcmp(title, "音乐"));
930     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
931     ASSERT_EQ(0, strcmp(artist, "张三"));
932     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
933     ASSERT_EQ(0, strcmp(album, "风景"));
934     close(fd);
935 }
936 
937 /**
938  * @tc.number    : DEMUXER_GBK_0070
939  * @tc.name      : demux flv file with gbk, check key
940  * @tc.desc      : function test
941  */
942 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0070, TestSize.Level2)
943 {
944     const char* title = nullptr;
945     const char *file = "/data/test/media/gbk.flv";
946     int fd = open(file, O_RDONLY);
947     int64_t size = GetFileSize(file);
948     cout << file << "----------------------" << fd << "---------" << size << endl;
949     source = OH_AVSource_CreateWithFD(fd, 0, size);
950     ASSERT_NE(source, nullptr);
951     demuxer = OH_AVDemuxer_CreateWithSource(source);
952     ASSERT_NE(demuxer, nullptr);
953     sourceFormat = OH_AVSource_GetSourceFormat(source);
954     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
955     ASSERT_EQ(0, strcmp(title, "张三"));
956     close(fd);
957 }
958 
959 /**
960  * @tc.number    : DEMUXER_GBK_0080
961  * @tc.name      : demux flv file with gb2312, check key
962  * @tc.desc      : function test
963  */
964 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0080, TestSize.Level2)
965 {
966     const char* title = nullptr;
967     const char *file = "/data/test/media/gb2312.flv";
968     int fd = open(file, O_RDONLY);
969     int64_t size = GetFileSize(file);
970     cout << file << "----------------------" << fd << "---------" << size << endl;
971     source = OH_AVSource_CreateWithFD(fd, 0, size);
972     ASSERT_NE(source, nullptr);
973     demuxer = OH_AVDemuxer_CreateWithSource(source);
974     ASSERT_NE(demuxer, nullptr);
975     sourceFormat = OH_AVSource_GetSourceFormat(source);
976     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
977     ASSERT_EQ(0, strcmp(title, "张三"));
978     close(fd);
979 }
980 
981 /**
982  * @tc.number    : DEMUXER_GBK_0090
983  * @tc.name      : demux flv file with gb18030, check key
984  * @tc.desc      : function test
985  */
986 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0090, TestSize.Level2)
987 {
988     const char* title = nullptr;
989     const char *file = "/data/test/media/gb18030.flv";
990     int fd = open(file, O_RDONLY);
991     int64_t size = GetFileSize(file);
992     cout << file << "----------------------" << fd << "---------" << size << endl;
993     source = OH_AVSource_CreateWithFD(fd, 0, size);
994     ASSERT_NE(source, nullptr);
995     demuxer = OH_AVDemuxer_CreateWithSource(source);
996     ASSERT_NE(demuxer, nullptr);
997     sourceFormat = OH_AVSource_GetSourceFormat(source);
998     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
999     ASSERT_EQ(0, strcmp(title, "张三"));
1000     close(fd);
1001 }
1002 
1003 /**
1004  * @tc.number    : DEMUXER_GBK_0100
1005  * @tc.name      : demux m4a file with gbk, check key
1006  * @tc.desc      : function test
1007  */
1008 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0100, TestSize.Level2)
1009 {
1010     const char* artist = nullptr;
1011     const char* album = nullptr;
1012     const char* title = nullptr;
1013     const char *file = "/data/test/media/audio/gbk.m4a";
1014     int fd = open(file, O_RDONLY);
1015     int64_t size = GetFileSize(file);
1016     cout << file << "----------------------" << fd << "---------" << size << endl;
1017     source = OH_AVSource_CreateWithFD(fd, 0, size);
1018     ASSERT_NE(source, nullptr);
1019     demuxer = OH_AVDemuxer_CreateWithSource(source);
1020     ASSERT_NE(demuxer, nullptr);
1021     sourceFormat = OH_AVSource_GetSourceFormat(source);
1022     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1023     ASSERT_EQ(0, strcmp(title, "音乐"));
1024     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
1025     ASSERT_EQ(0, strcmp(artist, "张三"));
1026     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
1027     ASSERT_EQ(0, strcmp(album, "风景"));
1028     close(fd);
1029 }
1030 
1031 /**
1032  * @tc.number    : DEMUXER_GBK_0110
1033  * @tc.name      : demux m4a file with gb2312, check key
1034  * @tc.desc      : function test
1035  */
1036 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0110, TestSize.Level2)
1037 {
1038     const char* artist = nullptr;
1039     const char* album = nullptr;
1040     const char* title = nullptr;
1041     const char *file = "/data/test/media/audio/gb2312.m4a";
1042     int fd = open(file, O_RDONLY);
1043     int64_t size = GetFileSize(file);
1044     cout << file << "----------------------" << fd << "---------" << size << endl;
1045     source = OH_AVSource_CreateWithFD(fd, 0, size);
1046     ASSERT_NE(source, nullptr);
1047     demuxer = OH_AVDemuxer_CreateWithSource(source);
1048     ASSERT_NE(demuxer, nullptr);
1049     sourceFormat = OH_AVSource_GetSourceFormat(source);
1050     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1051     ASSERT_EQ(0, strcmp(title, "音乐"));
1052     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
1053     ASSERT_EQ(0, strcmp(artist, "张三"));
1054     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
1055     ASSERT_EQ(0, strcmp(album, "风景"));
1056     close(fd);
1057 }
1058 
1059 /**
1060  * @tc.number    : DEMUXER_GBK_0120
1061  * @tc.name      : demux m4a file with gb18030, check key
1062  * @tc.desc      : function test
1063  */
1064 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0120, TestSize.Level2)
1065 {
1066     const char* artist = nullptr;
1067     const char* album = nullptr;
1068     const char* title = nullptr;
1069     const char *file = "/data/test/media/audio/gb18030.m4a";
1070     int fd = open(file, O_RDONLY);
1071     int64_t size = GetFileSize(file);
1072     cout << file << "----------------------" << fd << "---------" << size << endl;
1073     source = OH_AVSource_CreateWithFD(fd, 0, size);
1074     ASSERT_NE(source, nullptr);
1075     demuxer = OH_AVDemuxer_CreateWithSource(source);
1076     ASSERT_NE(demuxer, nullptr);
1077     sourceFormat = OH_AVSource_GetSourceFormat(source);
1078     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1079     ASSERT_EQ(0, strcmp(title, "音乐"));
1080     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
1081     ASSERT_EQ(0, strcmp(artist, "张三"));
1082     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
1083     ASSERT_EQ(0, strcmp(album, "风景"));
1084     close(fd);
1085 }
1086 
1087 /**
1088  * @tc.number    : DEMUXER_GBK_0130
1089  * @tc.name      : demux mkv file with gbk, check key
1090  * @tc.desc      : function test
1091  */
1092 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0130, TestSize.Level2)
1093 {
1094     const char* title = nullptr;
1095     const char *file = "/data/test/media/gbk.mkv";
1096     int fd = open(file, O_RDONLY);
1097     int64_t size = GetFileSize(file);
1098     cout << file << "----------------------" << fd << "---------" << size << endl;
1099     source = OH_AVSource_CreateWithFD(fd, 0, size);
1100     ASSERT_NE(source, nullptr);
1101     demuxer = OH_AVDemuxer_CreateWithSource(source);
1102     ASSERT_NE(demuxer, nullptr);
1103     sourceFormat = OH_AVSource_GetSourceFormat(source);
1104     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1105     ASSERT_EQ(0, strcmp(title, "张三"));
1106     close(fd);
1107 }
1108 
1109 /**
1110  * @tc.number    : DEMUXER_GBK_0140
1111  * @tc.name      : demux mkv file with gb2312, check key
1112  * @tc.desc      : function test
1113  */
1114 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0140, TestSize.Level2)
1115 {
1116     const char* title = nullptr;
1117     const char *file = "/data/test/media/gb2312.mkv";
1118     int fd = open(file, O_RDONLY);
1119     int64_t size = GetFileSize(file);
1120     cout << file << "----------------------" << fd << "---------" << size << endl;
1121     source = OH_AVSource_CreateWithFD(fd, 0, size);
1122     ASSERT_NE(source, nullptr);
1123     demuxer = OH_AVDemuxer_CreateWithSource(source);
1124     ASSERT_NE(demuxer, nullptr);
1125     sourceFormat = OH_AVSource_GetSourceFormat(source);
1126     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1127     ASSERT_EQ(0, strcmp(title, "张三"));
1128     close(fd);
1129 }
1130 
1131 /**
1132  * @tc.number    : DEMUXER_GBK_0150
1133  * @tc.name      : demux mkv file with gb18030, check key
1134  * @tc.desc      : function test
1135  */
1136 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0150, TestSize.Level2)
1137 {
1138     const char* title = nullptr;
1139     const char *file = "/data/test/media/gb18030.mkv";
1140     int fd = open(file, O_RDONLY);
1141     int64_t size = GetFileSize(file);
1142     cout << file << "----------------------" << fd << "---------" << size << endl;
1143     source = OH_AVSource_CreateWithFD(fd, 0, size);
1144     ASSERT_NE(source, nullptr);
1145     demuxer = OH_AVDemuxer_CreateWithSource(source);
1146     ASSERT_NE(demuxer, nullptr);
1147     sourceFormat = OH_AVSource_GetSourceFormat(source);
1148     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1149     ASSERT_EQ(0, strcmp(title, "张三"));
1150     close(fd);
1151 }
1152 
1153 /**
1154  * @tc.number    : DEMUXER_GBK_0160
1155  * @tc.name      : demux mov file with gbk, check key
1156  * @tc.desc      : function test
1157  */
1158 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0160, TestSize.Level2)
1159 {
1160     const char* title = nullptr;
1161     const char *file = "/data/test/media/gbk.mov";
1162     int fd = open(file, O_RDONLY);
1163     int64_t size = GetFileSize(file);
1164     cout << file << "----------------------" << fd << "---------" << size << endl;
1165     source = OH_AVSource_CreateWithFD(fd, 0, size);
1166     ASSERT_NE(source, nullptr);
1167     demuxer = OH_AVDemuxer_CreateWithSource(source);
1168     ASSERT_NE(demuxer, nullptr);
1169     sourceFormat = OH_AVSource_GetSourceFormat(source);
1170     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1171     ASSERT_EQ(0, strcmp(title, "张三"));
1172     close(fd);
1173 }
1174 
1175 /**
1176  * @tc.number    : DEMUXER_GBK_0170
1177  * @tc.name      : demux mov file with gb2312, check key
1178  * @tc.desc      : function test
1179  */
1180 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0170, TestSize.Level2)
1181 {
1182     const char* title = nullptr;
1183     const char *file = "/data/test/media/gb2312.mov";
1184     int fd = open(file, O_RDONLY);
1185     int64_t size = GetFileSize(file);
1186     cout << file << "----------------------" << fd << "---------" << size << endl;
1187     source = OH_AVSource_CreateWithFD(fd, 0, size);
1188     ASSERT_NE(source, nullptr);
1189     demuxer = OH_AVDemuxer_CreateWithSource(source);
1190     ASSERT_NE(demuxer, nullptr);
1191     sourceFormat = OH_AVSource_GetSourceFormat(source);
1192     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1193     ASSERT_EQ(0, strcmp(title, "张三"));
1194     close(fd);
1195 }
1196 
1197 /**
1198  * @tc.number    : DEMUXER_GBK_0180
1199  * @tc.name      : demux mov file with gb18030, check key
1200  * @tc.desc      : function test
1201  */
1202 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0180, TestSize.Level2)
1203 {
1204     const char* title = nullptr;
1205     const char *file = "/data/test/media/gb18030.mov";
1206     int fd = open(file, O_RDONLY);
1207     int64_t size = GetFileSize(file);
1208     cout << file << "----------------------" << fd << "---------" << size << endl;
1209     source = OH_AVSource_CreateWithFD(fd, 0, size);
1210     ASSERT_NE(source, nullptr);
1211     demuxer = OH_AVDemuxer_CreateWithSource(source);
1212     ASSERT_NE(demuxer, nullptr);
1213     sourceFormat = OH_AVSource_GetSourceFormat(source);
1214     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1215     ASSERT_EQ(0, strcmp(title, "张三"));
1216     close(fd);
1217 }
1218 
1219 /**
1220  * @tc.number    : DEMUXER_GBK_0190
1221  * @tc.name      : demux mp4 file with gbk, check key
1222  * @tc.desc      : function test
1223  */
1224 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0190, TestSize.Level2)
1225 {
1226     const char* title = nullptr;
1227     const char *file = "/data/test/media/gbk.mp4";
1228     int fd = open(file, O_RDONLY);
1229     int64_t size = GetFileSize(file);
1230     cout << file << "----------------------" << fd << "---------" << size << endl;
1231     source = OH_AVSource_CreateWithFD(fd, 0, size);
1232     ASSERT_NE(source, nullptr);
1233     demuxer = OH_AVDemuxer_CreateWithSource(source);
1234     ASSERT_NE(demuxer, nullptr);
1235     sourceFormat = OH_AVSource_GetSourceFormat(source);
1236     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1237     ASSERT_EQ(0, strcmp(title, "张三"));
1238     close(fd);
1239 }
1240 
1241 /**
1242  * @tc.number    : DEMUXER_GBK_0200
1243  * @tc.name      : demux mp4 file with gb2312, check key
1244  * @tc.desc      : function test
1245  */
1246 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0200, TestSize.Level2)
1247 {
1248     const char* title = nullptr;
1249     const char *file = "/data/test/media/gb2312.mp4";
1250     int fd = open(file, O_RDONLY);
1251     int64_t size = GetFileSize(file);
1252     cout << file << "----------------------" << fd << "---------" << size << endl;
1253     source = OH_AVSource_CreateWithFD(fd, 0, size);
1254     ASSERT_NE(source, nullptr);
1255     demuxer = OH_AVDemuxer_CreateWithSource(source);
1256     ASSERT_NE(demuxer, nullptr);
1257     sourceFormat = OH_AVSource_GetSourceFormat(source);
1258     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1259     ASSERT_EQ(0, strcmp(title, "张三"));
1260     close(fd);
1261 }
1262 
1263 /**
1264  * @tc.number    : DEMUXER_GBK_0210
1265  * @tc.name      : demux mp4 file with gb18030, check key
1266  * @tc.desc      : function test
1267  */
1268 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0210, TestSize.Level2)
1269 {
1270     const char* title = nullptr;
1271     const char *file = "/data/test/media/gb18030.mp4";
1272     int fd = open(file, O_RDONLY);
1273     int64_t size = GetFileSize(file);
1274     cout << file << "----------------------" << fd << "---------" << size << endl;
1275     source = OH_AVSource_CreateWithFD(fd, 0, size);
1276     ASSERT_NE(source, nullptr);
1277     demuxer = OH_AVDemuxer_CreateWithSource(source);
1278     ASSERT_NE(demuxer, nullptr);
1279     sourceFormat = OH_AVSource_GetSourceFormat(source);
1280     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1281     ASSERT_EQ(0, strcmp(title, "张三"));
1282     close(fd);
1283 }
1284 
1285 /**
1286  * @tc.number    : DEMUXER_GBK_0220
1287  * @tc.name      : demux wav file with gbk, check key
1288  * @tc.desc      : function test
1289  */
1290 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0220, TestSize.Level2)
1291 {
1292     const char* artist = nullptr;
1293     const char* album = nullptr;
1294     const char* title = nullptr;
1295     const char *file = "/data/test/media/audio/gbk.wav";
1296     int fd = open(file, O_RDONLY);
1297     int64_t size = GetFileSize(file);
1298     cout << file << "----------------------" << fd << "---------" << size << endl;
1299     source = OH_AVSource_CreateWithFD(fd, 0, size);
1300     ASSERT_NE(source, nullptr);
1301     demuxer = OH_AVDemuxer_CreateWithSource(source);
1302     ASSERT_NE(demuxer, nullptr);
1303     sourceFormat = OH_AVSource_GetSourceFormat(source);
1304     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1305     ASSERT_EQ(0, strcmp(title, "音乐"));
1306     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
1307     ASSERT_EQ(0, strcmp(artist, "张三"));
1308     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
1309     ASSERT_EQ(0, strcmp(album, "风景"));
1310     close(fd);
1311 }
1312 
1313 /**
1314  * @tc.number    : DEMUXER_GBK_0230
1315  * @tc.name      : demux wav file with gb2312, check key
1316  * @tc.desc      : function test
1317  */
1318 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0230, TestSize.Level2)
1319 {
1320     const char* artist = nullptr;
1321     const char* album = nullptr;
1322     const char* title = nullptr;
1323     const char *file = "/data/test/media/audio/gb2312.wav";
1324     int fd = open(file, O_RDONLY);
1325     int64_t size = GetFileSize(file);
1326     cout << file << "----------------------" << fd << "---------" << size << endl;
1327     source = OH_AVSource_CreateWithFD(fd, 0, size);
1328     ASSERT_NE(source, nullptr);
1329     demuxer = OH_AVDemuxer_CreateWithSource(source);
1330     ASSERT_NE(demuxer, nullptr);
1331     sourceFormat = OH_AVSource_GetSourceFormat(source);
1332     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1333     ASSERT_EQ(0, strcmp(title, "音乐"));
1334     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
1335     ASSERT_EQ(0, strcmp(artist, "张三"));
1336     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
1337     ASSERT_EQ(0, strcmp(album, "风景"));
1338     close(fd);
1339 }
1340 
1341 /**
1342  * @tc.number    : DEMUXER_GBK_0240
1343  * @tc.name      : demux wav file with gb18030, check key
1344  * @tc.desc      : function test
1345  */
1346 HWTEST_F(DemuxerFormatNdkTest, DEMUXER_GBK_0240, TestSize.Level2)
1347 {
1348     const char* artist = nullptr;
1349     const char* album = nullptr;
1350     const char* title = nullptr;
1351     const char *file = "/data/test/media/audio/gb18030.wav";
1352     int fd = open(file, O_RDONLY);
1353     int64_t size = GetFileSize(file);
1354     cout << file << "----------------------" << fd << "---------" << size << endl;
1355     source = OH_AVSource_CreateWithFD(fd, 0, size);
1356     ASSERT_NE(source, nullptr);
1357     demuxer = OH_AVDemuxer_CreateWithSource(source);
1358     ASSERT_NE(demuxer, nullptr);
1359     sourceFormat = OH_AVSource_GetSourceFormat(source);
1360     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &title));
1361     ASSERT_EQ(0, strcmp(title, "音乐"));
1362     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &artist));
1363     ASSERT_EQ(0, strcmp(artist, "张三"));
1364     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &album));
1365     ASSERT_EQ(0, strcmp(album, "风景"));
1366     close(fd);
1367 }