* morituri/common/checksum.py:

* morituri/common/common.py:
	* morituri/image/image.py:
	* morituri/image/table.py:
	* morituri/program/cdparanoia.py:
	  Move constants to common
This commit is contained in:
Thomas Vander Stichele
2009-05-16 09:21:55 +00:00
parent 204c5d6212
commit 59cb5d0dcb
6 changed files with 36 additions and 29 deletions

View File

@@ -28,15 +28,10 @@ import zlib
import gobject
import gst
from morituri.common import task
from morituri.common import common, task
# checksums are not CRC's. a CRC is a specific type of checksum.
SAMPLES_PER_FRAME = 588
WORDS_PER_FRAME = SAMPLES_PER_FRAME * 2
BYTES_PER_FRAME = SAMPLES_PER_FRAME * 4
FRAMES_PER_SECOND = 75
class ChecksumTask(task.Task):
"""
I am a task that calculates a checksum.
@@ -110,8 +105,8 @@ class ChecksumTask(task.Task):
gst.SEEK_TYPE_SET, self._frameStart,
gst.SEEK_TYPE_SET, self._frameEnd + 1) # half-inclusive interval
gst.debug('CRCing %s from sector %d to sector %d' % (
self._path, self._frameStart / SAMPLES_PER_FRAME,
(self._frameEnd + 1) / SAMPLES_PER_FRAME))
self._path, self._frameStart / common.SAMPLES_PER_FRAME,
(self._frameEnd + 1) / common.SAMPLES_PER_FRAME))
# FIXME: sending it with frameEnd set screws up the seek, we don't get
# everything for flac; fixed in recent -good
result = sink.send_event(event)
@@ -149,9 +144,9 @@ class ChecksumTask(task.Task):
# see http://bugzilla.gnome.org/show_bug.cgi?id=576505
self._adapter.push(buffer)
while self._adapter.available() >= BYTES_PER_FRAME:
while self._adapter.available() >= common.BYTES_PER_FRAME:
# FIXME: in 0.10.14.1, take_buffer leaks a ref
buffer = self._adapter.take_buffer(BYTES_PER_FRAME)
buffer = self._adapter.take_buffer(common.BYTES_PER_FRAME)
self._checksum = self.do_checksum_buffer(buffer, self._checksum)
self._bytes += len(buffer)
@@ -242,13 +237,13 @@ class AccurateRipChecksumTask(ChecksumTask):
# ... on 5th frame, only use last value
elif self._discFrameCounter == 5:
values = struct.unpack("<I", buffer[-4:])
checksum += SAMPLES_PER_FRAME * 5 * values[0]
checksum += common.SAMPLES_PER_FRAME * 5 * values[0]
checksum &= 0xFFFFFFFF
return checksum
# on last track, skip last 5 CD frames
if self._trackNumber == self._trackCount:
discFrameLength = self._frameLength / SAMPLES_PER_FRAME
discFrameLength = self._frameLength / common.SAMPLES_PER_FRAME
if self._discFrameCounter > discFrameLength - 5:
self.debug('skipping frame %d', self._discFrameCounter)
return checksum
@@ -260,9 +255,9 @@ class AccurateRipChecksumTask(ChecksumTask):
sum += (self._bytes / 4 + i + 1) * value
sum &= 0xFFFFFFFF
# offset = self._bytes / 4 + i + 1
# if offset % SAMPLES_PER_FRAME == 0:
# if offset % common.SAMPLES_PER_FRAME == 0:
# print 'THOMAS: frame %d, ends before %d, last value %08x, CRC %08x' % (
# offset / SAMPLES_PER_FRAME, offset, value, sum)
# offset / common.SAMPLES_PER_FRAME, offset, value, sum)
checksum += sum
checksum &= 0xFFFFFFFF

View File

@@ -24,6 +24,11 @@ import os
import tempfile
import shutil
SAMPLES_PER_FRAME = 588
WORDS_PER_FRAME = SAMPLES_PER_FRAME * 2
BYTES_PER_FRAME = SAMPLES_PER_FRAME * 4
FRAMES_PER_SECOND = 75
def msfToFrames(msf):
"""
Converts a string value in MM:SS:FF to frames