Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

receiver.c

Go to the documentation of this file.
00001 
00044 #include <cfg/os.h>
00045 #include <cfg/clock.h>
00046 #include <dev/board.h>
00047 
00048 #include <stdlib.h>
00049 #include <string.h>
00050 #include <stdio.h>
00051 #include <fcntl.h>
00052 #include <io.h>
00053 
00054 #include <sys/version.h>
00055 #include <sys/confnet.h>
00056 #include <sys/atom.h>
00057 #include <sys/heap.h>
00058 #include <sys/thread.h>
00059 #include <sys/timer.h>
00060 #include <sys/event.h>
00061 #include <sys/socket.h>
00062 
00063 #include <hxmp3/mp3dec.h>
00064 
00065 #include <netinet/tcp.h>
00066 #include <arpa/inet.h>
00067 #include <net/route.h>
00068 #include <pro/dhcp.h>
00069 
00070 #include "tlv320dac.h"
00071 #include "config.h"
00072 #include "receiver.h"
00073 #include "shoutcast.h"
00074 
00083 RECEIVERINFO * ReceiverCreate(RECEIVERPLUGIN *plugin)
00084 {
00085     RECEIVERINFO *rip;
00086 
00087     /* Allocate and initialize the receiver info structure. */
00088     if ((rip = malloc(sizeof(RECEIVERINFO))) != NULL) {
00089         memset(rip, 0, sizeof(RECEIVERINFO));
00090         rip->ri_rpp = plugin;
00091         /* Associate a new player plug-in instance. */
00092         if ((*plugin->rp_create) (rip)) {
00093             free(rip);
00094             rip = NULL;
00095         }
00096     }
00097     return rip;
00098 }
00099 
00109 static int ReceiverPlugInControl(RECEIVERINFO *rip, u_int sst, u_int xst)
00110 {
00111     int retries = 40;
00112 
00113     while (rip->ri_status != xst) {
00114         rip->ri_status = sst;
00115         NutEventPost(&rip->ri_cmdevt);
00116         if (retries-- <= 0) {
00117             printf("No receiver control\n");
00118             return -1;
00119         }
00120         NutEventWait(&rip->ri_stsevt, 500);
00121     }
00122     return 0;
00123 }
00124 
00132 u_int ReceiverStatus(RECEIVERINFO *rip)
00133 {
00134     return rip->ri_status;
00135 }
00136 
00144 int ReceiverStop(RECEIVERINFO *rip)
00145 {
00146     printf("[RSTOP]");
00147     return ReceiverPlugInControl(rip, RSTAT_STOP, RSTAT_IDLE);
00148 }
00149 
00158 int ReceiverStart(RECEIVERINFO *rip, STATIONINFO *sip)
00159 {
00160     /* Make sure that the receiver is not running. */
00161     if (ReceiverStop(rip)) {
00162         return -1;
00163     }
00164     printf("[RSTART]");
00165     rip->ri_sip = sip;
00166     rip->ri_wpos = 0;
00167     rip->ri_rpos = 0;
00168     rip->ri_avail = 0;
00169 
00170     if ((*rip->ri_rpp->rp_setup)(rip)) {
00171         return -1;
00172     }
00173     return ReceiverPlugInControl(rip, RSTAT_START, RSTAT_RUNNING);
00174 }
00175 

Generated on Fri Feb 23 17:28:49 2007 for SAM Internet Radio by  doxygen 1.4.4