[Redbutton-devel] SF.net SVN: redbutton: [224] redbutton-download/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-02-19 13:17:36
|
Revision: 224
http://svn.sourceforge.net/redbutton/?rev=224&view=rev
Author: skilvington
Date: 2007-02-19 05:17:28 -0800 (Mon, 19 Feb 2007)
Log Message:
-----------
caller provides output buffer when reading DVB tables
Modified Paths:
--------------
redbutton-download/trunk/TODO
redbutton-download/trunk/carousel.c
redbutton-download/trunk/findmheg.c
redbutton-download/trunk/list.c
redbutton-download/trunk/table.c
redbutton-download/trunk/table.h
Modified: redbutton-download/trunk/TODO
===================================================================
--- redbutton-download/trunk/TODO 2007-02-18 14:37:15 UTC (rev 223)
+++ redbutton-download/trunk/TODO 2007-02-19 13:17:28 UTC (rev 224)
@@ -1,5 +1,4 @@
cache PAT and PMTs
-also, better if caller provides output buffer for tables
need to kill all existing command connections on retune
(listen_data->carousel is stale for them)
Modified: redbutton-download/trunk/carousel.c
===================================================================
--- redbutton-download/trunk/carousel.c 2007-02-18 14:37:15 UTC (rev 223)
+++ redbutton-download/trunk/carousel.c 2007-02-19 13:17:28 UTC (rev 224)
@@ -34,7 +34,7 @@
void
load_carousel(struct carousel *car)
{
- unsigned char *table;
+ unsigned char table[MAX_TABLE_LEN];
bool done;
/* no modules yet */
@@ -46,7 +46,7 @@
do
{
struct dsmccMessageHeader *dsmcc;
- if((table = read_dsmcc_tables(car)) == NULL)
+ if(!read_dsmcc_tables(car, table))
fatal("Unable to read PID");
dsmcc = (struct dsmccMessageHeader *) &table[8];
if(dsmcc->protocolDiscriminator == DSMCC_PROTOCOL
Modified: redbutton-download/trunk/findmheg.c
===================================================================
--- redbutton-download/trunk/findmheg.c 2007-02-18 14:37:15 UTC (rev 223)
+++ redbutton-download/trunk/findmheg.c 2007-02-19 13:17:28 UTC (rev 224)
@@ -81,7 +81,7 @@
static struct avstreams *find_current_avstreams(struct carousel *, int, int);
static struct avstreams *find_service_avstreams(struct carousel *, int, int, int);
-static unsigned char *read_pmt(char *, uint16_t, unsigned int);
+static bool read_pmt(char *, uint16_t, unsigned int, unsigned char *);
bool
is_audio_stream(uint8_t stream_type)
@@ -107,7 +107,7 @@
struct carousel *
find_mheg(unsigned int adapter, unsigned int timeout, uint16_t service_id, int carousel_id)
{
- unsigned char *pmt;
+ unsigned char pmt[MAX_TABLE_LEN];
uint16_t section_length;
uint16_t offset;
uint8_t stream_type;
@@ -144,7 +144,7 @@
_car.modules = NULL;
/* get the PMT */
- if((pmt = read_pmt(_car.demux_device, service_id, timeout)) == NULL)
+ if(!read_pmt(_car.demux_device, service_id, timeout, pmt))
fatal("Unable to read PMT");
section_length = 3 + (((pmt[1] & 0x0f) << 8) + pmt[2]);
@@ -302,7 +302,7 @@
static struct avstreams *
find_service_avstreams(struct carousel *car, int service_id, int audio_tag, int video_tag)
{
- unsigned char *pmt;
+ unsigned char pmt[MAX_TABLE_LEN];
uint16_t section_length;
uint16_t offset;
uint8_t stream_type;
@@ -318,7 +318,7 @@
bzero(&_streams, sizeof(_streams));
/* get the PMT */
- if((pmt = read_pmt(car->demux_device, service_id, car->timeout)) == NULL)
+ if(!read_pmt(car->demux_device, service_id, car->timeout, pmt))
fatal("Unable to read PMT");
section_length = 3 + (((pmt[1] & 0x0f) << 8) + pmt[2]);
@@ -400,21 +400,26 @@
return &_streams;
}
-static unsigned char *
-read_pmt(char *demux, uint16_t service_id, unsigned int timeout)
+/*
+ * output buffer must be at least MAX_TABLE_LEN bytes
+ * returns false if it timesout
+ */
+
+bool
+read_pmt(char *demux, uint16_t service_id, unsigned int timeout, unsigned char *out)
{
- unsigned char *pat;
+ unsigned char pat[MAX_TABLE_LEN];
uint16_t section_length;
uint16_t offset;
uint16_t map_pid = 0;
bool found;
- unsigned char *pmt;
+ bool rc;
/* get the PAT */
- if((pat = read_table(_car.demux_device, PID_PAT, TID_PAT, timeout)) == NULL)
+ if(!read_table(_car.demux_device, PID_PAT, TID_PAT, timeout, pat))
{
error("Unable to read PAT");
- return NULL;
+ return false;
}
section_length = 3 + (((pat[1] & 0x0f) << 8) + pat[2]);
@@ -442,9 +447,10 @@
vverbose("PMT PID: %u", map_pid);
/* get the PMT */
- if((pmt = read_table(_car.demux_device, map_pid, TID_PMT, timeout)) == NULL)
+ rc = read_table(_car.demux_device, map_pid, TID_PMT, timeout, out);
+ if(!rc)
error("Unable to read PMT");
- return pmt;
+ return rc;
}
Modified: redbutton-download/trunk/list.c
===================================================================
--- redbutton-download/trunk/list.c 2007-02-18 14:37:15 UTC (rev 223)
+++ redbutton-download/trunk/list.c 2007-02-19 13:17:28 UTC (rev 224)
@@ -37,7 +37,7 @@
list_channels(unsigned int adapter, unsigned int timeout)
{
char demux_dev[PATH_MAX];
- unsigned char *sds;
+ unsigned char sds[MAX_TABLE_LEN];
uint16_t size;
uint16_t offset;
uint16_t service_id;
@@ -53,7 +53,7 @@
printf("==\t=======\n");
/* grab the Service Description Section table */
- if((sds = read_table(demux_dev, PID_SDT, TID_SDS, timeout)) == NULL)
+ if(!read_table(demux_dev, PID_SDT, TID_SDS, timeout, sds))
fatal("Unable to read SDT");
/* 12 bit section_length field */
Modified: redbutton-download/trunk/table.c
===================================================================
--- redbutton-download/trunk/table.c 2007-02-18 14:37:15 UTC (rev 223)
+++ redbutton-download/trunk/table.c 2007-02-19 13:17:28 UTC (rev 224)
@@ -38,21 +38,23 @@
#include <linux/dvb/dmx.h>
#endif
+#include "table.h"
#include "dsmcc.h"
#include "carousel.h"
#include "biop.h"
#include "utils.h"
-#define MAX_TABLE_LEN 4096
-
/* DSMCC table ID's we want */
#define TID_DSMCC_CONTROL 0x3b /* DSI or DII */
#define TID_DSMCC_DATA 0x3c /* DDB */
-static unsigned char _buf[MAX_TABLE_LEN];
+/*
+ * output buffer must be at least MAX_TABLE_LEN bytes
+ * returns false if it timesout
+ */
-unsigned char *
-read_table(char *device, uint16_t pid, uint8_t tid, unsigned int secs)
+bool
+read_table(char *device, uint16_t pid, uint8_t tid, unsigned int secs, unsigned char *out)
{
int fd_data;
struct dmx_sct_filter_params sctFilterParams;
@@ -63,7 +65,7 @@
if((fd_data = open(device, O_RDWR)) < 0)
{
error("open '%s': %s", device, strerror(errno));
- return NULL;
+ return false;
}
memset(&sctFilterParams, 0, sizeof(sctFilterParams));
@@ -77,14 +79,15 @@
{
error("ioctl DMX_SET_FILTER: %s", strerror(errno));
close(fd_data);
- return NULL;
+ return false;
}
timeout.tv_sec = secs;
timeout.tv_usec = 0;
do
{
- _buf[0] = 0xff; /* we never want table ID 0xff */
+ /* we check for out[0]==tid to see if we read the table */
+ out[0] = ~tid;
FD_ZERO(&readfds);
FD_SET(fd_data, &readfds);
if(select(fd_data + 1, &readfds, NULL, NULL, &timeout) < 0)
@@ -93,36 +96,38 @@
continue;
error("read_table: select: %s", strerror(errno));
close(fd_data);
- return NULL;
+ return false;
}
if(FD_ISSET(fd_data, &readfds))
{
- if((n = read(fd_data, _buf, sizeof(_buf))) < 0)
+ if((n = read(fd_data, out, MAX_TABLE_LEN)) < 0)
{
error("read: %s", strerror(errno));
close(fd_data);
- return NULL;
+ return false;
}
}
else
{
error("Timeout reading %s", device);
close(fd_data);
- return NULL;
+ return false;
}
}
- while(_buf[0] != tid);
+ while(out[0] != tid);
-// printf("PID: 0x%x table_id: 0x%x length: %d bytes\n", pid, _buf[0], n);
-// hexdump(_buf, n);
-
close(fd_data);
- return _buf;
+ return true;
}
-unsigned char *
-read_dsmcc_tables(struct carousel *car)
+/*
+ * output buffer must be at least MAX_TABLE_LEN bytes
+ * returns false if it timesout
+ */
+
+bool
+read_dsmcc_tables(struct carousel *car, unsigned char *out)
{
struct timeval timeout;
unsigned int i;
@@ -135,7 +140,7 @@
timeout.tv_usec = 0;
do
{
- _buf[0] = 0;
+ out[0] = 0;
/* work out the max fd number and set the fds we want to read from */
max = 0;
FD_ZERO(&readfds);
@@ -150,7 +155,7 @@
if(select(max + 1, &readfds, NULL, NULL, &timeout) < 0)
{
error("read_dsmcc_tables: select: %s", strerror(errno));
- return NULL;
+ return false;
}
/* see which fd is ready */
fd = -1;
@@ -172,25 +177,22 @@
if(fd == -1)
{
error("Timeout reading %s", car->demux_device);
- return NULL;
+ return false;
}
/* read the table */
- if((n = read(fd, _buf, sizeof(_buf))) < 0)
+ if((n = read(fd, out, MAX_TABLE_LEN)) < 0)
{
/*
* may get EOVERFLOW if we don't read quick enough,
* so just report it and have another go
*/
error("read: %s", strerror(errno));
- _buf[0] = 0;
+ out[0] = 0;
}
}
- while(_buf[0] != TID_DSMCC_CONTROL && _buf[0] != TID_DSMCC_DATA);
+ while(out[0] != TID_DSMCC_CONTROL && out[0] != TID_DSMCC_DATA);
-// printf("PID: 0x%x table_id: 0x%x length: %d bytes\n", car->current_pid, _buf[0], n);
-// hexdump(_buf, n);
-
- return _buf;
+ return out;
}
void
Modified: redbutton-download/trunk/table.h
===================================================================
--- redbutton-download/trunk/table.h 2007-02-18 14:37:15 UTC (rev 223)
+++ redbutton-download/trunk/table.h 2007-02-19 13:17:28 UTC (rev 224)
@@ -24,13 +24,17 @@
#define __TABLE_H__
#include <stdint.h>
+#include <stdbool.h>
#include "module.h"
-unsigned char *read_table(char *, uint16_t, uint8_t, unsigned int);
+/* max size of a DVB table */
+#define MAX_TABLE_LEN 4096
-unsigned char *read_dsmcc_tables(struct carousel *);
+bool read_table(char *, uint16_t, uint8_t, unsigned int, unsigned char *);
+bool read_dsmcc_tables(struct carousel *, unsigned char *);
+
void add_dsmcc_pid(struct carousel *, uint16_t);
#endif /* __TABLE_H__ */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|