Skip to content

Commit

Permalink
Merge branch 'master' into master-with-d
Browse files Browse the repository at this point in the history
  • Loading branch information
xtne6f committed Oct 21, 2023
2 parents 48ca003 + d600cb4 commit 0b3eee7
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions tsmemseg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,20 @@ void ProcessSegmentation(FILE *fp, bool enableFragmentation, uint32_t targetDura
bool firstAudioPacketArrived = false;
bool isFirstKey = true;
PAT pat = {};
uint8_t buf[188 * 16];
int countForOnRead = 0;
uint8_t buf[188];
size_t bufCount = 0;
size_t nRead;

while ((nRead = fread(buf + bufCount, 1, sizeof(buf) - bufCount, fp)) != 0) {
bufCount += nRead;
if (bufCount < sizeof(buf)) {
continue;
}
bufCount = 0;

if (onRead) {
if (onRead && ++countForOnRead == 16) {
countForOnRead = 0;
int64_t ptsDiff = (0x200000000 + pts - lastSegPts) & 0x1ffffffff;
if (ptsDiff >= 0x100000000) {
// PTS went back.
Expand All @@ -461,14 +467,12 @@ void ProcessSegmentation(FILE *fp, bool enableFragmentation, uint32_t targetDura
}
}

for (const uint8_t *packet = buf; packet < buf + sizeof(buf) && packet + 188 <= buf + bufCount; packet += 188) {
if (extract_ts_header_sync(packet) != 0x47) {
// Resynchronization is not implemented.
++syncError;
continue;
}
id3conv.AddPacket(packet);
if (extract_ts_header_sync(buf) != 0x47) {
// Resynchronization is not implemented.
++syncError;
continue;
}
id3conv.AddPacket(buf);

for (auto itPacket = id3conv.GetPackets().cbegin(); itPacket != id3conv.GetPackets().end(); itPacket += 188) {
const uint8_t *packet = &*itPacket;
Expand Down Expand Up @@ -641,11 +645,6 @@ void ProcessSegmentation(FILE *fp, bool enableFragmentation, uint32_t targetDura
packets.insert(packets.end(), packet, packet + 188);
}
id3conv.ClearPackets();

if (bufCount >= 188 && bufCount % 188 != 0) {
std::copy(buf + bufCount / 188 * 188, buf + bufCount, buf);
}
bufCount %= 188;
}
}
}
Expand Down

0 comments on commit 0b3eee7

Please sign in to comment.