Skip to content
This repository has been archived by the owner on May 31, 2019. It is now read-only.

Commit

Permalink
Fix TS packets merging when audio fragment has more then one componen…
Browse files Browse the repository at this point in the history
…t in the PMT
  • Loading branch information
e2iplayer committed Mar 15, 2019
1 parent ff62f16 commit 09f70f5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ long get_data_from_url_with_session(void **ptr_session, char *url, char **out, s
curl_easy_setopt(c, CURLOPT_RANGE, range);
curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(c, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(c, CURLOPT_VERBOSE, 1L);
//curl_easy_setopt(c, CURLOPT_VERBOSE, 1L);

if (session->speed_limit) {
curl_easy_setopt(c, CURLOPT_LOW_SPEED_LIMIT, session->speed_limit);
Expand Down
2 changes: 1 addition & 1 deletion src/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

static void print_help(const char *filename)
{
printf("hlsdl v0.25\n");
printf("hlsdl v0.26\n");
printf("(c) 2017-2019 @selsta, [email protected]\n");
printf("Usage: %s url [options]\n\n"
"-b ... Automaticly choose the best quality.\n"
Expand Down
38 changes: 29 additions & 9 deletions src/mpegts.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,16 +497,18 @@ static bool merge_pmt(const pmt_data_t *pmt1, const pmt_data_t *pmt2, pmt_data_t
{
bool bRet = false;

if (sizeof(pmt1->components) / sizeof(pmt1->components[0]) <= pmt1->component_num)
if (sizeof(pmt1->components) / sizeof(pmt1->components[0]) <= pmt1->component_num + pmt2->component_num)
{
MSG_ERROR("Components table to small!!!\n");
exit(-13);
}

/*
if (pmt2->component_num > 1)
{
MSG_WARNING("Audio fragment has more then one component in the PMT component_num: %u!!!!\n", (uint32_t)pmt2->component_num);
}
*/

if (pmt1->program != pmt2->program)
{
Expand All @@ -523,18 +525,25 @@ static bool merge_pmt(const pmt_data_t *pmt1, const pmt_data_t *pmt2, pmt_data_t

// update elementary_PID in component data
memcpy(ptr, pmt2->data + pmt2->componennt_idx, component_len2);
ptr[1] = ePID >> 8;
ptr[2] = ePID & 0xFF;
for (uint32_t cidx = 0; cidx < pmt2->component_num; ++cidx)
{
uint32_t idx = pmt2->components[cidx].offset - pmt2->components[0].offset;
ptr[idx + 1] = (ePID + cidx) >> 8;
ptr[idx + 2] = (ePID + cidx) & 0xFF;
}

bRet = merge_pmt_with_audio_component(pmt1, ptr, component_len2, pmt);
free(ptr);

if (bRet)
{
// add new component to component table
pmt->components[pmt->component_num] = pmt2->components[0];
pmt->components[pmt->component_num].elementary_PID = ePID;
pmt->component_num += 1;
// add new components to component table
for (uint32_t cidx = 0; cidx < pmt2->component_num; ++cidx)
{
pmt->components[pmt->component_num] = pmt2->components[cidx];
pmt->components[pmt->component_num].elementary_PID = ePID + cidx;
pmt->component_num += 1;
}
}
return bRet;
}
Expand Down Expand Up @@ -966,12 +975,23 @@ static size_t merge_ts_packets(merge_context_t *context, const uint8_t *pdata1,
{
uint16_t pid = ((pdata2[1] & 0x1f) << 8) | pdata2[2]; // PID - 13b
// if (TID_PAT != pid && pid != context->pmt2.pid)
if (pid == context->pmt2.components[0].elementary_PID)
bool found = false;
uint32_t cidx = 0;
for (; cidx < context->pmt2.component_num; ++cidx)
{
if (pid == context->pmt2.components[cidx].elementary_PID)
{
found = true;
break;
}
}

if (found)
{
if (context->out->write(pdata2, 1, context->out->opaque)) ret += 1;

// we need to update PID
pid = context->pmt.components[context->pmt.component_num-1].elementary_PID;
pid = context->pmt.components[context->pmt.component_num - (context->pmt2.component_num - cidx)].elementary_PID;
uint8_t tmp[2];
tmp[0] = (pdata2[1] & 0xE0) | (pid >> 8);
tmp[1] = pid & 0xFF;
Expand Down

0 comments on commit 09f70f5

Please sign in to comment.