Skip to content

Commit

Permalink
Provide information equivalent to #EXT-X-ENDLIST
Browse files Browse the repository at this point in the history
  • Loading branch information
xtne6f committed Aug 19, 2021
1 parent 59ef4fa commit dab988f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Specification of "listing pipe":
"listing pipe" contains the following binary data in 16 bytes units. All values are written in little endian.
The 0th byte of the first 16 bytes unit stores the number of following 16 bytes units. This is the same value as seg_num.
The sequence of 4-7th bytes stores the UNIX time when this list was updated.
8th stores whether this list will be updated later (0) or it has been no longer updated (1).

Subsequent 16 bytes units contain information about each segment. Newly updated segment is stored backward.
The 0th byte of the units stores the index of the segment pointed to. The range is between 1 and seg_num.
Expand Down
17 changes: 14 additions & 3 deletions tsmemseg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ void WriteUint32(uint8_t *buf, uint32_t n)
buf[3] = static_cast<uint8_t>(n >> 24);
}

void AssignSegmentList(std::vector<uint8_t> &buf, const std::vector<SEGMENT_CONTEXT> &segments, size_t segIndex)
void AssignSegmentList(std::vector<uint8_t> &buf, const std::vector<SEGMENT_CONTEXT> &segments, size_t segIndex, bool endList)
{
buf.assign(segments.size() * 16, 0);
WriteUint32(&buf[0], static_cast<uint32_t>(segments.size() - 1));
WriteUint32(&buf[4], GetCurrentUnixTime());
buf[8] = endList;
for (size_t i = segIndex, j = 1; j < segments.size(); ++j) {
WriteUint32(&buf[j * 16], static_cast<uint32_t>(i));
WriteUint32(&buf[j * 16 + 4], segments[i].segCount);
Expand Down Expand Up @@ -328,7 +329,7 @@ int main(int argc, char **argv)
fprintf(stderr, "Error: pipe creation failed.\n");
return 1;
}
AssignSegmentList(segments.front().buf, segments, 1);
AssignSegmentList(segments.front().buf, segments, 1, false);

int64_t baseTick = GetMsecTick();
std::recursive_mutex bufLock;
Expand Down Expand Up @@ -533,7 +534,7 @@ int main(int argc, char **argv)
SEGMENT_CONTEXT &segfr = segments.front();
std::vector<uint8_t> &segfrBuf =
!segfr.backBuf.empty() || segfr.pipes[0].connected || segfr.pipes[1].connected ? segfr.backBuf : segfr.buf;
AssignSegmentList(segfrBuf, segments, segIndex);
AssignSegmentList(segfrBuf, segments, segIndex, false);

lastPts45khz = pts45khz;
targetDurationMsec = nextTargetDurationMsec;
Expand All @@ -549,6 +550,16 @@ int main(int argc, char **argv)
bufCount %= 188;
}

{
lock_recursive_mutex lock(bufLock);

// End list
SEGMENT_CONTEXT &segfr = segments.front();
std::vector<uint8_t> &segfrBuf =
!segfr.backBuf.empty() || segfr.pipes[0].connected || segfr.pipes[1].connected ? segfr.backBuf : segfr.buf;
AssignSegmentList(segfrBuf, segments, segIndex, true);
}

if (syncError) {
fprintf(stderr, "Warning: %u sync error happened.\n", syncError);
}
Expand Down

0 comments on commit dab988f

Please sign in to comment.