In-car USB flash drive vs. in-car A2DP

Last time I was here I talked about a custom modification that I had made to GSPlayer – an MP3 player on my WinMo smartphone – to allow limited, transparent control of a Home Audio streaming zone from within GSPlayer itself.  And it has proven quite handy.  The first trial went well, but then I was dismayed to discover that the stream was skipping.  It wasn’t happening regularly, and it would only skip for about 0.5 seconds each time… but it was enough to be noticeable.

I was beginning to wonder if perhaps this was the main reason why I had switched from GSPlayer to PocketMusic.

Perhaps I’d have to dig into the code.  But after thinking about it overnight it dawned on me that this may be a simple buffering issue.  It wasn’t behaving strictly like a buffering issue – the display wasn’t showing that the player was rebuffering, and it wouldn’t make sense that it would take 0.5 seconds to rebuffer each and every time – but what the hey, I figured it was worth a shot.

So I up’d the buffer from 128k to 1024k (1MB) and that seems to have fixed it 🙂  The prebuffer is still 32k so playback begins just as quickly as before.

Anyhow, everything up to this point has been a digression.  But I mentioned it all because; 1) it’s related, and (2) when taken with the real intent of this article, it serves as a nice illustration of the logical progression of this sort of project.

So… here’s what happened last Friday.

I left work, and decided to play some songs off the flash drive.  But after 5 minutes or so I decided that I would rather listen to the queued tracks on a streaming zone.  So I connected my phone to home and started playback, only to realize that music was coming out of the phone’s speaker itself…???  As it turns out, the USB drive was still plugged in under the armrest meaning the Bluetooth music gateway was not.

Well that certainly sucked.  And while it would have been physically possible to remove one and insert the other, there were two overriding thoughts which nagged me incessantly:

1) Those cables are inconvenient to reach, especially when driving

2) Why should I have to physically switch anything???

So on that Friday I decided to listen to nothing at all for the duration.  But the experience served to solidify and accelerate an idea I had from the very moment I decided to power the gateway off the USB port – which was, to split the port so I could power the gateway and leave a flash drive connected at the same time.

Normally you’ll find USB cables that wire two ports in parallel for the purposes of drawing combined current from both ports.  Only the power wires are connected together; the data wires are connected to one port only.  This allows you to connect devices that might exceed the 500mA that a single USB port can provide.

In my case, I needed a cable that could take one port and split the power to two USB devices, while again providing data connectivity to only one of those devices.  And I figured I’d be okay in the power department, since people regularly power USB hard drives off their BMW USB ports without issue; certainly a lowly flash drive and bluetooth A2DP adapter would be less power-hungry than a hard drive.

After looking around for a suitable cable it became apparent I wouldn’t find one.  I would have to make one myself.  And while I had a spare USB-to-mini-USB cable that I could hack (which would provide power to the A2DP adapter via mini-USB) I had no USB cable with a male plug on one end and a female receptacle on the other.

As luck would have it, I found just such a cable this weekend… for $2!  Perfect price.

So I spliced in my other cable and I’ve now got a 6″ USB extension with a spliced-in 2.5′ cable ending in a mini-USB connector.  I did multiple tests along the way to make sure that everything would work.  And once in the car, everything worked.

One comment I have to make – the wires inside said cables are t-i-n-y.  I had to use an X-acto knife to slice the sheathing off, and in 10 cuts I think I managed to sever one strand.  And because the wires were made up of 5 or 6 such tiny strands, I had to tin them with solder.  After twisting them together I soldered them again to solidify the splices, wrapped each splice individually in electrical tape, and then wrapped the whole shebang with more tape.

So there it is – I can play tunage off the flash drive or off the phone without having to reach under the armrest.

The particular flash drive I’m using – an 8GB Kingston C10 that I scored for $20 off Dell – is loaded with all the tracks from my “fav’s” list on the Home Audio system.  Syncing the two is fairly trivial, and in the process the system generates genre playlists since… well, I’ll explain.

Some of my tracks have “compound” genres.  For example: “R&B/Reggae”.  While the car has the ability to read these genres, the problem occurs when such a track is not listed in the R&B genre or the Reggae genre.  Personally, I’d want it to be listed in both.

The solution therefore was to gen my own playlists – which the car can read – and make sure that the track is listed in both playlists.  Done – this occurs during the syncing process.  This also allows me to group other genres – Dance, House, Techno, Electronica all get grouped as Dance – so that I can play them all while still keeping the original genres intact (and indeed, the sync will gen playlists for the original genres but name the playlist as, say, “Dance (House)” for house tracks)

So that’s cool.  But you know me, always wondering what the next step can be.

Here’s the thing – the car can control iPod’s and, apparently, certain other MP3 players.  How does this work, this “control”?  For the iPod I believe it’s a special set of code specifically designed to work with the iPod and act as an interface for the iPod.  But for all other devices, the car looks at the device as a storage container housing tracks.  Those devices can either be a Mass Storage device – so, a USB flash drive – or they can be a Media Transfer Protocol compliant device.

