Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
User Journal

Journal Journal: RadioVo Source - Various comments

Here is how you add the daemon to start up on Virtual Console 1:

In /etc/inittab, replace the line beginning with "1:" with this:

1:2345:respawn:/sbin/agetty -i -n -l /MUSIC/bin/music_daemon.pl /dev/tty1 9600

You need to make sure you have "agetty" installed and that the path is right.

For some reason, /. put spaces in my "oggrec.conf" file at random spots. This is extremely annoying, but you will have to fix this yourself when you download it, because even editing the text manually on this journal doesn't work. Sorry. This is alpha-code and is a total hack.

If you are seriously determined to make as few changes as possible, you can message me and I will send the code to you. Hopefully I will read my messages. :-)

I welcome anyone who wants to modify the code. You can keep the mods to yourself if you want, or you can send them back to me. Do what you will. It would be great if someone would be so motivated as to post it to SourceForge and let me know so I can join the club, but I can't imagine my project actually getting any such attention.

Good luck. If you need more help, let me know.

User Journal

Journal Journal: RadioVo Source - Config File (oggrec.conf)

$date = `/bin/date +%Y%m%d%H%M%S`;
chop($date);

$genre="Radio";
$artist="Radio";
$title="Recording - $date";
$track="1";
$album="Recordings";

$time="1"; # Time in seconds

##############################################
# Stupid RAWREC can't be called with full path
##############################################
$rawrec="(PATH=$PATH:/usr/local/bin; rawrec)";
# $rawrec_args="-t $time";
$rawrec_args="";

$outfile="$MUSIC/recording/oggrec_$date.ogg";

$oggenc="/usr/bin/oggenc";

$oggenc_args="-a \"$artist\" -t \"$title\" -l \"$album\" -N $track -d \"$date\" -G \"$genre\" -r --downmix -o $outfile -";
User Journal

Journal Journal: RadioVo Source - Perl Module (oggrec.pm)

# Read the config file given as argv[0]
# All you give as an argument is the first
# part of the name of the config file

package oggrec;

sub new {
    my $this = {};
    bless $this;
    return $this;
}

sub oggrec {
    my $BASEDIR = "/MUSIC";
    my $MUSIC = "$BASEDIR/music";
    my $CONFIG = "$BASEDIR/config";
    my $STATUS = "$BASEDIR/status/status";
    my $oggrec_conf = "$CONFIG/oggrec.conf";

    my @config_files;
    push(@config_files, $oggrec_conf);

#    (my $time, my $conf) = &figure_args(@_);

    (my $conf) = @_;
    if($conf) {
        $rec_conf = "$CONFIG/$conf.conf";
        push(@config_files, $rec_conf);
    }

    foreach $conf_file (@config_files) {
        print "opening $conf_file\n";
        open(FILE, "$conf_file")    or die "Can't open $file: $!";
        my @config = <FILE>;
        close(FILE);

        foreach my $line (@config) {
            chomp($line);

            eval($line);
        }
    }

    open(STATUS_FILE, ">$STATUS");
    print STATUS_FILE "$outfile";
    close(STATUS_FILE);

    # print "cd $MUSIC && $rawrec $rawrec_args | $oggenc $oggenc_args\n\n";
    print "Recording...\n";

    my $output = `cd $MUSIC && $rawrec $rawrec_args 2>/dev/null | $oggenc $oggenc_args 2>&1`;
    # my $output = `cd $MUSIC && $rawrec $rawrec_args | $oggenc $oggenc_args `;
    print $output;

}

sub figure_args {
    local(@args) = @_;

    $size = @args;

    print "size=$size\n";

    if($size ne 1) {
        die "Wrong number of arguments\nPlease enter a time or configuration\n";
    }

    if($args[0] =~ /:/) {
        @time = split(/:/, $args[0]);
        $i=0;
        $total_time = 0;

        while($element = pop(@time)) {
            $total_time += $element*(60**$i);
            print "$total_time\n";
            $i += 1;
        }
        return($total_time, "");
    }else{
        return(0, $args[0]);
    }
}

return 1;
User Journal

Journal Journal: RadioVo Source - Main Daemon

#!/usr/bin/perl
#
#########################
#load required modules
#########################
use lib "/MUSIC/bin";
use strict;
use Term::ReadKey;
use POSIX qw(setsid);
use oggrec;

#########################
# set variables
#########################
my $return_val;
my %key_map;
my $char;
my $rec_pid;
my $STATUS_FILE = "/MUSIC/status/music.pid";
# my $std_out = $ARGV[0];

