March 11, 2014
Audio volume and mute per window object

I have finally found some time to finish a set of patches about a nice feature that will allow addon/firefox developers to control audio volumes for window object.

Through this new feature any window object has two new attributes: audioMuted and audioVolume (accessible from chrome code only using nsIDOMWindowUtils). The aim is to change the volume of any HTML5 media element and any WebAudio destination node (soon WebRTC and also FMRadio API). The control of the volumes works “on cascade” - if a window has an iframe, the iframe elements will be effected by the parent window audio attributes.

The code is just landed on m-c and it will be available on nightly in a few hours.

Also, in order to test this feature I wrote an addon. As you could see, the UI is not the best… I know, but it was just a proof of concept, I’m sure somebody else will do a better work! Download the addon.

This feature is currently disabled by default, but it’s easy to enable it by changing or creating a preference in about:config. Some instructions to do it: open ‘about:config’ in a new tab and add a new boolean preference called ‘media.useAudioChannelService' and set it to true. This property will enable the AudioChannelService for any HTMLMediaElement and any WebAudio destination node.

AudioChannelService is the audio policy controller of Firefox OS. You will know once you use it, that the AudioChannelService is enabled when, while changing tabs, media elements of invisible tabs will be muted. From now on, you can use the addon.

The addon UI can be open from Tools -> Web Developers -> Audio Test.

Here a screenshot:

AudioTest addon

From a code point of view, you can play with this audio feature from the nsIDOMWindowUtils interface. For instance:

var currentBrowser = tabbrowser.getBrowserAtIndex(0 /* an index */);
var utils = currentBrowser.contentWindow
                          .QueryInterface(Ci.nsIInterfaceRequestor)
                          .getInterface(Ci.nsIDOMWindowUtils);
dump("The default audioVolume should be 1.0: " + utils.audioVolume + "\n");
utils.audioVolume = 0.8;
dump("By default the window is not muted: " + utils.audioMuted + "\n");
utils.audioMuted = true;

(More info about tabbrowser object can be read from this page)

There is also a notification that is dispatched when a window starts and stops playing audio: media-playback. The value of this notification can be active or inactive. If you are interested about how to use them, there are a couple of tests on bug 923247.

What can we do with this new feature? Here some ideas:

  • we could change or animate the tab icon to let the users know which tab is playing.
  • addons to mix audio between tabs
  • advanced settings for disable audio by default - either to enable audio just for the visible tab or to specific origins, etc.
  • other options, such as “disable audio for all the tabs but this one” in some context menu.

Please, use this feature and let me know if you have problems, new ideas or needs. Good hack!

October 4, 2013
DataStore API

DataStore has landed. This new API has been written to share data between different applications.

The idea behind it aims to have apps with a set of DataStores, to store data into them and to let other apps access this data when the former app is not running.

DataStores have revisions. Those revisions can be used to synchronize apps and retrieve what is changed while an app was not active. All this process is protected by permissions and security checks. At the moment, it’s meant to be only for Firefox OS.

I do not wish to write too much about it, especially because I don’t want to duplicate the wonderful documentation I and the WebAPI team wrote here: https://wiki.mozilla.org/WebAPI/DataStore

However, if you are a b2g developer and you want to share data with other apps (contacts? bootmarks? weather reports?) - this API is for you.

If you want to see how DataStore API evolves, there is a meta-bug on bugzilla: Bug 916089.

January 14, 2013
BXR - my implementation of mxr

I would like to share with you a new tool, which was written over the weekend: bxr.

This tool implements a subset of the functionalities of mxr.mozilla.org using a local database and it can be used as a standalone application or combined with vim.

This is how I use it:

$ cd ~/Sources/m/central # this is a checkout of mozilla-central
$ bxr create .

With this command, bxr indexes the source tree and creates the database (.bxr.db). This operation should be done each time the tree is updated. It takes about 25 minutes.

Then, for searching, just type:

$ bxr identify nsIDOMFile

Result for: nsIDOMFile

File: ./content/base/public/nsDOMFile.h
Line: 37 -> class nsDOMFileBase : public nsIDOMFile,

File: ./ipc/glue/InputStreamUtils.cpp
Line: 14 -> #include "nsIDOMFile.h"
....

At the moment BXR can be used to:

  • identify, to search for the definitions of particular functions, variables, etc.
  • search, to search in the source code.
  • file, to find files whose name matches a pattern

I love working with this tool alongside vim using a plugin. This allows me to do:

:BI nsIDOMFile
:BF ArchiveReader
:BS ArchiveReader::V

This app is just an experiment. I am still working on it. What I want to do is to reduce the size of the database (right now 800~Mb are required for indexing mozilla-central…). I hope to have something stable and usable soon!

October 4, 2012
Transferable objects for FF

A short introduction: if you want to send data to/from a Web Worker, you have to use postMessage() method. Internally what happens is that the data is duplicated using the structured cloned algorithm and then the copy is sent.

To make this sharing faster, HTML5 specs add a new concept: transferable objects, data is transferred from one context to another without copy. Note: data is no longer available once transferred to the new context. Right now we can transfer just ArrayBuffers, but maybe in the future we will support other data types.

I wrote this patch (Bug 720083) and it will be available in the nightly build soon. Here a demo/benchmark app: demo. Here another one: demo2.

Have fun!

August 18, 2012
Archive API for DOM Blob!

I’m glad to present my first DOM API: The ArchiveReader. This new object allows to open ZIP files and read the content from javascript. Here the webIDL:

interface ArchiveRequest : DOMRequest
{
  [infallible]
  readonly attribute ArchiveReader reader;

  // In case of a getFilenames() request, the result is an array of DOMString
  // In case of a getFile() request, the result is a DOM File
}

[Constructor(Blob blob)]
interface ArchiveReader
{
  ArchiveRequest getFilenames();
  ArchiveRequest getFile(DOMString filename);
};

Ok, maybe this is not clear enough… an example is better: archivereader_example.html (keep in mind that this is a new API and it is just landed in the latest firefox nightly build so probably it won’t work with your browser).

The use of this API is extremely simple: * Create a new ArchiveReader starting from a DOM blob or a DOM file. * Use getFile() or getFilenames(). The return value of these two methods is an ArchiveRequest object.

Note: This API is completely asynchronous.

var blob = ...;
var reader = ArchiveReader(blob);

// how to extract the list of files contained in the archive:
var h = reader.getFilenames();
h.onerror = function() { ... }
h.onsuccess = function() {
  for (var i = 0; i < this.result.length; ++i) {
    something(this.result[i]); // this.result[i] is a DOMString
  }
}

// how to extract a specific file:
var hf = reader.getFile('image.png');
hf.onerror = function() { ... }
hf.onsuccess = function() {
  // this.result is a DOM File
  alert('Filename: ' + this.result.name + '\n' +
        'ContentType: ' + this.result.type + '\n' +
        'Size: ' + this.result.size);
}

The result of a getFile() is a DOM File and it can be used in many ways: FileReader, ArchiveReader, window.URL, etc. Read the example to see how to show images and plain/text files.

Note: this API is a draft. Any update will be posted on https://wiki.mozilla.org/WebAPI/ArchiveAPI

10:34pm  |   URL: http://tmblr.co/ZN3mauRh240a
Filed under: mozilla API 
August 6, 2012
MXR, a command-line tool for mxr.mozilla.org

My fist post is about a tool that I wrote last weekend. It’s a command-line interface for MXR website (Mozilla Cross-Reference) written in Ruby. Here the code: https://github.com/bakulf/mxr

I love MXR and I think it’s an extremely important resource for all the mozillian’ developers. It is a useful web application, however sometimes it’s preferable to have a command-line interface when using a terminal and working on a piece of code.

Here the list of features:

  • it supports any feature of the MXR website: identify, search, file, browse
  • it works in shell mode too.
  • It colourizes the output (-c option)
  • It guesses the right operation to do (it means that you can write ‘identify’ or ‘ident’, or ‘ide’ or ‘i’)
  • In shell mode it offers an easy way to browse the source code using the ID shown by the previous command. Example:
mxr> i nsIDOMFile
Result for: nsIDOMFile

File: (0) content/base/public/nsIDOMFile.idl
Line: (1) 65 -> interface nsIDOMFile : nsIDOMBlob   
    
File: (2) content/base/src/nsFormData.h
Line: (3) 14 -> class nsIDOMFile;  
...
mxr> b 1

…and the file nsIDOMFile.idl line 65 will be shown.

That’s it. It works on my machine and I’m happy with it. Patches are appreciated :)

5:04pm  |   URL: http://tmblr.co/ZN3mauQt1o_X
Filed under: mozilla ruby 
Liked posts on Tumblr: More liked posts »