2 # Copyright 2006 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
27 def make_fake_transport_stream_packet(npkts):
29 Return a sequence of 8-bit ints that represents an MPEG Transport Stream packet.
31 @param npkts: how many 188-byte packets to return
33 FYI, each ATSC Data Frame contains two Data Fields, each of which contains
34 312 data segments. Each transport stream packet maps to a data segment.
36 r = [0] * (npkts * 188)
38 for j in range(npkts):
39 r[i+0] = MPEG_SYNC_BYTE
40 r[i+1] = random.randint(0, 127) # top bit (transport error bit) clear
43 r[i + n] = random.randint(0, 255)
49 def pad_stream(src, sizeof_total, sizeof_pad):
50 sizeof_valid = sizeof_total - sizeof_pad
51 assert sizeof_valid > 0
52 assert (len(src) % sizeof_valid) == 0
53 npkts = len(src) // sizeof_valid
54 dst = [0] * (npkts * sizeof_total)
55 for i in range(npkts):
56 src_s = i * sizeof_valid
57 dst_s = i * sizeof_total
58 dst[dst_s:dst_s + sizeof_valid] = src[src_s:src_s + sizeof_valid]
62 def depad_stream(src, sizeof_total, sizeof_pad):
63 sizeof_valid = sizeof_total - sizeof_pad
64 assert sizeof_valid > 0
65 assert (len(src) % sizeof_total) == 0
66 npkts = len(src) // sizeof_total
67 dst = [0] * (npkts * sizeof_valid)
68 for i in range(npkts):
69 src_s = i * sizeof_total
70 dst_s = i * sizeof_valid
71 dst[dst_s:dst_s + sizeof_valid] = src[src_s:src_s + sizeof_valid]