iOS4 Background Audio Revisited

The other day I went ahead and revisited streaming audio apps for iOS4. I blogged previously about how it is the biggest pain in the ass to get working….properly. And it still is.  Background buffering was a pain to do, but I finally worked out how to apply it to AudioStreamer (a github project by mattgallagher). The solution in this StackOverflow post is incredibly useful.

So, I decided I’d checkout AudioStreamer from git, take a look at other people’s forks, try to merge all the fixes and features then add my own. That’s what I did the other day.

My current github fork of AudioStreamer is here: http://github.com/DigitalDJ/AudioStreamer (and it’s pretty damn stable, just sayin’).

Basically, my fork cherry-picks some commits from other users, notably:

- Shoutcast metadata [jfricker]
- MIME type detection [andybee]
- HE-AACv2 [idevsoftware]
- Level Metering [idevsoftware]
- NSThread memory leak [mattgallagher]

Then I set out to try and fix the bugs I had encountered…and fix up the sample app so that it worked fully with iOS4 multitasking:

- Fixed interruption crashes (crashes when you use iPod app then re-use the sample app, or receive a phone call)
- Background buffering (!!! AudioStreamer now buffers properly in the background)
- Play/pause from iPod controls (The sample app now works properly with the iPod controls)
- Stop all UI updating and timers while backgrounded (The sample app now correctly follows guidelines to stop all UI updating and unnecessary timers to save battery life)

- Retina display example (The sample app now has a retina display example…just to be iPhone 4 compatible)

- Support for Pause button in UI (Pausing now works properly, even for streams that don’t support it)
- Local Notifications (outside app) on error (Notification popup if there is a lack of connectivity when playing music outside the application)

There’s just one more bug for me to squash, and frankly I can’t figure it out. Notifications are sent from AudioStreamer to the UI  in case of an error, the UI then handles the notification with a UIAlertView. Sometimes the alerts refuse to show up, or instead, multiple show up, or…..sometimes it just works as intended (i.e. one alert popup). I’m not sure if it’s an iOS bug or something in my code. It’s rather odd as it isn’t easily reproducible and often a reboot of the device will fix the issue. Very very odd.

A Possible Fix: Xen HVM & Windows 2008

Recently, I switched my VPS from VMware ESX to a provider with Xen HVM since my original host disappeared off the face of the planet. However, the Xen HVM VPS has decided to randomly BSOD every 24-48 hours or so. Here’s how I troubleshooted and possibly fixed the issue.

The Issue:
BSODs randomly occur with the error “A clock interrupt was not received on a secondary processor within the allocated time interval.” and STOP code 0×00000101.

Caused by:
Well, the exact issue is unknown. I have a feeling that this occurs when the host has a higher than usual load, which causes some sort of delay of the RTC and eventual crashes. Examining 3 crash dumps showed that the Realtek networking driver (Rtnic64.sys) is always near the top of the stack trace with something to do with the RTC in the kernel.

The solution:
There are a few solutions. I’m not sure which one fixes the issue exactly, but here’s what you can try:

First try modifying your VM config to add these options (the first ensures time is always “wall clock time” and the second exposes the Hyper-V interface to the VM):
timer_mode = 2
viridian = 1

You can then also try
os_variant = "vista"

And if worse comes to worse, limit to 1 CPU core
vcpus = 1

Finally, if you run Windows you should install the GPL PV drivers. If you want to run Windows, you MUST use Xen HVM (Xen PV is unavailable). The default drivers when using HVM are designed to work with QEMU’s emulated devices and therefore carry a performance degrading overhead. Luckily, there’s been an effort to create PV drivers for Windows, so the VM can work more directly with the host’s hardware, creating less overheads and a significant performance boost.

Download the latest drivers (32 or 64bit, 2003/2008) from: http://www.meadowcourt.org/downloads/

If you run a 64-bit version of Windows later than 2003 (i.e. Vista, 7, 2008, 2008 R2) you need to disable driver signature integrity checks. You can also create a secondary boot option to disable the PV drivers and revert back to the less optimized drivers. For example:

Disable Driver Integrity Checks
bcdedit /set loadoptions DISABLE_INTEGRITY_CHECKS
bcdedit /set testsigning ON
bcdedit /set nointegritychecks ON

Create secondary boot option
bcdedit /enum /v
Note the GUID string next to "identifier" under "Windows Boot Loader"
bcdedit /copy {string from above} /d "Windows Server 2008 NOGPLPV"
Description can be whatever you want
bcdedit /set {new GUID from above} LOADOPTIONS "NOGPLPV"
Use the GUID outputted from the 2nd command

Now install the MSI, restart, open up Device Manager and you should find you have no more “Unknown Devices” and that you now have a different network card (among other things) installed.

Flash for iPhone 4? Yes! Frash 0.02!

DISCLAIMER: The compiled binaries are based upon ALPHA code by COMEX. Code from the github repository can change minutely creating a significantly more stable version of code. DO NOT expect this compiled code to work on every Flash object or even be the slightest bit stable.

So, jailbreak for the iPhone 4 is out and comex seems to have gotten around to updating the Frash source on github for both iOS and iPhone 4. Hooray! I set out on a mission to compile it from scratch. Here I’ll detail the steps you need to produce to compile it and provide a pre-compiled binary for the less so technical (or lazy). This is essentially Frash version 0.02, but as noted before, the github repository can be updated at any time fixing any number of bugs.

