MythTV  0.27pre
MythTV Architecture

# Introduction

Over the last couple years MythTV has grown into a rather large application. The purpose of these pages is to provide a portal into the code for developers to get their heads around it. This is intended for both those new to MythTV and experienced with it to get familiar with different aspects of the code base.

If you are just looking for the code formatting standards, see the official MythTV wiki article coding standards. If you are looking for the bug tracker, it can be found on the official pages. If you haven't already, you should subscribe to the developer mailing list and the Commits mailing list

If you just stumbled onto the developer pages by accident, maybe you want to go to the official MythTV User Documentation or MythTV Wiki.

If you are new to Qt programming it is essential that you keep in mind that almost all Qt objects are not thread-safe, including QString. The Qt containers QMap, QSet, QHash, QString, QList, etc are copy-on-write containers. This means that when you assign one container from another the data isn't actually copied. Instead a copy of a pointer to the data is made and the reference count is increased. Then when you actually modify the date or get a modifiable reference into the container an actual copy is made. This means you can return one of these containers efficiently from a function without needing C++11 support. This also means these containers are a bit less efficient than their STL equivalents most of the time. We still prefer them in MythTV code, especially QString due to the extensive i18n support in Qt. QList is actually equivalent to an STL deque. We also use the STL style iterators. This is both because it makes it easier to switch to an STL container in the rare case when it is necessary, such as when we need a reverse iterator iterator, and because they are more efficient than the Java style iterators that Qt also supports.

In Qt 3.x and Qt 4.0 assignment of one Qt copy-on-write was not yet thread-safe. Because of this you will see a number of ::detach() calls in MythTV code. These calls force a deep copy to be made immediately and should either be removed or a comment should be added in the rare case where this is done as an optimization and not just a hold-over from when copy-on-write wasn't yet thread-safe in Qt 4.0 and earlier.

There are some special dangers when using QObject outside the Qt event thread.

There is a short HOWTO on Profiling MythTV available in addition to documentation on the code itself.

There are also a few simple testing shortcuts.

# Libraries

MythTV is divided up into over 20 libraries:

libmythbase

Lowest-level MythTV library. Used by the Plugins.

Contains the \ref database_subsystem "database",
and network support code (used by the
\ref myth_network_protocol "MythTV network protocol" and
\ref lcd_subsystem "LCDproc interface").

This also contains some other basic functionality and classes which
are used by one or more of libmyth, libmythui and libmythtv.

Any changes to this library's ABI may trigger a MythTV binary version
change because the plugins depend on it.


libmythui

Main user interface rendering library. Used by the Plugins.

The mouse/touchscreen gesture, remote control
(\ref lirc_subsystem "LIRC" and AppleRemote)
and screen saver control code are also contained in this library.

This library depends on libmyth. Any changes to this library's ABI
may trigger a MythTV binary version change because the plugins depend on
it.


libmythupnp

Simple uPnP (universal Plug and Play) support.

This library depends on libmythbase.


libmyth

Core MythTV library. Used by the Plugins. The audio, language support, plugin manager, media manager, and some old UI widgets are implemented by libmyth.

This library depends on libav*, libmythbase, libmythui, libmythupnp, libsamplerate, libmythsoundtouch and libmythfreesurround.

Any changes to this library's ABI may trigger a MythTV binary version change because the plugins depend on it.

libmythtv

MythTV TV functionality library. Used by some Plugins. The OSD, recorders, video and A/V players are implemented by libmythtv.

This library basically depends on all the other libraries!

This library is used by some plugins so changes to it's ABI may require a MythTV binary version change.

Any changes to classes that are serialized by the MythTV network protocol (for example ProgramInfo) or to the protocol itself require the protocol version number to be incremented.

libavcodec/libavformat/libavutil/libpostproc/libswscale

These together form the FFmpeg A/V decoding library (aka avlib). Documented Externally.

These should be modified as little as possible, and any changes should be sent upstream for inclusion in the FFmpeg project's version of these libraries.

These libraries do not depend on any of our libraries.

libmythmpeg2

