-
Notifications
You must be signed in to change notification settings - Fork 0
/
cam.py
98 lines (85 loc) · 5.34 KB
/
cam.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from PyQt4 import QtCore
import gobject
gobject.threads_init()
import gst
class camThread(QtCore.QThread):
INSTANCE = None
def __init__(self,windowId,detectionWindowId):
camThread.INSTANCE = self
try:
QtCore.QThread.__init__(self)
self.windowId = windowId
self.detectionWindowId = detectionWindowId
self.gstInitialization()
except Exception, e:
print(e)
def on_sync_message(self, bus, message):
if message.structure is None:
return None
message_name = message.structure.get_name()
if message_name == "prepare-xwindow-id":
win_id = self.windowId
assert win_id
imagesink = message.src
imagesink.set_property("force-aspect-ratio", True)
imagesink.set_xwindow_id(win_id)
return message
def on_sync_message_detection(self, bus, message):
if message.structure is None:
return None
message_name = message.structure.get_name()
if message_name == "prepare-xwindow-id":
win_id = self.detectionWindowId
assert win_id
imagesink = message.src
imagesink.set_property("force-aspect-ratio", True)
imagesink.set_xwindow_id(win_id)
return message
def handle_segfault(self, bus, message):
try:
self.mainloop.quit()
except:
pass
print("SEGMENTATION FAULT")
self = camThread.INSTANCE
self.gstInitialization()
def run(self):
self.player.set_state(gst.STATE_PLAYING)
self.detectionPlayer.set_state(gst.STATE_PLAYING)
def quit(self):
self.player.set_state(gst.STATE_NULL)
self.detectionPlayer.set_state(gst.STATE_NULL)
if self.player:
del self.player
if self.bus:
del self.bus
#TODO
self.gstInitialization()
#self.cap.release()
def gstInitialization(self):
#self.player = gst.parse_launch('udpsrc port=5632 caps="application/x-rtp,payload=26,encoding-name=JPEG" ! queue ! rtpjpegdepay ! jpegdec ! xvimagesink sync=false')
#self.player = gst.parse_launch('udpsrc port=5632 caps="application/x-rtp,payload=26,encoding-name=JPEG" ! queue ! rtpjpegdepay ! jpegdec ! xvimagesink sync=false udpsrc port=6112 caps="application/x-rtp,media=(string)audio, clock-rate=(int)8000, width=16, height=16, encoding-name=(string)L16, encoding-params=(string)1, channels=(int)1, channel-positions=(int)1, payload=(int)96" ! rtpL16depay ! audioconvert ! alsasink sync=false') #current 2015
# self.player = gst.parse_launch('udpsrc port=5632 caps="application/x-rtp,payload=26,encoding-name=JPEG" ! queue ! rtpjpegdepay ! jpegdec ! xvimagesink udpsrc port=6112 caps="application/x-rtp, media=(string)audio, clock-rate=(int)8000, encoding-name=(string)AMR, encoding-params=(string)1, octet-align=(string)1, payload=(int)96" ! rtpamrdepay ! amrnbdec ! audioconvert ! alsasink')
#self.player = gst.parse_launch('udpsrc port=5632 caps="application/x-rtp,payload=26,encoding-name=JPEG" ! queue ! rtpjpegdepay ! jpegdec ! xvimagesink sync=false udpsrc port=6112 caps="application/x-rtp,media=(string)audio, clock-rate=(int)22000, width=16, height=16, encoding-name=(string)L16, encoding-params=(string)1, channels=(int)1, channel-positions=(int)1, payload=(int)96" ! rtpL16depay ! audioconvert ! alsasink sync=false')
#self.player = gst.parse_launch('udpsrc port=1234 caps="application/x-rtp, payload=127" ! rtph264depay ! ffdec_h264 ! xvimagesink sync=false')
#H264 2 Streams
#self.player = gst.parse_launch('udpsrc port=1234 caps="application/x-rtp, payload=127" ! rtph264depay ! ffdec_h264 ! xvimagesink sync=false udpsrc port=1235 caps="application/x-rtp, payload=127" ! rtph264depay ! ffdec_h264 ! xvimagesink sync=false')
#Drive stream setup
audioStr = ' udpsrc port=1236 caps="application/x-rtp, media=(string)audio, clock-rate=(int)8000, encoding-name=(string)AMR, encoding-params=(string)1, octet-align=(string)1, payload=(int)96" ! rtpamrdepay ! amrnbdec ! audioconvert ! alsasink'
#audioStr = ""
self.player = gst.parse_launch('udpsrc port=1234 caps="application/x-rtp, payload=127" ! gstrtpjitterbuffer ! rtpjpegdepay ! jpegdec ! xvimagesink sync=false' + audioStr)
self.bus = self.player.get_bus()
self.bus.add_signal_watch()
self.bus.enable_sync_message_emission()
self.bus.connect("sync-message::element", self.on_sync_message)
self.bus.connect("sync-message::error", self.handle_segfault)
#Detection stream setup
self.detectionPlayer = gst.parse_launch('udpsrc port=1235 caps="application/x-rtp, payload=127, latency=0" ! gstrtpjitterbuffer ! rtpjpegdepay ! jpegdec ! xvimagesink sync=false')
self.detectionBus = self.detectionPlayer.get_bus()
self.detectionBus.add_signal_watch()
self.detectionBus.enable_sync_message_emission()
self.detectionBus.connect("sync-message::element",
self.on_sync_message_detection)
self.detectionBus.connect("sync-message::error", self.handle_segfault)