As far as I know this will only work with armv7 devices, so: iPhone 3GS, iPod Touch 3G, iPad, iPhone 4. iOS4 / iPad 3.2.x only.

HOW TO INSTALL

1. Download the precompiled binary (Frash-0.02.deb | Mirror) and SFTP it to /tmp on your iPhone/iPad

2. SSH into your phone as root and type:

dpkg -i /tmp/Frash-0.02.deb

NOTE: If you had Frash 0.01 installed on your iPad, remove it first (look for it in Cydia packages). Also, I haven’t yet tested this on iPad, but it certainly works on iPhone 4 with iOS 4.0.1.

3. Reboot your device if you want, but you shouldn’t need to.

HOW TO COMPILE (ADVANCED USERS)

What you’ll need:

  • Mac OS X 10.6 with iPhone SDK 4.0 / 4.0.1 installed
  • git-osx-installer
  • libflashplayer.so from an Android 2.2 (Froyo) image (no link for this due to copyright issues, Google it!)
  • DebMaker-osx
  • ldid

Instructions:

1. Install git (just run the downloaded DMG) and check out the Frash git repository

git clone http://github.com/comex/frash.git
libflashplayer.so

2. Patch Xcode to compile Dynamic Libraries for iOS

a) Edit /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications/iPhoneOSProductTypes.xcspec

Make sure to place the code snippet in between the first “(” and the first “{“

    // Dynamic library
    {   Type = ProductType;
        Identifier = com.apple.product-type.library.dynamic;
        Class = PBXDynamicLibraryProductType;
        Name = "Dynamic Library";
        Description = "Dynamic library";
        IconNamePrefix = "TargetPlugin";
        DefaultTargetName = "Dynamic Library";
        DefaultBuildProperties = {
            FULL_PRODUCT_NAME = "$(EXECUTABLE_NAME)";
            MACH_O_TYPE = "mh_dylib";
            REZ_EXECUTABLE = YES;
            EXECUTABLE_SUFFIX = ".$(EXECUTABLE_EXTENSION)";
            EXECUTABLE_EXTENSION = "dylib";
            PUBLIC_HEADERS_FOLDER_PATH = "/usr/local/include";
            PRIVATE_HEADERS_FOLDER_PATH = "/usr/local/include";
            INSTALL_PATH = "/usr/local/lib";
            DYLIB_INSTALL_NAME_BASE = "$(INSTALL_PATH)";
            LD_DYLIB_INSTALL_NAME = "$(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(EXECUTABLE_PATH)";
            DYLIB_COMPATIBILITY_VERSION = "1";
            DYLIB_CURRENT_VERSION = "1";
            FRAMEWORK_FLAG_PREFIX = "-framework";
            LIBRARY_FLAG_PREFIX = "-l";
            LIBRARY_FLAG_NOSPACE = YES;
            STRIP_STYLE = "debugging";
            GCC_INLINES_ARE_PRIVATE_EXTERN = YES;
            CODE_SIGNING_ALLOWED = YES;
        };
        PackageTypes = (
            com.apple.package-type.mach-o-dylib   // default
        );
    },

b) Edit /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications/iPhoneOSPackageTypes.xcspec

Make sure to place the code snippet in between the first “(” and the first “{“

    // Mach-O dynamic library
    {   Type = PackageType;
        Identifier = com.apple.package-type.mach-o-dylib;
        Name = "Mach-O Dynamic Library";
        Description = "Mach-O dynamic library";
        DefaultBuildSettings = {
            EXECUTABLE_PREFIX = "";
            EXECUTABLE_SUFFIX = "";
            EXECUTABLE_NAME = "$(EXECUTABLE_PREFIX)$(PRODUCT_NAME)$(EXECUTABLE_VARIANT_SUFFIX)$(EXECUTABLE_SUFFIX)";
            EXECUTABLE_PATH = "$(EXECUTABLE_NAME)";
        };
        ProductReference = {
            FileType = compiled.mach-o.dylib;
            Name = "$(EXECUTABLE_NAME)";
            IsLaunchable = NO;
        };
    },

3. Patch Xcode to allow compilation without a Provisioning Profile (i.e. not paying the $99 Apple tax)

a) Open /Developer/Platforms/iPhoneOS.platform/Info.plist and replace all instances of “XCiPhoneOSCodeSignContext” with “XCCodeSignContext”

4. Create a self-signed certificate to sign the Frash libraries

a) Open Applications > Utilities > Keychain Access

b) From the Keychain Access menu choose Certificate Assistant > Create a Certificate

c) Choose any name, set the type to “Self Signed Root”, check “Let me override defaults” and make it a “Code Signing” certificate

d) Specify any serial number, set the expiry to whatever you want. Longer than a year if you want to compile other iPhone libraries in the future.

e) Fill in any details for Certificate Information

f) Skip to the end of the wizard, using the default settings

5. Install ldid

a) Copy the ldid file to /usr/bin and make it executable (as root)

sudo cp ldid /usr/bin/
sudo chmod +x /usr/bin/ldid

6. Install DebMaker

a) Extract the DebMaker zip and extract dpkg-dep for later use

sudo cp DebMaker.app/Contents/Resources/dpkg-deb /usr/bin/
sudo chmod +x /usr/bin/dpkg-deb

7. Edit the default Xcode configuration for Frash

a) Open Player2/Player2.xcodeproj in Xcode

