Hearing Sound from Firefox Using Bluetooth Headphones in FreeBSD

I’ve gotten myself Bluetooth Headphones and a USB Bluetooth dongles, and I want to hear sounds through my new headphones.

Since the headphones are a Bluetooth device, they should be discovered and paired. In the famous manual, FreeBSD Handbook , there are two sections in which to find instructions on Bluetooth and sound:

  • 33.5 Bluetooth – in chapter 33 – Advanced Networking.
    There is also a useful utility named bluetooth-config you can use to create or modify the files ‘/etc/bluetooth/hcsecd.conf.; and ‘/etc/bluetooth/hosts
  • 8.2.3. Setting up Bluetooth Sound Devices – in chapter 8 – Multimedia

Having configured Bluetooth and installed virtual_oss. All you have to do each time you want to listen through your Bluetooth headphones is to run the following commands replacing BT_ADDR by your device name:

  1. hccontrol -n ubt0hci create_onnection BT_ADDR
  2. virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 768 -R /dev/null -P /dev/bluetooth/BT_ADDR -d dsp

Now, if you use VLC to listen to audio, all you have to do is select the ‘dsp’ output device. But, if you want to hear the sounds plyed by Firefox, you should have to add a module to PulseAudio. I haven’t found any Bluetooth modules I can install on my FreeBSD, but have found that module-sndio can do the job for me,, to add it, run the command:

pkg install pulseaudio-module-sndio

And add the following line to ‘/usr/local/etc/pulse/default.pa

load-module module-sndio device=snd/0

To start the service sndio at boot time, add the following line to ‘/etc/rc.conf‘:

sndiod_enable="YES"

To hear sounds from the Firefox browser, make sure PulseAudio stream it to ‘/snd/0‘ My display manager is XFCE4, and I use the plugin ‘xfce4-pulseaudio-plugin’ to view my output devices. In the following image, you can see that firefox sounds are streamed to that device:

Now, if everythiing is set correctly, but you cannot hear the sound, type the follwing shell command as a regular user:

pulseaudio --kill

Rotate Your Movie

I have received by e-mail a rotated video in the ‘flv’ format. The video was supposed to be a vertical one, but it turned out to be horizontal, that is ROTATED. So, I wrote a little program to rotate it back using libming.
There are two things to take care of when processing the input FLV:

  • The video stream.
  • The sound stream.

Both can be taken from the FLV file.
The code is written in C++, but can be translated easily into PHP. Following is the code:

#include <iostream>
#include <mingpp.h>

using namespace std;

int main(){
  const char *flvFile ="/path/to/inputVideoFile.flv";

  // Get the video stream from the file. The input file can be in the FLV format.
  SWFVideoStream *stream = new SWFVideoStream(flvFile);

  SWFMovie mov (9);  // Create the movie object.

  // The method 'add' returns a display item.
  // Display items can be rotated, transformed, etc.
  SWFDisplayItem *di=mov.add(stream);  

  // Sound streams are taken from a file object. 
  FILE *soundFD = fopen(flvFile, "rb+");
  SWFSoundStream sound(soundFD);

  // The original dimensions of the video are 426 X 240.
  di->rotate(-90);  // Rotate the item 90 degrees clockwise
  di->move(240, 0);  // The rotation moves point (0,240) to (-240,0).


  mov.setSoundStream(&sound,0);  // Add the sound stream at the beginning
                                 // of the movie.

  // Show the frames one by one.
  int noFrames = stream->getNumFrames();
  for (int i=0; i<noFrames; i++)
      mov.nextFrame();

  mov.setDimension(240, 426); // The new dimensions.
  mov.save("/path/to/outputVideoFile.swf", 9);
  cerr<<"Fin\n";
  return 0;
}

This will create a real vertical movie. Don’t share it on YouTube or anywhere you cannot control your movie dimensions.