MythTV on Mac x86

From MythTV Official Wiki
Revision as of 22:45, 14 September 2006 by NigelPearson (talk | contribs) (Removed MMX YUV420->442 request - Mino wrote one)

Jump to: navigation, search

MythTV is working on the new Intel based Apple Macintosh platforms. This page is intended to share information among the people attempting to build and optimize the Intel Mac code.

In the 'contrib' directory of the MythTV source code, there is a perl script which automates the build process for MythTV on MacOS systems. The script is called The descriptions of changes needed assume that script as a starting point.

0.20 Status

Sept 14, 2006 -- Most of the build issues were resolved in recent svn updates. With the final 0.20 release, running will result in a working build, with no modifications. 0.20 included some late additions for MacOS, including an MMX optimized colorspace conversion routine for intel Macs resulting in lower CPU usage.

  • The 'enable Altivec colorspace conversion' option was changed to 'enable vector optimized colorspace conversion' to include MMX/SSE in intel based Macs.
  • Make sure the vector optimized colorspace option is enabled for Intel Macs. Without this enabled, video output may be distorted.

Changes Needed for older builds

Here's a brief summary of changes needed to build MythTV on an Intel based Mac system:

  • Update QT version being used. 3.3.4 doesn't compile with gcc 4.0; 3.3.5 compiles but generates a bus error when displaying Myth menus. Using a development snapshot of 3.3.6 seems to work. Replace the QT url in osx-packager with the following: (these snapshots are changed frequently, pick a current one from that directory)

A.Weder (18.03.2006): I had to remove "-no-style-mac" from the qt-mt conf options in, since I got compile errors about QMacStyle not being defined in widgets/qtabbar.cpp. This is for the qt 20060317 snapshot of qt-mac 3.3.6, but also seems to hold for earlier snapshots.

  • Override Host for sourceforge? I found the availability of packages to be spotty on the default host, if it fails, replace the hostname with a working host.
  • libdvdnav: Endian byte swapping missing from src/dvdread/bswap.h The following can be added to use Apple-supplied routines:
#elif defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define B2N_16(x) x = OSSwapBigToHostConstInt16(x) 
#define B2N_32(x) x = OSSwapBigToHostConstInt32(x)
#define B2N_64(x) x = OSSwapBigToHostConstInt64(x)

Note that this is not required with the latest version of the mythtv source and, because that library is not built.

  • libexif: compile failed. replace 'static ExifSShort' by just 'ExifSShort' in libexif/exif-utils.c near line 83. The latest uses the latest libexif and auto-applies a small fix for it to compile.
  • libdvdread: Endian byte swapping missing from dvdread/bswap.h See bswap.h changes above.