b) Make sure to switch the current configuration to Device 3.2 | Release

c) Open up “Get Info” for the Device 3.2 | Release configuration and  set the “Code Signing Identity” to the self-signed certificate made earlier and ensure the project is compiling for iPhone Device 3.2. Ignore warnings about setting to compile for armv6, keep it compiling for armv7.

d) Save the project and exit Xcode

8. Time to compile! Comex provides the build steps in the README for iPhone OS 3.2 but it needs to be changed slightly:

sudo ln -s /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk /var/sdk
sudo export PATH=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH
sudo cp -a /System/Library/Frameworks/IOSurface.framework/Versions/A/Headers Player2/IOSurface
sudo cp -a /System/Library/Frameworks/IOSurface.framework/Versions/A/Headers food/IOSurface
sudo cp -a /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreText.framework/Versions/A/Headers food/CoreText
sudo cp -a /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk/System/Library/Frameworks/IOKit.framework/Versions/A/Headers/ food/IOKit
sudo cp -a /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.2.sdk/System/Library/Frameworks/IOKit.framework/Versions/A/Headers/ Player2/IOKit
sudo cp /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk/Entitlements.plist .
sudo make -C rpc
sudo make -C utils
sudo make -C libgcc
sudo make -C food
sudo xcodebuild -alltargets -project Player2/Player2.xcodeproj

9. Now package it up into a deb

a) Edit DEBIAN/control and add a conflicts line to the end of the file. This will conflict with the Frash 0.01 deb released previously. You should remove that before installing this.

Conflicts: net.ozzapoo.frash

b) Place your copy of libflashplayer.so in the frash directory.

c) Modify fakeinstall to include libflashplayer.so by adding a line before “chown -R 501 iroot/var/mobile”

cp -a libflashplayer.so iroot/var/mobile/frash/

d) Make fakeinstall executable and run it as root. You should end up with a frash.deb file.

chmod +x fakeinstall
sudo ./fakeinstal
mv frash.deb Frash-0.02.deb

10. Hooray! Now follow the novice install section using the deb you just compiled (instead of the precompiled version, duh) to install Frash!

Every Single (Awesome) Game I’ve Played

Today, I spent a couple of hours thinking back to how awesome the good ol’ days of DOS games were and that now…I hardly play games. Mainly because I find them all pretty damn boring. I thought it’d be awesome to make a 1995 super-computer, say a couple of Pentium Pros and a kick-ass 3dfx Voodoo card (or two), just to play some retro games. Alas, finding rare parts, even on eBay, is rather difficult and it’d probably be a pretty expensive ordeal. Guess I’ll just have to stick with DOSbox and VMware.

On another note, I present you with the list of awesome game I’ve played. You’ll notice how it begins with a shit-ton of DOS games, ventures briefly into Windows, then heads to the PSX, then to WoW, and finally, the world of casual gaming.

