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
class Source(gst.BaseSrc):
__gsttemplates__ = (
gst.PadTemplate("src",
gst.PAD_SRC,
gst.PAD_ALWAYS,
gst.caps_new_any()),
)
blocksize = 4096
def __init__(self, name, config, track):
self.__gobject_init__()
self.set_name(name)
self.buf = Buffer(track, config=config)
def do_create(self, offset, size):
if self.buf.length and offset > self.buf.length:
return gst.FLOW_UNEXPECTED, None
while self.buf.pos < offset+size and not self.buf.finished:
sleep(0.1)
self.buf.file.seek(offset)
data = self.buf.file.read(size)
return gst.FLOW_OK, gst.Buffer(data)
def do_query(self, query):
if query.type == gst.QUERY_DURATION:
if query.parse_duration()[0] == gst.FORMAT_TIME:
length = int(self.buf.track.length)*1000000000
query.set_duration(gst.FORMAT_TIME, 123124123)
elif query.parse_duration()[0] == gst.FORMAT_BYTES:
query.set_duration(gst.FORMAT_BYTES, self.buf.length)
elif query.type == gst.QUERY_LATENCY:
query.set_latency(min_latency=0, live=False, max_latency=-1)
return True