hi Aubin,
I played around with you chchan, too but it always
complained about the input I gave it. Then I started
to hack some stuff together I found on the net when
I accidentaly removed the dxr3 when the machine was
running. (Mental Note: Always fix cards with the
screws provided) Which resulted in a broken DXR3...
So I can't test until I get video going on my epia-m.
Attached is a patch to add a channelchanger to
the c code. It uses your frequencies.[c|h] and
the v4l-kernel headers. I could not test if it
works but at least it does not break anything.
l8r...
Thomas
? chchan.c
? frequencies.c
? frequencies.h
? t
? timeshifter
? timeshifter.c.save
? ts.patch
? v4l.c
? v4l.h
Index: Makefile
===================================================================
RCS file: /cvsroot/freevo/freevo/WIP/Thomas/Makefile,v
retrieving revision 1.2
diff -a -u -r1.2 Makefile
--- Makefile 2 Mar 2003 06:07:12 -0000 1.2
+++ Makefile 2 Mar 2003 18:51:55 -0000
@@ -8,10 +8,13 @@
all: clean timeshifter link
timeshifter:
- $(CC) $(CFLAGS) -c timeshifter.c
+ $(CC) $(CFLAGS) -c frequencies.c timeshifter.c
+
+chchan:
+ $(CC) $(CFLAGS) -c chchan.c
link:
- $(CC) $(CFLAGS) -o timeshifter timeshifter.o
+ $(CC) $(CFLAGS) -o timeshifter frequencies.o timeshifter.o
clean:
-rm *.o
-rm timeshifter
Index: timeshifter.c
===================================================================
RCS file: /cvsroot/freevo/freevo/WIP/Thomas/timeshifter.c,v
retrieving revision 1.1
diff -a -u -r1.1 timeshifter.c
--- timeshifter.c 2 Mar 2003 06:07:12 -0000 1.1
+++ timeshifter.c 2 Mar 2003 18:51:56 -0000
@@ -3,16 +3,20 @@
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
+#include <sys/ioctl.h>
#include <string.h>
#include <stdio.h>
#include "ts.h"
#include <signal.h>
#include <errno.h>
#include "tserrors.h"
+#include "frequencies.h"
+#include <linux/videodev.h>
+
static pid_t *childpid = NULL;
/* ptr to array allocated at run-time */
-static int maxfd; /* from our open_max(), {Prog openmax} */
+static int maxfd; /* TODO Get this from the system */
#define SHELL "/bin/sh"
@@ -25,76 +29,76 @@
int popen2(const char *cmdstring, FILE** pfIn, FILE** pfOut)
{
- int i, pfr[2], pfw[2];
- pid_t pid;
-
- if (childpid == NULL) { /* first time through */
- /* allocate zeroed out array for child pids */
- maxfd = 100;
- if ( (childpid = calloc(maxfd, sizeof(pid_t))) == NULL)
- return(0);
+ int i, pfr[2], pfw[2];
+ pid_t pid;
+
+ if (childpid == NULL) { /* first time through */
+ /* allocate zeroed out array for child pids */
+ maxfd = 100;
+ if ( (childpid = calloc(maxfd, sizeof(pid_t))) == NULL)
+ return(0);
+ }
+
+ if (pipe(pfr) < 0)
+ return(0); /* errno set by pipe() */
+ if (pipe(pfw) < 0)
+ return(0); /* errno set by pipe() */
+
+ if ( (pid = fork()) < 0)
+ return(0); /* errno set by fork() */
+ else if (pid == 0) {
+ /* child */
+ close(pfr[0]);
+ if (pfr[1] != STDOUT_FILENO) {
+ dup2(pfr[1], STDOUT_FILENO);
+ close(pfr[1]);
}
-
- if (pipe(pfr) < 0)
- return(0); /* errno set by pipe() */
- if (pipe(pfw) < 0)
- return(0); /* errno set by pipe() */
-
- if ( (pid = fork()) < 0)
- return(0); /* errno set by fork() */
- else if (pid == 0) {
- /* child */
- close(pfr[0]);
- if (pfr[1] != STDOUT_FILENO) {
- dup2(pfr[1], STDOUT_FILENO);
- close(pfr[1]);
- }
- close(pfw[1]);
- if (pfw[0] != STDIN_FILENO) {
- dup2(pfw[0], STDIN_FILENO);
- close(pfw[0]);
- }
- /* close all descriptors in childpid[] */
- for (i = 0; i < maxfd; i++) {
- if (childpid[i] > 0)
- close(i);
- }
- execl(SHELL, "sh", "-c", cmdstring, (char *) 0);
- _exit(127);
+ close(pfw[1]);
+ if (pfw[0] != STDIN_FILENO) {
+ dup2(pfw[0], STDIN_FILENO);
+ close(pfw[0]);
+ }
+ /* close all descriptors in childpid[] */
+ for (i = 0; i < maxfd; i++) {
+ if (childpid[i] > 0)
+ close(i);
}
- /* parent */
- close(pfr[1]);
- if ( (*pfOut = fdopen(pfr[0], "r")) == NULL)
- return(0);
- close(pfw[0]);
- if ( (*pfIn = fdopen(pfw[1], "w")) == NULL)
- return(0);
- childpid[fileno(*pfOut)] = pid; /* remember child pid for this fd */
- childpid[fileno(*pfIn)] = pid;
- return 1;
+ execl(SHELL, "sh", "-c", cmdstring, (char *) 0);
+ _exit(127);
+ }
+ /* parent */
+ close(pfr[1]);
+ if ( (*pfOut = fdopen(pfr[0], "r")) == NULL)
+ return(0);
+ close(pfw[0]);
+ if ( (*pfIn = fdopen(pfw[1], "w")) == NULL)
+ return(0);
+ childpid[fileno(*pfOut)] = pid; /* remember child pid for this fd */
+ childpid[fileno(*pfIn)] = pid;
+ return 1;
}
int pclose2(FILE *fp)
{
- int fd, stat;
- pid_t pid;
-
- if (childpid == NULL)
- return(-1); /* popen() has never been called */
-
- fd = fileno(fp);
- if ( (pid = childpid[fd]) == 0)
- return(-1); /* fp wasn't opened by popen() */
-
- childpid[fd] = 0;
- if (fclose(fp) == EOF)
- return(-1);
-
- while (waitpid(pid, &stat, 0) < 0)
- if (errno != EINTR)
- return(-1); /* error other than EINTR from waitpid() */
-
- return(stat); /* return child's termination status */
+ int fd, stat;
+ pid_t pid;
+
+ if (childpid == NULL)
+ return(-1); /* popen() has never been called */
+
+ fd = fileno(fp);
+ if ( (pid = childpid[fd]) == 0)
+ return(-1); /* fp wasn't opened by popen() */
+
+ childpid[fd] = 0;
+ if (fclose(fp) == EOF)
+ return(-1);
+
+ while (waitpid(pid, &stat, 0) < 0)
+ if (errno != EINTR)
+ return(-1); /* error other than EINTR from waitpid() */
+
+ return(stat); /* return child's termination status */
}
caddr_t createMaster( char * filename, int filesize )
@@ -147,9 +151,9 @@
pHeader->writepointer += remainingsize ;
if ( msync( ts, pHeader->file_size, MS_SYNC ) == -1 )
{
- printf( "Error in msync.\n" ) ;
+ fprintf( stderr, "Error in msync.\n" ) ;
}
-// printf( "WP: %d\n", pHeader->writepointer ) ;
+ // fprintf( stderr, "WP: %d\n", pHeader->writepointer ) ;
return size ;
}
@@ -184,12 +188,69 @@
return TS_OK ;
}
+float get_freq (char *name, char *channel)
+{
+ int i, j;
+ float freq = 0.0;
+ i = 0;
+ while (chanlists[i].name != (char *) NULL)
+ {
+ /* fprintf (stderr, "Searching for %s: got %s\n", name, chanlists[i].name); */
+
+ /* Do the names match? */
+
+ if (strcasecmp (chanlists[i].name, name) == 0)
+ {
+ /* Yep, try to find the channel */
+ for (j = 0; j < chanlists[i].count; j++)
+ {
+ /* fprintf( stderr, "matching %s with %s\n", channel,
chanlists[i].list[j].name ) ; */
+ if (strcasecmp (chanlists[i].list[j].name, channel) == 0)
+ {
+ fprintf (stderr, "Channel frequency = %d kHz\n",
+ chanlists[i].list[j].freq);
+ freq = ((float) chanlists[i].list[j].freq) / 1000.0;
+ return (freq);
+ }
+ }
+ fprintf (stderr, "Couldn't find channel %s for the broadcast standard %s in "
+ "the table!\n", channel, name);
+ return (0.0);
+ }
+ i++;
+ }
+ fprintf (stderr, "Couldn't find broadcast standard %s in the table!\n", name);
+ return (0.0);
+}
+
+int setchannel( char* device, char* channel, char* norm, char* list, char* input )
+{
+ /* By Aubin Paul */
+ float freq ;
+ int fd ;
+ int iError ;
+ freq = get_freq( list, channel ) ;
+ if ( freq == 0.0 )
+ {
+ /* Error */
+ return TS_SYSTEM_ERROR ;
+ }
+ fd = open(device, O_TRUNC) ;
+ if ( fd < 0 )
+ {
+ fprintf( stderr, "Opening v4l-device %s failed.", device ) ;
+ return TS_SYSTEM_ERROR ;
+ }
+ iError = ioctl(fd, VIDIOCSFREQ, &freq) ;
+ return TS_OK ;
+}
+
#define ISCMD(x,y) strncmp( x, y, strlen(y) ) == 0
int inter( const char * command )
{
/* This is not the most beautiful way to
- do it. But it will do OK. */
+ do it. But it will do OK. */
if ( ISCMD( command, "JOIN" ) )
{
return join( ) ;
@@ -208,13 +269,34 @@
}
else if ( ISCMD( command, "CHANNEL" ) )
{
- return TS_NOT_IMPLEMENTED ;
+ char* cmd = malloc( strlen( command )-7 ) ;
+ char *channel, *norm, *list, *input, *device ;
+ if ( !cmd ) return TS_OUTOFMEM ;
+ strcpy( cmd, command+7 ) ;
+ device = strtok( cmd, " " ) ;
+ channel = strtok( NULL, " " ) ;
+ norm = strtok( NULL, " " ) ;
+ list = strtok( NULL, " " ) ;
+ input = strtok( NULL, "\n" ) ;
+ if ( !device || !channel || !norm || !list || !input || !*device || !*channel ||
!*norm || !*list || !*input )
+ {
+ fprintf( stderr, "Error parsing: %s", command + 7 ) ;
+ free( cmd ) ;
+ return TS_SYNTAX_ERROR ;
+ }
+ else {
+ int iRet ;
+ fprintf( stderr, "setchannel device=%s channel=%s norm=%s list=%s input=%s\n",
device, channel, norm, list, input ) ;
+ iRet = setchannel( device, channel, norm, list, input ) ;
+ free( cmd ) ;
+ return iRet ;
+ }
}
else if ( ISCMD( command, "FREQUENCY") )
{
return TS_NOT_IMPLEMENTED ;
}
-
+
return TS_UNKNOWN_COMMAND ;
}
@@ -230,10 +312,10 @@
if ( pnum != 3 )
{
- printf( "Usage: %s <file> <size>\n", params[0] ) ;
- printf( " <file> name of the buffer-file.\n" ) ;
- printf( " <size> size to allocate for the buffer-file.\n" ) ;
- exit(-1) ;
+ printf( "Usage: %s <file> <size>\n", params[0] ) ;
+ printf( " <file> name of the buffer-file.\n" ) ;
+ printf( " <size> size to allocate for the buffer-file.\n" ) ;
+ exit(-1) ;
}
fsize = atoi( params[2] ) ;
if ( fsize < sizeof(buffer) )
@@ -251,50 +333,50 @@
fdmax = 0 ;
if ( fpOut )
{
- FD_SET( fileno(fpOut), &rfds ) ;
- fdmax = (fileno(fpOut)>fdmax) ? fileno(fpOut) : fdmax ;
+ FD_SET( fileno(fpOut), &rfds ) ;
+ fdmax = (fileno(fpOut)>fdmax) ? fileno(fpOut) : fdmax ;
}
tv.tv_sec = TIMEOUTSECS ;
tv.tv_usec = TIMEOUTMILLI ;
int retval = select( fdmax+1, &rfds, NULL, NULL, &tv ) ;
switch ( retval ) {
- default:
- if ( FD_ISSET( 0, &rfds ) )
+ default:
+ if ( FD_ISSET( 0, &rfds ) )
+ {
+ int result ;
+ char buffer[401] ;
+ fgets( buffer, 400, stdin ) ; buffer[400] = 0 ;
+ result = inter( buffer ) ;
+ fprintf( stdout, "%.3d %s\n", result, TS_ERROR(result) ) ; fflush( stdout ) ;
+ }
+
+ if ( fpOut && ( FD_ISSET( fileno(fpOut), &rfds ) ) )
+ {
+ readBytes = fread( buffer, 1, sizeof( buffer ), fpOut ) ;
+ if ( readBytes > 0 )
{
- int result ;
- char buffer[401] ;
- fgets( buffer, 400, stdin ) ; buffer[400] = 0 ;
- result = inter( buffer ) ;
- fprintf( stdout, "%.3d %s\n", result, TS_ERROR(result) ) ; fflush( stdout ) ;
- }
-
- if ( fpOut && ( FD_ISSET( fileno(fpOut), &rfds ) ) )
+ ts_write( pMaster, buffer, readBytes ) ;
+ }
+ else if ( ( readBytes <= 0 ) && ( ferror( fpOut ) ) )
{
- readBytes = fread( buffer, 1, sizeof( buffer ), fpOut ) ;
- if ( readBytes > 0 )
- {
- ts_write( pMaster, buffer, readBytes ) ;
- }
- else if ( ( readBytes <= 0 ) && ( ferror( fpOut ) ) )
- {
- printf( "Read Error\n" ) ; fflush( stdout ) ;
- bRun = 0 ;
- }
- else if ( ( readBytes <= 0 ) && ( feof( fpOut ) ) )
- {
- fprintf( stdout, "%.3d %s\n", TS_CLIENT_EOF, TS_ERROR(TS_CLIENT_EOF) ) ;
fflush( stdout ) ;
- pclose2( fpOut ) ;
- fpOut = NULL ;
- }
+ printf( "Read Error\n" ) ; fflush( stdout ) ;
+ bRun = 0 ;
}
- break ;
- case 0:
- fprintf( stderr, "No Data for %d.%.3d seconds. Still sleeping.\n", TIMEOUTSECS,
TIMEOUTMILLI ) ;
- break ;
- case -1:
- fprintf( stderr, "Select Error.\n" ) ;
- bRun = 0 ;
- break ;
+ else if ( ( readBytes <= 0 ) && ( feof( fpOut ) ) )
+ {
+ fprintf( stdout, "%.3d %s\n", TS_CLIENT_EOF, TS_ERROR(TS_CLIENT_EOF) ) ;
fflush( stdout ) ;
+ pclose2( fpOut ) ;
+ fpOut = NULL ;
+ }
+ }
+ break ;
+ case 0:
+ fprintf( stderr, "No Data for %d.%.3d seconds. Still sleeping.\n", TIMEOUTSECS,
TIMEOUTMILLI ) ;
+ break ;
+ case -1:
+ fprintf( stderr, "Select Error.\n" ) ;
+ bRun = 0 ;
+ break ;
}
}
// TODO: Remove Master File
Index: tserrors.h
===================================================================
RCS file: /cvsroot/freevo/freevo/WIP/Thomas/tserrors.h,v
retrieving revision 1.1
diff -a -u -r1.1 tserrors.h
--- tserrors.h 2 Mar 2003 06:07:12 -0000 1.1
+++ tserrors.h 2 Mar 2003 18:51:56 -0000
@@ -3,10 +3,12 @@
const char * ERRORTEXT[] = { "OK",
"ALREADY RUNNING",
- "SYSTEM ERROR",
+ "SYSTEM ERROR",
"NOT IMPLEMENTED",
"UNKNOWN COMMAND",
- "EOF FROM CLIENT"
+ "EOF FROM CLIENT",
+ "OUT OF MEMORY",
+ "SYNTAX ERROR"
};
@@ -16,7 +18,9 @@
TS_SYSTEM_ERROR,
TS_NOT_IMPLEMENTED,
TS_UNKNOWN_COMMAND,
- TS_CLIENT_EOF
+ TS_CLIENT_EOF,
+ TS_OUTOFMEM,
+ TS_SYNTAX_ERROR
} ERROR ;