The DOS Era (1991 – 1997)
Ancients
Battle Chess 4000
Bio Menace
Blake Stone
Blood
Blues Brothers – Jukebox Adventure
Bouncing Babies
Captain Comic
Carmageddon
Catacombs 3-D
CD-Man
Command & Conquer: Red Alert
Commander Keen 1, 2, 3, 4, 5, Dreams, 6
Companions of Xanth
Cosmo’s Cosmic Adventure
Crysal Caves
Dangerous Dave
Descent, 2
Doom 1, 2
Duke Nukem 1, 2, 3D (Atomic)
Dune
Earthworm Jim
ElectroMan
Epic Pinball
Fantastic Dizzy
Flashback
Freddy Pharkas – Frontier Pharmacist
Fuzzy’s World of Miniature Space Golf
Gertrude’s Secrets
Goldfields
Gorillas (QBASIC)
Grand Theft Auto 1, 2
Heretic, Shadow of the Serpent Riders
Hexen: Beyond Heretic, Deathkings of the Dark Citadel
Hocus Pocus
Hugo’s House of Horrors, Whodunit, Jungle of Doom
IndyCar Racing
Jazz Jackrabbit, 2
Jetpack
Ken’s Labyrinth
King’s Quest 1, 2, 3, 4, 5, 6, 7
Lamborghini: American Challenge
Lemmings
Links: The Challenge of Golf
Lotus III: The Ultimate Challenge
Mario Is Missing
Monster Bash
Need for Speed
Nibbles (QBASIC)
Oddworld: Abe’s Oddysee
One Must Fall: 2097
Prince of Persia
Quake
Raptor
Reader Rabbit
Rise of the Triad
Sango Fighter
Shadow Warrior
Sherlock Holmes: Consulting Detective
Sim City 2000
Sim City Classic
Sim Farm
Stunts
SWIV 3D
Terminal Velocity
The Incredible Machine
Theme Park
Tomb Raider
Turok
Wacky Wheels
Warcraft 1, 2
Wipeout
Wolfenstein 3D (Spear of Destiny)
WordMAX
Worms
Zool
The Windows Era (~1995 – 2004)
3D Movie Maker
3D Pinball for Windows
Age of Empires 1, 2, 3
Ballistics
Battlefield 1942
Catz
Chip’s Challenge
Counter Strike
Crazy Taxi
Daytona USA
Deer Hunter
Destruction Derby
DogDay
Doom 3
Doom 3, Resurrection of Evil
Dope Wars
Elasto Mania
Enter The Matrix
FIFA 97
Flight Simulator 2004
Fury3
Grim Fandango
Half Life
Halo
Heretic II
HeXen II, Portal of Praevus
Hitman: Codename 47, 2: Silent Assassin, Contracts, Blood Money
Hong Kong Mahjong
Hover!
I.G.I.
Jurassic Park: Chaos Island
Kid Pix
Kingpin: Life of Crime
Math Blaster
Math Circus
Max Payne, Max Payne II
MechWarrior 2
Metal Gear Solid 2
Micro Machines V3
Microsoft Golf
MindMaze (that game in Microsoft Encarta!)
Monster Truck Madness
Motocross Madness 1, 2
Myst, Riven, III, IV, V, realMYST
Need for Speed 2
Need for Speed: Underground, Underground 2
Postal, 2
Putt-Putt
Pyst
Quake II, The Reckoning, Ground Zero
Quake III Arena, Team Arena, Quake Live,
Rainbow Six: Rouge Spear
Rally Championship
Red Faction
Redneck Rampage
Sega Rally
Sim Park
SimTower
SkiFree
Soldier of Fortune
Sonic CD
Starcraft, Brood War
SWAT
The Land of Um
The Sims
Theme Hospital
Titanic: Adventure Out Of Time
ToCA Race Driver 2
Typing of the Dead
Unreal, Unreal Tournament, Unreal Tournament 2003, Unreal 2, Unreal Tournament 2004,
Virtua Cop
V-Rally
Where In The World Is Carmen Sandiego?
Yoot Tower
The PSX Era (1999 – 2002)
Ace Combat 1, 2
Colin McRae Rally 1, 2.0
Crash Bandicoot, 2:Cortex Strikes Back, 3:Warped
Croc 1, 2
Die Hard
Dino Crisis
Driver
Gex
Gran Turismo 1, 2
Metal Gear Solid: Integral
Point Blank
R4: Ridge Racer Type 4
Silent Hill
Siphon Filter
Spyro the Dragon
Tenchu
Time Crisis
Wargames: Defcon 1
WoW Era (2005 – 2009)
World of Warcraft, Burning Crusade, Wrath of the Lich King
Post-WoW Era (2008 – 2010)
Colin McRae: DiRT 1, DiRT 2
Counter-Strike: Source
Crysis
Knytt, Stories
Left 4 Dead 1, Left 4 Dead 2
Portal
Team Fortress 2
Unreal Tournament 3
Within A Deep Forest
iPhone Era (2009 – 2010)
Angry Birds
BubblePRO
Doodle Jump
Flight Control
Need for Speed Undercover
Paper Toss
Peggle
Plants vs. Zombies
Rock Band
Spikey’s Bounce Around
Super Monkey Ball 1, 2
Tap Tap Revenge
Other
Donkey Kong Country (SNES)
GoldenEye (N64)
Granny’s Garden (C64)
Guitar Hero (Xbox 360)
Pokemon Red, Blue, Green, Yellow (GB)
Sonic 1, 2, 3, & Knuckles (Mega Drive)
Super Mario World (SNES)
Wayne Gretzky’s 3D Hockey (N64)
Wii Sports (Wii)

I am sure to update this list as I can think of any DOS games that come to mind. I currently have one game racking my brain that I played a ton and just can’t remember the name, sigh.

Making Vuze 64-bit (Windows)

Today I ventured into making Vuze (the popular BitTorrent client) x64 compatible.

At first, it seems like a pretty simple task, but it turns out it’s slightly more complicated than it seems.

Here’s how to do it yourself. If you’re lazy, there’s a link at the bottom of this post with all the compiled files.

Step 1: Get the 64-bit JRE

First, download and install the 64-bit Java Runtime Environment (or JDK, whatever you want). Here’s a link to the JRE (make sure to download the Windows x64 version): https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewProductDetail-Start?ProductRef=jre-6u21-oth-JPR@CDS-CDS_Developer

Step 2: Use the x64 Standard Widget Toolkit

Secondly, we must replace the main GUI toolkit that Vuze uses (SWT) with the x64 equivalent. Download the “SWT Binary and Source” for Windows (x86_64) from: http://www.eclipse.org/swt/ (make sure to click More). At the time of writing the stable version is at 3.5.2. Here’s a link to that version: http://download.eclipse.org/eclipse/downloads/drops/R-3.5.2-201002111343/download.php?dropFile=swt-3.5.2-win32-win32-x86_64.zip

Extract swt.jar from the zip file and place it in the Vuze folder (%PROGRAMFILES(X86)%\Vuze), replacing the file. Note that once you do this, you can’t go back to the x86 version unless you download the x86 SWT or reinstall Vuze. At this point, we can actually use Vuze in 64-bit with the command line using the 64-bit JRE: java -jar Azureus2.jar ….but we aren’t done yet.

Step 3: Make the iTunes plugin work

New versions of Vuze come with an iTunes plugin that uses native code that is x86 only. This particular plugin uses some COM calls using a bridge called JACOB. Open up your Vuze plugins folder (%PROGRAMFILES(X86)%\Vuze\plugins), open the azitunes folder and look for a file that looks like “jacob-x.xx.x-x86.dll”. We need to find the x64 version of that DLL, and match the version. So if x.xx.x is 1.14.3, we need JACOB 1.14.3. You can find all the JACOB versions at SourceForge: http://sourceforge.net/projects/jacob-project/files/ Open the folder with the relevant version and grab the zip file that DOES NOT end in “_src”. Open up the zip, and extract jacob-x.xx.x-x64.dll to %PROGRAMFILES(X86)%\Vuze\plugins\azitunes.

