META_INFO_SIZE 1024 TEXTURE_SIZE 45 1024 1024 TEXTURE_1_OFFSET META_IN

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
META_INFO_SIZE=(1024)
TEXTURE_SIZE=(45 * 1024 * 1024)
TEXTURE_1_OFFSET=META_INFO_SIZE
TEXTURE_2_OFFSET=(TEXTURE_SIZE + TEXTURE_1_OFFSET)
def getdata(memory, offset, size):
data = array.array('b', memory.buf[offset:offset+size])
return data
INFINITY = 4294967295
sharedmemory = shared_memory.SharedMemory(name=shared_memory_name, create=False, size=SHARED_MEMORY_SIZE)
texture1_mutex = win32event.OpenMutex(win32event.SYNCHRONIZE, false, texture1_mutex_name)
texture2_mutex = win32event.OpenMutex(win32event.SYNCHRONIZE, false, texture2_mutex_name)
texture_ready_event = win32event.OpenEvent(win32event.SYNCHRONIZE, false, texture_ready_name);
while True:
if win32event.WAIT_OBJECT_0 == win32event.WaitForSingleObject(texture_ready_event, -1):
meta = struct.unpack('IIII', sharedmemory)
data=array.array()
data_size = meta[0]*meta[1]*4
if meta[3] == 1:
if win32event.WaitForSingleObject(texture1_mutex, 0) == win32event.WAIT_OBJECT_0:
data=getdata(sharedmemory, TEXTURE_1_OFFSET, data_size)
win32event.ReleaseMutex(texture1_mutex)
elif win32event.WaitForSingleObject(texture2_mutex, 0) == win32event.WAIT_OBJECT_0:
data=getdata(sharedmemory, TEXTURE_2_OFFSET, data_size)
win32event.ReleaseMutex(texture2_mutex)
elif meta[3] == 2:
if win32event.WaitForSingleObject(texture2_mutex, 0) == win32event.WAIT_OBJECT_0:
data=getdata(sharedmemory, TEXTURE_2_OFFSET, data_size)
win32event.ReleaseMutex(texture2_mutex)
elif win32event.WaitForSingleObject(texture1_mutex, 0) == win32event.WAIT_OBJECT_0:
data=getdata(sharedmemory, TEXTURE_1_OFFSET, data_size)
win32event.ReleaseMutex(texture1_mutex)