View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 14 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
PostPosted: Tue Jul 05, 2005 12:45 am 
Offline
Joined: Mon Jun 20, 2005 1:02 am
Posts: 7
Hi. I live in Finland and am trying to set up MythTV 0.18 but am having a very hard time with it.

I seem to have everything working on the driver side, art least everything appropriate is mentioned in lspci and mythtv-setup detects my card right.

I have tried this both with KnoppMyth and Gentoo linux, both have led me to the following:

Myth starts normally, no problems there. The videos I have imported play normally and life seems peachy. When I try watching live TV, however, I get a black screen. I have scanned for channels and, as prompted, run mythfilldatabase --manual and that gave me no errors either. What the mythfrontend console outputs:
Quote:
2005-07-04 12:49:55.977 New DB connection, total: 2
2005-07-04 12:49:55.992 Connecting to backend server: localhost:6543 (try 1 of 5)
2005-07-04 12:49:56.000 Using protocol version 15
2005-07-04 12:49:56.034 Using protocol version 15
2005-07-04 12:50:01.114 taking too long to be allowed to read..
2005-07-04 12:50:06.116 taking too long to be allowed to read..
2005-07-04 12:50:11.117 taking too long to be allowed to read..
2005-07-04 12:50:11.117 Took more than 10 seconds to be allowed to read, aborting.
Couldn't read file: rbuf://localhost:6543/mnt/store//ringbuf1.nuv
2005-07-04 12:50:11.143 Changing from None to WatchingLiveTV
2005-07-04 12:50:11.143 Decoder not alive, and trying to play..
2005-07-04 12:50:12.121 RemoteFile::Read() failed in RingBuffer::safe_read().
2005-07-04 12:50:12.121 Changing from None to None

The permissions for /mnt/store are not too restrictive, so that shouldn't be a problem. The backend, which I have started with mythbackend --verbose channel to get more info on the channel it tries to play gives me this:
Quote:
2005-07-04 12:49:16.835 New DB connection, total: 2
2005-07-04 12:49:16.843 DVB#1 DVB SI Table Parser Started
2005-07-04 12:49:17.669 DVB#1 Using DVB card 1, with frontend VLSI VES1820 DVB-C.
2005-07-04 12:49:17.671 DVB#1 Trying to tune to channel 3.
2005-07-04 12:49:17.672 New DB connection, total: 3
2005-07-04 12:49:17.674 DVB#1 ERROR - Could not find dvb tuning parameters for transport 0
2005-07-04 12:49:17.674 DVB#1 ERROR - Failed to get channel options for channel 3.
2005-07-04 12:49:17.678 New DB scheduler connection
2005-07-04 12:49:17.683 mythbackend version: 0.18.1.20050510-1 www.mythtv.org
2005-07-04 12:49:17.683 Enabled verbose msgs : important general channel
2005-07-04 12:49:19.683 Reschedule requested for id -1.
2005-07-04 12:49:19.695 Scheduled 0 items in 0.0 = 0.01 match + 0.00 place
2005-07-04 12:49:19.698 Seem to be woken up by USER
2005-07-04 12:49:56.006 MainServer::HandleAnnounce Playback
2005-07-04 12:49:56.006 adding: 8 as a client (events: 0)
2005-07-04 12:49:56.029 MainServer::HandleAnnounce Playback
2005-07-04 12:49:56.029 adding: 8 as a client (events: 1)
2005-07-04 12:49:56.040 MainServer::HandleAnnounce Playback
2005-07-04 12:49:56.040 adding: 8 as a client (events: 0)
2005-07-04 12:49:56.054 MainServer::HandleAnnounce Playback
2005-07-04 12:49:56.054 adding: 8 as a client (events: 0)
2005-07-04 12:49:56.061 adding: 8 as a remote ringbuffer
2005-07-04 12:49:56.072 Changing from None to WatchingLiveTV
2005-07-04 12:49:56.089 DVB#1 Recorder: Card opened successfully (using PS mode).
2005-07-04 12:49:56.090 DVB#1 ERROR - No PIDS set, please correct your channel setup.
2005-07-04 12:49:57.091 DVB#1 WARNING - No data from card in 1 second. <SNIP! This message repeats once every second for the next 13 seconds>
2005-07-04 12:50:11.105 DVB#1 WARNING - No data from card in 1 second.
2005-07-04 12:50:11.117 Couldn't read data from the capture card in 15 seconds. Stopping.
2005-07-04 12:50:11.151 Changing from WatchingLiveTV to None
2005-07-04 12:50:12.106 DVB#1 WARNING - No data from card in 1 second.
2005-07-04 12:50:12.106 Closing DVB recorder


I also tried to look at the backend output with --verbose all but there was so much stuff. The relevant, I think, was that it said getting autoPID but still was unable to get a PID. I'm out of ideas so I thought I'd ask here...

Oh, I have another card, a Technotrend budget one and with that I get exactly the same results.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 7:13 pm 
Offline
Joined: Wed Mar 03, 2004 7:43 pm
Posts: 748
Location: Sydney, Australia
You say you did Scan for channels in mythtv-setup?

Did it list the channels in the CHannel Editor after the scan?

If so, then it is simply a matter of the starting channel (3) not existing. Go into "Input Connections" and change the 3 to a channel number that was scanned. And then restart the backend (/etc/init.d/mythtv-backend restart)

_________________
| Nigel Pearson, nigel.pearson.au@gmail.com
| "Things you own end up owning you" - Tyler, Fight Club


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 7:58 pm 
Offline
Joined: Mon May 10, 2004 8:08 pm
Posts: 1891
Location: Adelaide, Australia
I wish they would fix this problem in Mythtv. If it cant tune to the start channel, it should try the next channel in the list. I think it would have reduced a lot of "cant watch live-tv" posts in this forum!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 11:25 pm 
Offline
Joined: Wed Mar 03, 2004 7:43 pm
Posts: 748
Location: Sydney, Australia
I did the next best thing, which is to add a few sanity checks when you exit mythtv-setup. That will catch a few common mistakes.