Step 4: Enabling Windows specific Vuze settings

Vuze also uses a small portion of native code to perform some Windows specific tasks. These will be invisible to you until you compile aereg.dll into 64-bit. You will need to checkout the source code from the Vuze SVN respository and compile it with Visual Studio, making sure you target x64 rather than x86. To make it compile you’ll need the 64-bit JDK and to add some include paths to the project, specifically: jdkx.x.x_xx\include and jdkx.x.x_xx\include\win32. Don’t worry about the warnings, if you have any, they’re normal. Here’s the Vuze repository for aereg.dll: http://svn.vuze.com/public/client/trunk/azureus2/lib/libWIN32Access/ After you compile it to x64, make sure to RENAME IT to aereg64.dll. This took me quite some time to figure out, I had to do some source code digging to figure out why Vuze refused to load the 64-bit library.

Step 5: Making Azureus.exe / AzureusUpdater.exe use the 64-bit JRE

This is difficult since Vuze use commercial software, exe4j, to create the EXE launcher for the JAR. I went ahead and well…made it work. I have included the exe4j project files if you wish to compile the EXEs using exe4j by yourself. The final binaries are included at the end of the post. Vuze do not provide these projects, so it took me a while to mimic the exact project options that Vuze use to compile their EXEs. Here’s the projects: http://digitaldj.net/vuze/Vuze_exe4j.zip

Step 6: Edit the manifest

This is a minor step, that doesn’t really need to be completed. Open up Azureus.exe.manifest and make sure to replace all references of “x86″ with “amd64″.

Step 7: Move Vuze to Program Files

If you want, you can go ahead and move the Vuze folder to Program Files, instead of Program Files (x86)….but it isn’t necessary. If you do this, you’ll have to update your shortcuts and make sure your file associations (.torrent) point to the new folder location.

Hooray! We’re done. Now double click Azureus.exe and bam, you’re now using the 64-bit JRE. You can check task manager to ensure you’re not using the 32-bit version (it’ll have a *32 next to the process name).

And for the lazy or non-technical. Here’s the files you need to make your Vuze 64-bit: http://digitaldj.net/vuze/Vuze_x64_1.20.zip Simply extract the files (and overwrite all) to C:\Program Files (x86)\Vuze (these files are current to Azureus 4.4.0.6, and may work for future versions, but maybe not)

PS. Similar steps are taken for Linux and OSX. Minus the obvious. As far as I know, Linux has no native code, but OSX has a similar library to aereg.dll. You’d have to compile the source code here with XCode: http://svn.vuze.com/public/client/trunk/azureus2/lib/libOSXAccess/

iOS4 Multitasking: Developer’s Hell

I finally got around to installing iOS4, so I decided I’d go ahead and investigate what it takes to update the Fresh app (streaming radio) to support multitasking. Currently, my conclusion is that implementing ANY of the multitasking APIs is 110% hell unless you’re starting from scratch.

First of all, your application has to play nice while it’s sitting in the background. This means that you’re basically required to implement a whole lot of “if backgrounded” checks, unless you want to soak up the battery. This involves stopping unnecessary timers, updating the UI when the application comes back to the foreground (rather than per a specific event), and saving non-critical alerts for when the user pops back into the application. This basically requires a crapton of refactoring…and we all love how that introduces bugs. If you have any sort of complicated app, you’ll be having to manage state saving so that fast app switching works nicely. Oh, and not to mention that iOS never guarantees that your application stays backgrounded. It can be killed depending on resource usage, available memory or even just idle time. Every task (other than a few specific exceptions) is time limited, so you are constantly having to check and request more time for your task.

Now, this particular application is meant to take advantage of the background audio multitasking API. Now, as an aside, Apple does not provide any “simple” API to stream audio. What they provide is a primitive and generic audio buffer/queue that suits both local files and network streams. Basically, this means that if you want to stream audio over the network, you have to implement the protocol, manually send the requests to get data (via HTTP for example), then feed that data into a buffer (where you have to handle the size of incoming data vs. the size of the buffer), THEN…play the audio from the buffer or handle any errors that occurred along the way. Now, in any half decent modern API, surely, you’d have a perfected version of the algorithm where you could simply plug in a URL and instruct a magical black box to play it. But alas no, each developer is to implement the over complicated, primitive audio queue… just for a streaming radio application. Now combine that with the following multitasking API, and you’re in developer hell.

One of the official pages on backgrounding is nearly impossible to find on the Apple site, so here it is: http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html Now, if you look closely, you’ll see that most sections are detailed nicely….except background audio, fantastic. So, taking a quick look at that section reveals that if you simply “flag” your application as one that streams audio, you’re good to go. Hooray right? Well, sort of, not really, no.

Hurdle 1: Hooking into iPod controls

Surprisingly, this is the EASIEST part of implementing background audio. It seems to “just work” as long as you have fairly simple start/stop/pause methods for your radio streamer. One gotcha is that state changes can now take place from both your play/stop button and the iPod controls… so, basically you should be using some sort of event system for state changes and to reupdate the UI whenever your app hits the foregound again.

Hurdle 2: Interruptions

