decode_sdt.c   decode_sdt.c 
/************************************************************************** *** /************************************************************************** ***
* decode_sdt.c: SDT decoder example * decode_sdt.c: SDT decoder example
*------------------------------------------------------------------------- --- *------------------------------------------------------------------------- ---
* Copyright (C) 2001-2010 VideoLAN * Copyright (C) 2001-2011 VideoLAN
* $Id: decode_sdt.c,v 1.1 2002/12/11 13:04:56 jobi Exp $ * $Id: decode_sdt.c,v 1.1 2002/12/11 13:04:56 jobi Exp $
* *
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
* Johan Bilien <jobi@via.ecp.fr> * Johan Bilien <jobi@via.ecp.fr>
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version. * version 2.1 of the License, or (at your option) any later version.
* *
skipping to change at line 32 skipping to change at line 32
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-130 1 USA
* *
*------------------------------------------------------------------------- --- *------------------------------------------------------------------------- ---
* *
************************************************************************** ***/ ************************************************************************** ***/
#include "config.h" #include "config.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#if defined(HAVE_INTTYPES_H) #if defined(HAVE_INTTYPES_H)
#include <inttypes.h> #include <inttypes.h>
#elif defined(HAVE_STDINT_H) #elif defined(HAVE_STDINT_H)
#include <stdint.h> #include <stdint.h>
#endif #endif
/* The libdvbpsi distribution defines DVBPSI_DIST */ /* The libdvbpsi distribution defines DVBPSI_DIST */
skipping to change at line 59 skipping to change at line 60
#include <dvbpsi/dvbpsi.h> #include <dvbpsi/dvbpsi.h>
#include <dvbpsi/psi.h> #include <dvbpsi/psi.h>
#include <dvbpsi/demux.h> #include <dvbpsi/demux.h>
#include <dvbpsi/descriptor.h> #include <dvbpsi/descriptor.h>
#include <dvbpsi/sdt.h> #include <dvbpsi/sdt.h>
#endif #endif
/************************************************************************** *** /************************************************************************** ***
* ReadPacket * ReadPacket
************************************************************************** ***/ ************************************************************************** ***/
static int ReadPacket(int i_fd, uint8_t* p_dst) static bool ReadPacket(int i_fd, uint8_t* p_dst)
{ {
int i = 187; int i = 187;
int i_rc = 1; int i_rc = 1;
p_dst[0] = 0; p_dst[0] = 0;
while((p_dst[0] != 0x47) && (i_rc > 0)) while((p_dst[0] != 0x47) && (i_rc > 0))
{ {
i_rc = read(i_fd, p_dst, 1); i_rc = read(i_fd, p_dst, 1);
} }
while((i != 0) && (i_rc > 0)) while((i != 0) && (i_rc > 0))
{ {
i_rc = read(i_fd, p_dst + 188 - i, i); i_rc = read(i_fd, p_dst + 188 - i, i);
if(i_rc >= 0) if(i_rc >= 0)
i -= i_rc; i -= i_rc;
} }
return (i == 0) ? 1 : 0; return (i == 0) ? true : false;
} }
/************************************************************************** *** /************************************************************************** ***
* DumpDescriptors * DumpDescriptors
************************************************************************** ***/ ************************************************************************** ***/
static void DumpDescriptors(const char* str, dvbpsi_descriptor_t* p_descrip tor) static void DumpDescriptors(const char* str, dvbpsi_descriptor_t* p_descrip tor)
{ {
while(p_descriptor) while(p_descriptor)
{ {
int i; int i;
skipping to change at line 106 skipping to change at line 107
/************************************************************************** *** /************************************************************************** ***
* DumpSDT * DumpSDT
************************************************************************** ***/ ************************************************************************** ***/
static void DumpSDT(void* p_zero, dvbpsi_sdt_t* p_sdt) static void DumpSDT(void* p_zero, dvbpsi_sdt_t* p_sdt)
{ {
dvbpsi_sdt_service_t* p_service = p_sdt->p_first_service; dvbpsi_sdt_service_t* p_service = p_sdt->p_first_service;
printf( "\n"); printf( "\n");
printf( "New active SDT\n"); printf( "New active SDT\n");
printf( " ts_id : %d\n", printf( " ts_id : %d\n",
p_sdt->i_ts_id); p_sdt->i_extension);
printf( " version_number : %d\n", printf( " version_number : %d\n",
p_sdt->i_version); p_sdt->i_version);
printf( " network_id : %d\n", printf( " network_id : %d\n",
p_sdt->i_network_id); p_sdt->i_network_id);
printf( " | service_id \n"); printf( " | service_id \n");
while(p_service) while(p_service)
{ {
printf(" | 0x%02x \n", printf(" | 0x%02x \n",
p_service->i_service_id); p_service->i_service_id);
DumpDescriptors(" | ]", p_service->p_first_descriptor); DumpDescriptors(" | ]", p_service->p_first_descriptor);
p_service = p_service->p_next; p_service = p_service->p_next;
} }
dvbpsi_DeleteSDT(p_sdt); dvbpsi_sdt_delete(p_sdt);
}
/**************************************************************************
***
* DVBPSI messaging callback
**************************************************************************
***/
static void message(dvbpsi_t *handle, const dvbpsi_msg_level_t level, const
char* msg)
{
switch(level)
{
case DVBPSI_MSG_ERROR: fprintf(stderr, "Error: "); break;
case DVBPSI_MSG_WARN: fprintf(stderr, "Warning: "); break;
case DVBPSI_MSG_DEBUG: fprintf(stderr, "Debug: "); break;
default: /* do nothing */
return;
}
fprintf(stderr, "%s\n", msg);
} }
/************************************************************************** *** /************************************************************************** ***
* NewSubtable * NewSubtable
************************************************************************** ***/ ************************************************************************** ***/
static void NewSubtable(void * p_zero, dvbpsi_handle h_dvbpsi, static void NewSubtable(dvbpsi_t *p_dvbpsi, uint8_t i_table_id, uint16_t i_
uint8_t i_table_id, uint16_t i_extension) extension,
void * p_zero)
{ {
if(i_table_id == 0x42) if(i_table_id == 0x42)
{ {
dvbpsi_AttachSDT(h_dvbpsi, i_table_id, i_extension, DumpSDT, NULL); if (!dvbpsi_sdt_attach(p_dvbpsi, i_table_id, i_extension, DumpSDT, NUL
L))
fprintf(stderr, "Failed to attach SDT subdecoder\n");
} }
} }
/************************************************************************** *** /************************************************************************** ***
* main * main
************************************************************************** ***/ ************************************************************************** ***/
int main(int i_argc, char* pa_argv[]) int main(int i_argc, char* pa_argv[])
{ {
int i_fd; int i_fd;
uint8_t data[188]; uint8_t data[188];
dvbpsi_handle h_dvbpsi; dvbpsi_t *p_dvbpsi;
int b_ok; bool b_ok;
if(i_argc != 2) if(i_argc != 2)
return 1; return 1;
i_fd = open(pa_argv[1], 0); i_fd = open(pa_argv[1], 0);
if (i_fd < 0)
return 1;
h_dvbpsi = dvbpsi_AttachDemux(NewSubtable, NULL); p_dvbpsi = dvbpsi_new(&message, DVBPSI_MSG_DEBUG);
if (p_dvbpsi == NULL)
goto out;
if (!dvbpsi_AttachDemux(p_dvbpsi, NewSubtable, NULL))
goto out;
b_ok = ReadPacket(i_fd, data); b_ok = ReadPacket(i_fd, data);
while(b_ok) while(b_ok)
{ {
uint16_t i_pid = ((uint16_t)(data[1] & 0x1f) << 8) + data[2]; uint16_t i_pid = ((uint16_t)(data[1] & 0x1f) << 8) + data[2];
if(i_pid == 0x11) if(i_pid == 0x11)
dvbpsi_PushPacket(h_dvbpsi, data); dvbpsi_packet_push(p_dvbpsi, data);
b_ok = ReadPacket(i_fd, data); b_ok = ReadPacket(i_fd, data);
} }
dvbpsi_DetachDemux(h_dvbpsi); out:
if (p_dvbpsi)
{
dvbpsi_DetachDemux(p_dvbpsi);
dvbpsi_delete(p_dvbpsi);
}
close(i_fd);
return 0; return 0;
} }
 End of changes. 13 change blocks. 
14 lines changed or deleted 49 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/