class Source gst BaseSrc __gsttemplates__ gst PadTemplate src gst PAD_

 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
class Source(gst.BaseSrc):
__gsttemplates__ = (
gst.PadTemplate("src",
gst.PAD_SRC,
gst.PAD_ALWAYS,
gst.caps_new_any()),
)
blocksize = 4096
timestamp = False
live = False
def __init__(self, name, config, track):
gst.BaseSrc.__init__(self)
self.__gobject_init__()
self.set_name(name)
self.set_format(gst.FORMAT_BYTES)
self.buf = Buffer(track, config=config)
self.buf.start()
while not self.buf.started:
sleep(0.01)
def do_create(self, offset, size):
if self.buf.length and offset >= self.buf.length:
print 'PlayerGST2.py: Requested offset (%s) is over file length (%s)' % (offset, self.buf.length)
return gst.FLOW_UNEXPECTED, None
while self.buf.pos < offset+size and not self.buf.finished:
if self.buf.failed:
return gst.FLOW_UNEXPECTED, None
if self.unlock:
self.unlock = False
break
sleep(0.1)
data = self.buf.data[offset:offset+size]
if data:
return gst.FLOW_OK, gst.Buffer(data)
else:
return gst.FLOW_UNEXPECTED, None
def do_query (self, query):
if query.type == gst.QUERY_DURATION:
if query.parse_duration()[0] == gst.FORMAT_TIME:
print 'PlayerGST2.py/Source: Query (type duration) format TIME'
while not self.buf.track.length:
sleep(0.01)
print 'PlayerGST2.py/Source: Waiting for buffer to settle...'
lent = self.buf.track.length*gst.SECOND
query.set_duration(gst.FORMAT_TIME, lent)
return True
elif query.parse_duration()[0] == gst.FORMAT_BYTES:
print 'PlayerGST2.py/Source: Query (type duration) format BYTES'
while not self.buf.length:
sleep(0.01)
print 'PlayerGST2.py/Source: Waiting for buffer to settle...'
query.set_duration(format=gst.FORMAT_BYTES, duration=self.buf.length)
return True
else:
print 'PlayerGST2.py/Source: Unhandled query (type: duration)', query.parse_duration()
return False
return False
elif query.type == gst.QUERY_LATENCY:
print 'PlayerGST2.py/Source: Query latency request'
query.set_latency(min_latency=0, live=True, max_latency=-1)
return True
else:
print 'PlayerGST2.py/Source: Unhandled query, type:', query.type
return False
def do_get_size(self, *args):
while not self.buf.length:
sleep(0.01)
return int(self.buf.length)
def do_is_seekable(self):
"Answers is the source seekable (this source is)"
return True
def do_check_get_range(self, *args):
"Do not check range when start playing"
return False
gobject.type_register(Source)