Interruptions have existed since OS2. They cause your music to stop, usually when someone rings. However, now your application has to act more like the iPod application…except you can’t! Unlike the iPod application, which automatically restarts after you finish your call, the only way your application can automatically restart it’s stream is if the user brings it back to the foreground. Not only that, I’ve found that interruption events are very inconsistent. Sometimes they fire simultaneously with the interruption, sometimes they won’t fire until you bring the application to the foreground. On the times that they don’t fire with the interruption, I find that some sort of crazy auto deallocation of the streamer occurs which I can only fix with a terrible workaround. I am yet to find the actual cause of this.

Hurdle 3: iPhone Simulator

It sucks. Testing background audio with it is impossible! Even in the GM build, there is a bug that mutes all sound from your application when it is backgrounded. This makes it rather difficult to tell whether or not your application IS ACTUALLY SITTING IN THE BACKGROUND.

Hurdle 4: You’re free to do whatever you want…except when you need do something

So, as explained before, if you flag your application for streaming audio, your application can go ahead and play audio and do what it needs to do without any particular time limit or suspended state. Cool! Sort of like a free pass to do whatever the hell I want, right? Wrong. There’s a HUGE exception here: “if your application stops playing audio while in the background, your application is suspended.” Wow, that’s fantastic. So let me get this right…if my STREAMING AUDIO APPLICATION happens to need to BUFFER (i.e. STOP PLAYING AUDIO) while on a dodgy cellular connection, my application is essentially…fucked. Yes, that’s right. If you have a little bit of a network hiccup, and need to buffer, the user will need to jump back into the application to restart the audio stream! Not even the iPod controls (which are meant for external use) allow you restart the stream. I haven’t yet found a fix for this yet, but I’m assuming I’m going to have to go back to that mindfuck of a primitive audio queue to fill it with some sort of dummy audio while it buffers, so that iOS doesn’t fucking suspend my application in the middle of playing music. Doesn’t this found like fun?

Hurdle 5:Backwards Compatibility

Finally, as always, you need to aim for backwards compatibility. Apple claims to have completely culled OS2.x, but let’s face it, there are still 1st Generation iPod Touch users that DIDN’T pay the iOS3/4 upgrade tax, that want to use apps. You have to, at a minimum, ensure your application works on OS3 devices, which means making sure that some method calls, that are iOS4 specific, actually exist. Then using the simulator to test………. /facepalm.

FML.

Creating a custom iOS4 IPSW with Game Center

iOS4 has GM’d, but Apple is yet to finalize their Game Center app. Currently, there are two different versions of iOS 4.0. Firstly, the publicly available version and an developer’s version. The developers version is identical to the official update, but includes the Game Center app for developers. Unfortunately, tools like redsn0w, sn0wbreeze and PwnageTool don’t support the developers IPSW. Fortunately, PwnageTool is incredibly customizable for patching firmware, so a few customizations makes it accept the developers IPSW.

1) Download and extract PwnageTool 4.01

2) View the package contents of PwnageTool.app and browse to PwnageTool.app/Contents/Resources/FirmwareBundles/<Your iPhone/iPod firmware version>.bundle

3) Within this bundle is an Info.plist, open it and make the following modifications to the following keys:

3a) RootFilesystem: needs to match the root FS dmg filename in the developer IPSW. Find this by opening the IPSW with a ZIP application and find the filename of the DMG that is approximately 300-400MB in size (it should be something like xxx-xxxx-xxx.dmg)

3b) RootFilesystemKey: each root FS is encrypted. Finding the key is difficult. Instead, search for the DMG filename in Google and you should find a few places that host the key for that particular DMG.

3c) RootFilesystemMountVolume: usually this is something like ApexXXXXX.iPhoneOS. Change this to ApexXXXXX.iPhoneDeveloperOS.

3d) SHA1: this needs to match the SHA1 of the developer IPSW. You can find this by using the command “openssl sha1 <IPSW filename>”

4) Now you can save the Info.plist, open up PwnageTool and select the developer IPSW. Hooray!

iPad: The Verdict

Originally I intended to buy a netbook for overseas travel. After searching through an endless amount of models there was nothing I saw that has decent specs and a long battery life.

Apple announced the iPad… At first I figured it’d be a useless heap of junk, but after thinking about it for a while, it seemed like a logical netbook replacement. So, I bought one. A 64GB WiFi+3G one…with accessories. Here’s the review.

The Hardware

You can tell the iPad is a first generation Apple device. The screen isn’t 16:9, it has no front facing camera, let alone any camera. I’ve also found that the iPad has only 256MB of RAM. It’s essentially a giant iPhone. However, the only significant flaw of these, is the RAM. I’m still experimenting but even without backgrounding apps, things start to get a little low and laggy. Maybe I just need another factory restore. On the upside, it’s pretty fast, the screen is bright, it’s perfectly sized and the battery life is fantastic.

Another flaw is USB charging. The iPad requires a full 10W of power to charge and unfortunately most USB ports don’t supply that much power. Only ports that implement a new USB standard can charge the iPad (currently only new i7/i5 Macs). This sucks. It makes it impossible to keep your iPad fully charged and syncable at the same time. The only solution is the Wi-Fi Sync jailbreak app (which is fantastic, by the way) so that you can connect your iPad via the power connector and still sync. Without the jailbreak, this would be a show stopper for me as I intended to use the iPad in it’s dock next to my current monitors. Thank god for jailbreaking.

The Accessories

I bought the case, dock and camera kit. You could say I went all out.