MythTV changes:

  • Update to add configure parameters used in building MythTV. In the section "configure mythplugins, and mythtv, etc", the 'mythtv' portion should look something like this:
 =>  [
       '--extra-cxxflags=-msse -msse2 -msse3', 
       '--prefix=' . $PREFIX,
  • Adding '--disable-firewire' may be needed, if you get an error about a missing "AVCVideoServices" framework.
  • This diff, against the released 0.19 codebase, fixes a crash and allows video to work:
diff -ur mythtv-0.19/libs/libavcodec/liba52/resample.c /Users/ogre/src/mythtv-0.19/libs/libavcodec/liba52/resample.c
--- mythtv-0.19/libs/libavcodec/liba52/resample.c       2006-01-05 15:19:29.000000000 -0800
+++ /Users/ogre/src/mythtv-0.19/libs/libavcodec/liba52/resample.c       2006-03-16 13:31:42.000000000 -0800
@@ -13,14 +13,14 @@
 #include "resample_c.c"
-#ifdef ARCH_X86
+#ifdef HAVE_MMX
 #include "resample_mmx.c"
 void* a52_resample_init(uint32_t mm_accel,int flags,int chans){
 void* tmp;
-#ifdef ARCH_X86
+#ifdef HAVE_MMX
diff -ur mythtv-0.19/libs/libavcodec/msmpeg4.c /Users/ogre/src/mythtv-0.19/libs/libavcodec/msmpeg4.c
--- mythtv-0.19/libs/libavcodec/msmpeg4.c       2006-01-15 23:14:43.000000000 -0800
+++ /Users/ogre/src/mythtv-0.19/libs/libavcodec/msmpeg4.c       2006-03-16 13:25:10.000000000 -0800
@@ -725,7 +725,7 @@
        necessitate to modify mpegvideo.c. The problem comes from the
        fact they decided to store the quantized DC (which would lead
        to problems if Q could vary !) */
-#if (defined(ARCH_X86) || defined(ARCH_X86_64)) && !defined PIC
+#if defined(HAVE_MMX) && (defined(ARCH_X86) || defined(ARCH_X86_64)) && !defined PIC
     asm volatile(
         "movl %3, %%eax         \n\t"
         "shrl $1, %%eax         \n\t"
diff -ur mythtv-0.19/libs/libmythtv/videoout_quartz.cpp /Users/ogre/src/mythtv-0.19/libs/libmythtv/videoout_quartz.cpp
--- mythtv-0.19/libs/libmythtv/videoout_quartz.cpp      2005-11-26 08:38:42.000000000 -0800
+++ /Users/ogre/src/mythtv-0.19/libs/libmythtv/videoout_quartz.cpp      2006-03-16 13:59:53.000000000 -0800
@@ -1315,10 +1315,12 @@
     data->windowedMode = gContext->GetNumSetting("RunFrontendInWindow", 0);
     data->correctGamma = gContext->GetNumSetting("MacGammaCorrect", 0);
     if (gContext->GetNumSetting("MacYuvConversion", 1))
         data->yuvConverter = yuv2vuy_init_altivec();
-        data->yuvConverter = NULL;
+        data->yuvConverter = yuv2vuy_init_plain();
     if (!CreateQuartzBuffers())
diff -ur mythtv-0.19/libs/libmythtv/yuv2rgb.cpp /Users/ogre/src/mythtv-0.19/libs/libmythtv/yuv2rgb.cpp
--- mythtv-0.19/libs/libmythtv/yuv2rgb.cpp      2006-01-19 21:04:02.000000000 -0800
+++ /Users/ogre/src/mythtv-0.19/libs/libmythtv/yuv2rgb.cpp      2006-03-16 14:06:33.000000000 -0800
@@ -682,7 +682,6 @@
 static void non_vec_yuv420_2vuy (uint8_t * image, uint8_t * py,
                                  uint8_t * pu, uint8_t * pv,
                                  int h_size, int v_size,
@@ -717,6 +716,13 @@
+yuv2vuy_fun yuv2vuy_init_plain(void)
+       return non_vec_yuv420_2vuy;
 // Altivec code adapted from VLC's i420_yuv2.c (thanks to Titer and Paul Jara) 
 #define VEC_NEXT_LINES()                                                    \
diff -ur mythtv-0.19/libs/libmythtv/yuv2rgb.h /Users/ogre/src/mythtv-0.19/libs/libmythtv/yuv2rgb.h
--- mythtv-0.19/libs/libmythtv/yuv2rgb.h        2005-04-21 07:14:28.000000000 -0700
+++ /Users/ogre/src/mythtv-0.19/libs/libmythtv/yuv2rgb.h        2006-03-16 14:01:06.000000000 -0800
@@ -50,6 +50,7 @@
                               int vuy_stride, int y_stride, int uv_stride);
 yuv2vuy_fun yuv2vuy_init_altivec (void);
+yuv2vuy_fun yuv2vuy_init_plain(void);
 typedef void (* vuy2yuv_fun) (uint8_t * image, uint8_t * py,
                               uint8_t * pu, uint8_t * pv,

  • This fixes audio in v0.19. More recent versions (e.g. 0.19-fixes and 0.20) already have this fix:
diff -ur mythtv-0.19/libs/libmyth/audiooutputca.cpp /Users/ogre/src/mythtv-0.19/libs/libmyth/audiooutp\
--- mythtv-0.19/libs/libmyth/audiooutputca.cpp  2005-10-10 17:30:51.000000000 -0700                    
+++ /Users/ogre/src/mythtv-0.19/libs/libmyth/audiooutputca.cpp  2006-03-16 15:01:02.000000000 -0800    
@@ -107,8 +107,13 @@                                                                                   
     bzero(&conv_in_desc, sizeof(AudioStreamBasicDescription));                                        
     conv_in_desc.mSampleRate       = audio_samplerate;                                                
     conv_in_desc.mFormatID         = kAudioFormatLinearPCM;                                           
-    conv_in_desc.mFormatFlags      = kLinearPCMFormatFlagIsSignedInteger                              
-                                     | kLinearPCMFormatFlagIsBigEndian;                               
+    conv_in_desc.mFormatFlags      = kLinearPCMFormatFlagIsSignedInteger;
+#ifdef WORDS_BIGENDIAN                                                                                
+    conv_in_desc.mFormatFlags     |= kLinearPCMFormatFlagIsBigEndian;                                  
     conv_in_desc.mBytesPerPacket   = audio_bytes_per_sample;                                          
     conv_in_desc.mFramesPerPacket  = 1;                                                               
     conv_in_desc.mBytesPerFrame    = audio_bytes_per_sample;                                          

Enabling MMX

The frontend will run fine without MMX, but you can save a lot of CPU overhead by re-enabling the MMX optimizations in the MPEG2 decoding code, especially for HD video. Faster iMac or MacBook systems may be able to get by without this. To do HD video on the Mac Mini, the MMX patch is probably necessary.

  • Enable MMX and memlign_hack in the configure options in
 =>  [
       '--extra-cxxflags=-msse -msse2 -msse3', 
       '--prefix=' . $PREFIX,
  • Add "-read_only_relocs,warning" to the QMAKE_LFLAGS line in the MythTV build config. Without this change, I get an error: "ld: resample.o has local relocation entries in non-writable section (__TEXT,__text)"
  • Apply the patch found at this link. This changes involve mostly syntax revisions, to appease Apple's choice of tools.
  • For 0.19-fixes: I got "Undefined Symbols" errors in the MMX assembly code, related to the "relocation entries" errors above. The only way I could get it to compile is to remove the "MANGLE" macros in the assembly code in libavcodec. To 'mangle' the variables by hand, just add an underscore before the name. So the code would change from '"movq "MANGLE(magicF2W)", %%mm7 \n\t"' to '"movq _magicF2W, %%mm7 \n\t"'. The files affected are:

The MANGLE macro was fixed in the 0.20 svn code. So, a simpler solution would be to add those updates. I'll try to go back and do a clean build, with the 0.20 svn updates, and revise the info here.

Enabling Apple Remote

  • To get the apple remote working, apply the patch attached to this mythtv trac ticket. This patch is for the 0.19.fixes branch. There is a patch already applied to HEAD which enables this functionality.

Front Row integration

  • mt-daapd is a DAAP server that will let iTunes (and therefore FrontRow) see the mp3's you have on your myth backend. Movies are also served via DAAP, but mt-daapd doesn't support that yet.

With myth using all the remote buttons, you won't be able to activate Front Row. If you want to still be able to launch Front Row with mythtv running, you can save this bit of applescript somewhere like /usr/local/bin (compile it with applescript editor)

 tell application "System Events"
   key code 53 using {command down}
   delay 0.5
   key code 53
 end tell

Then add this section to the myth menu in programs/mythfrontend/library.xml

    <text>Front Row</text>
    <action>EXEC osascript /usr/local/bin/frontrow.scpt</action>

(I like to add it to the "Media Library" menu...)

Current Status

Application successfully compiles. MythTV menu system displays, communicates with backend, and displays video. HD MPEG2 video can be played on a Core Duo 1.66GHz Mac Mini.

  • AC3 SPDIF Passthrough results in static, similar to the standard audio before the endian update. I scanned through for similar code on the digital audio side, but have not yet found it.

Useful Links

  • Links on the IR receiver / remote included in the last iMac G5 and all intel based Macs. Basic integration, passing arrow keys, ESC, enter to mythfrontend should be feasible.

  • Apps to extend the functionality of the Apple remote:

  • Core Video Programming Guide All Intel Macs support Core Image / Core Video, which can be used for optimized video playback and offloading effects such as de-interlacing to the GPU.
  • CocoaMySQL - Excellent MySQL database GUI. Allows easy tweaking of MythTV settings in backend.


For anyone who just wants a binary, here are links to what people have compiled.