summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2017-04-26 11:19:05 +0200
committerJonas Smedegaard <dr@jones.dk>2017-04-26 11:19:05 +0200
commitb87b680ca361322d1066ecf40216a60a77e50699 (patch)
tree0e7a077fef85e0c934d4f0f9ae8536c4213fd4a8 /bin
parent0b40abd0a7bedf1ad2d81fc700e9ff17df55b59c (diff)
Tidy.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/capture+encode+serve62
1 files changed, 38 insertions, 24 deletions
diff --git a/bin/capture+encode+serve b/bin/capture+encode+serve
index 1d9f469..c545d45 100755
--- a/bin/capture+encode+serve
+++ b/bin/capture+encode+serve
@@ -15,24 +15,27 @@ use IPC::System::Simple qw(capturex);
BEGIN {
Glib::Object::Introspection->setup(
basename => 'Gst',
- version => '1.0',
- package => 'Gst',
+ version => '1.0',
+ package => 'Gst',
);
Glib::Object::Introspection->setup(
basename => 'GstRtspServer',
- version => '1.0',
- package => 'Gst',
+ version => '1.0',
+ package => 'Gst',
);
}
-my $ADDRESS = shift || $ENV{'ADDRESS'} || '127.0.0.1';
-my $PORT = shift || $ENV{'PORT'} || '8554';
+my $ADDRESS = shift || $ENV{'ADDRESS'} || '127.0.0.1';
+my $PORT = shift || $ENV{'PORT'} || '8554';
my $VDEVICES = shift || $ENV{'VDEVICES'} || '';
my $ADEVICES = shift || $ENV{'ADEVICES'} || '';
my $VFORMAT = shift || $ENV{'VFORMAT'} || 'VP8'; # H264 VP8 RAW - default: VP8
-my $AFORMAT = shift || $ENV{'AFORMAT'} || 'OPUS'; # AMR OPUS RAW - default: OPUS
+my $AFORMAT
+ = shift || $ENV{'AFORMAT'} || 'OPUS'; # AMR OPUS RAW - default: OPUS
+
+my @VDEVICES = $VDEVICES ? split ' ', $VDEVICES : sort split ' ',
+ capturex( 'find', qw(/dev -maxdepth 1 -type c -name video*) );
-my @VDEVICES = $VDEVICES ? split ' ', $VDEVICES : sort split ' ', capturex('find', qw(/dev -maxdepth 1 -type c -name video*));
# FIXME: Detect/blacklist and skip faulty devices
#my @ADEVICES = grep { /^hw:/ } capturex( 'arecord', qw(-L) );
my @ADEVICES = split ' ', $ADEVICES;
@@ -40,7 +43,7 @@ chomp @ADEVICES;
#use Data::Dump; die dd @ADEVICES;
-my $HEIGHT = 240;
+my $HEIGHT = 240;
my $FRAMERATE = 25;
my $AUDIORATE = 48000;
@@ -58,11 +61,14 @@ my $QUEUE = "queue max-size-bytes=100000000 max-size-time=0";
my %VFORMAT = (
H264 => {
- # * let x264 use low-latency sliced-threads (i.e. don't disable treads)
- VENC => "x264enc speed-preset=ultrafast tune=zerolatency bitrate=800 byte-stream=true key-int-max=15 intra-refresh=true option-string=\"slice-max-size=8192:vbv-maxrate=80:vbv-bufsize=10\" ! video/x-h264,profile=baseline ! $QUEUE ! rtph264pay",
+
+ # * let x264 use low-latency sliced-threads (i.e. don't disable treads)
+ VENC =>
+ "x264enc speed-preset=ultrafast tune=zerolatency bitrate=800 byte-stream=true key-int-max=15 intra-refresh=true option-string=\"slice-max-size=8192:vbv-maxrate=80:vbv-bufsize=10\" ! video/x-h264,profile=baseline ! $QUEUE ! rtph264pay",
},
VP8 => {
- VENC => "vp8enc threads=4 cpu-used=15 deadline=1000000 end-usage=1 target-bitrate=$VBITRATE undershoot=95 keyframe-max-dist=999999 max-quantizer=56 deadline=5000 static-threshold=500 ! video/x-vp8 ! $QUEUE ! rtpvp8pay",
+ VENC =>
+ "vp8enc threads=4 cpu-used=15 deadline=1000000 end-usage=1 target-bitrate=$VBITRATE undershoot=95 keyframe-max-dist=999999 max-quantizer=56 deadline=5000 static-threshold=500 ! video/x-vp8 ! $QUEUE ! rtpvp8pay",
},
RAW => {
VENC => "rtpvrawpay",
@@ -83,34 +89,42 @@ my %AFORMAT = (
our $nextpayload = 0;
-sub cam {
- my $device = shift;
+sub cam
+{
+ my $device = shift;
my $payload = "pay" . $nextpayload++;
my $factory = Gst::RTSPMediaFactory->new();
- $factory->set_launch("( v4l2src device=$device ! $QUEUE ! videoconvert ! $VCAPS ! $QUEUE ! $VFORMAT{$VFORMAT}{'VENC'} name=$payload )");
+ $factory->set_launch(
+ "( v4l2src device=$device ! $QUEUE ! videoconvert ! $VCAPS ! $QUEUE ! $VFORMAT{$VFORMAT}{'VENC'} name=$payload )"
+ );
$factory->set_shared(TRUE);
-say "media ($device): " . $factory->get_launch();
+ say "media ($device): " . $factory->get_launch();
+
# $factory->set_latency(5);
#say "latency ($device): " . $factory->get_latency();
return $factory;
}
-sub mic {
- my $device = shift;
+sub mic
+{
+ my $device = shift;
my $payload = "pay" . $nextpayload++;
my $factory = Gst::RTSPMediaFactory->new();
- $factory->set_launch("( alsasrc device=$device buffer-time=$ABUFFERS ! $QUEUE ! audioconvert ! $QUEUE ! $AFORMAT{$AFORMAT}{'AENC'} name=$payload )");
+ $factory->set_launch(
+ "( alsasrc device=$device buffer-time=$ABUFFERS ! $QUEUE ! audioconvert ! $QUEUE ! $AFORMAT{$AFORMAT}{'AENC'} name=$payload )"
+ );
$factory->set_shared(TRUE);
+
#say "media ($device): " . $factory->get_launch();
# $factory->set_latency(5);
#say "latency ($device): " . $factory->get_latency();
return $factory;
}
-Gst::init([ $0, @ARGV ]);
+Gst::init( [ $0, @ARGV ] );
my $loop = Glib::MainLoop->new( undef, FALSE );
# create a server instance
@@ -126,14 +140,14 @@ my $mounts = $server->get_mount_points();
my @mounts;
for my $i ( 0 .. $#VDEVICES ) {
my $mount = "/cam$i";
- $mounts->add_factory($mount, cam($VDEVICES[$i]));
+ $mounts->add_factory( $mount, cam( $VDEVICES[$i] ) );
push @mounts, $mount;
-};
+}
for my $i ( 0 .. $#ADEVICES ) {
my $mount = "/mic$i";
- $mounts->add_factory($mount, mic($ADEVICES[$i]));
+ $mounts->add_factory( $mount, mic( $ADEVICES[$i] ) );
push @mounts, $mount;
-};
+}
# don't need the ref to the mapper anymore
undef $mounts;