# Path: pave.py
# class PaVE:
#   def __init__( self ):
#     self.buf = ""
# 
#   def append( self, packet ):
#     self.buf += packet
# 
# 
#   def extract( self ):
#     "return single packet (header, payload)"
#     if not self.buf.startswith("PaVE"):
#       if "PaVE" in self.buf:
#         self.buf = self.buf[ self.buf.index("PaVE") : ]
# 
#     if len(self.buf) < 4+1+1+2+4:
#       # at least struct of version and header and payload sizes must be ready
#       return "",""
#     
#     if not self.buf.startswith( "PaVE" ):
#       return "",""
# 
#     version, codec, headerSize, payloadSize = struct.unpack_from("BBHI", self.buf, 4 )
#     if len(self.buf) < headerSize + payloadSize:
#       return "",""
# 
#     ret = self.buf[:headerSize], self.buf[headerSize:headerSize+payloadSize]
#     self.buf = self.buf[headerSize + payloadSize : ]
#     return ret


import sys
import struct
import socket
from threading import Thread,Event,Lock
from pave import PaVE
#!/usr/bin/python
"""
  Socket for filtering PaVE (Parrot Video Encapsulation) packets
       ./paveproxy.py <input file>
"""


HOST = 'localhost'    # access URL for cv2.VideoCapture
PORT = 50007
BUFFER_SIZE = 1024

class PaVEProxy( Thread ):
  def __init__( self, readCbk ):
    Thread.__init__( self )
    self.setDaemon(True)
    self.lock = Lock()
    self.shouldIRun = Event()
    self.shouldIRun.set()
    self.serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.socket, self.addr = None, None
    self.readCbk = readCbk

# Path: pave.py
# class PaVE:
#   def __init__( self ):
#     self.buf = ""
# 
#   def append( self, packet ):
#     self.buf += packet
# 
# 
#   def extract( self ):
#     "return single packet (header, payload)"
#     if not self.buf.startswith("PaVE"):
#       if "PaVE" in self.buf:
#         self.buf = self.buf[ self.buf.index("PaVE") : ]
# 
#     if len(self.buf) < 4+1+1+2+4:
#       # at least struct of version and header and payload sizes must be ready
#       return "",""
#     
#     if not self.buf.startswith( "PaVE" ):
#       return "",""
# 
#     version, codec, headerSize, payloadSize = struct.unpack_from("BBHI", self.buf, 4 )
#     if len(self.buf) < headerSize + payloadSize:
#       return "",""
# 
#     ret = self.buf[:headerSize], self.buf[headerSize:headerSize+payloadSize]
#     self.buf = self.buf[headerSize + payloadSize : ]
#     return ret


# Path: paveproxy.py
import sys
import struct
import socket
from threading import Thread,Event,Lock
from pave import PaVE

#!/usr/bin/python
"""
  Socket for filtering PaVE (Parrot Video Encapsulation) packets
       ./paveproxy.py <input file>
"""


HOST = 'localhost'    # access URL for cv2.VideoCapture
PORT = 50007
BUFFER_SIZE = 1024

class PaVEProxy( Thread ):
  def __init__( self, readCbk ):
    Thread.__init__( self )
    self.setDaemon(True)
    self.lock = Lock()
    self.shouldIRun = Event()
    self.shouldIRun.set()
    self.serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.socket, self.addr = None, None
    self.readCbk = readCbk

    self.pave = PaVE()