The case is great, it adds a tilt that is great for movie watching and typing…but you can’t dock the iPad in it’s case. Not a huge deal, but it’s pretty hard to pull the iPad out of the case once it’s in it. The dock works okay too, but it has no weight, so you have to hold down the dock to pull the iPad out. It would be nice if the dock included some sort of TV out or way to connect both power and USB, but alas it doesn’t…but it does sit nicely next to my other screens. I haven’t tested the camera kit yet, but I bought this since there have been reports of connecting other devices to the iPad. As jailbreaking evolves, this seems like logical device to toy around with other peripherals with the iPad.

The Operating System

iPhone OS 3.2 seems like it was rushed. It works, but a significant amount of features are disabled from the operating system for no good reason. Upon booting for the first time I realized that there’s no Weather, Calculator, Voice Recorder, Compass, Stocks or Clock app. I can’t decide whether or not Apple rushed it out or if they wanted to leave it to the developers, but it’s rather annoying since some of these applications use a private API, only accessible to Apple (the alarm feature in the Clock app, for example). Either way, it’s a bit disappointing. The apps that Apple have ported are rather decent. The iPod app is like a miniature iTunes and Calendar app has a great UI.

Tethering is completely disabled. So is voice control, but at least the latter can be enabled with a simple hack. Since there is no camera, any application that has a camera feature often crashes since there is no check for the hardware. And hell, why isn’t there an SMS app or Phone app. They could have least enabled the API for developers.

Apple claims the iPad supports iPhone applications…and it does…but frankly it sucks. iPhone applications show up in small area of the screen…or you can use pixel doubling to make it look like an awesomely distorted JPEG image. If you think that you’ll use an iPhone app for something the iPad does not yet support, then you’re kidding yourself. Frankly, the iPad is only good for native iPad apps, iPhone apps are an absolute last resort.

Luckily, there’s a jailbreak solution, sort of. FullForce will force iPhone apps to the native iPad UI. Unfortunately, your mileage may vary depending on the app. It does however work well for the Facebook app, for which there is no native iPad app, yet. Keep in mind though, most applications are just mobile front ends to websites…and now that you have a giant screen, you can can get an excellent experience from MobileSafari.

Jailbreak users will be a bit disappointed, at least for now. There are several apps that simply don’t work with OS3.2. However, I spent some time going through jailbreak apps that I feel are 100% essential: ProSwitcher (Palm Pre style task manager), SBSettings (toggle pad that works in 3.2) and LockInfo (lock screen information). Luckily, at least ProSwitcher has active development. The github repository has partially working code for the iPad… And it’ll probably be ready soonish.

I feel OS4 will make the iPad shine. There are a couple of cool things in OS3.2 though: SpringBoard now rotates to landscape, there’s a rotation lock, and the keyboard is fantastically huge. Yes, I’m typing this article on an onscreen keyboard, and it’s actually productive!

The Apps

Even though the iPad has been out for a month or so, there is a lack of decent apps. No doubt, over time this will sort it self out. Also, you’ll find that app store prices are incredibly inflated at the moment. Angry Birds for iPad (a popular game for the iPhone) is 5, yes f i v e, times the price of the iPhone version…and to top it off, there are only 2 chapters in the iPad version vs. 4 in the iPhone version (say wut?!). Nevertheless, first I’ll go through some alternatives to the default iPhone apps (Weather, etc.) then I’ll cover some gems for the iPad.

Alternatives
Compass: Compass-HD
Weather: Pocket Weather
Stocks: Bloomberg (really informative on the iPad)
World Clocks: MyWorld Clock
Calculator: Calculator HD for iPad
Alarm: Weather Watch (has a fantastic UI that merges alarm clock and weather display)
Voice Recorder: Voice Recorder for iPad

iPad Gems
AirVideo: this application is one of the killer apps on iPad. It allows you to stream video from a computer to your iPad. It supports just about every type of video format as it transcodes on the fly using the server software you install on your computer (transcoding is done with ffdshow). The application just works. I’ve even used this with 3G by VPNing to home. Even with 256kbit upload, I was able to pull up a TV show with just 60 seconds of initial buffering. From then on in, the video played flawlessly. It automatically transcodes to an acceptable video bit rate depending on the amount of bandwidth available.

WunderRadio: this is also an iPhone app. It has a vast and extensive database of internet radio streams, including many of the Australian radio stations. Another app that just works.

iTap RDP: is a Windows remote desktop application. The 1024×768 screen of the iPad makes these applications shine. iTap supports a ton of touch gestures and has a few innovations up its sleeve to make it easier to use on the iPad. Unfortunately, it doesn’t support files on the clipboard, but that’s where the next app comes in…

FileBrowser: supports file sharing and SMB share browsing, so you can grab files and send files between your iPad and computer. It also supports an “Open With” function so you can grab a word document and open it with Pages.

iSSH: if you want VNC instead of RDP, this is where it’s at. It also supports SSH, which is fantastic for jailbreak users since MobileTerminal isn’t yet iPad compatible.

Sociable: while MobileSafari is pretty pleasing experience…sometimes it’s nice to have a native app. Sociable is a good alternative for the iPhone Digg or iReddit app.

Twitterific: this is where it’s at in terms of Twitter clients. Nuff said.

Beejive: while I was rather pissed that I had to pay another $8 for Beejive, since I already had the iPhone app, it’s a worth while purchase. It supports MSN, Facebook, AIM, ICQ, Gtalk, Jabber, MySpace and Yahoo!

