Commit 7cfea795 authored by Jean-Paul Saman's avatar Jean-Paul Saman

examples: update API used.

parent d5b28e05
/***************************************************************************** /*****************************************************************************
* decode_bat.c: BAT decoder example * decode_bat.c: BAT decoder example
*---------------------------------------------------------------------------- *----------------------------------------------------------------------------
* Copyright (C) 2001-2010 VideoLAN * Copyright (C) 2001-2011 VideoLAN
* $Id: decode_bat.c 01 2010-04-01 17:55:18 zhuzlu $ * $Id: decode_bat.c 01 2010-04-01 17:55:18 zhuzlu $
* *
* Authors: Zhu zhenglu <zhuzlu@gmail.com> * Authors: Zhu zhenglu <zhuzlu@gmail.com>
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#include "config.h" #include "config.h"
#include <stdio.h> #include <stdio.h>
...@@ -198,15 +197,19 @@ static void DumpBAT(void* p_zero, dvbpsi_bat_t* p_bat) ...@@ -198,15 +197,19 @@ static void DumpBAT(void* p_zero, dvbpsi_bat_t* p_bat)
/***************************************************************************** /*****************************************************************************
* NewSubtable * NewSubtable
*****************************************************************************/ *****************************************************************************/
static void NewSubtableBAT(void * p_zero, dvbpsi_handle h_dvbpsi, static void NewSubtableBAT(void * p_zero, dvbpsi_t *p_dvbpsi,
uint8_t i_table_id, uint16_t i_extension) uint8_t i_table_id, uint16_t i_extension)
{ {
if(i_table_id == 0x4a) if(i_table_id == 0x4a)
{ {
dvbpsi_AttachBAT(h_dvbpsi, i_table_id, i_extension, DumpBAT, NULL); dvbpsi_AttachBAT(p_dvbpsi, i_table_id, i_extension, DumpBAT, NULL);
} }
} }
static void message(dvbpsi_t *handle, const char* msg)
{
fprintf(stderr, "%s\n", msg);
}
/***************************************************************************** /*****************************************************************************
* main * main
...@@ -215,15 +218,22 @@ int main(int i_argc, char* pa_argv[]) ...@@ -215,15 +218,22 @@ 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; int 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(NewSubtableBAT, NULL); p_dvbpsi = dvbpsi_NewHandle(&message, DVBPSI_MSG_DEBUG);
if (p_dvbpsi == NULL)
goto out;
dvbpsi_t *p_demux = dvbpsi_AttachDemux(p_dvbpsi, NewSubtableBAT, NULL);
if(p_demux == NULL)
goto out;
b_ok = ReadPacket(i_fd, data); b_ok = ReadPacket(i_fd, data);
...@@ -231,11 +241,16 @@ int main(int i_argc, char* pa_argv[]) ...@@ -231,11 +241,16 @@ int main(int i_argc, char* pa_argv[])
{ {
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_PushPacket(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_DeleteHandle(p_dvbpsi);
}
close(i_fd);
return 0; return 0;
} }
/***************************************************************************** /*****************************************************************************
* decode_mpeg.c: MPEG decoder example * decode_mpeg.c: MPEG decoder example
*---------------------------------------------------------------------------- *----------------------------------------------------------------------------
* Copyright (C) 2001-2010 VideoLAN * Copyright (C) 2001-2011 VideoLAN
* $Id: decode_mpeg.c 104 2005-03-21 13:38:56Z massiot $ * $Id: decode_mpeg.c 104 2005-03-21 13:38:56Z massiot $
* *
* Authors: Jean-Paul Saman <jpsaman #_at_# m2x dot nl> * Authors: Jean-Paul Saman <jpsaman #_at_# m2x dot nl>
...@@ -100,7 +100,7 @@ typedef int64_t mtime_t; ...@@ -100,7 +100,7 @@ typedef int64_t mtime_t;
typedef struct typedef struct
{ {
dvbpsi_handle handle; dvbpsi_t * handle;
int i_pat_version; int i_pat_version;
int i_ts_id; int i_ts_id;
...@@ -119,7 +119,7 @@ typedef struct ts_pid_s ...@@ -119,7 +119,7 @@ typedef struct ts_pid_s
typedef struct ts_pmt_s typedef struct ts_pmt_s
{ {
dvbpsi_handle handle; dvbpsi_t * handle;
int i_number; /* i_number = 0 is actually a NIT */ int i_number; /* i_number = 0 is actually a NIT */
int i_pmt_version; int i_pmt_version;
...@@ -285,6 +285,11 @@ static void report_PCRPacketTiming( int i_cc, ts_pid_t *ts_pid, ...@@ -285,6 +285,11 @@ static void report_PCRPacketTiming( int i_cc, ts_pid_t *ts_pid,
#endif #endif
} }
static void message(dvbpsi_t *handle, const char* msg)
{
fprintf(stderr, "%s\n", msg);
}
/***************************************************************************** /*****************************************************************************
* DumpPAT * DumpPAT
*****************************************************************************/ *****************************************************************************/
...@@ -293,6 +298,14 @@ static void DumpPAT(void* p_data, dvbpsi_pat_t* p_pat) ...@@ -293,6 +298,14 @@ static void DumpPAT(void* p_data, dvbpsi_pat_t* p_pat)
dvbpsi_pat_program_t* p_program = p_pat->p_first_program; dvbpsi_pat_program_t* p_program = p_pat->p_first_program;
ts_stream_t* p_stream = (ts_stream_t*) p_data; ts_stream_t* p_stream = (ts_stream_t*) p_data;
if (p_stream->pmt.handle)
{
fprintf(stderr, "freeing old PMT\n");
dvbpsi_DetachPMT(p_stream->pmt.handle);
dvbpsi_DeleteHandle(p_stream->pmt.handle);
p_stream->pmt.handle = NULL;
}
p_stream->pat.i_pat_version = p_pat->i_version; p_stream->pat.i_pat_version = p_pat->i_version;
p_stream->pat.i_ts_id = p_pat->i_ts_id; p_stream->pat.i_ts_id = p_pat->i_ts_id;
...@@ -307,8 +320,19 @@ static void DumpPAT(void* p_data, dvbpsi_pat_t* p_pat) ...@@ -307,8 +320,19 @@ static void DumpPAT(void* p_data, dvbpsi_pat_t* p_pat)
p_stream->pmt.i_number = p_program->i_number; p_stream->pmt.i_number = p_program->i_number;
p_stream->pmt.pid_pmt = &p_stream->pid[p_program->i_pid]; p_stream->pmt.pid_pmt = &p_stream->pid[p_program->i_pid];
p_stream->pmt.pid_pmt->i_pid = p_program->i_pid; p_stream->pmt.pid_pmt->i_pid = p_program->i_pid;
p_stream->pmt.handle = dvbpsi_AttachPMT( p_program->i_number, DumpPMT, p_stream ); dvbpsi_t *p_dvbpsi = dvbpsi_NewHandle(&message, DVBPSI_MSG_DEBUG);
if (p_dvbpsi == NULL)
{
fprintf(stderr, "could not allocate new dvbpsi_t handle\n");
break;
}
p_stream->pmt.handle = dvbpsi_AttachPMT(p_dvbpsi, p_program->i_number, DumpPMT, p_stream );
if (p_stream->pmt.handle == NULL)
{
dvbpsi_DeleteHandle(p_dvbpsi);
fprintf(stderr, "could not attach PMT\n");
break;
}
fprintf( stderr, " | %14d @ 0x%x (%d)\n", fprintf( stderr, " | %14d @ 0x%x (%d)\n",
p_program->i_number, p_program->i_pid, p_program->i_pid); p_program->i_number, p_program->i_pid, p_program->i_pid);
p_program = p_program->p_next; p_program = p_program->p_next;
...@@ -636,8 +660,15 @@ int main(int i_argc, char* pa_argv[]) ...@@ -636,8 +660,15 @@ int main(int i_argc, char* pa_argv[])
report_Header( i_report ); report_Header( i_report );
#endif #endif
dvbpsi_t *p_dvbpsi = dvbpsi_NewHandle(&message, DVBPSI_MSG_DEBUG);
if (p_dvbpsi == NULL)
goto dvbpsi_out;
p_stream->pat.handle = dvbpsi_AttachPAT(p_dvbpsi, DumpPAT, p_stream);
if (p_stream->pat.handle == NULL)
{
goto dvbpsi_out;
}
/* Enter infinite loop */ /* Enter infinite loop */
p_stream->pat.handle = dvbpsi_AttachPAT( DumpPAT, p_stream );
while( i_len > 0 ) while( i_len > 0 )
{ {
int i = 0; int i = 0;
...@@ -754,9 +785,15 @@ int main(int i_argc, char* pa_argv[]) ...@@ -754,9 +785,15 @@ int main(int i_argc, char* pa_argv[])
#endif #endif
} }
if( p_stream->pmt.handle ) if( p_stream->pmt.handle )
{
dvbpsi_DetachPMT( p_stream->pmt.handle ); dvbpsi_DetachPMT( p_stream->pmt.handle );
dvbpsi_DeleteHandle( p_stream->pmt.handle );
}
if( p_stream->pat.handle ) if( p_stream->pat.handle )
{
dvbpsi_DetachPAT( p_stream->pat.handle ); dvbpsi_DetachPAT( p_stream->pat.handle );
dvbpsi_DeleteHandle( p_stream->pat.handle );
}
/* clean up */ /* clean up */
if( filename ) if( filename )
...@@ -779,6 +816,13 @@ int main(int i_argc, char* pa_argv[]) ...@@ -779,6 +816,13 @@ int main(int i_argc, char* pa_argv[])
out_of_memory: out_of_memory:
fprintf( stderr, "Out of memory\n" ); fprintf( stderr, "Out of memory\n" );
dvbpsi_out:
if( p_stream->pat.handle )
{
dvbpsi_DetachPAT( p_stream->pat.handle );
dvbpsi_DeleteHandle( p_stream->pat.handle );
}
error: error:
if( p_data ) free( p_data ); if( p_data ) free( p_data );
if( filename ) free( filename ); if( filename ) free( filename );
......
/***************************************************************************** /*****************************************************************************
* decode_pat.c: PAT decoder example * decode_pat.c: PAT decoder example
*---------------------------------------------------------------------------- *----------------------------------------------------------------------------
* Copyright (C) 2001-2010 VideoLAN * Copyright (C) 2001-2011 VideoLAN
* $Id$ * $Id$
* *
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#include "config.h" #include "config.h"
#include <stdio.h> #include <stdio.h>
...@@ -49,7 +48,6 @@ ...@@ -49,7 +48,6 @@
#include <dvbpsi/pat.h> #include <dvbpsi/pat.h>
#endif #endif
/***************************************************************************** /*****************************************************************************
* ReadPacket * ReadPacket
*****************************************************************************/ *****************************************************************************/
...@@ -97,6 +95,10 @@ static void DumpPAT(void* p_zero, dvbpsi_pat_t* p_pat) ...@@ -97,6 +95,10 @@ static void DumpPAT(void* p_zero, dvbpsi_pat_t* p_pat)
dvbpsi_DeletePAT(p_pat); dvbpsi_DeletePAT(p_pat);
} }
static void message(dvbpsi_t *handle, const char* msg)
{
fprintf(stderr, "%s\n", msg);
}
/***************************************************************************** /*****************************************************************************
* main * main
...@@ -105,15 +107,23 @@ int main(int i_argc, char* pa_argv[]) ...@@ -105,15 +107,23 @@ 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; int 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;
p_dvbpsi = dvbpsi_NewHandle(&message, DVBPSI_MSG_DEBUG);
if (p_dvbpsi == NULL)
goto out;
h_dvbpsi = dvbpsi_AttachPAT(DumpPAT, NULL); dvbpsi_t *p_tmp = dvbpsi_AttachPAT(p_dvbpsi, DumpPAT, NULL);
if (p_tmp == NULL)
goto out;
b_ok = ReadPacket(i_fd, data); b_ok = ReadPacket(i_fd, data);
...@@ -121,11 +131,17 @@ int main(int i_argc, char* pa_argv[]) ...@@ -121,11 +131,17 @@ int main(int i_argc, char* pa_argv[])
{ {
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 == 0x0) if(i_pid == 0x0)
dvbpsi_PushPacket(h_dvbpsi, data); dvbpsi_PushPacket(p_dvbpsi, data);
b_ok = ReadPacket(i_fd, data); b_ok = ReadPacket(i_fd, data);
} }
dvbpsi_DetachPAT(h_dvbpsi); out:
if (p_dvbpsi == NULL)
{
dvbpsi_DetachPAT(p_dvbpsi);
dvbpsi_DeleteHandle(p_dvbpsi);
}
close(i_fd);
return 0; return 0;
} }
......
/***************************************************************************** /*****************************************************************************
* decode_pmt.c: PAT decoder example * decode_pmt.c: PAT decoder example
*---------------------------------------------------------------------------- *----------------------------------------------------------------------------
* Copyright (C) 2001-2010 VideoLAN * Copyright (C) 2001-2011 VideoLAN
* $Id$ * $Id$
* *
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr> * Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#include "config.h" #include "config.h"
#include <stdio.h> #include <stdio.h>
...@@ -239,6 +238,10 @@ static void DumpPMT(void* p_zero, dvbpsi_pmt_t* p_pmt) ...@@ -239,6 +238,10 @@ static void DumpPMT(void* p_zero, dvbpsi_pmt_t* p_pmt)
dvbpsi_DeletePMT(p_pmt); dvbpsi_DeletePMT(p_pmt);
} }
static void message(dvbpsi_t *handle, const char* msg)
{
fprintf(stderr, "%s\n", msg);
}
/***************************************************************************** /*****************************************************************************
* main * main
...@@ -247,18 +250,27 @@ int main(int i_argc, char* pa_argv[]) ...@@ -247,18 +250,27 @@ 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; int b_ok;
uint16_t i_program_number, i_pmt_pid; uint16_t i_program_number, i_pmt_pid;
if(i_argc != 4) if (i_argc != 4)
return 1; return 1;
i_fd = open(pa_argv[1], 0); i_fd = open(pa_argv[1], 0);
if (i_fd < 0)
return 1;
i_program_number = atoi(pa_argv[2]); i_program_number = atoi(pa_argv[2]);
i_pmt_pid = atoi(pa_argv[3]); i_pmt_pid = atoi(pa_argv[3]);
h_dvbpsi = dvbpsi_AttachPMT(i_program_number, DumpPMT, NULL); p_dvbpsi = dvbpsi_NewHandle(&message, DVBPSI_MSG_DEBUG);
if (p_dvbpsi == NULL)
goto out;
dvbpsi_t *p_tmp = dvbpsi_AttachPMT(p_dvbpsi, i_program_number, DumpPMT, NULL);
if (p_tmp == NULL)
goto out;
b_ok = ReadPacket(i_fd, data); b_ok = ReadPacket(i_fd, data);
...@@ -266,11 +278,17 @@ int main(int i_argc, char* pa_argv[]) ...@@ -266,11 +278,17 @@ int main(int i_argc, char* pa_argv[])
{ {
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 == i_pmt_pid) if(i_pid == i_pmt_pid)
dvbpsi_PushPacket(h_dvbpsi, data); dvbpsi_PushPacket(p_dvbpsi, data);
b_ok = ReadPacket(i_fd, data); b_ok = ReadPacket(i_fd, data);
} }
dvbpsi_DetachPMT(h_dvbpsi); out:
if (p_dvbpsi)
{
dvbpsi_DetachPMT(p_dvbpsi);
dvbpsi_DeleteHandle(p_dvbpsi);
}
close(i_fd);
return 0; return 0;
} }
......
/***************************************************************************** /*****************************************************************************
* 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>
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
* *
*****************************************************************************/ *****************************************************************************/
#include "config.h" #include "config.h"
#include <stdio.h> #include <stdio.h>
...@@ -54,7 +53,6 @@ ...@@ -54,7 +53,6 @@
#include <dvbpsi/sdt.h> #include <dvbpsi/sdt.h>
#endif #endif
/***************************************************************************** /*****************************************************************************
* ReadPacket * ReadPacket
*****************************************************************************/ *****************************************************************************/
...@@ -123,15 +121,23 @@ static void DumpSDT(void* p_zero, dvbpsi_sdt_t* p_sdt) ...@@ -123,15 +121,23 @@ static void DumpSDT(void* p_zero, dvbpsi_sdt_t* p_sdt)
dvbpsi_DeleteSDT(p_sdt); dvbpsi_DeleteSDT(p_sdt);
} }
/*****************************************************************************
* DVBPSI messaging callback
*****************************************************************************/
static void message(dvbpsi_t *handle, const char* msg)
{
fprintf(stderr, "%s\n", msg);
}
/***************************************************************************** /*****************************************************************************
* NewSubtable * NewSubtable
*****************************************************************************/ *****************************************************************************/
static void NewSubtable(void * p_zero, dvbpsi_handle h_dvbpsi, static void NewSubtable(void * p_zero, dvbpsi_t *p_dvbpsi,
uint8_t i_table_id, uint16_t i_extension) uint8_t i_table_id, uint16_t i_extension)
{ {
if(i_table_id == 0x42) if(i_table_id == 0x42)
{ {
dvbpsi_AttachSDT(h_dvbpsi, i_table_id, i_extension, DumpSDT, NULL); dvbpsi_AttachSDT(p_dvbpsi, i_table_id, i_extension, DumpSDT, NULL);
} }
} }
...@@ -142,15 +148,23 @@ int main(int i_argc, char* pa_argv[]) ...@@ -142,15 +148,23 @@ 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; int 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;
p_dvbpsi = dvbpsi_NewHandle(&message, DVBPSI_MSG_DEBUG);
if (p_dvbpsi == NULL)
goto out;
h_dvbpsi = dvbpsi_AttachDemux(NewSubtable, NULL); dvbpsi_t *p_demux= dvbpsi_AttachDemux(p_dvbpsi, NewSubtable, NULL);
if (p_demux == NULL)
goto out;
b_ok = ReadPacket(i_fd, data); b_ok = ReadPacket(i_fd, data);
...@@ -158,12 +172,17 @@ int main(int i_argc, char* pa_argv[]) ...@@ -158,12 +172,17 @@ int main(int i_argc, char* pa_argv[])
{ {
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_PushPacket(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_DeleteHandle(p_dvbpsi);
}
close(i_fd);
return 0; return 0;
} }
/***************************************************************************** /*****************************************************************************
* get_pcr_pid.c: stdout the PID of the PCR of a given program * get_pcr_pid.c: stdout the PID of the PCR of a given program
***************************************************************************** *****************************************************************************
* Copyright (C) 2009-2010 VideoLAN * Copyright (C) 2009-2011 VideoLAN
* $Id: pcread.c 15 2006-06-15 22:17:58Z cmassiot $ * $Id: pcread.c 15 2006-06-15 22:17:58Z cmassiot $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
...@@ -63,11 +63,19 @@ ...@@ -63,11 +63,19 @@
static int i_fd = -1; static int i_fd = -1;
static int i_ts_read = 0; static int i_ts_read = 0;
static dvbpsi_handle p_pat_dvbpsi_fd; static dvbpsi_t *p_pat_dvbpsi_fd;
static int i_nb_programs = 0; static int i_nb_programs = 0;
static uint16_t i_program = 0; static uint16_t i_program = 0;
static uint16_t pi_pmt_pids[MAX_PROGRAMS]; static uint16_t pi_pmt_pids[MAX_PROGRAMS];
static dvbpsi_handle p_pmt_dvbpsi_fds[MAX_PROGRAMS]; static dvbpsi_t *p_pmt_dvbpsi_fds[MAX_PROGRAMS];
/*****************************************************************************
* DVBPSI messaging callback
*****************************************************************************/
static void message(dvbpsi_t *handle, const char* msg)
{
fprintf(stderr, "%s\n", msg);
}
/***************************************************************************** /*****************************************************************************
* PMTCallback * PMTCallback
...@@ -92,19 +100,31 @@ static void PATCallback( void *_unused, dvbpsi_pat_t *p_pat ) ...@@ -92,19 +100,31 @@ static void PATCallback( void *_unused, dvbpsi_pat_t *p_pat )
{ {
dvbpsi_pat_program_t *p_program; dvbpsi_pat_program_t *p_program;
if (i_nb_programs >= MAX_PROGRAMS)
{
fprintf(stderr, "Too many PMT programs\n");
dvbpsi_DeletePAT( p_pat );
return;
}
for( p_program = p_pat->p_first_program; p_program != NULL; for( p_program = p_pat->p_first_program; p_program != NULL;
p_program = p_program->p_next ) p_program = p_program->p_next )
{ {
if( p_program->i_number != 0 if( p_program->i_number != 0
&& (!i_program || i_program == p_program->i_number) ) && (!i_program || i_program == p_program->i_number) )
{ {
dvbpsi_t *p_dvbpsi;
pi_pmt_pids[i_nb_programs] = p_program->i_pid; pi_pmt_pids[i_nb_programs] = p_program->i_pid;
p_dvbpsi = dvbpsi_NewHandle(&message, DVBPSI_MSG_DEBUG);
if (p_dvbpsi)
{
p_pmt_dvbpsi_fds[i_nb_programs] = p_pmt_dvbpsi_fds[i_nb_programs] =
dvbpsi_AttachPMT( p_program->i_number, PMTCallback, dvbpsi_AttachPMT(p_dvbpsi, p_program->i_number, PMTCallback,
NULL ); NULL );
i_nb_programs++; i_nb_programs++;
} }
} }
}
dvbpsi_DeletePAT( p_pat ); dvbpsi_DeletePAT( p_pat );
} }
...@@ -151,7 +171,9 @@ static void TSHandle( uint8_t *p_ts ) ...@@ -151,7 +171,9 @@ static void TSHandle( uint8_t *p_ts )
*****************************************************************************/ *****************************************************************************/
int main( int i_argc, char **pp_argv ) int main( int i_argc, char **pp_argv )
{ {
dvbpsi_t *p_dvbpsi;
uint8_t *p_buffer; uint8_t *p_buffer;
int result = EXIT_FAILURE;
if ( i_argc < 2 || i_argc > 3 || !strcmp( pp_argv[1], "-" ) ) if ( i_argc < 2 || i_argc > 3 || !strcmp( pp_argv[1], "-" ) )
{ {
...@@ -169,9 +191,17 @@ int main( int i_argc, char **pp_argv ) ...@@ -169,9 +191,17 @@ int main( int i_argc, char **pp_argv )
if ( i_argc == 3 ) if ( i_argc == 3 )
i_program = strtol( pp_argv[2], NULL, 0 ); i_program = strtol( pp_argv[2], NULL, 0 );
p_pat_dvbpsi_fd = dvbpsi_AttachPAT( PATCallback, NULL ); p_dvbpsi = dvbpsi_NewHandle(&message, DVBPSI_MSG_DEBUG);
if (p_dvbpsi == NULL)
goto out;
p_pat_dvbpsi_fd = dvbpsi_AttachPAT(p_dvbpsi, PATCallback, NULL );
if (p_pat_dvbpsi_fd == NULL)
goto out;
p_buffer = malloc( TS_SIZE * READ_ONCE ); p_buffer = malloc( TS_SIZE * READ_ONCE );
if (p_buffer == NULL)
goto out;
for ( ; ; ) for ( ; ; )
{ {
...@@ -196,9 +226,22 @@ int main( int i_argc, char **pp_argv ) ...@@ -196,9 +226,22 @@ int main( int i_argc, char **pp_argv )
} }
} }
for( int i = 0; i < MAX_PROGRAMS; i++)
{
dvbpsi_DetachPMT(p_pmt_dvbpsi_fds[i]);
dvbpsi_DeleteHandle(p_pmt_dvbpsi_fds[i]);
p_pmt_dvbpsi_fds[i] = NULL;
}
result = EXIT_SUCCESS;
out:
if (p_dvbpsi == NULL)
{
dvbpsi_DetachPAT(p_dvbpsi);
dvbpsi_DeleteHandle(p_dvbpsi);
}
close( i_fd ); close( i_fd );
fprintf( stderr, "no PAT/PMT found\n" ); fprintf( stderr, "no PAT/PMT found\n" );
return EXIT_FAILURE; return result;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment