Index: MythTV_PlugIn.cpp =================================================================== --- MythTV_PlugIn.cpp (revision 20423) +++ MythTV_PlugIn.cpp (working copy) @@ -51,6 +51,12 @@ #include "../Orbiter_Plugin/OH_Orbiter.h" +#define SCRIPT_DIR "/usr/pluto/bin" +#define SCRIPT_SYNC_TO_DB SCRIPT_DIR + "/MythTvSyncDB.sh" +#define SCRIPT_TUNE SCRIPT_DIR + "/TuneToChannel.sh" +#define SCRIPT_RESTART_BACKEND SCRIPT_DIR + "/Restart_MythBackend.sh" +#define SCRIPT_INITIAL_FILLDB SCRIPT_DIR + "/MythTvInitialFillDB.sh" + // For sorting channels static bool ChannelComparer(MythChannel *x, MythChannel *y) { @@ -963,33 +969,20 @@ return; } - UpdateMythSetting("JobAllowUserJob1","1","*"); - UpdateMythSetting("AutoRunUserJob1","1",""); - UpdateMythSetting("UserJob1","/usr/pluto/bin/SaveMythRecording.sh %CHANID% %STARTTIME% %DIR% %FILE%",""); - UpdateMythSetting("UserJobDesc1","Save the recorded show into Pluto's database",""); - UpdateMythSetting("Language","EN","*",true); + string cmd = SYNC_TO_DB; + string args = "master " + ((pDevice_Core && !pDevice_Core->m_sIPAddress.empty()) ? + pDevice_Core->m_sIPAddress : m_pRouter->sDBHost_get()); - UpdateMythSetting("PreferredMPEG2Decoder","xv","*"); - UpdateMythSetting("AutoCommercialFlag","0","*"); - UpdateMythSetting("AutoCommflagWhileRecording","0","*"); - UpdateMythSetting("VertScanPercentage","2","*"); - UpdateMythSetting("HorizScanPercentage","1","*"); - UpdateMythSetting("NetworkControlEnabled","1","*"); - UpdateMythSetting("NetworkControlPort","10001","*"); - UpdateMythSetting("UseChromaKeyOSD","0","*"); - UpdateMythSetting("UseOpenGLVSync","0","*"); - UpdateMythSetting("SelectChangesChannel","1","*"); - UpdateMythSetting("Deinterlace","1","*"); - UpdateMythSetting("DeinterlaceFilter","bobdeint","*"); - UpdateMythSetting("FFRewSpeed0","1","*"); - UpdateMythSetting("FFRewSpeed1","2","*"); - UpdateMythSetting("FFRewSpeed2","4","*"); - UpdateMythSetting("FFRewSpeed3","8","*"); - UpdateMythSetting("FFRewSpeed4","16","*"); + DeviceData_Base *pDevice_App_Server = (DeviceData_Router *) + m_pData->FindFirstRelatedDeviceOfCategory(DEVICECATEGORY_App_Server_CONST); + if (pDevice_App_Server) + { + DCE::CMD_Spawn_Application CMD_Spawn_Application( + m_dwPK_Device,pDevice_App_Server->m_dwPK_Device, + cmd, args, "", "", "", false, false, false, false); + SendCommand(CMD_Spawn_Application); + } - UpdateMythSetting("MasterServerIP",pDevice_Core && pDevice_Core->m_sIPAddress.empty()==false ? pDevice_Core->m_sIPAddress : m_pRouter->sDBHost_get( ),""); - UpdateMythSetting("MasterServerPort","6543",""); - ListDeviceData_Router *pListDeviceData_Router = m_pRouter->m_mapDeviceByTemplate_Find(DEVICETEMPLATE_MythTV_Player_CONST); if( pListDeviceData_Router ) { @@ -1005,10 +998,15 @@ Row_DeviceTemplate *pRow_DeviceTemplate = pRow_Device_PC->FK_DeviceTemplate_getrow(); if( pRow_DeviceTemplate && pRow_DeviceTemplate->FK_DeviceCategory_get()!=DEVICECATEGORY_Core_CONST ) sHostname = "moon" + StringUtils::itos(pRow_Device_PC->PK_Device_get()); - UpdateMythSetting("BackendServerIP",pRow_Device_PC->IPaddress_get(),sHostname); - UpdateMythSetting("MasterServerPort","6543",sHostname); - UpdateMythSetting("BackendServerPort","6543",sHostname); - UpdateMythSetting("BackendServerStatus","6544",sHostname); + + if (pDevice_App_Server) + { + args = "slave " + pRow_Device_PC->IPaddress_get() + " " + sHostname; + DCE::CMD_Spawn_Application CMD_Spawn_Application( + m_dwPK_Device,pDevice_App_Server->m_dwPK_Device, + cmd, args, "", "", "", false, false, false, false); + SendCommand(CMD_Spawn_Application); + } } else { @@ -1353,7 +1351,9 @@ if( pRow_Device_External ) { - sSQL = "UPDATE cardinput SET externalcommand='/usr/pluto/bin/TuneToChannel.sh " + StringUtils::itos(pRow_Device_External->PK_Device_get()) + " " + StringUtils::itos(sourceid) + "' WHERE cardinputid=" + StringUtils::itos(cardinputid); + sSQL = "UPDATE cardinput SET externalcommand='" + SCRIPT_TUNE + " " + + StringUtils::itos(pRow_Device_External->PK_Device_get()) + " " + + StringUtils::itos(sourceid) + "' WHERE cardinputid=" + StringUtils::itos(cardinputid); if( m_pDBHelper_Myth->threaded_db_wrapper_query(sSQL)>0 ) { LoggerWrapper::GetInstance()->Write(LV_STATUS,"MythTV_PlugIn::CMD_Sync_Providers_and_Cards bModifiedRows=true %s",sSQL.c_str()); @@ -2070,7 +2070,7 @@ string sArguments = StringUtils::itos(pScanJob->m_pRow_Device_Tuner->PK_Device_get()) + "\t" + StringUtils::itos(pScanJob->m_pRow_Device_CaptureCard->PK_Device_get()); DCE::CMD_Spawn_Application CMD_Spawn_Application(m_dwPK_Device,pDevice_App_Server->m_dwPK_Device, - "/usr/pluto/bin/" + pScanJob->m_sScanJob,"scanchannels",sArguments,sScanFailed,"",false,false,false,true); + SCRIPT_DIR + pScanJob->m_sScanJob,"scanchannels",sArguments,sScanFailed,"",false,false,false,true); string sResponse; if( !SendCommand(CMD_Spawn_Application,&sResponse) || sResponse!="OK" ) { @@ -2286,7 +2286,8 @@ if( pDevice_App_Server ) { DCE::CMD_Spawn_Application CMD_Spawn_Application(m_dwPK_Device,pDevice_App_Server->m_dwPK_Device, - "/usr/bin/screen","restart_myth","-d\t-m\t-S\tRestart_Myth_Backend\t/usr/pluto/bin/Restart_MythBackend.sh","","",false,false,false,false); + "/usr/bin/screen", "restart_myth", "-d\t-m\t-S\tRestart_Myth_Backend\t" + SCRIPT_RESTART_BACKEND, + "", "", false, false, false, false); CMD_Spawn_Application.m_pMessage->m_eRetry=MR_Retry; SendCommand(CMD_Spawn_Application); @@ -2311,7 +2312,7 @@ { string sResponse = "fill done"; DCE::CMD_Spawn_Application CMD_Spawn_Application_fill(m_dwPK_Device,pDevice_App_Server->m_dwPK_Device, - "/usr/pluto/bin/FillDbAndFetchIcons.sh","filldb","","","",false,false,true,false); + SCRIPT_INITIAL_FILLDB, "filldb", "", "", "", false, false, true, false); CMD_Spawn_Application_fill.m_pMessage->m_eRetry=MR_Persist; if( !SendCommand(CMD_Spawn_Application_fill) ) { @@ -2532,7 +2533,7 @@ if( pDevice_App_Server ) { DCE::CMD_Spawn_Application CMD_Spawn_Application(m_dwPK_Device,pDevice_App_Server->m_dwPK_Device, - "/usr/pluto/bin/ForciblyKillProcess.sh","killmyth","mythbackend","","",false,false,false,true); + SCRIPT_DIR + "/ForciblyKillProcess.sh","killmyth","mythbackend","","",false,false,false,true); SendCommand(CMD_Spawn_Application); } Index: MythTvInitialFillDB.sh =================================================================== --- MythTvInitialFillDB.sh (revision 0) +++ MythTvInitialFillDB.sh (revision 0) @@ -0,0 +1,68 @@ +#!/bin/bash + +. /usr/pluto/bin/Config_Ops.sh + +FILLDB=/usr/bin/mythfilldatabase + +# If the user installed a their own mythfilldatabase, adjust.. +if test -f /usr/local/bin/mythfilldatabase ; then + FILLDB=/usr/local/bin/mythfilldatabase +fi + +# Run mythfilldatabase on a single core if possible +if test x"" != x'which taskset' ; then + FILLDB="taskset -c 0 "$FILLDB +fi + +HAS_IGNORE_BACKEND=`$FILLDB --help | grep ignore-backend` +if test x"" != x"$HAS_IGNORE_BACKEND" ; then + FILLDB=$FILLDB" --ignore-backend" +fi + +# Lock the MythFillDatabase lock to another script from running mythfilldatabase +echo "MythTvInitialFillDB.sh waiting for MythFillDatabase lock" +WaitLock "MythFillDatabase" "MythTvInitialFillDB.sh" nolog +echo "MythTvInitialFillDB.sh got MythFillDatabase lock" + +# lock schema, this makes sure that we don't run this while the DB schema is +# being upgraded by another mythtv process. +echo "LOCK TABLE schemalock WRITE; UNLOCK TABLES;" | mysql mythconverg + +# Download today's scheduling data, so that we can tune LiveTV immediately +$FILLDB --refresh-today --max-days 1 + +# Download the channel icons +$FILLDB --import-icon-map /home/mythtv/master_iconmap.xml --update-icon-map + +# Myth puts the icons in the current user's home directory. We want /home/mythtv +echo "UPDATE channel SET icon=REPLACE(icon,'/root/.mythtv','/home/mythtv')" | mysql mythconverg +# Move the icons.. +mkdir -p /home/mythtv/channels +if test x`echo/root/.mythtv/channels/*`x != x""x ; then + mv -f /root/.mythtv/channels/* /home/mythtv/channels + chmod a+r /home/mythtv/channels/* +fi + +# Send a sync command to fix up the directories +/usr/pluto/bin/MessageSend $DCERouter -targetType template -r 0 36 1 824 + +# Restart all the backends.. +/usr/pluto/bin/Restart_Backend_With_SchemaLock.sh + +# Tell the user it's now safe to use MythTV +R=$(echo "SELECT * FROM videosource LIMIT 1" | mysql mythconverg) +if [[ -n "$R" ]]; then + # Notify all the orbiters that myth is ready to be used + /usr/pluto/bin/MessageSend $DCERouter -targetType template -r 0 12 1 406 9 \ + "MythTV is ready. However it may take several more minutes before the guide data is fully populated." 102 300 + /usr/pluto/bin/MessageSend $DCERouter -targetType template -r 0 36 1 910 9 \ + "Finished retrieving channels" +fi + +# Unlock the MythFillDatabase lock +Unlock "MythFillDatabase" "MythTvInitialFillDB.sh" nolog + +# if we ran without a mythbackend connection, tell the backend to reschedule.. +if test x"" != x"$HAS_IGNORE_BACKEND" ; then + mythbackend --resched > /dev/null & +fi Property changes on: MythTvInitialFillDB.sh ___________________________________________________________________ Name: svn:executable + * Index: FillDbAndFetchIcons.sh =================================================================== --- FillDbAndFetchIcons.sh (revision 20423) +++ FillDbAndFetchIcons.sh (working copy) @@ -1,63 +0,0 @@ -#!/bin/bash - -. /usr/pluto/bin/Config_Ops.sh - -FILLDB=/usr/bin/mythfilldatabase - -# If the user installed a their own mythfilldatabase, adjust.. -if test -f /usr/local/bin/mythfilldatabase ; then - FILLDB=/usr/bin/mythfilldatabase -fi - -# Run mythfilldatabase on a single core if possible -if test x"" != x'which taskset' ; then - FILLDB="taskset -c 0 "$FILLDB -fi - -HAS_IGNORE_BACKEND=`$FILLDB --help | grep ignore-backend` -if test x"" != x"$HAS_IGNORE_BACKEND" ; then - FILLDB=$FILLDB" --ignore-backend" -fi - -# Download the minimum data needed to get the channel lists -# $FILLDB --only-update-channels -# ^^^^ Not needed since we download today's data below... - -# Download today's scheduling data, so that we can tune LiveTV immediately -$FILLDB --refresh-today --max-days 1 - -# Download the channel icons -$FILLDB --import-icon-map /home/mythtv/master_iconmap.xml --update-icon-map - -# lock schema, this makes sure that we don't run this while the DB schema is -# being upgraded by another mythtv process. -echo "LOCK TABLE schemalock WRITE; UNLOCK TABLES;" | mysql mythconverg -# Myth puts the icons in the current user's home directory. We want /home/mythtv -echo "UPDATE channel SET icon=REPLACE(icon,'/root/.mythtv','/home/mythtv')" | mysql mythconverg -# Move the icons.. -mkdir -p /home/mythtv/channels -if test x`echo/root/.mythtv/channels/*`x != x""x ; then - mv -f /root/.mythtv/channels/* /home/mythtv/channels - chmod a+r /home/mythtv/channels/* -fi - -# Send a sync command to fix up the directories -/usr/pluto/bin/MessageSend $DCERouter -targetType template -r 0 36 1 824 - -R=$(echo "SELECT * FROM videosource LIMIT 1" | mysql mythconverg) -if [[ -n "$R" ]]; then - # Notify all the orbiters that myth is ready to be used - /usr/pluto/bin/MessageSend $DCERouter -targetType template -r 0 12 1 406 9 \ - "MythTV is ready. However it may take several more minutes before the guide data is fully populated." 102 300 - /usr/pluto/bin/MessageSend $DCERouter -targetType template -r 0 36 1 910 9 \ - "Finished retrieving channels" -fi - -/usr/pluto/bin/Restart_Backend_With_SchemaLock.sh - -# Now that we have channels and icons, go ahead and fill the database. If the user interrupts this now it's ok -# because it will grab partial data and continue the next time -$FILLDB - -# tell the backend to reschedule -mythbackend --resched > /dev/null & Index: MythTvDailyFillDB.sh =================================================================== --- MythTvDailyFillDB.sh (revision 0) +++ MythTvDailyFillDB.sh (revision 0) @@ -0,0 +1,48 @@ +#!/bin/bash + +. /usr/pluto/bin/Config_Ops.sh + +FILLDB=/usr/bin/mythfilldatabase + +# If the user installed a their own mythfilldatabase, adjust.. +if test -f /usr/local/bin/mythfilldatabase ; then + FILLDB=/usr/local/bin/mythfilldatabase +fi + +# Run mythfilldatabase on a single core if possible +if test x"" != x'which taskset' ; then + FILLDB="taskset -c 0 "$FILLDB +fi + +HAS_IGNORE_BACKEND=`$FILLDB --help | grep ignore-backend` +if test x"" != x"$HAS_IGNORE_BACKEND" ; then + FILLDB=$FILLDB" --ignore-backend" +fi + +# Lock the MythFillDatabase lock to another script from running mythfilldatabase +echo "MythTvDailyFillDB.sh waiting for MythFillDatabase lock" +WaitLock "MythFillDatabase" "MythTvDailyFillDB.sh" nolog +echo "MythTvDailyFillDB.sh got MythFillDatabase lock" + +# lock schema, this makes sure that we don't run this while the DB schema is +# being upgraded by another mythtv process. +echo "LOCK TABLE schemalock WRITE; UNLOCK TABLES;" | mysql mythconverg + +# Download today's scheduling data, so that we can tune LiveTV immediately +$FILLDB + +# Tell the user it's now safe to use MythTV +R=$(echo "SELECT * FROM videosource LIMIT 1" | mysql mythconverg) +if [[ -n "$R" ]]; then + # Notify all the orbiters that myth is ready to be used + /usr/pluto/bin/MessageSend $DCERouter -targetType template -r 0 36 1 910 9 \ + "Finished retrieving scheduling data" +fi + +# Unlock the MythFillDatabase lock +Unlock "MythFillDatabase" "MythTvDailyFillDB.sh" nolog + +# if we ran without a mythbackend connection, tell the backend to reschedule.. +if test x"" != x"$HAS_IGNORE_BACKEND" ; then + mythbackend --resched > /dev/null & +fi Property changes on: MythTvDailyFillDB.sh ___________________________________________________________________ Name: svn:executable + * Index: MythTvSyncDB.sh =================================================================== --- MythTvSyncDB.sh (revision 0) +++ MythTvSyncDB.sh (revision 0) @@ -0,0 +1,147 @@ +#!/bin/sh +# /usr/pluto/bin/MythTvSyncDB.sh +# Copyright 2008 Daniel Kristjansson +# Licensed under the GPL, version 2; or, at your option, a later version. + +DBHostName="localhost" +DBUserName="mythtv" +DBName="mythconverg" +DBPassword="mythtv" +DBPort="3306" + +if [ -f /etc/mythtv/mysql.txt ]; then + . /etc/mythtv/mysql.txt +fi + +MYSQLPIPE="mysql -h $DBHostName -P $DBPort -u $DBUserName -p$DBPassword mythconverg --skip-column-names" +NAMES=$(echo "SELECT hostname FROM settings WHERE hostname IS NOT NULL GROUP BY hostname;" | $MYSQLPIPE) + +function UpdateMythSetting { + SETTING_VALUE="$1" + SETTING_DATA="$2" + SETTING_HOST="$3" + + if [ x"$SETTING_HOST" = x"NULL" ] ; then + echo "DELETE FROM settings WHERE value = '${SETTING_VALUE}' AND hostname IS NULL;" | $MYSQLPIPE + echo "INSERT INTO settings(value,data) VALUES ('$SETTING_VALUE','$SETTING_DATA');" | $MYSQLPIPE + else + echo "DELETE FROM settings WHERE value = '${SETTING_VALUE}' AND hostname = '${SETTING_HOST}';" | $MYSQLPIPE + echo "INSERT INTO settings(value,data,hostname) VALUES ('$SETTING_VALUE', '$SETTING_DATA', '$SETTING_HOST');" | $MYSQLPIPE + fi +} + +function InsertMythSetting { + SETTING_VALUE="$1" + SETTING_DATA="$2" + SETTING_HOST="$3" + + if [ x"$SETTING_HOST" = x"NULL" ] ; then + COUNT=$(echo "SELECT count(1) FROM settings WHERE value = '${SETTING_VALUE}' AND hostname IS NULL;" | $MYSQLPIPE) + else + COUNT=$(echo "SELECT count(1) FROM settings WHERE value = '${SETTING_VALUE}' AND hostname = '${SETTING_HOST}';" | $MYSQLPIPE) + fi + + if [ x"$COUNT" == x"0" ] ; then + UpdateMythSetting "$SETTING_VALUE" "$SETTING_DATA" "$SETTING_HOST" + fi +} + +function UpdateMythSettingAllHosts { + SETTING_VALUE="$1" + SETTING_DATA="$2" + + for NAME in $NAMES ; do + UpdateMythSetting "$SETTING_VALUE" "$SETTING_DATA" "$NAME" + done +} + +function InsertMythSettingAllHosts { + SETTING_VALUE="$1" + SETTING_DATA="$2" + + for NAME in $NAMES ; do + InsertMythSetting "$SETTING_VALUE" "$SETTING_DATA" "$NAME" + done +} + +if [ x"$1" = x"master" ] ; then + IPADDR="$2" + if [ x"" = x"$IPADDR" ] ; then + echo "Must set IP Address of MythTV Master server." + exit 1 + fi + + # Do NOT remove this user job, it is required for MythTV recordings + # to show up in LMCE's recording list with metadata. + UpdateMythSettingAllHosts "JobAllowUserJob1" "1" + UpdateMythSetting "AutoRunUserJob1" "1" "NULL" + UpdateMythSetting "UserJob1" "/usr/pluto/bin/SaveMythRecording.sh %CHANID% %STARTTIME% %DIR% %FILE%" "NULL" + UpdateMythSetting "UserJobDesc1" "Save the recorded show into Pluto\'s database" "NULL" + + # This is only to default to English, if you set a different + # set of languages within MythTV these will not be inserted. + InsertMythSettingAllHosts "Language" "EN" + InsertMythSettingAllHosts "ISO639Language0" "eng" + InsertMythSettingAllHosts "ISO639Language1" "eng" + + # Changing any of these are know to cause problems within MythTV + # LMCE will still function, but MythTV will not function optimally. + UpdateMythSettingAllHosts "PreferredMPEG2Decoder" "ffmpeg" + UpdateMythSettingAllHosts "UseChromaKeyOSD" "0" + UpdateMythSettingAllHosts "UseOpenGLVSync" "0" + + # This can be safely changed, but beware that Xine can not take + # advantage of this flagging and it consumes considerable CPU. + UpdateMythSettingAllHosts "AutoCommercialFlag" "0" + UpdateMythSettingAllHosts "AutoCommflagWhileRecording" "0" + + # Do NOT change the network control setup, the MythTV_PlugIn will get confused. + UpdateMythSettingAllHosts "NetworkControlEnabled" "1" + UpdateMythSettingAllHosts "NetworkControlPort" "10001" + + # This channel changing option can be safely changed + UpdateMythSettingAllHosts "SelectChangesChannel" "1" + + # These playback options can be safely changed + UpdateMythSettingAllHosts "VertScanPercentage" "2" + UpdateMythSettingAllHosts "HorizScanPercentage" "1" + UpdateMythSettingAllHosts "Deinterlace" "1" + UpdateMythSettingAllHosts "DeinterlaceFilter" "bobdeint" + + # Changing these will cause problems with fast forward in the Orbiter UI + UpdateMythSettingAllHosts "FFRewSpeed0" "1" + UpdateMythSettingAllHosts "FFRewSpeed1" "2" + UpdateMythSettingAllHosts "FFRewSpeed2" "4" + UpdateMythSettingAllHosts "FFRewSpeed3" "8" + UpdateMythSettingAllHosts "FFRewSpeed4" "16" + + # Don't disable mythfilldatabase even with EIT scheduling data. + # mythfilldatabase also performs some housecleaning tasks. + UpdateMythSetting "MythFillEnabled" "1" "NULL" + UpdateMythSetting "MythFillPeriod" "1" "NULL" + UpdateMythSetting "MythFillMinHour" "0" "NULL" + UpdateMythSetting "MythFillMaxHour" "19" "NULL" + UpdateMythSetting "MythFillDatabasePath" "/usr/pluto/bin/MythTvDailyFillDB.sh" "NULL" + UpdateMythSetting "MythFillDatabaseLog" "/var/log/mythtv/mythfilldatabase.log" + + # Don't change this unless you KNOW what you are doing + UpdateMythSetting "MasterServerIP" $IPADDR "NULL" + UpdateMythSetting "MasterServerPort" "6543" "NULL" +elif [ x"$1" = x"slave" ] ; then + IPADDR="$2" + NAME="$3" + if [ x"" = x"$IPADDR" ] ; then + echo "Must set IP Address of MythTV server." + exit 1 + fi + if [ x"" = x"$NAME" ] ; then + echo "Must set name of MythTV server." + exit 2 + fi + + # Don't change this unless you KNOW what you are doing + UpdateMythSetting "BackendServerIP" $IPADDR $NAME + UpdateMythSetting "MasterServerPort" "6543" $NAME + UpdateMythSetting "BackendServerPort" "6543" $NAME + UpdateMythSetting "BackendServerStatus" "6544" $NAME +fi \ No newline at end of file Property changes on: MythTvSyncDB.sh ___________________________________________________________________ Name: svn:executable + *