On Thu, Nov 24, 2011 at 10:51 AM, Ben Francis <
b...@krellian.com> wrote:
> Hi there,
>
> In the last WebAPI meeting we discussed options for the storage of media
> like photographs and reservations were made about implementing the W3C's File
> <goog_1445904292>API: Directories and
> System<
http://www.w3.org/TR/file-system-api/>[1]
> specification.
>
> Instead it was suggested that maybe a multimedia storage API could be
> developed, specifically for storing images, audio and video.
>
> Having looked into this a little further I came across a W3C editors draft
> called The Gallery API <
http://dev.w3.org/2009/dap/gallery/>[2]. I was
> wondering whether anyone is familiar with this work?
>
> Just as a reminder, the use cases which triggered this discussion are:
>
> 1. Locally storing photographs in such a way that they can be accessed
> from multiple web apps
> 2. Mounting the stored photographs as a file system, where the user
> agent device (e.g. a smartphone) acts as a USB mass storage device plugged
> into a USB host (e.g. a desktop PC), or a memory card is taken from the
> device and placed in a memory card reader to be plugged into a host device
> (e.g. a desktop PC)
> 3. Accessing media stored on external storage (e.g. where the user agent
> device is a desktop PC and a USB flash drive is plugged in)
Sweet! This matches exactly the use-cases I have had in mind (not
entirely surprisingly since much of my thinking was set off by you
bringing it up on the above mentioned call :) ).
On the API-side, I think we can cover all above use cases using two APIs:
1. An API for reading and writing media files to a central storage
area on the device.
For image/video files this is pretty easy. The set of files store is
basically just a straight list of File objects. To save a file the
page would provide a Blob object, we'd slap a unique name and the
current time on it and store it. (Note that the current File
implementation in Gecko doesn't allow accessing the lastModifiedDate,
but that's easily fixed). When reading, the page can use asynchronous
APIs to retrieve a list of File objects.
Remaining metadata, such as EXIF, video length, etc, can be retrieved
from the Blob itself.
For things like music libraries we *might* be able to get away with
something even as simple as this. Most music files comes with a fair
amount of meta-data, such as artist, song name, album name, album
cover-picture, etc. Technically this data can usually be read from the
music file itself, but I'm not sure if that will produce good enough
performance. So maybe we'll need something more advanced for the music
library. In any case I suspect we'll want to keep the music library
separate from for example media files that the user creates since they
are synched differently (you don't want to move your music files to
your desktop computer, you want to copy it there).
2. An API for retrieving a list of File objects that exist on an
external device, such as a memory card, or USB mass storage.
This API can be used to read data from a phone which is connected
through USB, as well as from memory cards which have been moved from a
camera and inserted into the device (the latter is especially common
for laptops or desktops).
Additionally this API likely needs a way to delete selected files from
the memory card/USB storage.
Each File object will contain their full path, so if the pathname
happens to be meaningfull the webapp can get to it, but for the common
case when it's not, the webapp doesn't need to care about it.
Implementation-wise, the first API would likely write to some
dedicated directory structure which follows the DCIM [1] standard.
We'd then expose this directory whenever the device was plugged in
through USB. This way a web-app running on the desktop computer can
use the second API to read in that data.
Some of the advantages with this approach is:
* We get a central storage on the B2G device for pictures. So if you
have multiple camera apps installed (the default camera app +
hipstamatic + instagram) they all store their pictures in the same
location and so will all be synced whenever you sync your device.
* The API for reading files from memory cards will be super easy to
use and very easy to implement. From the web apps point of view it's
simply a list of all the files they are interested in. No need to
write recursive directory traversing functions, and no need to worry
about where the files are stored on the card. In most cases the
directory and file names are meaningless anyway.
* Since each media file is given a unique name, apps that insert files
can keep managing just the files it has created if it so desires.
* We technically could implement the first API described above using
IndexedDB if that makes for better performance for things like
enumerating. But that's something we can worry about later once we
have time.
[1]
http://en.wikipedia.org/wiki/Design_rule_for_Camera_File_system
/ Jonas