1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import gst
23 from twisted.internet import defer
24
25 from flumotion.common import errors, messages
26 from flumotion.common.i18n import N_, gettexter
27 from flumotion.component import feedcomponent
28
29 __version__ = "$Rev: 6695 $"
30 T_ = gettexter()
31
32
33
34
35 -class Firewire(feedcomponent.ParseLaunchComponent):
44
49
51 width = props.get('width', 240)
52 height = props.get('height', int(576 * width/720.))
53 guid = props.get('guid', None)
54
55
56 self.fixRenamedProperties(props, [
57 ('scaled_width', 'scaled-width'),
58 ('is_square', 'is-square'),
59 ])
60 scaled_width = props.get('scaled-width', width)
61 is_square = props.get('is-square', False)
62 framerate = props.get('framerate', (30, 2))
63 framerate_float = float(framerate[0]) / framerate[1]
64
65 scale_correction = width - scaled_width
66
67 if 12.5 < framerate_float <= 25:
68 drop_factor = 1
69 elif 6.3 < framerate_float <= 12.5:
70 drop_factor = 2
71 elif 3.2 < framerate_float <= 6.3:
72 drop_factor = 4
73 else:
74 drop_factor = 8
75
76 if is_square:
77 square_pipe = ',pixel-aspect-ratio=(fraction)1/1'
78 else:
79 square_pipe = ''
80
81
82
83
84 if scale_correction > 0:
85
86
87
88 pad_pipe = '! ffmpegcolorspace ! videobox right=-%d ! video/x-raw-yuv,format=(fourcc)I420 ' % scale_correction
89 else:
90 pad_pipe = ''
91
92
93
94 interlaced_height = 288
95
96
97
98
99
100 template = ('dv1394src %(guid)s'
101 ' ! tee name=t'
102 ' ! queue leaky=2 max-size-time=1000000000'
103 ' ! dvdemux name=demux'
104 ' demux. ! queue ! dvdec drop-factor=%(df)d'
105 ' ! video/x-raw-yuv,format=(fourcc)YUY2'
106 ' ! videorate ! videoscale'
107 ' ! video/x-raw-yuv,width=%(sw)s,height=%(ih)s%(sq)s'
108 ' ! videoscale'
109 ' ! video/x-raw-yuv,width=%(sw)s,height=%(h)s,framerate=%(fr)s,format=(fourcc)YUY2'
110 ' %(pp)s'
111 ' ! @feeder:video@'
112 ' demux. ! queue ! audio/x-raw-int ! volume name=setvolume'
113 ' ! level name=volumelevel message=true ! audiorate'
114 ' ! @feeder:audio@'
115 ' t. ! queue ! @feeder:dv@'
116 % dict(df=drop_factor, ih=interlaced_height,
117 sq=square_pipe, pp=pad_pipe,
118 sw=scaled_width, h=height,
119 guid=(guid and ('guid=%s' % guid) or ''),
120 fr=('%d/%d' % (framerate[0], framerate[1]))))
121
122 return template
123
135
137 return self.volume.get_property('volume')
138
140 """
141 @param value: float between 0.0 and 4.0
142 """
143 self.debug("Setting volume to %f" % (value))
144 self.volume.set_property('volume', value)
145
146
148 """
149 @param bus: the message bus sending the message
150 @param message: the message received
151 """
152 if message.structure.get_name() == "ieee1394-bus-reset":
153
154 s = message.structure
155
156 if s.has_key('current-device-change'):
157 if s['current-device-change'] != 0:
158
159
160
161
162 for m in self.state.get('messages'):
163 if m.id.startswith('firewire-bus-reset'):
164 self.state.remove('messages',m)
165
166 if s['current-device-change'] == 1:
167
168 m = messages.Info(T_(N_(
169 "The camera has now been reconnected.")),
170 mid="firewire-bus-reset-%d" % s['nodecount'],
171 priority=40)
172 self.state.append('messages', m)
173 elif s['current-device-change'] == -1:
174
175 m = messages.Warning(T_(N_(
176 "The camera has been disconnected.")),
177 mid="firewire-bus-reset-%d" % s['nodecount'],
178 priority=40)
179 self.state.append('messages', m)
180