TWiTPad: a fan of Leo? Then this is for you.

Quota: a usage tracking application that works for just about any Australian mobile provider and ISP. It has a pretty damned good UI.

GlobeConvert: everyone needs a unit converter. This one has a fantastic UI and selection of units. The company also makes WordBook XL, an excellent offline dictionary and thesaurus.

Bento: is hard to explain. It’s like a journal…a library of things. A database? I’m not sure. It has a pretty UI and it seems like a decent application to store some….stuff.

1Password: sort of like Bento, but with security. This is a great app to store all your sensitive information. It’s pretty much a wallet.

Penultimate: if you have a stylus…or want a OneNote style application, this is it.

Magic Piano: this is from the same company that made Ocarina. Fun++

Star Walk: if you like astronomy, you might wanna give this a go. It has support for the compass and accelerometer so you can figure out where constellations are.

Atomic Web Browser: this is an alternative web browser with a Firefox-ish layout and an adblocker.

Korg iELECTRIBE: if you’re a DJ, this is fantastic. It’s an easy to use interface for loops. It has a pretty decent database of synths and effects.

InstaPaper & The Early Edition: these are two separate apps, but great if you like to read articles in a newspaper style. InstaPaper is able to save webpages for offline viewing and The Early Edition is a fancy RSS reader that lays out articles into a newspaper template.

The Apple Suite (iBooks, Pages, Numbers, Keynote): I was a tad pissed that these aren’t included on the iPad by default and that the prices of the office suite are in the $10 range. The apps however, are quality. Apple kept it simple and it worked. I would think that for people that read, iBooks is the killer app, but I don’t read…so I can’t comment on that.

The Verdict

I’m not quite sure I know the exact use for my iPad…yet, but I feel that once the apps evolve and OS4 comes out that it’ll be clear. If you haven’t yet got your iPad, and want one, I’d wait a month then test the waters. The few quality applications that are out nearly make it worth it, but somethings still need a bit of polish. If you do buy one, be prepared to change your work style for the iPad…as in it’s current state, I don’t think the iPad will influence the way you work. No doubt this is a luxury device, but I feel that Apple do have the price set a tad high.

Do I recommend one? If you have the money and you feel the iPad can fill a gap, then yes.

For now, I have tried to avoid using my laptop, and I’ve been fairly successful. The iPad can handle most of my day to day tasks…and if not, there’s remote desktop ;)

Sent from my iPad… (WordPress.app)

Today I was over productive

I don’t normally blog about personal crap, but today…oddly, I was over productive.

It’s closing in on about a 20 hour day, but so far I’ve accomplished the following:

Organised Mother’s Day presents
Met to discuss iPhone App Development
Had lunch a long lunch
Organised seating arrangements for Hawaii trip
Organised travel insurance
Haircut
Finished PhD Proposal Methodology (4 pages)
Finished iPhone App Proposal (5 pages)
Created a new CV
Sorted a lot of files
Updated a bunch of PCs with new software
Hacked new Vuze version

On top of it all of that I managed to watch numerous episodes of TBBT and Seinfeld….and play Angry Birds.

If I was this productive every day…well…who knows what would happen.

Time for bed.

Fixing a character spacing issue in Windows 7

I’ve noticed this a couple of times: Windows decides to go a bit crazy with it’s UI font. Luckily, this is purely a cosmetic problem.

Symptoms:

  • Title bar text becomes compacted.
  • Text is inconsistently spaced in some areas of the UI. For example, typing “this text is awesome” into the Start Menu search bar shows something along the lines of “th i s t ext is aweso me”.
  • Upon the first few seconds seeing your Desktop at start up, most fonts default to Arial (notably the Date/Time in the notification area). Something kicks in a few seconds later and fixes some of the fonts, but not all of them.

It’s all quite odd. I have no idea what causes this exactly because generally, it occurs after a reboot and I don’t reboot for days on end. The default font for the Winodws UI is Segoe UI. I’m not sure if this problem is font specific as I’ve never used anything other than the default.

I haven’t seen anything critical in the Event Log or noticed any applications failing to work they way they should, but it bugged me enough to figure out how to fix it. I started at Google, which seemed to be of little help due to vague keywords. Generally, you’d find random people complaining about how to fix their character spacing in word processing applications.

I used a few steps to troubleshoot the issue. These commands are run as Administrator. You should probably reboot after each step:

  1. Rebuild the MUI cache: mcbuilder
  2. Rebuild the Font Cache:
    a) Stop the Windows Font Cache Service: net stop FontCache
    b) Delete the Font Cache: del %WINDIR%\system32\FNTCACHE.DAT
    c) Start the Windows Font Cache Service: net start FontCache
  3. If all else fails, check for corrupt system files and fonts:
    a) System File Checker scan: sfc /SCANNOW
    b) Reapply any system file patches (e.g. tcpip.sys, termsrv.dll, uxtheme.dll, MUI watermark removers)
  4. If all else fails (try to avoid this), copy all Fonts from a working machine of Windows 7
    a) Find a machine running the same build of Windows 7 (edition, i.e. Ultimate / Home Premium, does not matter) that does not have this problem
    b) Copy all fonts from the working install to the broken install. Fonts are located in %WINDIR%\Fonts
    c) Repeat steps 1 to 3. This is important as you will rebuild caches with the working font files

That should do the trick. If not, it’s probably time to reformat and reinstall… or live with it.