-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoStreamInitialLocalWindowController.py
137 lines (113 loc) · 4.43 KB
/
VideoStreamInitialLocalWindowController.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
# Copyright (C) 2014 AG Projects. See LICENSE for details.
#
from AppKit import (NSWindowController, NSFloatingWindowLevel, NSWindow)
from Foundation import NSBundle, NSTimer
import objc
import AppKit
from BlinkLogger import BlinkLogger
from util import run_in_gui_thread
from sipsimple.threading import run_in_twisted_thread
ALPHA = 1.0
class VideoStreamInitialLocalWindowController(NSWindowController):
window = None
finished = False
initial_size = None
dif_y = 0
def __new__(cls, *args, **kwargs):
return cls.alloc().init()
@run_in_twisted_thread
def __init__(self, videoWindowController):
self.videoWindowController = videoWindowController
self.log_debug('Init %s' % self)
if self.stream.video_windows is not None:
# Stream may have died in the mean time
self.sdl_window = self.stream.video_windows.local
self.initial_size = self.sdl_window.size
self.log_info('Opened local video at %0.fx%0.f resolution' % (self.initial_size[0], self.initial_size[1]))
self.stream.video_windows.local.size = (self.initial_size[0]/2, self.initial_size[1]/2)
self.window = NSWindow(cobject=self.sdl_window.native_handle)
self.window.setAlphaValue_(ALPHA)
self.window.setDelegate_(self)
self.window.setTitle_(self.videoWindowController.title)
self.window.orderFront_(None)
self.window.center()
self.window.setLevel_(NSFloatingWindowLevel)
# this hold the height of the Cocoa window title bar
self.dif_y = self.window.frame().size.height - self.stream.video_windows.local.size[1]
@property
def stream(self):
return self.videoWindowController.streamController.stream
@property
def streamController(self):
if self.videoWindowController:
return self.videoWindowController.streamController
else:
return None
@property
def sessionController(self):
if self.streamController:
return self.streamController.sessionController
else:
return None
def log_debug(self, log):
if self.sessionController:
self.sessionController.log_debug(log)
else:
BlinkLogger().log_debug(log)
def log_info(self, log):
if self.sessionController:
self.sessionController.log_info(log)
else:
BlinkLogger().log_info(log)
def dealloc(self):
self.log_debug('Dealloc %s' % self)
self.videoWindowController = None
super(VideoStreamInitialLocalWindowController, self).dealloc()
def windowDidBecomeMain_(self, notification):
if self.videoWindowController.window:
# remote video window opened faster than local video window
if self.videoWindowController.window.isVisible():
self.hide()
def windowWillResize_toSize_(self, window, frameSize):
currentSize = self.window.frame().size
scaledSize = frameSize
scaleFactor = float(self.initial_size[0]) / self.initial_size[1]
scaledSize.width = frameSize.width
scaledSize.height = scaledSize.width / scaleFactor
scaledSize.height += self.dif_y
return scaledSize
def windowDidResize_(self, notification):
# stuff may vanish while we drag the window
if not self.videoWindowController:
return
if not self.streamController:
return
if not self.stream:
return
frame = self.window.frame()
if frame.size.width != self.stream.video_windows.local.size[0]:
self.stream.video_windows.local.size = (frame.size.width, frame.size.height - self.dif_y)
def windowShouldClose_(self, sender):
if self.finished:
return True
self.streamController.sessionController.end()
if self.window:
self.window.close()
return True
@run_in_gui_thread
def windowWillClose_(self, sender):
self.finished = True
def keyDown_(self, event):
if event.keyCode() == 53:
self.streamController.sessionController.end()
self.hide()
@run_in_gui_thread
def hide(self):
if self.window:
self.window.close()
@run_in_twisted_thread
def close(self):
self.log_debug('Close %s' % self)
if self.window:
self.window.close()
self.release()