Skip to content

Commit 54aadc8

Browse files
committed
Added alsa transform gui application
1 parent 7b47cc3 commit 54aadc8

File tree

14 files changed

+1104
-1
lines changed

14 files changed

+1104
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Gst_ALSA
2+
The purpose of this application is to implement the playback and recording functions of gstreamer+alsa on the QTI platform.
3+
4+
## Note:
5+
6+
- If pulseaudio service is enabled, disable it and start the alsa-restore service.
7+
```bash
8+
$ systemctl stop pulseaudio
9+
$ apt-get install alsa-utils
10+
$ systemctl start alsa-restore.service
11+
```
12+
BTW, if you want to disable this service, please run:
13+
```
14+
$ systemctl disable qc-alsa-restore
15+
```
16+
### Steps to run alsa playback and recording application
17+
- Go to the downloaded directory on RB5
18+
```bash
19+
cd /gst-python-samples/Gstreamer-Applications/gst-alsa
20+
```
21+
- Run the alsa playback and record application
22+
23+
-**Alsa audio playback:** Provide playback as the first argument for audio playback.
24+
```bash
25+
python3 gst-alsa playback audiofile.wav
26+
```
27+
-**Alsa audio recording:** Provide capture as the first argument for alsa audio recording.
28+
```bash
29+
python3 gst-alsa capture audiorecord.wav
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import sys
2+
import gi
3+
import logging
4+
import os
5+
gi.require_version("GLib", "2.0")
6+
gi.require_version("GObject", "2.0")
7+
gi.require_version("Gst", "1.0")
8+
from gi.repository import Gst, GLib, GObject
9+
from numpy import ndarray
10+
11+
12+
#Playback sample code
13+
def gst_sample_playback(content):
14+
# Create the empty pipeline
15+
pipeline = Gst.Pipeline.new("audio playback")
16+
filesrc = Gst.ElementFactory.make("filesrc", "file_src")
17+
wavparse = Gst.ElementFactory.make("wavparse", "wav_parse");
18+
alsasink = Gst.ElementFactory.make("alsasink", "alsa_sink");
19+
20+
if not pipeline or not filesrc or not wavparse or not alsasink:
21+
print("Create pipeline/filesrc/wavparse/alsasink element failed.")
22+
sys.exit(1)
23+
24+
#set properties to the elements
25+
filesrc.set_property('location',content)
26+
alsasink.set_property('device',"hw:0,0")
27+
28+
#Build pipeline
29+
#Add elements to the pipeline and link them
30+
pipeline.add(filesrc)
31+
pipeline.add(wavparse)
32+
pipeline.add(alsasink)
33+
34+
if not filesrc.link(wavparse):
35+
print("ERROR: Could not link filesrc to wavparse")
36+
sys.exit(1)
37+
if not wavparse.link(alsasink):
38+
print("ERROR: Could not link wavparse to alsasink")
39+
sys.exit(1)
40+
41+
pipeline.set_state(Gst.State.PLAYING)
42+
print("Start");
43+
bus = pipeline.get_bus()
44+
bus_id = bus.add_signal_watch()
45+
msg = bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE,Gst.MessageType.ERROR | Gst.MessageType.EOS)
46+
47+
if msg:
48+
t = msg.type
49+
if t == Gst.MessageType.ERROR:
50+
err, dbg = msg.parse_error()
51+
print("ERROR:", msg.src.get_name(), ":", err.message)
52+
if dbg:
53+
print("debugging info:", dbg)
54+
elif t == Gst.MessageType.EOS:
55+
print("Stop end-Of-Stream reached")
56+
else:
57+
print("ERROR: Unexpected message received.")
58+
59+
pipeline.set_state(Gst.State.NULL)
60+
Gst.Object.unref(bus)
61+
Gst.deinit()
62+
sys.exit(1)
63+
64+
65+
#Capture sample code
66+
def gst_sample_capture(content):
67+
#create the empty pipeline
68+
alsasrc = Gst.ElementFactory.make("alsasrc", "alsa_src");
69+
capsfilter = Gst.ElementFactory.make("capsfilter", "caps_filter");
70+
wavenc = Gst.ElementFactory.make("wavenc", "wav_enc");
71+
filesink = Gst.ElementFactory.make("filesink", "file_sink");
72+
pipeline = Gst.Pipeline.new("audio_capture_stream");
73+
74+
if not pipeline or not alsasrc or not capsfilter or not wavenc or not filesink:
75+
print("Create pipeline/alsasrc/capsfilter/wavenc/filesink element failed.")
76+
sys.exit(1)
77+
78+
#set properties to the elements
79+
alsasrc.set_property("device","hw:0,0")
80+
alsasrc.set_property("num-buffers",1000)
81+
alsasrc.set_property("buffer-time",10000)
82+
caps=Gst.Caps.new_empty_simple("audio/x-raw")
83+
capsfilter.set_property("caps",caps)
84+
filesink.set_property("location",content)
85+
86+
#Build the pipeline. Add elements to the pipeline and link them
87+
pipeline.add(alsasrc)
88+
pipeline.add(capsfilter)
89+
pipeline.add(wavenc)
90+
pipeline.add(filesink)
91+
92+
if not alsasrc.link(capsfilter):
93+
print("ERROR: Could not link alsasrc to capsfilter")
94+
sys.exit(1)
95+
if not capsfilter.link(wavenc):
96+
print("ERROR: Could not link capsfilter to wavenc")
97+
sys.exit(1)
98+
if not wavenc.link(filesink):
99+
print("ERROR: Could not link wavenc to filesink")
100+
sys.exit(1)
101+
102+
pipeline.set_state(Gst.State.PLAYING)
103+
print("Start");
104+
105+
bus = pipeline.get_bus()
106+
bus_id = bus.add_signal_watch()
107+
msg = bus.timed_pop_filtered(Gst.CLOCK_TIME_NONE,Gst.MessageType.ERROR | Gst.MessageType.EOS)
108+
if msg:
109+
t = msg.type
110+
if t == Gst.MessageType.ERROR:
111+
err, dbg = msg.parse_error()
112+
print("ERROR:", msg.src.get_name(), ":", err.message)
113+
if dbg:
114+
print("debugging info:", dbg)
115+
elif t == Gst.MessageType.EOS:
116+
print("Stop end-Of-Stream reached")
117+
else:
118+
print("ERROR: Unexpected message received.")
119+
120+
pipeline.set_state(Gst.State.NULL)
121+
Gst.Object.unref(bus)
122+
Gst.deinit()
123+
sys.exit(1)
124+
125+
126+
def main():
127+
Gst.init(sys.argv)
128+
if len(sys.argv) < 2:
129+
print("Missing <output-location> parameter")
130+
sys.exit(1)
131+
else:
132+
if (sys.argv[1]=="playback"):
133+
gst_sample_playback(sys.argv[2]);
134+
elif(sys.argv[1]=="capture"):
135+
gst_sample_capture(sys.argv[2]);
136+
else:
137+
print("Unexpected operation %s", sys.argv[1]);
138+
139+
140+
if __name__ == "__main__":
141+
main()
30.3 KB
Loading
33.1 KB
Loading
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Graphical User Interface Application
2+
3+
This sample shows a gui application which demonstrates camera display, camera recording, and mp4 playback.
4+
5+
6+
## Prerequisite on RB5
7+
8+
- Make sure to check python version.PyQt will require python 3.6 or above
9+
```bash
10+
python --version
11+
```
12+
- Installing python dev tools & PyQt library
13+
```bash
14+
apt-get install python3-dev
15+
apt-get install python-qt5
16+
```
17+
- Installing PyQt5 & PyQt5-tools
18+
```bash
19+
pip install pyqt5
20+
pip install pyqt5-tools
21+
```
22+
- Setting the Display variables
23+
24+
```bash
25+
export QT_QPA_PLATFORM=wayland
26+
```
27+
28+
29+
## GUI Application
30+
31+
### Launch ```gui_app```
32+
33+
+ Connect the board to screen through HDMI output
34+
+ Connect keyboard and mouse to the board
35+
```bash
36+
python3 gui_app.py
37+
```
38+
39+
40+
## Snapshot
41+
42+
![Iamge text](image/gui-app-snapshot.png)
43+
44+
## Settings
45+
46+
### Camera Settings
47+
48+
Camera settings set camera parameters for display and recording.
49+
50+
+ Camera ID (0~4)
51+
+ Resolution: width and height
52+
+ Framerate
53+
54+
### Transform Settings
55+
56+
Transform settings set transform parameters for display only.
57+
58+
+ Flip: horizontal or vertical
59+
+ Rotate: 90CW, 90CCW, and 180
60+
+ Crop: x, y, width, height
61+
62+
### View Settings
63+
64+
View settings set view parameters for display and playback.
65+
66+
+ Fullscreen
67+
+ Location: x, y
68+
+ Size: width and height
69+
70+
71+
## Operations
72+
73+
There are 3 operations in this application.
74+
75+
### Display
76+
77+
+ Click ```Display``` button. Camera view will display on the screen.
78+
79+
+ Click ```Stop``` to stop display.
80+
81+
### Record
82+
83+
+ Click ```Record``` button. A file dialog will popup to specify the mp4 file name to be saved. Then recording will start. The camera view will also display on the screen.
84+
85+
+ Click ```Stop``` to stop recording.
86+
87+
### Playback
88+
89+
+ Click ```Playback``` button. A file dialog will popup to specify the mp4 file name to playback. Then playback will start.
90+
91+
+ Click ```Stop``` to stop playback.
92+

0 commit comments

Comments
 (0)