Method of embedding DTS into PCM

Discuss issues related to PS3 Media Server development (only for programmers)

Method of embedding DTS into PCM

Postby PS3owner » Thu Sep 02, 2010 5:34 pm

I looked into the method used in PS3MediaServer to disguise a DTS stream as an PCM stream.

The DTS stream is modified by TSMuxerVideo, using DTSAudioOutputStream and PCMAudioOutputStream.
Each DTS frame is embedded into a larger (2048b) PCM frame, and addition space within is zero padded.
The funny thing is that also an LPCM header is generated, but it seems to be never written to the stream.
So, I wonder what the trick is to make the DTS look like PCM format.
I tried various things, but I always loose proper format detection, even with powerful PC-tools.

For reference, I add the code I use to attempt to do the same, based on the Java code in PS3MediaServer. Any pointers from anyone?

Code: Select all
from array import *
from struct import *

PCM_WRAPPED_FRAME_SIZE=2048

def lpcm_header(nr_channels, sample_freq, bits_sample):
        blocksize = 2 * int((nr_channels+1)/2) * sample_freq * bits_sample / 1600
        payload = array('B', [0, 0, 49, 0])
        payload[0] = ((blocksize >> 8) & 0xff)
        payload[1] = ((blocksize+256)%256)
        payload[3] = (16*(bits_sample-12))
        payload.byteswap()
        return payload

def pack_dts_as_pcm(infile, outfile):
        dts = open(infile, 'rb')
        pcm = open(outfile, 'wb')

        bits = [16, 16, 20, 20, 0, 24, 24]
        data = array('B')

        try:
                while 1:
                        header = array('B')
                        header.fromfile(dts, 16)
                        if header[0] == 0x64 and header[1] == 0x58 and header[2] == 0x20 and header[3] == 0x25:
                                print "Found DTS-HD frame"
                                # TODO
                        elif header[0] == 0x7f and header[1] == 0xfe and header[2] == 0x80 and header[3] == 0x01:
                                #print "Found DTS frame"
                                framesize = ((header[5] & 0x03) << 12) + ((header[6] & 0xff) << 4) + ((header[7] & 0xf0) >> 4) + 1
                                bitspersample = bits[((header[11] & 0x01) << 2) + ((header[12] & 0xfc) >> 6)]
                               
                                # Should we prepend the DTS content with a LPCM header?
                                #lpcm_header(2, 48000, 16).tofile(pcm)
                               
                                # write DTS header
                                header.tofile(pcm)

                                # write DTS frame
                                frame = array('B')
                                frame.fromfile(dts, framesize - 16)
                                frame.tofile(pcm)

                                # zero pad to fill frame
                                array('B', [0 for i in range(PCM_WRAPPED_FRAME_SIZE - framesize)]).tofile(pcm)
                        else:
                                print >> sys.stderr, "Content not recognized"
                                return 1

        except EOFError:
                return 0
PS3owner
 
Posts: 1
Joined: Thu Sep 02, 2010 5:11 pm

Re: Method of embedding DTS into PCM

Postby shagrath » Fri Jan 14, 2011 9:15 pm

check the method beforeChunkSend of the PCMAudioOutputStream class. it writes the LPCM header and it's called by the FlowParserOuputStream class, which is kind of a custom OutputStream implementation i wrote for this kind of parsing/rearranging
shagrath
Project Lead
 
Posts: 2667
Joined: Wed Jan 14, 2009 1:39 pm


Return to Developers

Who is online

Users browsing this forum: No registered users and 0 guests