[Redbutton-devel] SF.net SVN: redbutton: [289] redbutton-download/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-04-24 10:24:55
|
Revision: 289
http://svn.sourceforge.net/redbutton/?rev=289&view=rev
Author: skilvington
Date: 2007-04-24 03:24:53 -0700 (Tue, 24 Apr 2007)
Log Message:
-----------
cache the SDT
Modified Paths:
--------------
redbutton-download/trunk/findmheg.c
redbutton-download/trunk/list.c
redbutton-download/trunk/table.c
redbutton-download/trunk/table.h
Modified: redbutton-download/trunk/findmheg.c
===================================================================
--- redbutton-download/trunk/findmheg.c 2007-04-24 09:57:13 UTC (rev 288)
+++ redbutton-download/trunk/findmheg.c 2007-04-24 10:24:53 UTC (rev 289)
@@ -30,16 +30,8 @@
#include "findmheg.h"
#include "table.h"
#include "assoc.h"
-#include "cache.h"
#include "utils.h"
-/* Programme Association Table and Section */
-#define PID_PAT 0x0000
-#define TID_PAT 0x00
-
-/* Programme Map Section */
-#define TID_PMT 0x02
-
/* stream_types we are interested in */
#define STREAM_TYPE_VIDEO_MPEG2 0x02
#define STREAM_TYPE_AUDIO_MPEG1 0x03
@@ -83,8 +75,6 @@
static struct avstreams *find_current_avstreams(struct carousel *, int, int);
static struct avstreams *find_service_avstreams(struct carousel *, int, int, int);
-static bool read_pat(char *, unsigned int, unsigned char *);
-static bool read_pmt(char *, uint16_t, unsigned int, unsigned char *);
bool
is_audio_stream(uint8_t stream_type)
@@ -409,89 +399,3 @@
return &_streams;
}
-/*
- * output buffer must be at least MAX_TABLE_LEN bytes
- * returns false if it timesout
- */
-
-static bool
-read_pat(char *demux, unsigned int timeout, unsigned char *out)
-{
- /* is it in the cache */
- if(cache_load("pat", out))
- return true;
-
- /* read it from the DVB card */
- if(!read_table(demux, PID_PAT, TID_PAT, timeout, out))
- {
- error("Unable to read PAT");
- return false;
- }
-
- /* cache it */
- cache_save("pat", out);
-
- return true;
-}
-
-/*
- * output buffer must be at least MAX_TABLE_LEN bytes
- * returns false if it timesout
- */
-
-static bool
-read_pmt(char *demux, uint16_t service_id, unsigned int timeout, unsigned char *out)
-{
- char cache_item[PATH_MAX];
- unsigned char pat[MAX_TABLE_LEN];
- uint16_t section_length;
- uint16_t offset;
- uint16_t map_pid = 0;
- bool found;
- bool rc;
-
- /* is it in the cache */
- snprintf(cache_item, sizeof(cache_item), "pmt-%u", service_id);
- if(cache_load(cache_item, out))
- return true;
-
- /* get the PAT */
- if(!read_pat(demux, timeout, pat))
- return false;
-
- section_length = 3 + (((pat[1] & 0x0f) << 8) + pat[2]);
-
- /* find the PMT for this service_id */
- found = false;
- offset = 8;
- /* -4 for the CRC at the end */
- while((offset < (section_length - 4)) && !found)
- {
- if((pat[offset] << 8) + pat[offset+1] == service_id)
- {
- map_pid = ((pat[offset+2] & 0x1f) << 8) + pat[offset+3];
- found = true;
- }
- else
- {
- offset += 4;
- }
- }
-
- if(!found)
- fatal("Unable to find PMT PID for service_id %u", service_id);
-
- vverbose("PMT PID: %u", map_pid);
-
- /* get the PMT */
- rc = read_table(demux, map_pid, TID_PMT, timeout, out);
-
- /* cache it */
- if(rc)
- cache_save(cache_item, out);
- else
- error("Unable to read PMT");
-
- return rc;
-}
-
Modified: redbutton-download/trunk/list.c
===================================================================
--- redbutton-download/trunk/list.c 2007-04-24 09:57:13 UTC (rev 288)
+++ redbutton-download/trunk/list.c 2007-04-24 10:24:53 UTC (rev 289)
@@ -26,10 +26,6 @@
#include "table.h"
#include "utils.h"
-/* PID and TID we want */
-#define PID_SDT 0x0011
-#define TID_SDS 0x42
-
/* service_descriptor tag */
#define TAG_SERVICE_DESCRIPTOR 0x48
@@ -37,7 +33,7 @@
list_channels(unsigned int adapter, unsigned int timeout)
{
char demux_dev[PATH_MAX];
- unsigned char sds[MAX_TABLE_LEN];
+ unsigned char sdt[MAX_TABLE_LEN];
uint16_t size;
uint16_t offset;
uint16_t service_id;
@@ -52,29 +48,29 @@
printf("ID\tChannel\n");
printf("==\t=======\n");
- /* grab the Service Description Section table */
- if(!read_table(demux_dev, PID_SDT, TID_SDS, timeout, sds))
+ /* grab the Service Description Table */
+ if(!read_sdt(demux_dev, timeout, sdt))
fatal("Unable to read SDT");
/* 12 bit section_length field */
- size = 3 + (((sds[1] & 0x0f) << 8) + sds[2]);
+ size = 3 + (((sdt[1] & 0x0f) << 8) + sdt[2]);
/* loop through the services */
offset = 11;
/* -4 for the CRC at the end */
while(offset < (size - 4))
{
- service_id = (sds[offset] << 8) + sds[offset+1];
+ service_id = (sdt[offset] << 8) + sdt[offset+1];
printf("%u\t", service_id);
/* move on to the descriptors */
offset += 3;
- desc_loop_length = ((sds[offset] & 0x0f) << 8) + sds[offset+1];
+ desc_loop_length = ((sdt[offset] & 0x0f) << 8) + sdt[offset+1];
offset += 2;
/* find the service_descriptor tag */
while(desc_loop_length != 0)
{
- desc_tag = sds[offset];
- desc_length = sds[offset+1];
+ desc_tag = sdt[offset];
+ desc_length = sdt[offset+1];
offset += 2;
desc_loop_length -= 2;
if(desc_tag == TAG_SERVICE_DESCRIPTOR)
@@ -82,18 +78,18 @@
/* service_type = sds[offset]; */
offset += 1;
/* service_provider_name */
- name_len = sds[offset];
+ name_len = sdt[offset];
offset += 1 + name_len;
/* service_name */
- name_len = sds[offset];
+ name_len = sdt[offset];
offset += 1;
- printf("%.*s\n", name_len, &sds[offset]);
+ printf("%.*s\n", name_len, &sdt[offset]);
offset += name_len;
}
else
{
vverbose("desc_tag: %u", desc_tag);
- vhexdump(&sds[offset], desc_length);
+ vhexdump(&sdt[offset], desc_length);
offset += desc_length;
}
desc_loop_length -= desc_length;
Modified: redbutton-download/trunk/table.c
===================================================================
--- redbutton-download/trunk/table.c 2007-04-24 09:57:13 UTC (rev 288)
+++ redbutton-download/trunk/table.c 2007-04-24 10:24:53 UTC (rev 289)
@@ -42,8 +42,20 @@
#include "dsmcc.h"
#include "carousel.h"
#include "biop.h"
+#include "cache.h"
#include "utils.h"
+/* Programme Association Table PID and TID */
+#define PID_PAT 0x0000
+#define TID_PAT 0x00
+
+/* Programme Map Table TID */
+#define TID_PMT 0x02
+
+/* Service Description Table PID and TID */
+#define PID_SDT 0x0011
+#define TID_SDT 0x42
+
/* DSMCC table ID's we want */
#define TID_DSMCC_CONTROL 0x3b /* DSI or DII */
#define TID_DSMCC_DATA 0x3c /* DDB */
@@ -54,6 +66,117 @@
*/
bool
+read_pat(char *demux, unsigned int timeout, unsigned char *out)
+{
+ /* is it in the cache */
+ if(cache_load("pat", out))
+ return true;
+
+ /* read it from the DVB card */
+ if(!read_table(demux, PID_PAT, TID_PAT, timeout, out))
+ {
+ error("Unable to read PAT");
+ return false;
+ }
+
+ /* cache it */
+ cache_save("pat", out);
+
+ return true;
+}
+
+/*
+ * 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)
+{
+ char cache_item[PATH_MAX];
+ unsigned char pat[MAX_TABLE_LEN];
+ uint16_t section_length;
+ uint16_t offset;
+ uint16_t map_pid = 0;
+ bool found;
+ bool rc;
+
+ /* is it in the cache */
+ snprintf(cache_item, sizeof(cache_item), "pmt-%u", service_id);
+ if(cache_load(cache_item, out))
+ return true;
+
+ /* get the PAT */
+ if(!read_pat(demux, timeout, pat))
+ return false;
+
+ section_length = 3 + (((pat[1] & 0x0f) << 8) + pat[2]);
+
+ /* find the PMT for this service_id */
+ found = false;
+ offset = 8;
+ /* -4 for the CRC at the end */
+ while((offset < (section_length - 4)) && !found)
+ {
+ if((pat[offset] << 8) + pat[offset+1] == service_id)
+ {
+ map_pid = ((pat[offset+2] & 0x1f) << 8) + pat[offset+3];
+ found = true;
+ }
+ else
+ {
+ offset += 4;
+ }
+ }
+
+ if(!found)
+ fatal("Unable to find PMT PID for service_id %u", service_id);
+
+ vverbose("PMT PID: %u", map_pid);
+
+ /* get the PMT */
+ rc = read_table(demux, map_pid, TID_PMT, timeout, out);
+
+ /* cache it */
+ if(rc)
+ cache_save(cache_item, out);
+ else
+ error("Unable to read PMT");
+
+ return rc;
+}
+
+/*
+ * output buffer must be at least MAX_TABLE_LEN bytes
+ * returns false if it timesout
+ */
+
+bool
+read_sdt(char *demux, unsigned int timeout, unsigned char *out)
+{
+ /* is it in the cache */
+ if(cache_load("sdt", out))
+ return true;
+
+ /* read it from the DVB card */
+ if(!read_table(demux, PID_SDT, TID_SDT, timeout, out))
+ {
+ error("Unable to read SDT");
+ return false;
+ }
+
+ /* cache it */
+ cache_save("sdt", out);
+
+ return true;
+}
+
+/*
+ * output buffer must be at least MAX_TABLE_LEN bytes
+ * returns false if it timesout
+ */
+
+bool
read_table(char *device, uint16_t pid, uint8_t tid, unsigned int secs, unsigned char *out)
{
int fd_data;
Modified: redbutton-download/trunk/table.h
===================================================================
--- redbutton-download/trunk/table.h 2007-04-24 09:57:13 UTC (rev 288)
+++ redbutton-download/trunk/table.h 2007-04-24 10:24:53 UTC (rev 289)
@@ -31,6 +31,10 @@
/* max size of a DVB table */
#define MAX_TABLE_LEN 4096
+bool read_pat(char *, unsigned int, unsigned char *);
+bool read_pmt(char *, uint16_t, unsigned int, unsigned char *);
+bool read_sdt(char *, unsigned int, unsigned char *);
+
bool read_table(char *, uint16_t, uint8_t, unsigned int, unsigned char *);
bool read_dsmcc_tables(struct carousel *, unsigned char *);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|