def process_video_tag(self, videosink, data): import flvscreen, zlib (frametype, codecid) = ord(data[0]) >> 4, ord(data[0]) & 0xf # must be ScreenVideo if codecid != 3: return (blockwidth, imagewidth) = ord(data[1]) >> 4, (ord(data[1]) & 0xf) << 8 | ord(data[2]) (blockheight, imageheight) = ord(data[3]) >> 4, (ord(data[3]) & 0xf) << 8 | ord(data[4]) blockwidth = (blockwidth+1)*16 blockheight = (blockheight+1)*16 hblocks = (imagewidth+blockwidth-1)/blockwidth vblocks = (imageheight+blockheight-1)/blockheight if not videosink.initialized: videosink.init_screen(imagewidth, imageheight) fp = StringIO(data[5:]) changed = [] for y in xrange(vblocks): for x in xrange(hblocks): (length,) = unpack('>H', fp.read(2)) if not length: continue data = fp.read(length) x0 = x*blockwidth y0 = imageheight - (y+1)*blockheight w = min(blockwidth, imagewidth-x0) h = blockheight if y0 < 0: h += y0 y0 = 0 data = zlib.decompress(data) data = flvscreen.flv2rgba(w, h, data) changed.append((x,vblocks-y-1)) videosink.update_screen_rgbabits((x0, y0), (w, h), data) return
def process_video_tag(self, videosink, data): import flvscreen, zlib (frametype, codecid) = ord(data[0]) >> 4, ord(data[0]) & 0xf # must be ScreenVideo if codecid != 3: return (blockwidth, imagewidth) = ord(data[1]) >> 4, (ord(data[1]) & 0xf) << 8 | ord( data[2]) (blockheight, imageheight) = ord(data[3]) >> 4, (ord(data[3]) & 0xf) << 8 | ord( data[4]) blockwidth = (blockwidth + 1) * 16 blockheight = (blockheight + 1) * 16 hblocks = (imagewidth + blockwidth - 1) / blockwidth vblocks = (imageheight + blockheight - 1) / blockheight if not videosink.initialized: videosink.init_screen(imagewidth, imageheight) fp = StringIO(data[5:]) changed = [] for y in xrange(vblocks): for x in xrange(hblocks): (length, ) = unpack('>H', fp.read(2)) if not length: continue data = fp.read(length) x0 = x * blockwidth y0 = imageheight - (y + 1) * blockheight w = min(blockwidth, imagewidth - x0) h = blockheight if y0 < 0: h += y0 y0 = 0 data = zlib.decompress(data) data = flvscreen.flv2rgba(w, h, data) changed.append((x, vblocks - y - 1)) videosink.update_screen_rgbabits((x0, y0), (w, h), data) return
def testFLV2RGBA(self): self.assertEqual(flvscreen.flv2rgba(2, 2, "123456abcdef"), "cba\x00fed\x00321\x00654\x00") self.assertRaises(flvscreen.FlvError, lambda: flvscreen.flv2rgba(2, 2, "12")) return
def testFLV2RGBA(self): self.assertEqual(flvscreen.flv2rgba(2, 2, '123456abcdef'), 'cba\x00fed\x00321\x00654\x00') self.assertRaises(flvscreen.FlvError, lambda: flvscreen.flv2rgba(2, 2, '12')) return