-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio.py
More file actions
39 lines (29 loc) · 1.46 KB
/
Copy pathaudio.py
File metadata and controls
39 lines (29 loc) · 1.46 KB
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
import sys, gi, os, socket, time, subprocess, psutil
from cam import Camera
gi.require_version('Gst', '1.0')
gi.require_version('GLib', '2.0')
from gi.repository import GObject, Gst, GstRtspServer, GLib, GObject
class AudioStream:
def __init__(self, name, audio_pipeline, rtp_payloader, encoded_caps):
self.rtp_payloader = rtp_payloader
self.name = name
self.audio = Gst.parse_launch(f'{audio_pipeline} ! '
f'interpipesink name={name} blocksize=0 max-lateness=2000000000 max-buffers=0 processing-deadline=5000000000 buffer-list=1 ')
self.shmsrc_str = f'interpipesrc listen-to={name} is-live=1 format=time stream-sync=restart-ts blocksize=0 max-time=2000000000 leaky-type=downstream ! {encoded_caps} '
def shutdown(self):
# Run on driver shutdown, no need to cleanup anything here..
set_state(Gst.State.NONE)
def run(self):
self.audio.get_bus().connect("message", self.snd_message)
self.audio.get_bus().add_signal_watch()
self.audio.set_state(Gst.State.PLAYING)
def snd_message(self, obj, event):
if event.src == self.audio:
if event.type == Gst.MessageType.STATE_CHANGED:
prev, new, pending = event.parse_state_changed()
if pending == Gst.State.VOID_PENDING:
print("New audio state: %s" % new)
def shmsrc(self):
return self.shmsrc_str
def payloader(self):
return self.rtp_payloader