mirror of https://github.com/python/cpython
CL.py: adapted to newest version of CL library.
cdplayer.py: It is now also possible to give the CD's TOC as argument to init(). The TOC is a string consisting of 2 digits giving the number of tracks and then for each track the length of the track as number of minutes and number of seconds (2 digits each). cddb.py: Interface to the .cddb directory. Usage is the same as for cdplayer.py.
This commit is contained in:
parent
23bafde01d
commit
4fff13faca
216
Lib/irix5/CL.py
216
Lib/irix5/CL.py
|
@ -1,84 +1,172 @@
|
|||
# typedef enum CL_OriginalFormat
|
||||
RGB = 0
|
||||
RGBX = 1
|
||||
RGBA = 2
|
||||
YCrCb444 = 3
|
||||
YCrCb422 = 4
|
||||
YCrCb411 = 5
|
||||
RGB332 = 6
|
||||
COLORMAP8 = 7
|
||||
COLORMAP12 = 8
|
||||
GRAYSCALE = 9
|
||||
MONO = 10
|
||||
STEREO_INTERLEAVED = 11
|
||||
QUAD_INTERLEAVED = 12
|
||||
SURROUND_SOUND = 13
|
||||
#
|
||||
# cl.h - Compression Library typedefs and prototypes
|
||||
#
|
||||
# 02/18/92 Original Version by Brian Knittel
|
||||
#
|
||||
|
||||
MAX_NUMBER_OF_AUDIO_ALGORITHMS = 32
|
||||
MAX_NUMBER_OF_VIDEO_ALGORITHMS = 32
|
||||
#
|
||||
# originalFormat parameter values
|
||||
#
|
||||
MAX_NUMBER_OF_ORIGINAL_FORMATS = (32)
|
||||
|
||||
# typedef enum CL_CompressionScheme
|
||||
UNCOMPRESSED = 0
|
||||
G711_ULAW = 1
|
||||
G711_ALAW = 2
|
||||
G722 = 3
|
||||
UNCOMPRESSED_VIDEO = MAX_NUMBER_OF_AUDIO_ALGORITHMS
|
||||
RLE = UNCOMPRESSED_VIDEO + 1
|
||||
JPEG = RLE + 1
|
||||
MPEG_VIDEO = JPEG + 1
|
||||
MVC1 = MPEG_VIDEO + 1
|
||||
# Audio
|
||||
MONO = (0)
|
||||
STEREO_INTERLEAVED = (1)
|
||||
|
||||
# Video
|
||||
# YUV is defined to be the same thing as YCrCb (luma and two chroma components).
|
||||
# 422 is appended to YUV (or YCrCb) if the chroma is sub-sampled by 2
|
||||
# horizontally, packed as U Y1 V Y2 (byte order).
|
||||
# 422HC is appended to YUV (or YCrCb) if the chroma is sub-sampled by 2
|
||||
# vertically in addition to horizontally, and is packed the same as
|
||||
# 422 except that U & V are not valid on the second line.
|
||||
#
|
||||
RGB = (0)
|
||||
RGBX = (1)
|
||||
RGBA = (2)
|
||||
RGB332 = (3)
|
||||
|
||||
GRAYSCALE = (4)
|
||||
Y = (4)
|
||||
YUV = (5)
|
||||
YCbCr = (5)
|
||||
YUV422 = (6) # 4:2:2 sampling
|
||||
YCbCr422 = (6) # 4:2:2 sampling
|
||||
YUV422HC = (7) # 4:1:1 sampling
|
||||
YCbCr422HC = (7) # 4:1:1 sampling
|
||||
|
||||
MAX_NUMBER_OF_AUDIO_ALGORITHMS = (32)
|
||||
MAX_NUMBER_OF_VIDEO_ALGORITHMS = (32)
|
||||
|
||||
#
|
||||
# "compressionScheme" argument values
|
||||
#
|
||||
UNCOMPRESSED_AUDIO = (0)
|
||||
G711_ULAW = (1)
|
||||
ULAW = (1)
|
||||
G711_ALAW = (2)
|
||||
ALAW = (2)
|
||||
G722 = (3)
|
||||
|
||||
UNCOMPRESSED = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 0)
|
||||
UNCOMPRESSED_VIDEO = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 0)
|
||||
RLE = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 1)
|
||||
JPEG = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 2)
|
||||
MPEG_VIDEO = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 3)
|
||||
MVC1 = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 4)
|
||||
RTR = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 5)
|
||||
RTR1 = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 5)
|
||||
|
||||
#
|
||||
# Parameters
|
||||
#
|
||||
# typedef enum CL_Parameters
|
||||
SPEED = 0
|
||||
ACTUAL_FRAME_INDEX = 1
|
||||
COMPRESSION_FORMAT = 2
|
||||
QUALITY_FACTOR = 3
|
||||
NUMBER_OF_PARAMS = 4
|
||||
MAX_NUMBER_OF_PARAMS = (256)
|
||||
# Default Parameters
|
||||
IMAGE_WIDTH = (0)
|
||||
IMAGE_HEIGHT = (1)
|
||||
ORIGINAL_FORMAT = (2)
|
||||
INTERNAL_FORMAT = (3)
|
||||
COMPONENTS = (4)
|
||||
BITS_PER_COMPONENT = (5)
|
||||
FRAME_RATE = (6)
|
||||
COMPRESSION_RATIO = (7)
|
||||
EXACT_COMPRESSION_RATIO = (8)
|
||||
FRAME_BUFFER_SIZE = (9)
|
||||
COMPRESSED_BUFFER_SIZE = (10)
|
||||
BLOCK_SIZE = (11)
|
||||
PREROLL = (12)
|
||||
UNIQUE = (13)
|
||||
FRAME_TYPE = (14)
|
||||
OVERWRITE_MODE = (15)
|
||||
NUMBER_OF_PARAMS = (16)
|
||||
|
||||
MAX_NUMBER_OF_PARAMS = 32
|
||||
# JPEG Specific Parameters
|
||||
QUALITY_FACTOR = (NUMBER_OF_PARAMS + 0)
|
||||
|
||||
# MPEG Specific Parameters
|
||||
SPEED = (NUMBER_OF_PARAMS + 0)
|
||||
ACTUAL_FRAME_INDEX = (NUMBER_OF_PARAMS + 1)
|
||||
|
||||
# RTR Specific Parameters
|
||||
QUALITY_LEVEL = (NUMBER_OF_PARAMS + 0)
|
||||
|
||||
# #define clTypeIsFloat(v) (*(float *)&(v))
|
||||
# #define clTypeIsLong(v) (*(long *)&(v))
|
||||
#
|
||||
# RATIO_1 = (65536.0)
|
||||
# #define clFloatToRatio(f) ((long)((float)(f) * RATIO_1))
|
||||
# #define clRatioToFloat(f) ((float)(f) / RATIO_1)
|
||||
# RATIO_SHIFT = (16)
|
||||
# #define clRatioMul(m, r) ((m) * (r))
|
||||
# #define clRatioToLong(r) ((r) >> RATIO_SHIFT)
|
||||
# #define clLongToRatio(r) ((r) << RATIO_SHIFT)
|
||||
|
||||
#
|
||||
# Parameter value types
|
||||
#
|
||||
# typedef enum CL_ParameterTypes
|
||||
ENUM_VALUE = 0 # only certain constant values are valid
|
||||
RANGE_VALUE = 1 # any value in a given range is valid
|
||||
POINTER = 2 # any legal pointer is valid
|
||||
ENUM_VALUE = (0) # only certain constant values are valid
|
||||
RANGE_VALUE = (1) # any value in a given range is valid
|
||||
FLOATING_ENUM_VALUE = (2) # only certain constant floating point values are valid
|
||||
FLOATING_RANGE_VALUE = (3) # any value in a given floating point range is valid
|
||||
POINTER = (4) # any legal pointer is valid
|
||||
|
||||
# typedef enum AlgorithmType
|
||||
AUDIO = 0
|
||||
VIDEO = 1
|
||||
#
|
||||
# Algorithm types
|
||||
#
|
||||
AUDIO = (0)
|
||||
VIDEO = (1)
|
||||
|
||||
# typedef enum AlgorithmFunctionality
|
||||
DECOMPRESSOR = 1
|
||||
COMPRESSOR = 2
|
||||
CODEC = 3
|
||||
#
|
||||
# Algorithm Functionality
|
||||
#
|
||||
DECOMPRESSOR = (1)
|
||||
COMPRESSOR = (2)
|
||||
CODEC = (3)
|
||||
|
||||
#
|
||||
# Buffer types
|
||||
#
|
||||
NONE = (0)
|
||||
FRAME = (1)
|
||||
DATA = (2)
|
||||
|
||||
#
|
||||
# error codes
|
||||
#
|
||||
BAD_NOT_IMPLEMENTED = 0 # not impimented yet
|
||||
BAD_NO_BUFFERSPACE = 1 # no space for internal buffers
|
||||
BAD_QSIZE = 2 # attempt to set an invalid queue size
|
||||
BAD_BUFFER_NULL = 3 # null buffer pointer
|
||||
BAD_COUNT_NEG = 4 # negative count
|
||||
BAD_PVBUFFER = 5 # param/val buffer doesn't make sense
|
||||
BAD_BUFFERLENGTH_NEG = 6 # negative buffer length
|
||||
BAD_BUFFERLENGTH_ODD = 7 # odd length parameter/value buffer
|
||||
BAD_PARAM = 8 # invalid parameter
|
||||
BAD_COMPRESSION_SCHEME = 9 # compression scheme parameter invalid
|
||||
BAD_COMPRESSOR_HANDLE = 10 # compression handle parameter invalid
|
||||
BAD_COMPRESSOR_HANDLE_POINTER = 11 # compression handle pointer invalid
|
||||
BAD_CALLBACK_FUNCTION = 12 # callback function invalid
|
||||
BAD_COMPRESSION_FORMAT_POINTER = 13 # compression format parameter invalid
|
||||
BAD_POINTER_FROM_CALLBACK_FUNCTION = 14 # pointer from callback invalid
|
||||
JPEG_ERROR = 15 # error from libjpeg
|
||||
NO_SEMAPHORE = 16 # could not get semaphore
|
||||
BAD_WIDTH_OR_HEIGHT = 17 # width or height invalid
|
||||
BAD_FRAME_COUNT = 18 # frame count invalid
|
||||
BAD_NOT_IMPLEMENTED = ( -1) # not impimented yet
|
||||
BAD_NO_BUFFERSPACE = ( -2) # no space for internal buffers
|
||||
BAD_BUFFER_NULL = ( -3) # null buffer pointer
|
||||
BAD_COUNT_NEG = ( -4) # negative count
|
||||
BAD_PVBUFFER = ( -5) # param/val buffer doesn't make sense
|
||||
BAD_BUFFERLENGTH_NEG = ( -6) # negative buffer length
|
||||
BAD_BUFFERLENGTH_ODD = ( -7) # odd length parameter/value buffer
|
||||
BAD_PARAM = ( -8) # invalid parameter
|
||||
BAD_COMPRESSION_SCHEME = ( -9) # compression scheme parameter invalid
|
||||
BAD_COMPRESSOR_HANDLE = (-10) # compression handle parameter invalid
|
||||
BAD_COMPRESSOR_HANDLE_POINTER = (-11) # compression handle pointer invalid
|
||||
BAD_BUFFER_HANDLE = (-12) # callback function invalid
|
||||
BAD_ALGORITHM_INFO = (-13) # algorithm info invalid
|
||||
BAD_CL_BAD_WIDTH_OR_HEIGHT = (-14) # compressor width or height invalid
|
||||
BAD_POINTER_FROM_CALLBACK_FUNCTION = (-15) # pointer from callback invalid
|
||||
JPEG_ERROR = (-16) # error from libjpeg
|
||||
NO_SEMAPHORE = (-17) # could not get semaphore
|
||||
BAD_WIDTH_OR_HEIGHT = (-18) # width or height invalid
|
||||
BAD_FRAME_COUNT = (-19) # frame count invalid
|
||||
BAD_FRAME_INDEX = (-20) # frame index invalid
|
||||
BAD_FRAME_BUFFER = (-21) # frame buffer pointer invalid
|
||||
BAD_FRAME_SIZE = (-22) # frame size invalid
|
||||
BAD_DATA_BUFFER = (-23) # data buffer pointer invalid
|
||||
BAD_DATA_SIZE = (-24) # data buffer size invalid
|
||||
BAD_TOTAL_NUMBER_OF_FRAMES = (-25) # total number of frames invalid
|
||||
BAD_IMAGE_FORMAT = (-26) # image format invalid
|
||||
BAD_BITS_PER_COMPONENT = (-27) # bits per component invalid
|
||||
BAD_FRAME_RATE = (-28) # frame rate invalid
|
||||
BAD_INSUFFICIENT_DATA_FROM_CALLBACK_FUNCTION = (-29) # insufficient data from callback invalid
|
||||
PARAM_OUT_OF_RANGE = (-30) # parameter out of range
|
||||
ADDED_ALGORITHM_ERROR = (-31) # added algorithm had a unique error
|
||||
BAD_ALGORITHM_TYPE = (-32) # bad algorithm type
|
||||
BAD_ALGORITHM_NAME = (-33) # bad algorithm name
|
||||
BAD_FRAME_INDEXING = (-34) # bad frame indexing
|
||||
BAD_BUFFERING = (-35) # bad buffering calls
|
||||
BUFFER_NOT_CREATED = (-36) # buffer not created
|
||||
BAD_BUFFER_EXISTS = (-37) # buffer already created
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
# This file implements a class which forms an interface to the .cddb
|
||||
# directory that is maintained by SGI's cdman program.
|
||||
#
|
||||
# Usage is as follows:
|
||||
#
|
||||
# import readcd
|
||||
# r = readcd.Readcd().init()
|
||||
# c = Cddb().init(r.gettrackinfo())
|
||||
#
|
||||
# Now you can use c.artist, c.title and c.track[trackno] (where trackno
|
||||
# starts at 1). When the CD is not recognized, all values will be the empty
|
||||
# string.
|
||||
# It is also possible to set the above mentioned variables to new values.
|
||||
# You can then use c.write() to write out the changed values to the
|
||||
# .cdplayerrc file.
|
||||
|
||||
import string
|
||||
|
||||
_cddbrc = '.cddb/'
|
||||
_DB_ID_NTRACKS = 5
|
||||
_dbid_map = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@_=+abcdefghijklmnopqrstuvwxyz'
|
||||
def _dbid(v):
|
||||
if v >= len(_dbid_map):
|
||||
return string.zfill(v, 2)
|
||||
else:
|
||||
return _dbid_map[v]
|
||||
|
||||
class Cddb():
|
||||
def init(self, tracklist):
|
||||
self.artist = ''
|
||||
self.title = ''
|
||||
if type(tracklist) == type(''):
|
||||
t = []
|
||||
for i in range(2, len(tracklist), 4):
|
||||
t.append((None, \
|
||||
(string.atoi(tracklist[i:i+2]), \
|
||||
string.atoi(tracklist[i+2:i+4]))))
|
||||
tracklist = t
|
||||
ntracks = len(tracklist)
|
||||
self.track = [None] + [''] * ntracks
|
||||
self.id = _dbid((ntracks >> 4) & 0xF) + _dbid(ntracks & 0xF)
|
||||
if ntracks <= _DB_ID_NTRACKS:
|
||||
nidtracks = ntracks
|
||||
else:
|
||||
nidtracks = _DB_ID_NTRACKS - 1
|
||||
min = 0
|
||||
sec = 0
|
||||
for track in tracklist:
|
||||
start, length = track
|
||||
min = min + length[0]
|
||||
sec = sec + length[1]
|
||||
min = min + sec / 60
|
||||
sec = sec % 60
|
||||
self.id = self.id + _dbid(min) + _dbid(sec)
|
||||
for i in range(nidtracks):
|
||||
start, length = tracklist[i]
|
||||
self.id = self.id + _dbid(length[0]) + _dbid(length[1])
|
||||
self.toc = string.zfill(ntracks, 2)
|
||||
for track in tracklist:
|
||||
start, length = track
|
||||
self.toc = self.toc + string.zfill(length[0], 2) + \
|
||||
string.zfill(length[1], 2)
|
||||
try:
|
||||
import posix
|
||||
file = posix.environ['HOME'] + '/' + _cddbrc + self.id + '.rdb'
|
||||
f = open(file, 'r')
|
||||
except IOError:
|
||||
return self
|
||||
import regex
|
||||
reg = regex.compile('^\\([^.]*\\)\\.\\([^:]*\\):\t\\(.*\\)')
|
||||
while 1:
|
||||
line = f.readline()
|
||||
if not line:
|
||||
break
|
||||
if reg.match(line) == -1:
|
||||
print 'syntax error in ' + file
|
||||
continue
|
||||
name1 = line[reg.regs[1][0]:reg.regs[1][1]]
|
||||
name2 = line[reg.regs[2][0]:reg.regs[2][1]]
|
||||
value = line[reg.regs[3][0]:reg.regs[3][1]]
|
||||
if name1 == 'album':
|
||||
if name2 == 'artist':
|
||||
self.artist = value
|
||||
elif name2 == 'title':
|
||||
self.title = value
|
||||
elif name2 == 'toc':
|
||||
if self.toc != value:
|
||||
print 'toc\'s don\'t match'
|
||||
elif name1[:5] == 'track':
|
||||
trackno = string.atoi(name1[5:])
|
||||
self.track[trackno] = value
|
||||
f.close()
|
||||
return self
|
||||
|
||||
def write(self):
|
||||
import posix
|
||||
file = posix.environ['HOME'] + '/' + _cddbrc + self.id + '.rdb'
|
||||
f = open(file, 'w')
|
||||
f.write('album.title:\t' + self.title + '\n')
|
||||
f.write('album.artist:\t' + self.artist + '\n')
|
||||
f.write('album.toc:\t' + self.toc + '\n')
|
||||
for i in range(1, len(self.track)):
|
||||
f.write('track' + `i` + '.title:\t' + self.track[i] + '\n')
|
||||
f.close()
|
|
@ -21,6 +21,13 @@ class Cdplayer():
|
|||
import string
|
||||
self.artist = ''
|
||||
self.title = ''
|
||||
if type(tracklist) == type(''):
|
||||
t = []
|
||||
for i in range(2, len(tracklist), 4):
|
||||
t.append((None, \
|
||||
(string.atoi(tracklist[i:i+2]), \
|
||||
string.atoi(tracklist[i+2:i+4]))))
|
||||
tracklist = t
|
||||
self.track = [None] + [''] * len(tracklist)
|
||||
self.id = 'd' + string.zfill(len(tracklist), 2)
|
||||
for track in tracklist:
|
||||
|
|
|
@ -1,84 +1,172 @@
|
|||
# typedef enum CL_OriginalFormat
|
||||
RGB = 0
|
||||
RGBX = 1
|
||||
RGBA = 2
|
||||
YCrCb444 = 3
|
||||
YCrCb422 = 4
|
||||
YCrCb411 = 5
|
||||
RGB332 = 6
|
||||
COLORMAP8 = 7
|
||||
COLORMAP12 = 8
|
||||
GRAYSCALE = 9
|
||||
MONO = 10
|
||||
STEREO_INTERLEAVED = 11
|
||||
QUAD_INTERLEAVED = 12
|
||||
SURROUND_SOUND = 13
|
||||
#
|
||||
# cl.h - Compression Library typedefs and prototypes
|
||||
#
|
||||
# 02/18/92 Original Version by Brian Knittel
|
||||
#
|
||||
|
||||
MAX_NUMBER_OF_AUDIO_ALGORITHMS = 32
|
||||
MAX_NUMBER_OF_VIDEO_ALGORITHMS = 32
|
||||
#
|
||||
# originalFormat parameter values
|
||||
#
|
||||
MAX_NUMBER_OF_ORIGINAL_FORMATS = (32)
|
||||
|
||||
# typedef enum CL_CompressionScheme
|
||||
UNCOMPRESSED = 0
|
||||
G711_ULAW = 1
|
||||
G711_ALAW = 2
|
||||
G722 = 3
|
||||
UNCOMPRESSED_VIDEO = MAX_NUMBER_OF_AUDIO_ALGORITHMS
|
||||
RLE = UNCOMPRESSED_VIDEO + 1
|
||||
JPEG = RLE + 1
|
||||
MPEG_VIDEO = JPEG + 1
|
||||
MVC1 = MPEG_VIDEO + 1
|
||||
# Audio
|
||||
MONO = (0)
|
||||
STEREO_INTERLEAVED = (1)
|
||||
|
||||
# Video
|
||||
# YUV is defined to be the same thing as YCrCb (luma and two chroma components).
|
||||
# 422 is appended to YUV (or YCrCb) if the chroma is sub-sampled by 2
|
||||
# horizontally, packed as U Y1 V Y2 (byte order).
|
||||
# 422HC is appended to YUV (or YCrCb) if the chroma is sub-sampled by 2
|
||||
# vertically in addition to horizontally, and is packed the same as
|
||||
# 422 except that U & V are not valid on the second line.
|
||||
#
|
||||
RGB = (0)
|
||||
RGBX = (1)
|
||||
RGBA = (2)
|
||||
RGB332 = (3)
|
||||
|
||||
GRAYSCALE = (4)
|
||||
Y = (4)
|
||||
YUV = (5)
|
||||
YCbCr = (5)
|
||||
YUV422 = (6) # 4:2:2 sampling
|
||||
YCbCr422 = (6) # 4:2:2 sampling
|
||||
YUV422HC = (7) # 4:1:1 sampling
|
||||
YCbCr422HC = (7) # 4:1:1 sampling
|
||||
|
||||
MAX_NUMBER_OF_AUDIO_ALGORITHMS = (32)
|
||||
MAX_NUMBER_OF_VIDEO_ALGORITHMS = (32)
|
||||
|
||||
#
|
||||
# "compressionScheme" argument values
|
||||
#
|
||||
UNCOMPRESSED_AUDIO = (0)
|
||||
G711_ULAW = (1)
|
||||
ULAW = (1)
|
||||
G711_ALAW = (2)
|
||||
ALAW = (2)
|
||||
G722 = (3)
|
||||
|
||||
UNCOMPRESSED = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 0)
|
||||
UNCOMPRESSED_VIDEO = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 0)
|
||||
RLE = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 1)
|
||||
JPEG = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 2)
|
||||
MPEG_VIDEO = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 3)
|
||||
MVC1 = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 4)
|
||||
RTR = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 5)
|
||||
RTR1 = (MAX_NUMBER_OF_AUDIO_ALGORITHMS + 5)
|
||||
|
||||
#
|
||||
# Parameters
|
||||
#
|
||||
# typedef enum CL_Parameters
|
||||
SPEED = 0
|
||||
ACTUAL_FRAME_INDEX = 1
|
||||
COMPRESSION_FORMAT = 2
|
||||
QUALITY_FACTOR = 3
|
||||
NUMBER_OF_PARAMS = 4
|
||||
MAX_NUMBER_OF_PARAMS = (256)
|
||||
# Default Parameters
|
||||
IMAGE_WIDTH = (0)
|
||||
IMAGE_HEIGHT = (1)
|
||||
ORIGINAL_FORMAT = (2)
|
||||
INTERNAL_FORMAT = (3)
|
||||
COMPONENTS = (4)
|
||||
BITS_PER_COMPONENT = (5)
|
||||
FRAME_RATE = (6)
|
||||
COMPRESSION_RATIO = (7)
|
||||
EXACT_COMPRESSION_RATIO = (8)
|
||||
FRAME_BUFFER_SIZE = (9)
|
||||
COMPRESSED_BUFFER_SIZE = (10)
|
||||
BLOCK_SIZE = (11)
|
||||
PREROLL = (12)
|
||||
UNIQUE = (13)
|
||||
FRAME_TYPE = (14)
|
||||
OVERWRITE_MODE = (15)
|
||||
NUMBER_OF_PARAMS = (16)
|
||||
|
||||
MAX_NUMBER_OF_PARAMS = 32
|
||||
# JPEG Specific Parameters
|
||||
QUALITY_FACTOR = (NUMBER_OF_PARAMS + 0)
|
||||
|
||||
# MPEG Specific Parameters
|
||||
SPEED = (NUMBER_OF_PARAMS + 0)
|
||||
ACTUAL_FRAME_INDEX = (NUMBER_OF_PARAMS + 1)
|
||||
|
||||
# RTR Specific Parameters
|
||||
QUALITY_LEVEL = (NUMBER_OF_PARAMS + 0)
|
||||
|
||||
# #define clTypeIsFloat(v) (*(float *)&(v))
|
||||
# #define clTypeIsLong(v) (*(long *)&(v))
|
||||
#
|
||||
# RATIO_1 = (65536.0)
|
||||
# #define clFloatToRatio(f) ((long)((float)(f) * RATIO_1))
|
||||
# #define clRatioToFloat(f) ((float)(f) / RATIO_1)
|
||||
# RATIO_SHIFT = (16)
|
||||
# #define clRatioMul(m, r) ((m) * (r))
|
||||
# #define clRatioToLong(r) ((r) >> RATIO_SHIFT)
|
||||
# #define clLongToRatio(r) ((r) << RATIO_SHIFT)
|
||||
|
||||
#
|
||||
# Parameter value types
|
||||
#
|
||||
# typedef enum CL_ParameterTypes
|
||||
ENUM_VALUE = 0 # only certain constant values are valid
|
||||
RANGE_VALUE = 1 # any value in a given range is valid
|
||||
POINTER = 2 # any legal pointer is valid
|
||||
ENUM_VALUE = (0) # only certain constant values are valid
|
||||
RANGE_VALUE = (1) # any value in a given range is valid
|
||||
FLOATING_ENUM_VALUE = (2) # only certain constant floating point values are valid
|
||||
FLOATING_RANGE_VALUE = (3) # any value in a given floating point range is valid
|
||||
POINTER = (4) # any legal pointer is valid
|
||||
|
||||
# typedef enum AlgorithmType
|
||||
AUDIO = 0
|
||||
VIDEO = 1
|
||||
#
|
||||
# Algorithm types
|
||||
#
|
||||
AUDIO = (0)
|
||||
VIDEO = (1)
|
||||
|
||||
# typedef enum AlgorithmFunctionality
|
||||
DECOMPRESSOR = 1
|
||||
COMPRESSOR = 2
|
||||
CODEC = 3
|
||||
#
|
||||
# Algorithm Functionality
|
||||
#
|
||||
DECOMPRESSOR = (1)
|
||||
COMPRESSOR = (2)
|
||||
CODEC = (3)
|
||||
|
||||
#
|
||||
# Buffer types
|
||||
#
|
||||
NONE = (0)
|
||||
FRAME = (1)
|
||||
DATA = (2)
|
||||
|
||||
#
|
||||
# error codes
|
||||
#
|
||||
BAD_NOT_IMPLEMENTED = 0 # not impimented yet
|
||||
BAD_NO_BUFFERSPACE = 1 # no space for internal buffers
|
||||
BAD_QSIZE = 2 # attempt to set an invalid queue size
|
||||
BAD_BUFFER_NULL = 3 # null buffer pointer
|
||||
BAD_COUNT_NEG = 4 # negative count
|
||||
BAD_PVBUFFER = 5 # param/val buffer doesn't make sense
|
||||
BAD_BUFFERLENGTH_NEG = 6 # negative buffer length
|
||||
BAD_BUFFERLENGTH_ODD = 7 # odd length parameter/value buffer
|
||||
BAD_PARAM = 8 # invalid parameter
|
||||
BAD_COMPRESSION_SCHEME = 9 # compression scheme parameter invalid
|
||||
BAD_COMPRESSOR_HANDLE = 10 # compression handle parameter invalid
|
||||
BAD_COMPRESSOR_HANDLE_POINTER = 11 # compression handle pointer invalid
|
||||
BAD_CALLBACK_FUNCTION = 12 # callback function invalid
|
||||
BAD_COMPRESSION_FORMAT_POINTER = 13 # compression format parameter invalid
|
||||
BAD_POINTER_FROM_CALLBACK_FUNCTION = 14 # pointer from callback invalid
|
||||
JPEG_ERROR = 15 # error from libjpeg
|
||||
NO_SEMAPHORE = 16 # could not get semaphore
|
||||
BAD_WIDTH_OR_HEIGHT = 17 # width or height invalid
|
||||
BAD_FRAME_COUNT = 18 # frame count invalid
|
||||
BAD_NOT_IMPLEMENTED = ( -1) # not impimented yet
|
||||
BAD_NO_BUFFERSPACE = ( -2) # no space for internal buffers
|
||||
BAD_BUFFER_NULL = ( -3) # null buffer pointer
|
||||
BAD_COUNT_NEG = ( -4) # negative count
|
||||
BAD_PVBUFFER = ( -5) # param/val buffer doesn't make sense
|
||||
BAD_BUFFERLENGTH_NEG = ( -6) # negative buffer length
|
||||
BAD_BUFFERLENGTH_ODD = ( -7) # odd length parameter/value buffer
|
||||
BAD_PARAM = ( -8) # invalid parameter
|
||||
BAD_COMPRESSION_SCHEME = ( -9) # compression scheme parameter invalid
|
||||
BAD_COMPRESSOR_HANDLE = (-10) # compression handle parameter invalid
|
||||
BAD_COMPRESSOR_HANDLE_POINTER = (-11) # compression handle pointer invalid
|
||||
BAD_BUFFER_HANDLE = (-12) # callback function invalid
|
||||
BAD_ALGORITHM_INFO = (-13) # algorithm info invalid
|
||||
BAD_CL_BAD_WIDTH_OR_HEIGHT = (-14) # compressor width or height invalid
|
||||
BAD_POINTER_FROM_CALLBACK_FUNCTION = (-15) # pointer from callback invalid
|
||||
JPEG_ERROR = (-16) # error from libjpeg
|
||||
NO_SEMAPHORE = (-17) # could not get semaphore
|
||||
BAD_WIDTH_OR_HEIGHT = (-18) # width or height invalid
|
||||
BAD_FRAME_COUNT = (-19) # frame count invalid
|
||||
BAD_FRAME_INDEX = (-20) # frame index invalid
|
||||
BAD_FRAME_BUFFER = (-21) # frame buffer pointer invalid
|
||||
BAD_FRAME_SIZE = (-22) # frame size invalid
|
||||
BAD_DATA_BUFFER = (-23) # data buffer pointer invalid
|
||||
BAD_DATA_SIZE = (-24) # data buffer size invalid
|
||||
BAD_TOTAL_NUMBER_OF_FRAMES = (-25) # total number of frames invalid
|
||||
BAD_IMAGE_FORMAT = (-26) # image format invalid
|
||||
BAD_BITS_PER_COMPONENT = (-27) # bits per component invalid
|
||||
BAD_FRAME_RATE = (-28) # frame rate invalid
|
||||
BAD_INSUFFICIENT_DATA_FROM_CALLBACK_FUNCTION = (-29) # insufficient data from callback invalid
|
||||
PARAM_OUT_OF_RANGE = (-30) # parameter out of range
|
||||
ADDED_ALGORITHM_ERROR = (-31) # added algorithm had a unique error
|
||||
BAD_ALGORITHM_TYPE = (-32) # bad algorithm type
|
||||
BAD_ALGORITHM_NAME = (-33) # bad algorithm name
|
||||
BAD_FRAME_INDEXING = (-34) # bad frame indexing
|
||||
BAD_BUFFERING = (-35) # bad buffering calls
|
||||
BUFFER_NOT_CREATED = (-36) # buffer not created
|
||||
BAD_BUFFER_EXISTS = (-37) # buffer already created
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
# This file implements a class which forms an interface to the .cddb
|
||||
# directory that is maintained by SGI's cdman program.
|
||||
#
|
||||
# Usage is as follows:
|
||||
#
|
||||
# import readcd
|
||||
# r = readcd.Readcd().init()
|
||||
# c = Cddb().init(r.gettrackinfo())
|
||||
#
|
||||
# Now you can use c.artist, c.title and c.track[trackno] (where trackno
|
||||
# starts at 1). When the CD is not recognized, all values will be the empty
|
||||
# string.
|
||||
# It is also possible to set the above mentioned variables to new values.
|
||||
# You can then use c.write() to write out the changed values to the
|
||||
# .cdplayerrc file.
|
||||
|
||||
import string
|
||||
|
||||
_cddbrc = '.cddb/'
|
||||
_DB_ID_NTRACKS = 5
|
||||
_dbid_map = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@_=+abcdefghijklmnopqrstuvwxyz'
|
||||
def _dbid(v):
|
||||
if v >= len(_dbid_map):
|
||||
return string.zfill(v, 2)
|
||||
else:
|
||||
return _dbid_map[v]
|
||||
|
||||
class Cddb():
|
||||
def init(self, tracklist):
|
||||
self.artist = ''
|
||||
self.title = ''
|
||||
if type(tracklist) == type(''):
|
||||
t = []
|
||||
for i in range(2, len(tracklist), 4):
|
||||
t.append((None, \
|
||||
(string.atoi(tracklist[i:i+2]), \
|
||||
string.atoi(tracklist[i+2:i+4]))))
|
||||
tracklist = t
|
||||
ntracks = len(tracklist)
|
||||
self.track = [None] + [''] * ntracks
|
||||
self.id = _dbid((ntracks >> 4) & 0xF) + _dbid(ntracks & 0xF)
|
||||
if ntracks <= _DB_ID_NTRACKS:
|
||||
nidtracks = ntracks
|
||||
else:
|
||||
nidtracks = _DB_ID_NTRACKS - 1
|
||||
min = 0
|
||||
sec = 0
|
||||
for track in tracklist:
|
||||
start, length = track
|
||||
min = min + length[0]
|
||||
sec = sec + length[1]
|
||||
min = min + sec / 60
|
||||
sec = sec % 60
|
||||
self.id = self.id + _dbid(min) + _dbid(sec)
|
||||
for i in range(nidtracks):
|
||||
start, length = tracklist[i]
|
||||
self.id = self.id + _dbid(length[0]) + _dbid(length[1])
|
||||
self.toc = string.zfill(ntracks, 2)
|
||||
for track in tracklist:
|
||||
start, length = track
|
||||
self.toc = self.toc + string.zfill(length[0], 2) + \
|
||||
string.zfill(length[1], 2)
|
||||
try:
|
||||
import posix
|
||||
file = posix.environ['HOME'] + '/' + _cddbrc + self.id + '.rdb'
|
||||
f = open(file, 'r')
|
||||
except IOError:
|
||||
return self
|
||||
import regex
|
||||
reg = regex.compile('^\\([^.]*\\)\\.\\([^:]*\\):\t\\(.*\\)')
|
||||
while 1:
|
||||
line = f.readline()
|
||||
if not line:
|
||||
break
|
||||
if reg.match(line) == -1:
|
||||
print 'syntax error in ' + file
|
||||
continue
|
||||
name1 = line[reg.regs[1][0]:reg.regs[1][1]]
|
||||
name2 = line[reg.regs[2][0]:reg.regs[2][1]]
|
||||
value = line[reg.regs[3][0]:reg.regs[3][1]]
|
||||
if name1 == 'album':
|
||||
if name2 == 'artist':
|
||||
self.artist = value
|
||||
elif name2 == 'title':
|
||||
self.title = value
|
||||
elif name2 == 'toc':
|
||||
if self.toc != value:
|
||||
print 'toc\'s don\'t match'
|
||||
elif name1[:5] == 'track':
|
||||
trackno = string.atoi(name1[5:])
|
||||
self.track[trackno] = value
|
||||
f.close()
|
||||
return self
|
||||
|
||||
def write(self):
|
||||
import posix
|
||||
file = posix.environ['HOME'] + '/' + _cddbrc + self.id + '.rdb'
|
||||
f = open(file, 'w')
|
||||
f.write('album.title:\t' + self.title + '\n')
|
||||
f.write('album.artist:\t' + self.artist + '\n')
|
||||
f.write('album.toc:\t' + self.toc + '\n')
|
||||
for i in range(1, len(self.track)):
|
||||
f.write('track' + `i` + '.title:\t' + self.track[i] + '\n')
|
||||
f.close()
|
|
@ -21,6 +21,13 @@ class Cdplayer():
|
|||
import string
|
||||
self.artist = ''
|
||||
self.title = ''
|
||||
if type(tracklist) == type(''):
|
||||
t = []
|
||||
for i in range(2, len(tracklist), 4):
|
||||
t.append((None, \
|
||||
(string.atoi(tracklist[i:i+2]), \
|
||||
string.atoi(tracklist[i+2:i+4]))))
|
||||
tracklist = t
|
||||
self.track = [None] + [''] * len(tracklist)
|
||||
self.id = 'd' + string.zfill(len(tracklist), 2)
|
||||
for track in tracklist:
|
||||
|
|
Loading…
Reference in New Issue