Think Diff

Posted by Orville Bennett on 13 July 2008
Read time: about 4 minutes

Apple has an interesting little utility which they provide with Xcode called FileMerge. I don't actually know if it merges files as the name implies, but I would assume so. I've been using it to see file diffs here on os x. It seems to be a quick and dirty app, but it's easy to use and works well (albeit without the visual pulchritude of your typical os x programs).

So now you might be wondering (or if you're me reading this a few months from now, I might be wondering) why I was using this. Well. Amarok 2 (yes, that again) has recently, due to a number of breakthroughs gained the ability to play audio, and lo, video on os x; as long as the path to the file being played doesn't contain a space. After e-mailing the phonon-backend dudes, i got an informative e-mail from Richard @ Nokia/Trolltech (née Trolltech) informing me that the latest qt snapshot might have a fix for this. Thank you Richard! qt-copy is still @ 4.4.0 though which means those trying the KDE/Mac packages would miss this fix until qt-copy got synched to 4.4.2 (and who knows when that'll happen). Solution: patch!

qt-copy has a directory for patches so I added one after hunting down the code necessary to fix the problem in one of the qt 4.4.2 snapshots. It's the snapshot from 2008-07-08 for those of you wondering. Now KDE/Mac packages should pick up the fix when the patch is applied. Just need to update the A2 on OS X wiki to inform those building from source that they'll need to run apply_patches in src and then we'll be "GOOD 2 GO!" as Elephant Man usually says.

But back to FileMerge; so I used it to compare all the .cpp files in the src/3rdparty/kdebase/runtime/phonon/qt7/ directory of qt-copy and the qt-snapshot. Near the "end of the line" I got a one-liner in quicktimevideoplayer.cpp. Not even a one-liner, a one-worder. While it seemed that this might be the change Rich @ Trolltech was referring to, I was a bit skeptical. I decided to go do the same in phonon for qt's kdelibs dir; looking for more substantial changes. There were a LOT more files there. Owing the that, and the speed of my new macbook (make -j4 is awesomeness people) I decided to just compile the change and test to see if that actually fixed the problem. And lo! It did.

Index: src/3rdparty/kdebase/runtime/phonon/qt7/quicktimevideoplayer.cpp
--- src/3rdparty/kdebase/runtime/phonon/qt7/quicktimevideoplayer.cpp    (revision 820342)
+++ src/3rdparty/kdebase/runtime/phonon/qt7/quicktimevideoplayer.cpp    (working copy)
@@ -451,7 +451,7 @@</code>
 void QuickTimeVideoPlayer::openMovieFromUrl()
-    QCFString urlString = QCFString(m_mediaSource.url().toString());
+    QCFString urlString = QCFString(m_mediaSource.url().toEncoded());
     CFURLRef url = CFURLCreateWithString(0, urlString, 0);
     DataReferenceRecord dataRef = {0, 0};
     QTNewDataReferenceFromCFURL(url, 0, &amp;dataRef.dataRef, &amp;dataRef.dataRefType);

Whodathunk? I'd started looking into fixing this bug right before I wrote the phonon-backend ML and I'm glad they already fixed this. If I had continued I'd still be pouring over the audio* or backend* files trying to figure out where it all went wrong. Maybe even media*. Would've never suspected the quicktimevideo.cpp file though. After all, I was getting the bug for audio too, the problem couldn't be in there ... sigh See what (almost) happens when we assume?

I'm pretty happy with that. I'm still "new" to the whole "software design/programming" (as opposed to hacking) thing so I'm relatively confident I wouldn't have found and fixed the bug in a timely manner, if at all. Unless I really tried; which, I rarely do. I know, I suck, but my eyes start glossing over at around hour 3 with nothing still done :-/