Skip to content

Commit

Permalink
updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
futzu authored Nov 25, 2024
1 parent 547a417 commit 7c9fa8b
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions examples/continuity_counters/re_cc.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import sys
from functools import partial

from threefive import Stream


class ResetCC(Stream):
def re_cc(self, proxy=True):
def re_cc(self, proxy=True, fixed_file="re_cced.ts"):
"""
Stream.re_,,,cc resets the continuity counters.
Stream.re_cc resets the continuity counters.
MPEGTS packets are written to stdout for piping.
"""
re_filed = fixed_file
if not self._find_start():
return False
pcount = 600
pcount = 128
outfile = sys.stdout.buffer
if not proxy:
outfile = open("re_cc.ts", "wb+")
outfile = open(re_filed, "wb+")
for chunk in iter(partial(self._tsdata.read, self._PACKET_SIZE * pcount), b""):
chunky = memoryview(bytearray(chunk))
chunks = [
Expand All @@ -27,29 +27,32 @@ def re_cc(self, proxy=True):
self._tsdata.close()
if not proxy:
outfile.close()
print(f"\nwrote {re_filed}\n")
return True

def re_cc_file(self):
return self.re_cc(proxy=False)
def re_cc_file(self, fixed_file):
return self.re_cc(False, fixed_file)

def _set_cc(self, pkt):
pid = self._parse_pid(pkt[1], pkt[2])
if pid == 0x1FFF:
return pkt
new_cc = 0
if pid in self._pid_cc:
last_cc = self._pid_cc[pid]
if last_cc != 15:
new_cc = last_cc + 1
if pid in self.maps.pid_cc:
last_cc = self.maps.pid_cc[pid]
new_cc = (last_cc + 1) % 16
# print(f"{new_cc}", end='\r')
pkt[3] &= 0xF0
pkt[3] += new_cc
self._pid_cc[pid] = new_cc
self.maps.pid_cc[pid] = new_cc
return pkt


if __name__ == "__main__":

arg = sys.argv[1]

resetter = ResetCC(arg)
resetter.re_cc_file()
if len(sys.argv) < 3:
print("usage: python3 re_cc.py in_file.ts out_file.ts")
sys.exit()
inarg = sys.argv[1]
outarg = sys.argv[2]
resetter = ResetCC(inarg)
resetter.re_cc_file(outarg)

0 comments on commit 7c9fa8b

Please sign in to comment.