Skip to content

Commit

Permalink
test(demuxerUnitTest): add hls aac pts
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai committed Feb 24, 2020
1 parent c6e28d4 commit 592e622
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 30 deletions.
55 changes: 37 additions & 18 deletions framework/tests/demuxer/demuxerUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -123,31 +142,31 @@ 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);
}

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);
}

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);
}

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);
}
27 changes: 15 additions & 12 deletions framework/utils/mediaFrame.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
#include <string.h>
#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)
{
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions framework/utils/mediaFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ extern "C" {

CICADA_EXTERN void releaseMeta(Stream_meta *pMeta);

CICADA_EXTERN void releaseSourceMeta(Source_meta *meta);

#ifdef __cplusplus
};
#endif
Expand Down

0 comments on commit 592e622

Please sign in to comment.