The difference between the two is  down to semantics, at the higher level at least.  Again, the car sees both as a storage of files.  In the case of Mass Storage, the device is a drive that the car mounts.  When you want to play a track the car opens the file and reads the data off the drive.  In the case of MTP, the car queries the device via MTP commands; when you want to play a track, the car asks the device for the data and the device sends it over.

So you can see that, to the end user, they both seem to operate the same way.  And indeed, the iPod appears to as well.  But the iPod’s interface is proprietary, and there may be more going on than I’m aware.

Actually I’m guessing about MTP as well, but it’s an educated guess.  And here’s where the magic would happen:

Unlike Mass Storage, there’s no reason why the files on an MTP device have to be on the device itself.  When the car queries for a list of tracks, or genres, or whatever, the MTP device can act as a mere proxy and query some other device for that info, then report back to the car.  When the car wants to play a track, the MTP device proxies the file from some other device and feeds the data back to the car.

Surely you see where I’m heading.  A full blown, customized implementation of this protocol would have me plug my phone into the USB port, then have an application that talks to the car via MTP on one “side” and on the other “side” it talks to my Home Audio system via VPN over 3G.  All of the constructs – albums, songs, playlists – exist on the Home Audio system.

That’s not the approach I’d take though, if only because I can just imagine what would happen trying to proxy metadata for 30,000 tracks.  Rather, you’d likely proxy metadata for a single playlist, or perhaps for the playlists only.  Something like that.

But the whole point of the exercise would be to provide a seamless way to connect back to the Home Audio system and use the car’s media system to playback songs and browse the collection.  Imagine seeing my list of fav tracks on my I-Drive screen, being pulled in realtime from my network at home.  With MTP this would be possible!

How much work is required?  Well, I can wrap my head around the concept and interaction of all the moving parts.  The good news is that we wouldn’t need to worry about decoding/encoding MP3 in the app, since we’d just be proxying song data.  The great unknown is the amount of work (or feasibility) of coding a WinMo app that can take over the USB port.

Whole Home Automation – what’s new?

Time sure is flying.  Sometime in spring I made tentative plans to see “The Expendables” with a friend in August.  At the time I thought that the date – August 13th – was soooo far away.

Ya, right.

I’m not here to bemoan the rapid passing of Time though; I’ll leave that for another entry – which may or may not ever get written btw.  No, I’m here to continue the chronicle that is my Whole Home Automation journey.

Now, I can’t say that the scope of the project has changed.  It’s still limited to audio and surveillance.  On the surveillance side there’s not much to report; occupant detection is working, and although I haven’t hacked any USB Bluetooth dongles I can also say that the system is working acceptably as-is so I’m in no rush to change things.

On the audio front it’s been a case of small updates and bugfixes here and there.  One of the bigger useability updates has been to allow the download of a .zip file of select tracks.  This makes it easy to download a selection of tracks to a local device, or download an entire album to Shelly’s phone.  It’s not something that I’ll use often, but it’s nice to have.

Something that should be more useful for me, however, is a project I just completed that’s physically removed from the system at home – but interacts with it nonetheless.  I’m talking about playback of streaming zones, and in particular, playback of streaming zones using _my_ Windows Mobile smartphone.

Here’s the scenario.  I’ve got some tracks queued on a streaming zone.  I hop in the car, connect to home, and start playing that zone through my phone (and obviously through the car stereo).  Then I hit a joint that’s bangin’ – or lame – and I want to repeat that joint or skip it altogether.

Traditionally this has been possible, but it meant having a browser open on the phone and connected to the zone page for the streaming zone in question.  You press a transport control on the webpage, and some seconds later (up to 15 seconds in some cases) the streaming buffer gets around to reflecting the changes.

“Wouldn’t it better”, I wondered, “if you could use the player’s transport controls to control the zone directly?!?”

Yes, it would.  And so now it is.

I toyed with the idea of writing an app from scratch.  And while this is something I may still do, the opening lines of this entry are quite clear in this respect: Time is at a premium.  Sometimes you have to settle with something that works rather than something that’s perfect.  It’s not a mantra that I usually adopt, but in some cases – as with the Bluetooth dongle – it’s acceptable.

So as it turns out, GSPlayer is open-source.  It’s a player I’ve used in the past, and I think that I passed it over in favour of PocketMusic because the latter is purtier and has bigger buttons.  But if the buttons aren’t useful, then who cares?  That, and PocketMusic has some stability issues – to the tune of often requiring a soft-reset of the entire phone.

Anyhow, I modified GSPlayer and captured transport control events so that it will send RPC commands to the backend server.  So if I press the “next track” button in GSPlayer, it will tell the backend to move to the next track.  It will also disconnect/reconnect the stream to make sure the streaming buffer is cleared.

And of course, it only does all of this if a stream is active *and* that stream appears to be connected to my server.

So ya, that’s that.  I did a quick test on my phone and it seems to work.  I’m off to run a few errands shortly and I’ll do the trial-by-fire at that point.