#########################
# Set Key Map
#########################
$key_map{'r'} = "\&start_record();";
$key_map{'m'} = "\&start_record(\"mk\");";
$key_map{'s'} = "\&stop_record;";
$key_map{'p'} = "\&kill_child(my \$pid, 'STOP');";
$key_map{'c'} = "\&kill_child(my \$pid, 'CONT');";
$key_map{'x'} = "\&exit_routine;";

#########################
# Set up Signal catching
#########################
$SIG{CHLD} = \&REAPER;
$SIG{USR1} = \&CATCH_USR1;
$SIG{USR2} = \&CATCH_USR2;

#########################
# flush the buffer
#########################
$| = 1;

##########################
# daemonize the program
##########################
&daemonize;

##########################
# Set the terminal to read 1 char at a time
##########################
ReadMode('cbreak');

##########################
# our infinite loop
##########################
while(1) {
    ##########################
    # Read a character, using:
    # -1 -> non-blocking
    # 0  -> blocking
    # >0 -> timed
    ##########################
    $char = ReadKey(0);

    ##########################
    # If the character has been mapped, eval the mapping
    ##########################
    if($key_map{$char}) {
        $return_val = eval($key_map{$char});
        print "return = $return_val\n";
        print STDERR $@;
    } else {
        print "Key \"$char\" not assigned.\n";
    }

    print "-----------------------\n";

}

sub exit_routine {
    if($rec_pid) {
        &stop_record;
    }
    ReadMode('normal');
    close(STAT);
    exit(0);
}

sub start_record {
    print "Starting Recording...\n";

    ##########################
    # Return if rec_pid exists
    ##########################
    if($rec_pid) {
        print "Already recording...\n";
        return(1);
    }

    ##########################
    # Fork
    ##########################
    defined(my $pid = fork)        or die "Can't fork: $!";

    ##########################
    # Return if parent
    ##########################
    if($pid) {
        $rec_pid = $pid;
        print "rec_pid = $rec_pid\n";
        return;
    }

    ##########################
    # I'm the child
    # Set Session ID so the parent can kill
    #  all of the children together
    ##########################
    setsid;

    print "I'm the Child - $$\n";

#    print " args = @_\n";
#    my $time = "0:10";
#    my $conf = "";
    oggrec::oggrec(@_);

}

#########################
# Stop recording
#########################
sub stop_record {
    if($rec_pid) {
        &kill_child($rec_pid, 'TERM');
        $rec_pid = "";
    } else {
        print "Not recording...\n";
    }
}

#########################
# Send a kill signal to the sub
# kill_child(PID, SIGNAL);
#########################
sub kill_child {
    my $proc;
    my $sig;
    ($proc, $sig) = @_;

    print "Killing Child - $proc with $sig\n";

    #########################
    # When we fork, we use setsid so that we can kill a process group
    # by killing the "negative" process group parent
    #########################
    kill($sig, -$proc);
}

#########################
# Forks and exits
#########################
sub daemonize {
    $| = 1;
    chdir '/'            or die "Can't chdir to /: $!";
    umask 0;

    #########################
    # Open and lock status file
    #########################
    my $PID = `cat $STATUS_FILE`;
    if($PID>0) {
        my $STAT = `ps -ef | grep -v grep | grep $PID`;
        if($STAT) {
            print "STAT=$STAT";
            exit(1);
        }
    }
    open(STAT,">$STATUS_FILE")    or die "Can't open $STATUS_FILE: $!";
    flock(STAT, "1")        or die "Can't lock $STATUS_FILE: $!";
    print STAT "$$";
    close(STAT);

#    open(STDIN,'/dev/$std_out')    or die "Can't read /dev/$std_out $!";
#    open(STDOUT,'>/dev/$std_out')    or die "Can't write /dev/$std_out $!";
#    open(STDERR,'>/dev/$std_out')    or die "Can't write /dev/$std_out $!";
#    defined(my $pid = fork)        or die "Can't fork: $!";
#    exit if $pid;
#    setsid                or die "Can't start a new session: $!";

    print "############################\n";
    print "Starting Music Daemon\n";
    print "############################\n";

}

sub REAPER {
    my $waitedpid = wait;
    # loathe sysV: it makes us not only reinstate
    # the handler, but place it after the wait
    $SIG{CHLD} = \&REAPER;
}

sub CATCH_USR1 {
    print "someone told me to USR1\n";
    #########################
    # This is where we:
    #  - start recording
    #########################
    &start_record();

}

sub CATCH_USR2 {
    print "someone told me to USR1\n";
    #########################
    # This is where we:
    #  - stop recording
    #########################
    &stop_record;

}

Slashdot Top Deals

ASCII a stupid question, you get an EBCDIC answer.

Working...