(several times I have forgotten to change the default start channel of 3 to something like 7 or 9)

Changing the channel change logic is a bit harder (I think the behaviour you describe would require changes to the frontend too, because it would be blindly putting up OSDs that say 3, when in fact the backend has skipped that to something like 7).

A better fix would be for the backend to send a static image that says "This channel doesn't exist", or "This channel isn't transmitting" or "I can't tune to this channel". Also a bigger change than I can manage right now :(

_________________
| Nigel Pearson, nigel.pearson.au@gmail.com
| "Things you own end up owning you" - Tyler, Fight Club


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 2:27 am 
Offline
Joined: Mon Jun 20, 2005 1:02 am
Posts: 7
nigelpearson wrote:
You say you did Scan for channels in mythtv-setup?

Did it list the channels in the CHannel Editor after the scan?

If so, then it is simply a matter of the starting channel (3) not existing. Go into "Input Connections" and change the 3 to a channel number that was scanned. And then restart the backend (/etc/init.d/mythtv-backend restart)


I did not manage to get a scan, I got the channels with mythfilldatabase --manual

The scan gives me a "error parsing parameters"

However, I have set the starting channel to 1 so that shouldn't be the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 5:07 am 
Offline
Joined: Wed Mar 03, 2004 7:43 pm
Posts: 748
Location: Sydney, Australia
Phekko wrote:
nigelpearson wrote:
You say you did Scan for channels in mythtv-setup?


I did not manage to get a scan, I got the channels with mythfilldatabase --manual


OK, then that is your problem. Setting up a Video Source, or inserting the data associated with it (what you did with mythfilldatabase) only gives you TV channel programming information. It does not actually set the channels up (the transponder frequencies and PIDs).

Quote:
The scan gives me a "error parsing parameters"
I haven't seen this error, so I am guessing here. Where was this error displayed?

Did you give it a transponder frequency? How about a bandwidth?

Quote:
However, I have set the starting channel to 1 so that shouldn't be the problem.
It is a problem, because your backend doesn't know how to tune to _any_ channels. It knows some channel numbers, but not the frequency or PID to filter from that frequency.

_________________
| Nigel Pearson, nigel.pearson.au@gmail.com
| "Things you own end up owning you" - Tyler, Fight Club


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 8:13 am 
Offline
Joined: Mon Jun 20, 2005 1:02 am
Posts: 7
Ah yes. The error I mentioned I get when I go to the fifth menu in mythtv-setup and try to scan for channels. There is a scan progress window in the background but it doesn't progress and the error pops up.

If instead of a full scan I try an existing transport scan I get another kind of error. I'm guessing it is because I don't have any transports set up and I have no idea what to do about it or how, not sure where this is needed really. The setup instructions I have are kind of vague around that point I'm afraid.

If, however, I make a full scan of existing transports I get no errors but also no channels are found.

I have been able to get a channel lock with czap so I'm guessing the card and modules are ok. I got a channels.conf, do you think I can use this to set up the channels in some way?

Sorry to be such a newbie, I'm not the guru I wish I was ;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 2:52 am 
Offline
Joined: Wed Mar 03, 2004 7:43 pm
Posts: 748
Location: Sydney, Australia
OK. Here is a script that _might_ do the trick. Let me know if it works, or if not what errors you get from either it or the backend.

#!/usr/bin/perl -w
# ============================================================================
# = NAME
# channels.conf-import
#
# = PURPOSE
# Insert DVB channel information into the MythTV database
#
# = USAGE
# channels.conf-import
# channels.conf-import -c # Parse czap format channels.conf file
# channels.conf-import -s # Parse szap format channels.conf file
# channels.conf-import -t # Parse tzap format channels.conf file
# channels.conf-import -d # Extra debugging output
# channels.conf-import -n # No execute (safe or simulation) mode
#
# = DESCRIPTION
# For each line in channels.conf, this script tries to match a
# channel in the the database. If there is no exact match by name,
# it prompts the user to select a channel record. If none is selected,
# or if the frequency and PIDs don't match, it prompts for re-insertion
# of the channel.
#
# = REVISION
# $Id$
#
# = AUTHORS
# Malcolm Smith, Nigel Pearson
# ============================================================================

use strict;
use DBI();
use Getopt::Long;
use File::Basename;

# configuration
my @mysqldir = ( '~/.mythtv', '/usr/share/mythtv', '/usr/local/share/mythtv' );

#my $channelsconf = "/root/.szap/channels.conf";
#my $channelsconf = "/usr/src/DVB/apps/szap/channels.conf-dvbt-oxford";
my $channelsconf = "channels.conf";

# type of channels.conf file
my $channelsconftype = "tzap";

# MythTV database stuff
my $sourceid = 1;
my $chanid_start = 1000;

my $sql1="Invalid";

# do nothing
my $simulate = 0;

# extra console output
my $DEBUG = 1;

# ============================================================================
# Parse any command-line arguments
#
my $arg;

for $arg ( @ARGV )
{
if ( $arg eq '-c' )
{ $channelsconftype = 'czap' }
elsif ( $arg eq '-d' )
{ $DEBUG = 1 }
elsif ( $arg eq '-n' )
{ $simulate = 1 }
elsif ( $arg eq '-s' )
{ $channelsconftype = 'szap' }
elsif ( $arg eq '-t' )
{ $channelsconftype = 'tzap' }
elsif ( $arg eq '-v' )
{ $channelsconftype = 'vdr' }
else
{ die "Invalid argument '$arg'\n" }
}

# ============================================================================
# variable definition
#
my $networkid;
my $transportid;
my @channeldata;
my %channelhash;
my $db_host;
my $db_user;
my $db_name;
my $db_pass;

# ============================================================================
# Given a list of parsed fields, generate an SQL statement to
# insert these fields and values into the dtv_multiplex table

sub genMux($@)
{
my ($mplexid, $sourceid, @fields) = @_;

my $sql = 'REPLACE INTO dtv_multiplex ' .
'(mplexid, sourceid, visible,' .
' sistandard, serviceversion, updatetimestamp, ' .
join (', ', @fields) . ")\n" .
"VALUES ($mplexid, $sourceid, 1, 'dvb', 33, ";

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

$sql .= sprintf("%4d%02d%02d%02d%02d%02d",
$year+1900, $mon+1, $mday, $hour, $min, $sec) . ', ';


my $field;
foreach $field ( @fields )
{
if ( defined $channelhash{$field} )
{
my $val = $channelhash{$field};

if ( $val =~ /^\d*$/ ) # If value is a number
{ $sql .= "$val, " }
else
{ $sql .= "'$val', " }
}
else
{
print "\$channelhash{'$field'} does not exist\n";
$sql .= '0, ';
}
}

chop $sql;chop $sql; # Remove trailing ', '

return "$sql)";
}

# ============================================================================
# Routines to parse ZAP-style files
#

sub fix_zCodeRates
{
$channelhash{'lp_code_rate'} =~ s/FEC_//g;
$channelhash{'lp_code_rate'} =~ s/_/\//g;
$channelhash{'hp_code_rate'} =~ s/FEC_//g;
$channelhash{'hp_code_rate'} =~ s/_/\//g;
}

sub fix_zInversion
{
if ($channelhash{'inversion'} eq "INVERSION_ON" )
{ $channelhash{'inversion'} = '1' }

if ($channelhash{'inversion'} eq "INVERSION_OFF" )
{ $channelhash{'inversion'} = '0' }

if ($channelhash{'inversion'} eq "INVERSION_AUTO" )
{ $channelhash{'inversion'} = 'a' }
}

sub fix_zConstellation
{
# make constellation lowercase
$channelhash{'constellation'} =~ s/QAM/qam/g;
}

sub parseCZAP(@)
{
$channelhash{'frequency'} = shift @channeldata;
$channelhash{'inversion'} = shift @channeldata;
$channelhash{'symbolrate'} = shift @channeldata;
$channelhash{'fec'} = shift @channeldata;
$channelhash{'modulation'} = shift @channeldata;

&fix_zInversion;
&fix_zCodeRates;
&fix_zConstellation;
}

sub parseSZAP(@)
{
$channelhash{'frequency'} = (shift @channeldata) . '000';
$channelhash{'polarity'} = shift @channeldata;
$channelhash{'satid'} = shift @channeldata;
$channelhash{'symbolrate'} = (shift @channeldata) . '000';

# on dvb-s we always have qpsk
$channelhash{'constellation'} = 'qpsk';
}

sub parseTZAP(@)
{
$channelhash{'frequency'} = shift @channeldata;
$channelhash{'inversion'} = shift @channeldata;
$channelhash{'bandwidth'} = shift @channeldata;
$channelhash{'lp_code_rate'} = shift @channeldata;
$channelhash{'hp_code_rate'} = shift @channeldata;
$channelhash{'constellation'} = shift @channeldata;
$channelhash{'transmission_mode'} = shift @channeldata;
$channelhash{'guard_interval'} = shift @channeldata;
$channelhash{'hierarchy'} = shift @channeldata;

# Set some defaults
$channelhash{'fec'} = 'auto';
$channelhash{'modulation'} = 'auto';
$channelhash{'polarity'} = 'V';
$channelhash{'symbolrate'} = '69000';

&fix_zInversion;
&fix_zCodeRates;
&fix_zConstellation;

$channelhash{'bandwidth'} =~ s/BANDWIDTH_//;
$channelhash{'bandwidth'} =~ s/_.*//;

$channelhash{'guard_interval'} =~ s/GUARD_INTERVAL_//g;
$channelhash{'guard_interval'} =~ s/_/\//g;

if ($channelhash{'hierarchy'} eq "HIERARCHY_NONE" )
{ $channelhash{'hierarchy'} = 'n' }
else
{ $channelhash{'hierarchy'} = 'auto' }

$channelhash{'lp_code_rate'} =~ s/FEC_//g;
$channelhash{'lp_code_rate'} =~ s/_/\//g;

$channelhash{'transmission_mode'} =~ s/TRANSMISSION_MODE_//g;
$channelhash{'transmission_mode'} =~ s/K//g;
}

sub parseZAP
{
if ( $channelsconftype eq 'szap' )
{ &parseSZAP(@channeldata) }
elsif ( $channelsconftype eq 'czap' )
{ &parseCZAP(@channeldata) }
elsif ( $channelsconftype eq 'tzap' )
{ &parseTZAP(@channeldata) }
else
{ die "Illegal channelconftype in perl script" }

$channelhash{'vpid'} = shift @channeldata;
$channelhash{'apid'} = shift @channeldata;
$channelhash{'serviceid'} = shift @channeldata;
chop $channelhash{'serviceid'};
}

# ============================================================================
# Routines to parse VDR-style file

sub parseVDRs
{
die "Sorry - Nigel hasn't implemented VDRs parsing yet";
}

sub parseVDRc
{
die "Sorry - Nigel hasn't implemented VDRc parsing yet";
}

sub parseVDRt
{
die "Sorry - Nigel hasn't implemented VDRt parsing yet";
}

sub parseVDR
{
if ( grep m/:T:27500:/, @channeldata )
{ &parseVDRt }
elsif ( grep m/:M.*:C:/, @channeldata )
{ &parseVDRc }
else
{ &parseVDRs }
}

# ============================================================================

# Read the mysql.txt file in use by MythTV.

while (my $dir = shift @mysqldir)
{
if (open(CONF, "$dir/mysql.txt"))
{ last }
}

if (! @mysqldir)
{ die ("Unable to find mysql.txt\n\n") }

while (my $line = <CONF>) {
chomp($line);
$line =~ s/^str //;
my ($var, $val) = split(/\=/, $line, 2);
next unless ($var && $var =~ /\w/);
if ($var eq 'DBHostName') {
$db_host = $val;
}
elsif ($var eq 'DBUserName') {
$db_user = $val;
}
elsif ($var eq 'DBName') {
$db_name = $val;
}
elsif ($var eq 'DBPassword') {
$db_pass = $val;
}
}
close CONF;

# Connect to the database
my $dbh = DBI->connect("dbi:mysql:database=$db_name:host=$db_host",
$db_user, $db_pass)
or die "Cannot connect to database: $!\n\n";

if ($simulate) {
print "Simulation mode. SQL not done.\n";
};


# Check the version
my $db_ver = $dbh->prepare("SELECT data FROM settings" .
" WHERE value='DBSchemaVer'");
$db_ver->execute() or die "Could not execute db version query";
my $ver;
if (my @row = $db_ver->fetchrow_array) {
$ver = $row[0];
}

if ( !$ver ) {
die "Could not get backend database version";
}

if ( $ver < 1063 ) {
print "This script is not compatible with the backend and database.\n",
"Database DVB tables were redesigned between MythTV 0.16 and 0.17.\n",
"Please use an older version of this script.\n";
exit 0;
}

if ( $ver > 1062 ) {
print "\nThis backend should be capable of scanning for DVB channels.\n\n",
"Try running mythtv-setup, clearing your capture cards,",
" and re-adding them.\n",
"There should be a 'Scan' button in the Channel Editor\n\n",
"Do you want to try and use this script anyway? [n]/y:";
my $selection = <>;
chomp($selection);
if ($selection ne "y" )
{ exit 0 }
}


# Go through each line in channels.conf:

open (CHANNELSCONF, "<$channelsconf")
or die "failed opening channels.conf: $!";

my @channelsconf = <CHANNELSCONF>;

foreach my $channel_line ( @channelsconf )
{
# get the information out of the channelsconf row
@channeldata = split(/:/, $channel_line);

my $name = shift @channeldata;

%channelhash = (); # Clear previous insert's values
$channelhash{'satid'} = 0; # Default of NULL is inappropriate
$channelhash{'sistandard'} = 'dvb';


if ( $channelsconftype =~ m/zap$/ )
{ &parseZAP }
elsif ($channelsconftype eq 'vdr')
{ &parseVDR(@channeldata) }

if ( $DEBUG )
{
print "name : $name\n";
print "lp_code_rate : $channelhash{'lp_code_rate'}\n";
print "hp_code_rate : $channelhash{'hp_code_rate'}\n";
print "inversion : $channelhash{'inversion'}\n";
print "transmission_mode : $channelhash{'transmission_mode'}\n";
print "guard_interval : $channelhash{'guard_interval'}\n";
print "hierarchy : $channelhash{'hierarchy'}\n";
print "frequency : $channelhash{'frequency'}\n";
print "bandwidth : $channelhash{'bandwidth'}\n";
print "polarity : $channelhash{'polarity'}\n";
print "symbolrate : $channelhash{'symbolrate'}\n";
#print "satid : $channelhash{'satid'}\n";
print "modulation : $channelhash{'modulation'}\n";
print "VPID : $channelhash{'vpid'}\n";
print "APID : $channelhash{'apid'}\n";
}


# Now retrieve data from the channel table.
my $tb_channel = $dbh->prepare("SELECT * FROM channel " .
"WHERE sourceid=$sourceid AND name='$name'");
my $num_valid_chans = $tb_channel->execute();

if ( $num_valid_chans == 0 )
{
# No channels matching the name? Try to get all the channels
$tb_channel->finish();
$tb_channel = $dbh->prepare("SELECT * FROM channel" .
" WHERE sourceid=$sourceid");
$num_valid_chans = $tb_channel->execute();

if ( $num_valid_chans == 0 )
{ print "Channels table is empty. " }
}

if ( $num_valid_chans > 1 )
{
# Select from all the channels
my @chanids = ();
my $i = 1;

print "Found these channels:\n";
while (my $ref = $tb_channel->fetchrow_hashref())
{
print "$i\t$ref->{'chanid'}\t$ref->{'channum'}\t$ref->{'name'}\n";
push @chanids, $ref->{'chanid'};
if ( $ref->{'chanid'} > $chanid_start )
{ $chanid_start = $ref->{'chanid'} }
}

print "What to do [number to select, anything else to ignore]? ";
my $selection = <>;
chomp($selection);

if ($selection !~ /^\d+$/)
{
$num_valid_chans = 0; # Force possible insertion
}
else
{
my $chanid = $chanids[$selection - 1];
($DEBUG) && print "using row $selection (chanid $chanid)\n";
$tb_channel->finish();
$tb_channel = $dbh->prepare("SELECT * FROM channel" .
" WHERE chanid=$chanid");
$num_valid_chans = $tb_channel->execute();
}
}

if ( $num_valid_chans == 0 )
{
print "Insert channel '$name'? [n]/y:";
my $selection = <>;
chomp($selection);
if ($selection ne "y" )
{
$tb_channel->finish();
next; # read next channel from channels.conf
}

# Insert
++ $chanid_start;
$sql1 = "REPLACE INTO channel (chanid,channum,sourceid,name,serviceid)"
. " VALUES ($chanid_start, '$chanid_start', $sourceid, "
. "'$name', $channelhash{'serviceid'})";
if ( $simulate )
{
print "If not in simulate mode, we would do:",
"$sql1\n",
"(and probably a dtv_multiplex record too!";
next;
}
else
{ $dbh->do($sql1) }

# Re-read whole record:
$tb_channel->finish();
$tb_channel = $dbh->prepare("SELECT * FROM channel" .
" WHERE chanid=$chanid_start");
$num_valid_chans = $tb_channel->execute();
}

if ( $num_valid_chans != 1 )
{
print "**** Logic Error ****\nNigel stuffed up!\n";
exit -1;
}

# Access the selected/inserted channel record:
my $ref = $tb_channel->fetchrow_hashref();

my $chanid = $ref->{'chanid'};

# Some sanity checks:
if ( exists $ref->{'freqid'} &&
$ref->{'freqid'} && $ref->{'freqid'} ne 'NULL' )
{
$dbh->do("REPLACE INTO channel (chanid,freqid) VALUES ($chanid,NULL)")
}

if ( $ref->{'serviceid'} ne $channelhash{'serviceid'} )
{
$dbh->do("REPLACE INTO channel (chanid, serviceid)" .
" VALUES ($chanid, $channelhash{'serviceid'})")
}

my $mplexid = $ref->{'mplexid'};
if ( ! $mplexid || $mplexid !~ /^\d+$/ || $mplexid < 1 )
{
# Need to insert a dtv_multiplex record. First, get highest id:
$mplexid = 0;
my $tb_dtv = $dbh->prepare("SELECT mplexid FROM dtv_multiplex");
$tb_dtv->execute();
while ( my $ref = $tb_dtv->fetchrow_hashref() )
{
if ( $ref->{'mplexid'} > $mplexid )
{ $mplexid = $ref->{'mplexid'} }
}
$tb_dtv->finish();

# Point channel record to new id:
++ $mplexid;
$dbh->do("REPLACE INTO channel (chanid, mplexid)"
. " VALUES ($chanid, $mplexid)")
}

my $tb_dtv = $dbh->prepare("SELECT * FROM dtv_multiplex " .
"WHERE mplexid=$mplexid");
my $muxes = $tb_dtv->execute();

if ( $muxes > 1 )
{ die "Logic error in dtv_multiplex table" }

if ( $muxes == 1 )
{
# Check that the fields are the same, update if not

}
else
{

if ($channelsconftype eq 'czap') {
$sql1 = &genMux($mplexid, $sourceid,
'transportid', 'networkid', 'frequency',
'inversion', 'symbolrate', 'fec',
'modulation', 'bandwidth');
}

if ($channelsconftype eq 'szap') {
$sql1 = &genMux($mplexid, $sourceid,
'transportid', 'networkid', 'frequency',
'inversion', 'symbolrate',
'polarity', 'modulation');
}

if ($channelsconftype eq 'tzap') {
$sql1 = &genMux($mplexid, $sourceid,
'transportid', 'networkid', 'frequency',
'inversion', 'symbolrate', 'fec',
'polarity', 'modulation', 'bandwidth',
'lp_code_rate', 'transmission_mode',
'guard_interval', 'constellation', 'hierarchy',
'hp_code_rate');
}

$dbh->do($sql1) || print "$sql1 failed\n";
}
$tb_dtv->finish();
}

$dbh->disconnect();

_________________
| Nigel Pearson, nigel.pearson.au@gmail.com
| "Things you own end up owning you" - Tyler, Fight Club


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 4:50 am 
Offline
Joined: Mon Jun 20, 2005 1:02 am
Posts: 7
Thanks again for the reply. Afraid the script and my mysql aren't in a very co-operative mood as I get this when trying to add channels:
Quote:
Insert channel 'TV1'? [n]/y:y
Use of uninitialized value in concatenation (.) or string at ./channels.conf-import line 460, <> line 3.
DBD::mysql::db do failed: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 at ./channels.conf-import line 471, <> line 3.
**** Logic Error ****
Nigel stuffed up!


Not very good at debugging this stuff, was barely able to find where to change the path to channels.conf ;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 11:18 pm 
Offline
Joined: Fri Jan 28, 2005 8:15 am
Posts: 41
Location: Maine
been away from knoppmyth playing with freevo, but wanting to do knoppmyth long run...I think the ring buffer errors etc, are poor consistant signal quality problems. Yes knoppmyth should recognize reception problems and drop back to some default channel or error message or whatever. even though I was able to get azap to get in the 90's on some channels, if my specified starting channel was marginal after a scan, then I get the ring buffer error. Long time to go before this is prime time quality as you would have with a built in hdtv tuner on a real hdtv.

_________________
Mythic Dragon V1.0, R5F27
--
Stars Up, Lights Down...
Be a good neighbor, shield your lights, save electricity, and be more secure. Darksky.org


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 6:14 am 
Offline
Joined: Wed Mar 03, 2004 7:43 pm
Posts: 748
Location: Sydney, Australia
Phekko wrote:
DBD::mysql::db do failed: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 at ./channels.conf-import line 471, <> line 3.
**** Logic Error ****
Nigel stuffed up!
Could you provide the channels.conf file you used?

Quote:
Not very good at debugging this stuff, was barely able to find where to change the path to channels.conf ;)
I have spent most of the day trying to work out why the "INSERT INTO channels" doesn't populate the fields, but the same one in a mysql program works fine. So I am not much better :(

_________________
| Nigel Pearson, nigel.pearson.au@gmail.com
| "Things you own end up owning you" - Tyler, Fight Club


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 7:43 pm 
Offline
Joined: Mon Jun 20, 2005 1:02 am
Posts: 7
Channels.conf can be found at:

http://hummeri.lousy.org/pkiikka/channels.conf


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 10, 2005 11:04 pm 
Offline
Joined: Wed Mar 03, 2004 7:43 pm
Posts: 748
Location: Sydney, Australia
That is a DVB-C file, but you are trying to insert it as a DVB-T file.
You need to use the -c argument.

But the script has a bug with arg processing. Thy this one:

Code:
#!/usr/bin/perl -w
# ============================================================================
# = NAME
# channels.conf-import
#
# = PURPOSE
# Insert DVB channel information into the MythTV database
#
# = USAGE
# channels.conf-import
# channels.conf-import -c   # Parse czap format channels.conf file
# channels.conf-import -s   # Parse szap format channels.conf file
# channels.conf-import -t   # Parse tzap format channels.conf file
# channels.conf-import -d   # Extra debugging output
# channels.conf-import -n   # No execute (safe or simulation) mode
#
# = DESCRIPTION
# For each line in channels.conf, this script tries to match a
# channel in the the database. If there is no exact match by name,
# it prompts the user to select a channel record. If none is selected,
# or if the frequency and PIDs don't match, it prompts for re-insertion
# of the channel.
#
# = REVISION
# $Id$
#
# = AUTHORS
# Malcolm Smith, Nigel Pearson
# ============================================================================

use strict;
use DBI();
use Getopt::Long;
use File::Basename;

# configuration
my @mysqldir = ( '~/.mythtv', '/usr/share/mythtv', '/usr/local/share/mythtv' );

#my $channelsconf = "/root/.szap/channels.conf";
#my $channelsconf = "/usr/src/DVB/apps/szap/channels.conf-dvbt-oxford";
my $channelsconf = "channels.conf";

# type of channels.conf file
my $channelsconftype = "tzap";

# MythTV database stuff
my $sourceid     = 1;
my $chanid_start = 1000;

my $sql1="Invalid";

# do nothing
my $simulate = 0;

# extra console output
my $DEBUG = 1;

# ============================================================================
# Parse any command-line arguments
#
#my $arg;

#for $arg ( @ARGV )
while (my $arg = shift @ARGV )
{
    if ( $arg eq '-c' )
    {   $channelsconftype = 'czap'   }
    elsif ( $arg eq '-d' )
    {   $DEBUG = 1   }
    elsif ( $arg eq '-n' )
    {   $simulate = 1   }
    elsif ( $arg eq '-s' )
    {   $channelsconftype = 'szap'   }
    elsif ( $arg eq '-t' )
    {   $channelsconftype = 'tzap'   }
    elsif ( $arg eq '-v' )
    {   $channelsconftype = 'vdr'   }
    else
    {   die "Invalid argument '$arg'\n"   }
}

# ============================================================================
# variable definition
#
my $networkid;
my $transportid;
my @channeldata;
my %channelhash;
my $db_host;
my $db_user;
my $db_name;
my $db_pass;
my $dbh;

# ============================================================================

sub runSQL($)
{
    my ($command) = @_;

    if ( $simulate )
    {   print "If not in simulate mode, we would do: $command\n"   }
    else
    {
        if ( $dbh->do($command) )
        {
            if ( $DEBUG )
            {   print "$command\n"   }
        }
        else
        {   print "$command failed\n"   }
    }
}

# Given a list of parsed fields, generate an SQL statement to
# insert these fields and values into the dtv_multiplex table

sub genMux($@)
{
    my ($mplexid, $sourceid, @fields) = @_;

    my $sql = 'REPLACE INTO dtv_multiplex ' .
              '(mplexid, sourceid, visible,' .
              ' sistandard, serviceversion, updatetimestamp, ' .
              join (', ', @fields) . ")\n" .
              "VALUES ($mplexid, $sourceid, 1, 'dvb', 33, ";

    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

    $sql .= sprintf("%4d%02d%02d%02d%02d%02d",
                    $year+1900, $mon+1, $mday, $hour, $min, $sec) . ', ';


    my $field;
    foreach $field ( @fields )
    {
        if ( defined $channelhash{$field} )
        {
            my $val = $channelhash{$field};

            if ( $val =~ /^\d*$/ )   # If value is a number
            {   $sql .= "$val, "    }
            else
            {   $sql .= "'$val', "  }
        }
        else
        {
            print "\$channelhash{'$field'} does not exist\n";
            $sql .= '0, ';
        }
    }

    chop $sql;chop $sql;    # Remove trailing ', '

    return "$sql)";
}

# ============================================================================
# Routines to parse ZAP-style files
#

sub fix_zCodeRates
{
    $channelhash{'lp_code_rate'} =~ s/FEC_//g;
    $channelhash{'lp_code_rate'} =~ s/_/\//g;
    $channelhash{'hp_code_rate'} =~ s/FEC_//g;
    $channelhash{'hp_code_rate'} =~ s/_/\//g;
}

sub fix_zInversion
{
    if ($channelhash{'inversion'} eq "INVERSION_ON" )
    {   $channelhash{'inversion'} = '1'  }

    if ($channelhash{'inversion'} eq "INVERSION_OFF" )
    {   $channelhash{'inversion'} = '0'  }

    if ($channelhash{'inversion'} eq "INVERSION_AUTO" )
    {   $channelhash{'inversion'} = 'a'  }
}

sub fix_zConstellation
{
    # make constellation lowercase
    $channelhash{'constellation'} =~ s/QAM/qam/g;
}

sub parseCZAP(@)
{
    $channelhash{'frequency'}     = shift @channeldata;
    $channelhash{'inversion'}     = shift @channeldata;
    $channelhash{'symbolrate'}    = shift @channeldata;
    $channelhash{'lp_code_rate'} = $channelhash{'hp_code_rate'}
                                  = shift @channeldata;
    $channelhash{'constellation'} = shift @channeldata;

    if ( ! defined $channelhash{'constellation'} )
    {
        print "Input file is probably not a DVB-C file.",
              " Please use -s argument?\n";
        exit -1;
    }

    &fix_zInversion;
    &fix_zCodeRates;
    &fix_zConstellation;
}

sub parseSZAP(@)
{
    $channelhash{'frequency'}  = (shift @channeldata) . '000';
    $channelhash{'polarity'}   = shift @channeldata;
    $channelhash{'satid'}      = shift @channeldata;
    $channelhash{'symbolrate'} = (shift @channeldata) . '000';

    # on dvb-s we always have qpsk
    $channelhash{'constellation'} = 'qpsk';
}

sub parseTZAP(@)
{
    $channelhash{'frequency'} = shift @channeldata;
    $channelhash{'inversion'} = shift @channeldata;
    $channelhash{'bandwidth'} = shift @channeldata;
    $channelhash{'lp_code_rate'}      = shift @channeldata;
    $channelhash{'hp_code_rate'}      = shift @channeldata;
    $channelhash{'constellation'}     = shift @channeldata;
    $channelhash{'transmission_mode'} = shift @channeldata;
    $channelhash{'guard_interval'}    = shift @channeldata;
    $channelhash{'hierarchy'}         = shift @channeldata;

    if ( ! defined $channelhash{'hierarchy'} )
    {
        print "Input file is probably not a DVB-T file.",
              " Please use -c or -s argument.\n";
        exit -1;
    }

    # Set some defaults
    $channelhash{'polarity'}   = 'V';
    $channelhash{'symbolrate'} = '69000';

    &fix_zInversion;
    &fix_zCodeRates;
    &fix_zConstellation;

    $channelhash{'bandwidth'} =~ s/BANDWIDTH_//;
    $channelhash{'bandwidth'} =~ s/_.*//;

    $channelhash{'guard_interval'} =~ s/GUARD_INTERVAL_//g;
    $channelhash{'guard_interval'} =~ s/_/\//g;

    if ($channelhash{'hierarchy'} eq "HIERARCHY_NONE" )
    {   $channelhash{'hierarchy'} = 'n'  }
    else
    {   $channelhash{'hierarchy'} = 'auto'  }

    $channelhash{'lp_code_rate'} =~ s/FEC_//g;
    $channelhash{'lp_code_rate'} =~ s/_/\//g;

    $channelhash{'transmission_mode'} =~ s/TRANSMISSION_MODE_//g;
    $channelhash{'transmission_mode'} =~ s/K//g;
}

sub parseZAP
{
    if (    $channelsconftype eq 'szap' )
    {    &parseSZAP(@channeldata)    }
    elsif ( $channelsconftype eq 'czap' )
    {    &parseCZAP(@channeldata)    }
    elsif ( $channelsconftype eq 'tzap' )
    {    &parseTZAP(@channeldata)    }
    else
    {    die "Illegal channelconftype in perl script"    }

    $channelhash{'vpid'}      = shift @channeldata;
    $channelhash{'apid'}      = shift @channeldata;
    $channelhash{'serviceid'} = shift @channeldata;
    chop $channelhash{'serviceid'};
}

# ============================================================================
# Routines to parse VDR-style file

sub parseVDRs
{
    die "Sorry - Nigel hasn't implemented VDRs parsing yet";
}

sub parseVDRc
{
    die "Sorry - Nigel hasn't implemented VDRc parsing yet";
}

sub parseVDRt
{
    die "Sorry - Nigel hasn't implemented VDRt parsing yet";
}

sub parseVDR
{
    if ( grep m/:T:27500:/, @channeldata )
    {   &parseVDRt   }
    elsif ( grep m/:M.*:C:/, @channeldata )
    {   &parseVDRc   }
    else
    {   &parseVDRs   }
}

# ============================================================================

# Read the mysql.txt file in use by MythTV.

while (my $dir = shift @mysqldir)
{
    if (open(CONF, "$dir/mysql.txt"))
    {   last   }
}

if (! @mysqldir)
{   die ("Unable to find mysql.txt\n\n")   }

while (my $line = <CONF>) {
  chomp($line);
  $line =~ s/^str //;
  my ($var, $val) = split(/\=/, $line, 2);
  next unless ($var && $var =~ /\w/);
  if ($var eq 'DBHostName') {
    $db_host = $val;
  }
  elsif ($var eq 'DBUserName') {
    $db_user = $val;
  }
  elsif ($var eq 'DBName') {
    $db_name = $val;
  }
  elsif ($var eq 'DBPassword') {
    $db_pass = $val;
  }
}
close CONF;

# Connect to the database
$dbh = DBI->connect("dbi:mysql:database=$db_name:host=$db_host",
                       $db_user, $db_pass)
          or die "Cannot connect to database: $!\n\n";

if ($simulate) {
  print "Simulation mode. SQL not done.\n";
};


# Check the version
my $db_ver = $dbh->prepare("SELECT data FROM settings" .
                           " WHERE value='DBSchemaVer'");
$db_ver->execute() or die "Could not execute db version query";
my $ver;
if (my @row = $db_ver->fetchrow_array) {
    $ver = $row[0];
}

if ( !$ver ) {
    die "Could not get backend database version";
}

if ( $ver < 1063 ) {
    print "This script is not compatible with the backend and database.\n",
          "Database DVB tables were redesigned between MythTV 0.16 and 0.17.\n",
          "Please use an older version of this script.\n";
    exit 0;
}

if ( $ver > 1062 ) {
    print "\nThis backend should be capable of scanning for DVB channels.\n\n",
          "Try running mythtv-setup, clearing your capture cards,",
          " and re-adding them.\n",
          "There should be a 'Scan' button in the Channel Editor\n\n",
          "Do you want to try and use this script anyway? y/[n]:";
    my $selection = <>;
    chomp($selection);
    if ($selection ne "y" )
    {   exit 0   }

    print "\n\n";
}


# Go through each line in channels.conf:

open (CHANNELSCONF, "<$channelsconf")
    or die "failed opening channels.conf: $!";

my @channelsconf = <CHANNELSCONF>;

foreach my $channel_line ( @channelsconf )
{
    # get the information out of the channelsconf line
    @channeldata = split(/:/, $channel_line);

    my $name = shift @channeldata;

    %channelhash = ();          # Clear previous insert's values
    $channelhash{'bandwidth'}   = '10';
    $channelhash{'fec'}         = 'auto';
    $channelhash{'networkid'}   = '1';
    $channelhash{'modulation'}  = 'auto';
    $channelhash{'transportid'} = '1';
    $channelhash{'sistandard'}  = 'dvb';

    if ( $channelsconftype =~ m/zap$/ )
    {   &parseZAP  }
    elsif ($channelsconftype eq 'vdr')
    {   &parseVDR(@channeldata)   }

 
    print "Found channel '$name'. Insert? y/[n]:";
    my $selection = <>;
    chomp($selection);
    if ($selection ne "y" )
    {   next   }

    if ( $DEBUG )
    {
        foreach my $field ( sort keys %channelhash )
        {   print "$field: $channelhash{$field}\n"   }
    }


    # Now retrieve data from the channel table.
    my $tb_channel = $dbh->prepare("SELECT * FROM channel " .
                                   "WHERE sourceid=$sourceid AND name='$name'");
    my $num_valid_chans = $tb_channel->execute();

    if ( $num_valid_chans == 0 )
    {
        # No channels matching the name? Try to get all the channels
        $tb_channel->finish();
        $tb_channel = $dbh->prepare("SELECT * FROM channel" .
                                    " WHERE sourceid=$sourceid");
        $num_valid_chans = $tb_channel->execute();

        if ( $num_valid_chans == 0 )
        {   print "Channels table is empty. "   }
    }

    if ( $num_valid_chans > 1 )
    {
        # Select from all the channels
        my @chanids = ();
        my $i = 1;

        print "Backend database contains these channels:\n";
        while (my $ref = $tb_channel->fetchrow_hashref())
        {
            print "$i\t$ref->{'chanid'}\t$ref->{'channum'}\t$ref->{'name'}\n";
            ++ $i;
            push @chanids, $ref->{'chanid'};
            if ( $ref->{'chanid'} > $chanid_start )
            {   $chanid_start = $ref->{'chanid'}   }
        }

        print "Select a channel to update [anything else to insert new]: ";
        my $selection = <>;
        chomp($selection);

        if ($selection !~ /^\d+$/)
        {
            $num_valid_chans = 0;   # Force possible insertion
        }
        else
        {
            my $chanid = $chanids[$selection - 1];
            ($DEBUG) && print "using row $selection (chanid $chanid)\n";
            $tb_channel->finish();
            $tb_channel = $dbh->prepare("SELECT * FROM channel" .
                                        " WHERE chanid=$chanid");
            $num_valid_chans = $tb_channel->execute();
        }
    }

    if ( $num_valid_chans == 0 )
    {
        # Insert
        ++ $chanid_start;
        $sql1 = "REPLACE INTO channel (chanid,channum,sourceid,name,serviceid)"
                . " VALUES ($chanid_start, '$chanid_start', $sourceid, "
                         . "'$name', $channelhash{'serviceid'})";
        &runSQL($sql1);


        # Re-read whole record:
        $tb_channel->finish();
        $tb_channel = $dbh->prepare("SELECT * FROM channel" .
                                    " WHERE chanid=$chanid_start");
        $num_valid_chans = $tb_channel->execute();
    }

    if ( $num_valid_chans != 1 )
    {
        print "**** Logic Error ****\nNigel stuffed up!\n";
        exit -1;
    }

    # Access the selected/inserted channel record:
    my $ref = $tb_channel->fetchrow_hashref();

    my $chanid = $ref->{'chanid'};

    # Some sanity checks:
    if ( exists $ref->{'freqid'} &&
         $ref->{'freqid'} && $ref->{'freqid'} ne 'NULL' )
    {
        &runSQL("REPLACE INTO channel (chanid,freqid) VALUES ($chanid,NULL)")
    }

    if ( ! exists $ref->{'serviceid'} ||
         $ref->{'serviceid'} ne $channelhash{'serviceid'} )
    {
        &runSQL("REPLACE INTO channel (chanid, serviceid)" .
                " VALUES ($chanid, $channelhash{'serviceid'})")
    }

    my $mplexid = $ref->{'mplexid'};
    if ( ! $mplexid || $mplexid !~ /^\d+$/ || $mplexid < 1 )
    {
        # Need to insert a dtv_multiplex record. First, get highest id:
        $mplexid = 0;
        my $tb_dtv = $dbh->prepare("SELECT mplexid FROM dtv_multiplex");
        $tb_dtv->execute();
        while ( my $ref = $tb_dtv->fetchrow_hashref() )
        {
            if ( $ref->{'mplexid'} > $mplexid )
            {   $mplexid = $ref->{'mplexid'}   }
        }
        $tb_dtv->finish();

        # Point channel record to new id:
        ++ $mplexid;
        &runSQL("REPLACE INTO channel (chanid,mplexid)"
                         . " VALUES ($chanid, $mplexid)")
    }

    my $tb_dtv = $dbh->prepare("SELECT * FROM dtv_multiplex " .
                                        "WHERE mplexid=$mplexid");
    my $muxes = $tb_dtv->execute();

    if ( $muxes > 1 )
    {   die "Logic error in dtv_multiplex table"   }

    if ( $muxes == 1 )
    {
        # Check that the fields are the same, update if not

    }
    else
    {

        if ($channelsconftype eq 'czap') {
            $sql1 = &genMux($mplexid, $sourceid,
                            'transportid', 'networkid', 'frequency',
                            'inversion',   'symbolrate', 'fec',
                            'modulation',  'bandwidth');
        }

        if ($channelsconftype eq 'szap') {
            $sql1 = &genMux($mplexid, $sourceid,
                            'transportid', 'networkid', 'frequency',
                            'inversion',   'symbolrate',
                            'polarity',    'modulation');
        }

        if ($channelsconftype eq 'tzap') {
            $sql1 = &genMux($mplexid, $sourceid,
                            'transportid', 'networkid', 'frequency',
                            'inversion',   'symbolrate', 'fec',
                            'polarity',    'modulation',  'bandwidth',
                            'lp_code_rate', 'transmission_mode',
                            'guard_interval', 'constellation', 'hierarchy',
                            'hp_code_rate');
        }

        &runSQL($sql1);
    }
    $tb_dtv->finish();
}

$dbh->disconnect();
[/code]

_________________
| Nigel Pearson, nigel.pearson.au@gmail.com
| "Things you own end up owning you" - Tyler, Fight Club


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 12:01 am 
Offline
Joined: Mon Jun 20, 2005 1:02 am
Posts: 7
Hi again!

Been on holiday so it took a while to get back to you. Afraid this script didn't give me much love, either:
Quote:
Found channel 'Jetix'. Insert? y/[n]:
DBI::db=HASH(0x82eda8c)->disconnect invalidates 1 active statement handle (either destroy statement handles or call finish on them before disconnecting) at ./channels.conf-import line 587, <> line 140.


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 68 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu