sync two processes at some system call - linux

Is it possible to synchronize two linux processes at some system calls without modifying their code?
A real world example: v4l2-ctl is a tool that can be used to set certain controls of a web camera. After running it to set some controls, ffmpeg is used to capture a movie with the camera. However, setting only some controls on it's own and resetting some other, ffmpeg ruins the careful adjustments made by v4l2-ctl.
Now it would be useful to remedy this problem without having to modify and rebuilt one or both of this tools. This would be possible if ffmpeg could be started, but would be suspended after it opened and configured /dev/video0 (most likely some ioctls happened) and v4l2-ctl would be invoked then to apply the settings. After that, ffmpeg would be resumed and start capturing with the right settings in place.
Is this possible to track one processes io operations and suspend it on some by easy means?

If you're feeling adventurous and don't mind the performance hit of using a debug-compiled ffmpeg, you could conceivably start it under gdb and set a breakpoint after opening /dev/video0 (or anywhere else. You'll need the source either way.)
You could then run the binary until it hits the breakpoint, tweak v4l2-ctl and then tell ffmpeg to continue past the breakpoint.

Related

Raspbian hangs in qemu

i'm running raspbian (2015-05-05-raspbian-wheezy.img) in qemu using compiled kernel (https://github.com/dhruvvyas90/qemu-rpi-kernel) on ubuntu 14.04. my final goal is to launch my python script within the emulation.
i'm following manual from http://www.unixmen.com/emulating-raspbian-using-qemu/, though many others suggest very similar sequence of actions.
things i'm trying and issues i'm experiencing:
first boot is more or less ok. i comment the line in /etc/ld.so.preload as suggested and reboot.
on second boot (after i remove init=/bin/bash) and all subsequent boots i get
ERROR ../libkmod/libkmod.c:554 kmod_search_moddep: could not open moddep file '/lib/modules/3.10.25/modules.dep.bin'
some googling suggested to run "sudo rpi-update". it didn't help, same message during boot.
on second boot (after i remove init=/bin/bash) and all subsequent boots i get
fsck died with exit status 6
looking into "/var/log/fsck/checkfs" as suggested tells that some location is not there, but it doesn't say which one
running "startx" produces error message from 1. it loads the UI eventually, but desktop only has "wastebasket" icon. there is also a thick white stripe on top of the screen blinking, like it keeps trying to load a tab but fails everytime. qemu window stops to respond to further interaction after this.
running "sudo apt-get upgrade" installs some packages, but after reboot i can't even get to UI - just blank screen with mouse cursor.
i'm not very experienced with how linux is configured at low level. i understand that i might be doing something completely stoopid.
so, my questions are:
how do i debug? i couldn't figure out the settings for qemu to write logs. i really don't want to fallback to gdb, as i'm not debugging qemu itself, just want to get notification on it's events.
ctrl key doesn't seem to work inside qemu window.
no copy-paste available. or i can't see how to turn it on.
am i missing something? from all the manuals i have seen it seems like this should go much much smoother. like it should "just work".
Since your post many things changed. The most important things is that now using Andrew Baumann GitHub repo you can build QEMU that boots recent Raspbian. I described my experience woth this code here. Instructions are straight forward. Implementation needs polishing but it best compilation of work so far.
To answer your questions:
QEMU have -s and -S options for GDB. First option setup gdb server hook and second freez CPU, so you can connect debugger. This is not for QEMU debugging this for guest system debugging. Default QEMU logging is to stderr, so if something valuable happen you will see it in terminal. You can raise QEMU verbosity by uncommenting various *DEBUG_ statements in source code. Also check help for -d and -D command line flags of QEMU.
Not sure I can help with this. Only thing that I can say is that my QEMU version 2.5.50 reacts to Ctrl+Alt which exits from GUI after capturing cursor, so it looks like QEMU understand Ctrl key. I assume that QEMU do not capture your special keys combination because your window manager do it before passing to QEMU.
This also not work for me, but I see some work was done in this area. Not sure how to enable and use that feature.
Emulating any hardware is very complex and requires a lot of work. All emulated targets are limited to some most important features. BCM2835/BCM2836 (Raspberry Pi/Raspberry Pi 2) SoC are still not accepted by mainline QEMU, so just work will not apply to those platforms.

Upgrading audio code to new WASAPI standard

We have an application that uses waveXXX() and mixerXXX() functions to handle the audio I/O to and from some instruments (think: oscilloscope or electronics rather than musical instruments, not that it much matters). It's finally time to stop deploying it on Windows XP, and move it to Windows 7 and/or 8.
From reading a variety of material on WASAPI, it sounds like the bulk of the application (based on waveXXX() functions) might actually work fine, but the mixer() stuff used to set master output volume, line in volume, and mute the microphone will definitely have to change, and use IAudioEndPointVolume calls instead.
Is it possible to change only the mixerXXX() calls? Is it desirable?
Logically, this application requires exclusive use of its audio endpoints (speaker out, line in). If I want to ensure exclusive access through software, would that force me to rewrite all the waveXXX() code too? (The alternative is to warn users that other audio applications may interfere with this one).
My recommendation:
If you need exclusive access, convert everything to WASAPI
If you are using line-in, convert everything to WASAPI
If you have time, convert everything to WASAPI
If you are strictly only using speaker and microphone in shared mode, replace mixerXXX() with the ISimpleAudioVolume interface (and several other interfaces to get to it), then test whether existing waveXXX() code behaves as you need it to. Then test each time hardware, OS or audio drivers change. Better still, just convert to WASAPI.
In my case, exclusive speaker output is critical - this drives the instrument that generates a related input signal. I guess I don't mind if another application wants to share access to that incoming signal, but logically it is a system that wants an exclusive contract with its audio endpoints.
That exclusivity requires that I obtain an IMMDevice instance for both speaker output and line-in input, Activate() the IAudioClient interface on them and Initialize() both using AUDCLNT_SHAREMODE_EXCLUSIVE (see also this answer).
But have I actually selected line-in by such a process? Probably not. All I can be sure of is annoying any other applications who were previously sharing my endpoints by cutting them off.
Having done this much, it's really not clear what will happen to waveInXXX() calls - maybe they'll take from line-in, maybe from microphone - maybe it depends on how the hardware vendor implements their end of the deal. It's also never been clear to me whether line-in and microphone are always multiplexed (i.e. selectable), always mixed (i.e. you can only simulate selection by muting the other one) or there is no standard one can rely on.
Because of factors like that, it's a gamble not to use WASAPI throughout.

Changing camera exposure on frame by frame basis

Is it possible to change exposure of a webcam on a frame-to-frame basis, with proper synchronization. My operating system is Ubuntu 14.04. Webcam - Logitech HD Pro 920
I know for sure that it's not possible with OpenCV.
And certainly it would also depend upon the webcam being used.
What I need is a callback mechanism which notifies me when the setting of exposure change has taken effect. And also, to be able to synchronize the exposure change setting command at the correct frame boundaries (just in case this is required to be done by the user).
I assume something like using V4L2 would be my best bet?
Kindly guide me.
You can use v4l2-ctl terminal commands or OpenCV to do this.
In OpenCV you can use this function:
VideoCapture.set(CV_CAP_PROP_EXPOSURE,value);
In a linux terminal you can use:
v4l2-ctl --set-ctrl=exposure_absolute=value --device=/dev/video1
For both ways you can use the get command in a similar way to see the current setting

Capturing Global Keyboard Events On Linux With NodeJS

I have a headless Debian ARM machine that I'm running Node on. The device has hard buttons that are mapped to normal keyboard events using gpio-keys.
My goal is to capture the global events from both the hard buttons as well as any attached keyboards in Node. I need a solution that can capture the keydown/keyup events independently of the terminal that it's run in (it will be run over an SSH session). It doesn't have to be cross-platform, as long as it works on ARM Debian I'll accept it.
I am imagining something reading directly from whatever sysfs attributes are necessary, but that's not a requirement.
Can anyone help me on this? I've been stuck for a while.
One of the device files /dev/input/event* will represent the gpio-keys device. You can figure out which one in a number of ways; one easy one is to look at the contents of the uevent file for the device, e.g. /sys/class/input/event0/device/uevent. It'll contain a number of useful key-value properties.
Once you've figured out which device you want, you can open and read from it. It'll return a stream of struct input_events, as defined in <linux/input.h>. These events will correspond to presses and releases for each of your buttons.
You may also want to take a look for existing solutions for at least part of the problem, such as node-keyboard: https://github.com/Bornholm/node-keyboard

Is it possible to record audio to variable/RAM in LiveCode?

Is it possible to record audio to a variable/RAM in LiveCode?
Normal recording requires to use a file, but I'm trying to figure out a way to not have to use the extra step of writing to disk, only to then read it from disk and send through sockets.
This is currently impossible and there is no good way to stream content from within LiveCode. When I tried to use video recording and sockets at the same time, I ran into a bug that caused LiveCode (Revolution at the time) to crash. Looking into the crash files, it appeared to me that using the recording routines and the socket routines at the same time caused a memory address conflict. After sending roughly 1000 recorded frames through a socket, Revolution would inevitably crash. To my best knowledge, this problem has never been fixed.
I would recommend dedicated software for streaming. A possibility might be VLC. You can use VLC from the command line, which means that you can set up a stream from within LiveCode, using the shell() function.

Resources