Browse Source

update to what is in FreeBSD's repo...

atschuff.py#1
mpegts.py#42
tssel.py#8

[git-p4: depot-paths = "//depot/": change = 1089]
replace/b43bf02ddeddd088c0e6b94974ca1a46562eb3db
John-Mark Gurney 17 years ago
parent
commit
718e881275
3 changed files with 545 additions and 110 deletions
  1. +69
    -0
      mpegts/atschuff.py
  2. +463
    -105
      mpegts/mpegts.py
  3. +13
    -5
      mpegts/tssel.py

+ 69
- 0
mpegts/atschuff.py View File

@@ -0,0 +1,69 @@
#!/usr/bin/env python
#
# Copyright 2006 John-Mark Gurney.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $Id$
#

__all__ = [ 'decode_title', 'decode_description' ]

try:
from ctypes import *
import ctypes.util
import os.path

path = os.path.dirname(__file__)
if not path:
path = '.'
hd = ctypes.cdll.LoadLibrary(os.path.join(path, 'libhuffdecode.so.1'))
hd.decodetitle.restype = c_int
hd.decodetitle.argtypes = [ c_char_p, c_char_p, c_int ]
hd.decodedescription.restype = c_int
hd.decodedescription.argtypes = [ c_char_p, c_char_p, c_int ]

def docall(fun, s):
buflen = 256
while True:
buf = ctypes.create_string_buffer(buflen)
cnt = fun(s, buf, buflen)
if cnt < buflen:
break

buflen *= 2

return buf.value.decode('iso8859-1')

decode_title = lambda x: docall(hd.decodetitle, x)
decode_description = lambda x: docall(hd.decodedescription, x)

except ImportError:
def foo(*args):
raise NotImplementedError, 'Failed to import ctypes'
decode_title = decode_description = foo

except OSError:
def foo(*args):
raise NotImplementedError, 'Failed to find library huffdecode'
decode_title = decode_description = foo

+ 463
- 105
mpegts/mpegts.py
File diff suppressed because it is too large
View File


+ 13
- 5
mpegts/tssel.py View File

@@ -32,9 +32,9 @@ sys.path.append('/Users/jgurney/p4/bktrau/info')

import itertools
import mpegts
import sys
import sets
import struct
import sys

def usage():
print >>sys.stderr, 'Usage: %s <file> <pmtpid> <pid> ...' % sys.argv[0]
@@ -75,12 +75,20 @@ def producets(inp, pmtpid, *pids):
frst = ord(i[1])
# Get first and error bits for testing.
pid = (frst & 0x1f) << 8 | ord(i[2])
if pid == 0 and didpmt:
if frst & 0x80:
continue
elif pid == 0 and didpmt:
yield pats.next()
elif pid == pmtpid:
elif pid == pmtpid and frst & 0x40:
if not didpmt:
assert i[4] == '\x00' and i[5] == '\x02'
pats = itertools.cycle(genpats(pmtpid, struct.unpack('>H', i[8:10])[0]))
startpmt = 4
if ((ord(i[3]) >> 4) & 0x3) == 0x3:
# Has adaptation field
startpmt += ord(i[startpmt]) + 1

startpmt += ord(i[startpmt]) + 1
assert i[startpmt] == '\x02', (startpmt, i[0:10])
pats = itertools.cycle(genpats(pmtpid, struct.unpack('>H', i[startpmt + 3:startpmt + 5])[0]))
yield pats.next()
didpmt = True
# XXX - we probably want to rewrite the PMT to only


Loading…
Cancel
Save