Category Archives: ubuntu

Kivy and vite-vite

Note to self: Use Kivy (Open source Python library for rapid development of applications for multiple platforms) and vite-vite (Toolkit for building business and productivity apps on Android using the Kivy framework) for next prototype.

Livestream webcam via webm to browsers

Here’s a work in progress: livestream webcam video to browsers using Node.js. From here. Ubuntu requires the ‘nodejs’ executable instead of just ‘node’

var express = require('express')
var net = require('net');
var child = require('child_process');

var cmd = 'gst-launch-0.10';
var args = '';
var options = null;

var app = express();

app.get('/', function(req, res) {
  var date = new Date();

  res.writeHead(200, {
    'Date':date.toUTCString(),
    'Connection':'close',
    'Cache-Control':'private',
    'Content-Type':'video/webm',
    'Server':'CustomStreamer/0.0.1',
    });

  var server = net.createServer(function (socket) {
    socket.on('data', function (data) {
      res.write(data);
    });
    socket.on('close', function(had_error) {
      res.end();
    });
  });

  server.maxConnections = 1;

  server.listen(function() {
    args =
    ['v4l2src device=/dev/video0',
    '!', 'video/x-raw-rgb,framerate=30/1',
    '!', 'ffmpegcolorspace',
    '!', 'vp8enc', 'speed=2',
    '!', 'queue2',
    '!', 'm.', 'audiotestsrc', 'is-live=1',
    '!', 'audioconvert',
    '!', 'vorbisenc',
    '!', 'queue2',
    '!', 'm.', 'webmmux', 'name=m', 'streamable=true',
    '!', 'tcpclientsink', 'host=localhost',
    'port='+server.address().port];

    var gstMuxer = child.spawn(cmd, args, options);

    gstMuxer.stderr.on('data', onSpawnError);
    gstMuxer.on('exit', onSpawnExit);

    res.connection.on('close', function() {
      gstMuxer.kill();
    });
  });
});

app.listen(9001);

function onSpawnError(data) {
  console.log(data.toString());
}

function onSpawnExit(code) {
  if (code != null) {
    console.error('GStreamer error, exit code ' + code);
  }
}

process.on('uncaughtException', function(err) {
  console.debug(err);
});

USB/IP under Ubuntu

USB/IP is a general USB device sharing system over IP network. Unfortunately, on newer  Ubuntu’s the usb/ip device driver isn’t compatible with the userspace tools. Here’s how to fix this on Ubuntu 12.10 (and probably some older versions).

Grab Linard Verstraete’s script from launchpad. Change the last line from

sudo ln -s /usr/local/lib/libusbip.so.0 /usr/lib/libusbip.so.0.0.1

to

sudo ln -s /usr/local/lib/libusbip.so.0 /usr/lib/libusbip.so.0

and run the script. You now have a compatible device driver and userspace tool. Install on both client and server and check the run instructions from the kernel source. Good luck – I couldn’t get it to work correctly but I did want to share these tips! Drop a note in the comments if you’re more successful.