-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream_client.py
executable file
·153 lines (125 loc) · 4.54 KB
/
stream_client.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os, requests
import subprocess
import socket, fcntl, struct
from PyQt4 import QtGui, QtCore, uic
from stream_pos import ScreenPosWindow
raspberry_ip = "192.168.42.1"
raspberry_port = "8080"
raspberry_ip_page = "whatismyip3534"
raspberry_control_page = raspberry_ip + ":" + raspberry_port + "/" + "control3434"
def get_ip_address(ifname): # http://code.activestate.com/recipes/439094-get-the-ip-address-associated-with-a-network-inter/
s= socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ip = socket.inet_ntoa( fcntl.ioctl(
s.fileno(), 0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
return ip
def what_is_my_ip(server_ip, server_port, server_page):
#values = {'comm': lauchAndPort}
#r = requests.get("http://" + raspberry_control_page, params= values)
try:
r = requests.get("http://" + server_ip + ":" + server_port + "/" + server_page)
content = str(r.content)
except requests.exceptions.RequestException as e:
print "what_is_my_ip" + e
content = "0.0.0.0"
return content
win = None
commandList = []
uiMainWindow = uic.loadUiType('mainwindow.ui')[0]
class TestApp(QtGui.QMainWindow, uiMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.screen_window = None
self.setupUi(self)
self.ipSetting.setText( what_is_my_ip(raspberry_ip, raspberry_port, raspberry_ip_page) ) # get ip from web server runs on raspberry pi
@QtCore.pyqtSlot()
def on_pos_set_button_clicked(self):
try:
#width, height = self.screen_pos.text().split(',')
#width, height = int(width), int(height)
width, height = (int(i) for i in self.resolutionSetting.currentText().split('x'))
except:
width, height = 640, 480
try:
x, y = (int(i) for i in self.screen_pos.text().split(','))
except:
x, y = 0, 0
if self.screen_window != None:
self.screen_window.close()
self.screen_window = ScreenPosWindow(x, y, width, height, self.setPosition)
@QtCore.pyqtSlot()
def on_start_button_clicked(self):
_IP = win.ipSetting.text()
_PORT = win.portSetting.text()
_MBIT = win.mbitCombo.currentText() + "000" # "20" + "000" gibi
_RESOLUTION = win.resolutionSetting.currentText()
_FPS = win.fpsSetting.currentText()
_BITRATE = win.bitrate_edit.text()
_MAX_BITRATE = win.max_bitrate_edit.text()
_SLICE_MAX_SIZE = win.slice_max_size_edit.text()
_SCREEN_POS = win.screen_pos.text()
start_stream(_IP, _PORT, _MBIT, _RESOLUTION, _FPS, _BITRATE,
_MAX_BITRATE, _SLICE_MAX_SIZE, _SCREEN_POS)
if stream_info() == True:
self.start_button.setText("Durdur")
else:
self.start_button.setText("Başlat")
@QtCore.pyqtSlot()
def on_advancedButton_clicked(self):
self.stackedWidget.setCurrentIndex( (self.stackedWidget.currentIndex() + 1) % 2) # sayfalar arası geçiş
@QtCore.pyqtSlot(int)
def on_mbitCombo_activated(self, index):
self.setMegabitSetting(self.mbitCombo.currentText())
def setMegabitSetting(self, mbit):
self.bitrate_edit.setText(str(mbit + "000"))
self.max_bitrate_edit.setText( str(int(int(mbit + "000") * (1.75))) )
def setPosition(self, x, y):
self.screen_pos.setText("%s,%s" % (x+1366, y))
def closeEvent(self, event):
print "TestApp.closeEvent"
if self.screen_window != None:
self.screen_window.close()
self.screen_window = None
################################### stream ##########################################################
pop = None
def stream_info():
return pop != None
def start_stream(_IP, _PORT, _MBIT, _RESOLUTION, _FPS, _BITRATE, _MAX_BITRATE, _SLICE_MAX_SIZE, _SCREEN_POS):
global pop
# process calistir
commandList = []
commandList.append("./server_libav.sh")
commandList.append(_FPS)
commandList.append(_RESOLUTION)
commandList.append(_BITRATE)
commandList.append(_MAX_BITRATE)
commandList.append(_SLICE_MAX_SIZE)
commandList.append(_IP + ':' + _PORT)
commandList.append(_SCREEN_POS)
if pop == None:
pop = subprocess.Popen(commandList)
lauchAndPort = "opengstlaunch-start " + str(_PORT)
values = {'comm': lauchAndPort}
r = requests.get("http://" + raspberry_control_page, params= values)
else:
pop.terminate()
pop = None
values = {'comm': "opengstlaunch-stop"}
r = requests.get("http://" + raspberry_control_page, params= values)
# print _IP, _PORT, _MBIT, _RESOLUTION, _FPS, _BITRATE, _MAX_BITRATE
if __name__ == "__main__":
try:
app = QtGui.QApplication(sys.argv)
win = TestApp()
win.show()
sys.exit(app.exec_())
finally:
if win.screen_window != None:
win.screen_window = None
print "finally screen_window"
if pop != None:
pop.terminate()
print "program kapandi"