Alternate MPEG-1/2 A/V decoding library. Documented externally. This is offered as an option for software decoding of MPEG-1 and MPEG-2 files. FFmpeg is still used for decoding MPEG still frames when this library is selected for playback.

This library does not depend on any of our libraries.

libsamplerate

Audio resampling library. Documented Externally. We use this to support different output sample rates than the sample rate used in the audio streams we play.

This library does not depend on any of our libraries.

libmythsoundtouch

Pitch preserving audio resampling library. External Website. We use this for the time-stretch feature.

This library does not depend on any of our libraries.

libmythbluray/libmythdvdnav

Used for navigating Blu Ray and DVD menus when using the internal player.

This library should not depend on any of our libraries.

libmythfreemheg

UK interactive TV viewer.

This library does not depend on any of our libraries.


libmythfreesurround

Support for some multi-channel audio transforms.

This library does not depend on any of our libraries.


libmythnvctrl

Interface between X-windows and NVidia drivers.

This library does not depend on any of our libraries.


libmythlivemedia

Support for the FreeBox recorder device.

This library does not depend on any of our libraries.


libmythhdhomerun

Interface to the SiliconDust HDHomeRun EtherNet connected TV tuner products.

This library does not depend on any of our libraries.

Two libraries libmythmpeg2 and libsamplerate appear redundant, but libmpeg2 decodes MPEG-2 more quickly than ffmpeg on some systems, and libsamplerate resamples audio with better quality when we only need to match the hardware sample rate to the A/V streams audio sample rate.

# Database Schema

The database schema is documented here.

# Applications

MythTV contains 13 applications which are installed by make install

mythbackend
This is the backend server which runs the recorders. On frontend only systems, the binary needs to be installed to perform some functions for the frontend, but does not need to be constantly running – the frontend will run it as needed.
mythfrontend
This is the frontend which is the main application for viewing programs and using the MythTV plugins.
mythtv-setup
This is the program which sets up the database to use a machine as a backend server.
mythavtest
For testing audio and video playback. Was once an "External Player" used to play video files from within mythfrontend. Setting the player command to "internal" achieves the same thing now.
mythtvosd
This is used externally by programs that want to pop-up an on screen display in MythTV while one is watching a recording.
mythfilldatabase
This is used both internally and externally to fetch program listings. Tribune Media provides listings in exchange for demographic information in the USA, and Australia has a community-driven TV guide originally developed for OzTiVo. Other markets are served by the XMLTV web spiders.
mythtranscode
This is used both internally and externally to transcode videos from one format to another. This is used to shrink HDTV programs to lower quality recordings that match the hardware the user has.
mythjobqueue
This can be run on a frontend only system instead of mythbackend to handle commercial flagging, transcode and user jobs. The only advantage over running a full mythbackend is to use sligtly less memory.
mythcommflag
This is used internally by mythfrontend to flag commercials. It can also be used to repair keyframe maps for recordings.
mythlcdserver
This is an interface between a number of Myth clients and a small text display (LCDProc server).
mythwelcome/mythshutdown
These programs manage Power Saving (shutdown/wakeup) on your MythTV PCs.
mythlogserver
A tool that records log messages from a number of other myth applications in one stream, storing them in any or all of; a logfile, the Unix system log (if availale), and the MySQL database.

# Frontend Plugins

mytharchive
Creates themed video DVDs from recordings and other video files.
mythbrowser
Provides a simple web browser.
mythgallery
A simple picture viewer for your TV.
mythgame
Launches PC games and game system emulators.
mythmusic
A simple music player for your TV.
mythnews
mythweather
mythzoneminder
Video surveilance system interface.

# Associated Applications

mythweb
Provides a PHP based web pages to control mythbackend.

# Support Scripts

These tools are in the packaging repository:

osx-packager-qtsdk.pl
Downloads and builds all dependencies, then the source, of MythTV and all the official plugins, on Mac OS 10.7 and 10.8
osx-packager.pl
Downloads and builds all dependencies, then the source, of MythTV and all the official plugins, on Mac OS (10.3?, 10.4?,) 10.5 and 10.6
win32-packager.pl
Similar tool for Windows XP, Vista and 7