From 592e622c7f5af0862edbd9f7c66c50c29f206e28 Mon Sep 17 00:00:00 2001 From: pingkai Date: Mon, 3 Feb 2020 11:09:30 +0800 Subject: [PATCH] test(demuxerUnitTest): add hls aac pts Signed-off-by: pingkai --- framework/tests/demuxer/demuxerUnitTest.cpp | 55 ++++++++++++++------- framework/utils/mediaFrame.c | 27 +++++----- framework/utils/mediaFrame.h | 2 + 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/framework/tests/demuxer/demuxerUnitTest.cpp b/framework/tests/demuxer/demuxerUnitTest.cpp index 3ab520452..188ead7fc 100644 --- a/framework/tests/demuxer/demuxerUnitTest.cpp +++ b/framework/tests/demuxer/demuxerUnitTest.cpp @@ -28,6 +28,15 @@ TEST(format, mp4) delete source; } +inline uint64_t getSize(const uint8_t *data, unsigned int len, unsigned int shift) +{ + uint64_t size(0); + const uint8_t *dataE(data + len); + for (data; data < dataE; ++data) + size = size << shift | *data; + return size; +}; + TEST(format, aac) { const char *hls_id3 = "id3v2_priv.com.apple.streaming.transportStreamTimestamp"; @@ -39,20 +48,30 @@ TEST(format, aac) ASSERT_GE(ret, 0); Source_meta *meta = nullptr; service->GetSourceMeta(&meta); - while (meta != nullptr) { - if (meta->key && meta->value) { - AF_LOGD("%s:%s", meta->key, meta->value); - } - if (meta->key) { - free(meta->key); - } - if (meta->value) { - free(meta->value); + Source_meta *meta1 = meta; + while (meta1 != nullptr) { + if (meta1->key && meta1->value) { + AF_LOGD("%s:[%s]", meta1->key, meta1->value); + int ptr = 0; + if (strcmp(meta1->key, hls_id3) == 0) { + uint8_t buf[8]; + int v; + for (unsigned char &i : buf) { + if (sscanf(meta1->value + ptr, "\\x%02x", &v) == 1) { + ptr += 4; + i = v; + } else { + i = *(meta1->value + ptr); + ptr++; + } + } + uint64_t ps = getSize(buf, 8, 8); + AF_LOGD("ps is %u\n", ps); + } } - Source_meta *meta1 = meta; - meta = meta->next; - free(meta1); + meta1 = meta1->next; } + releaseSourceMeta(meta); service->close(); delete source; @@ -73,7 +92,7 @@ int64_t callback_seek(void *arg, int64_t offset, int whence) TEST(ts, pts) { std::string url = - "https://alivc-demo-vod.aliyuncs.com/ddb0c76ce153450081cd4c45118371a7/d30995ad97bc4643bf0a8c4cedd0c81f-007b1abb398f0e4c6f46d30b0125da41-sd-00001.ts"; + "https://alivc-demo-vod.aliyuncs.com/ddb0c76ce153450081cd4c45118371a7/d30995ad97bc4643bf0a8c4cedd0c81f-007b1abb398f0e4c6f46d30b0125da41-sd-00001.ts"; auto source = dataSourcePrototype::create(url); source->Open(0); int ret = 0; @@ -109,7 +128,7 @@ TEST(first_seek, mp4) TEST(first_seek, hls) { std::string url = - "https://alivc-demo-vod.aliyuncs.com/ddb0c76ce153450081cd4c45118371a7/d30995ad97bc4643bf0a8c4cedd0c81f-e16b4635a4cb03424234c3a3d0e7f7e1-sd.m3u8"; + "https://alivc-demo-vod.aliyuncs.com/ddb0c76ce153450081cd4c45118371a7/d30995ad97bc4643bf0a8c4cedd0c81f-e16b4635a4cb03424234c3a3d0e7f7e1-sd.m3u8"; testFirstSeek(url, 100000000, 10000000); } @@ -123,7 +142,7 @@ TEST(mergeHeader, mp4) TEST(mergeHeader, ts) { std::string url = - "https://alivc-demo-vod.aliyuncs.com/ddb0c76ce153450081cd4c45118371a7/d30995ad97bc4643bf0a8c4cedd0c81f-007b1abb398f0e4c6f46d30b0125da41-sd-00001.ts"; + "https://alivc-demo-vod.aliyuncs.com/ddb0c76ce153450081cd4c45118371a7/d30995ad97bc4643bf0a8c4cedd0c81f-007b1abb398f0e4c6f46d30b0125da41-sd-00001.ts"; test_mergeHeader(url, true); test_mergeHeader(url, false); } @@ -131,7 +150,7 @@ TEST(mergeHeader, ts) TEST(mergeHeader, hls) { std::string url = - "https://alivc-demo-vod.aliyuncs.com/ddb0c76ce153450081cd4c45118371a7/d30995ad97bc4643bf0a8c4cedd0c81f-e16b4635a4cb03424234c3a3d0e7f7e1-sd.m3u8"; + "https://alivc-demo-vod.aliyuncs.com/ddb0c76ce153450081cd4c45118371a7/d30995ad97bc4643bf0a8c4cedd0c81f-e16b4635a4cb03424234c3a3d0e7f7e1-sd.m3u8"; test_mergeHeader(url, true); test_mergeHeader(url, false); } @@ -139,7 +158,7 @@ TEST(mergeHeader, hls) TEST(mergeHeader, hls_aes) { std::string url = - "https://alivc-demo-vod.aliyuncs.com/d2c89d7210d443109434685f45ed607b/45ed0cccd8092bf25ee33764b5a52be4-sd-encrypt-stream.m3u8"; + "https://alivc-demo-vod.aliyuncs.com/d2c89d7210d443109434685f45ed607b/45ed0cccd8092bf25ee33764b5a52be4-sd-encrypt-stream.m3u8"; test_mergeHeader(url, true); test_mergeHeader(url, false); } @@ -147,7 +166,7 @@ TEST(mergeHeader, hls_aes) TEST(mergeHeader, hls_multi) { std::string url = - "https://alivc-demo-vod.aliyuncs.com/59f748948daa4438b42e42db755ae01e/9d44b2b86d334c6b9df649e35ad0240f.m3u8"; + "https://alivc-demo-vod.aliyuncs.com/59f748948daa4438b42e42db755ae01e/9d44b2b86d334c6b9df649e35ad0240f.m3u8"; test_mergeHeader(url, true); test_mergeHeader(url, false); } \ No newline at end of file diff --git a/framework/utils/mediaFrame.c b/framework/utils/mediaFrame.c index 7d90af867..32e7e2ba9 100644 --- a/framework/utils/mediaFrame.c +++ b/framework/utils/mediaFrame.c @@ -5,6 +5,20 @@ #include #include "mediaFrame.h" +void releaseSourceMeta(Source_meta *meta) +{ + while (meta != NULL) { + if (meta->key) + free(meta->key); + + if (meta->value) + free(meta->value); + + Source_meta *meta1 = meta; + meta = meta->next; + free(meta1); + } +} void releaseMeta(Stream_meta *pMeta) { @@ -24,18 +38,7 @@ void releaseMeta(Stream_meta *pMeta) } Source_meta *meta = pMeta->meta; - - while (meta != NULL) { - if (meta->key) - free(meta->key); - - if (meta->value) - free(meta->value); - - Source_meta *meta1 = meta; - meta = meta->next; - free(meta1); - } + releaseSourceMeta(meta); pMeta->meta = NULL; } diff --git a/framework/utils/mediaFrame.h b/framework/utils/mediaFrame.h index 72098ec03..d600a80d9 100644 --- a/framework/utils/mediaFrame.h +++ b/framework/utils/mediaFrame.h @@ -14,6 +14,8 @@ extern "C" { CICADA_EXTERN void releaseMeta(Stream_meta *pMeta); +CICADA_EXTERN void releaseSourceMeta(Source_meta *meta); + #ifdef __cplusplus }; #endif