Commit 056e14dd authored by Daniel Kamil Kozar's avatar Daniel Kamil Kozar Committed by Jean-Paul Saman

Check for NULLs returned from decode functions in dvbinfo

dvbinfo now checks whether the libdvbpsi decode functions could properly decode
a descriptor before actually passing it to the dump function.
Signed-off-by: default avatarJean-Paul Saman <jpsaman@videolan.org>
parent 6fb74f62
...@@ -946,16 +946,18 @@ static char const* GetDescriptorName(uint8_t tag) ...@@ -946,16 +946,18 @@ static char const* GetDescriptorName(uint8_t tag)
/***************************************************************************** /*****************************************************************************
* DumpMaxBitrateDescriptor * DumpMaxBitrateDescriptor
*****************************************************************************/ *****************************************************************************/
static void DumpMaxBitrateDescriptor(dvbpsi_max_bitrate_dr_t* bitrate_descriptor) static void DumpMaxBitrateDescriptor(const void *p_descriptor)
{ {
const dvbpsi_max_bitrate_dr_t* bitrate_descriptor = p_descriptor;
printf("Bitrate: %d\n", bitrate_descriptor->i_max_bitrate); printf("Bitrate: %d\n", bitrate_descriptor->i_max_bitrate);
} }
/***************************************************************************** /*****************************************************************************
* DumpSmoothingBufferDescriptor * DumpSmoothingBufferDescriptor
*****************************************************************************/ *****************************************************************************/
static void DumpSmoothingBufferDescriptor(dvbpsi_smoothing_buffer_dr_t *smoothing_descriptor) static void DumpSmoothingBufferDescriptor(const void *p_descriptor)
{ {
const dvbpsi_smoothing_buffer_dr_t *smoothing_descriptor = p_descriptor;
printf("Leak rate: %d \n", smoothing_descriptor->i_sb_leak_rate); printf("Leak rate: %d \n", smoothing_descriptor->i_sb_leak_rate);
printf("Size: %d \n", smoothing_descriptor->i_sb_size); printf("Size: %d \n", smoothing_descriptor->i_sb_size);
} }
...@@ -963,16 +965,18 @@ static void DumpSmoothingBufferDescriptor(dvbpsi_smoothing_buffer_dr_t *smoothin ...@@ -963,16 +965,18 @@ static void DumpSmoothingBufferDescriptor(dvbpsi_smoothing_buffer_dr_t *smoothin
/***************************************************************************** /*****************************************************************************
* DumpSTDDescriptor * DumpSTDDescriptor
*****************************************************************************/ *****************************************************************************/
static void DumpSTDDescriptor(dvbpsi_std_dr_t* std_descriptor) static void DumpSTDDescriptor(const void *p_descriptor)
{ {
const dvbpsi_std_dr_t* std_descriptor = p_descriptor;
printf("Leak valid flag: %d\n", std_descriptor->b_leak_valid_flag); printf("Leak valid flag: %d\n", std_descriptor->b_leak_valid_flag);
} }
/***************************************************************************** /*****************************************************************************
* DumpIBPDescriptor * DumpIBPDescriptor
*****************************************************************************/ *****************************************************************************/
static void DumpIBPDescriptor(dvbpsi_ibp_dr_t *ibp_descriptor) static void DumpIBPDescriptor(const void *p_descriptor)
{ {
const dvbpsi_ibp_dr_t *ibp_descriptor = p_descriptor;
printf("Closed GOP flag: %d \n", ibp_descriptor->b_closed_gop_flag); printf("Closed GOP flag: %d \n", ibp_descriptor->b_closed_gop_flag);
printf("Identical GOP flag: %d \n", ibp_descriptor->b_identical_gop_flag); printf("Identical GOP flag: %d \n", ibp_descriptor->b_identical_gop_flag);
printf("Max GOP length: %" PRIu16 " \n", ibp_descriptor->i_max_gop_length); printf("Max GOP length: %" PRIu16 " \n", ibp_descriptor->i_max_gop_length);
...@@ -981,8 +985,9 @@ static void DumpIBPDescriptor(dvbpsi_ibp_dr_t *ibp_descriptor) ...@@ -981,8 +985,9 @@ static void DumpIBPDescriptor(dvbpsi_ibp_dr_t *ibp_descriptor)
/***************************************************************************** /*****************************************************************************
* DumpSystemClockDescriptor * DumpSystemClockDescriptor
*****************************************************************************/ *****************************************************************************/
static void DumpSystemClockDescriptor(dvbpsi_system_clock_dr_t* p_clock_descriptor) static void DumpSystemClockDescriptor(const void *p_descriptor)
{ {
const dvbpsi_system_clock_dr_t* p_clock_descriptor = p_descriptor;
printf("External clock: %s, Accuracy: %E\n", printf("External clock: %s, Accuracy: %E\n",
p_clock_descriptor->b_external_clock_ref ? "Yes" : "No", p_clock_descriptor->b_external_clock_ref ? "Yes" : "No",
p_clock_descriptor->i_clock_accuracy_integer * p_clock_descriptor->i_clock_accuracy_integer *
...@@ -992,16 +997,18 @@ static void DumpSystemClockDescriptor(dvbpsi_system_clock_dr_t* p_clock_descript ...@@ -992,16 +997,18 @@ static void DumpSystemClockDescriptor(dvbpsi_system_clock_dr_t* p_clock_descript
/***************************************************************************** /*****************************************************************************
* DumpStreamIdentifierDescriptor * DumpStreamIdentifierDescriptor
*****************************************************************************/ *****************************************************************************/
static void DumpStreamIdentifierDescriptor(dvbpsi_stream_identifier_dr_t* p_si_descriptor) static void DumpStreamIdentifierDescriptor(const void *p_descriptor)
{ {
const dvbpsi_stream_identifier_dr_t* p_si_descriptor = p_descriptor;
printf("Component tag: %d\n", p_si_descriptor->i_component_tag); printf("Component tag: %d\n", p_si_descriptor->i_component_tag);
} }
/***************************************************************************** /*****************************************************************************
* DumpCAIdentifierDescriptor * DumpCAIdentifierDescriptor
*****************************************************************************/ *****************************************************************************/
static void DumpCAIdentifierDescriptor(dvbpsi_ca_identifier_dr_t *p_ca_descriptor) static void DumpCAIdentifierDescriptor(const void *p_descriptor)
{ {
const dvbpsi_ca_identifier_dr_t *p_ca_descriptor = p_descriptor;
printf("CA system id\n"); printf("CA system id\n");
for(int i = 0; i < p_ca_descriptor->i_number; i++ ) for(int i = 0; i < p_ca_descriptor->i_number; i++ )
printf("\t%d: %d\n", i, p_ca_descriptor->p_system[i].i_ca_system_id); printf("\t%d: %d\n", i, p_ca_descriptor->p_system[i].i_ca_system_id);
...@@ -1134,8 +1141,9 @@ static const char *GetContentSubCategory( const int i_type ) ...@@ -1134,8 +1141,9 @@ static const char *GetContentSubCategory( const int i_type )
return "Unknown"; return "Unknown";
} }
static void DumpContentDescriptor(dvbpsi_content_dr_t *p_content_descriptor) static void DumpContentDescriptor(const void *p_descriptor)
{ {
const dvbpsi_content_dr_t *p_content_descriptor = p_descriptor;
dr_content_category_t content_category[] = { dr_content_category_t content_category[] = {
{ DVBPSI_CONTENT_CAT_UNDEFINED, "Undefined" }, { DVBPSI_CONTENT_CAT_UNDEFINED, "Undefined" },
{ DVBPSI_CONTENT_CAT_MOVIE, "Movie" }, { DVBPSI_CONTENT_CAT_MOVIE, "Movie" },
...@@ -1171,9 +1179,10 @@ static void DumpContentDescriptor(dvbpsi_content_dr_t *p_content_descriptor) ...@@ -1171,9 +1179,10 @@ static void DumpContentDescriptor(dvbpsi_content_dr_t *p_content_descriptor)
/***************************************************************************** /*****************************************************************************
* DumpSubtitleDescriptor * DumpSubtitleDescriptor
*****************************************************************************/ *****************************************************************************/
static void DumpSubtitleDescriptor(dvbpsi_subtitling_dr_t* p_subtitle_descriptor) static void DumpSubtitleDescriptor(const void *p_descriptor)
{ {
int a; int a;
const dvbpsi_subtitling_dr_t* p_subtitle_descriptor = p_descriptor;
printf("%d subtitles,\n", p_subtitle_descriptor->i_subtitles_number); printf("%d subtitles,\n", p_subtitle_descriptor->i_subtitles_number);
for (a = 0; a < p_subtitle_descriptor->i_subtitles_number; ++a) for (a = 0; a < p_subtitle_descriptor->i_subtitles_number; ++a)
...@@ -1191,8 +1200,9 @@ static void DumpSubtitleDescriptor(dvbpsi_subtitling_dr_t* p_subtitle_descriptor ...@@ -1191,8 +1200,9 @@ static void DumpSubtitleDescriptor(dvbpsi_subtitling_dr_t* p_subtitle_descriptor
/***************************************************************************** /*****************************************************************************
* DumpAACDescriptor * DumpAACDescriptor
*****************************************************************************/ *****************************************************************************/
static void DumpAACDescriptor(dvbpsi_aac_dr_t *p_aac_descriptor) static void DumpAACDescriptor(const void *p_descriptor)
{ {
const dvbpsi_aac_dr_t *p_aac_descriptor = p_descriptor;
printf("AAC audio descriptor\n"); printf("AAC audio descriptor\n");
printf("\tprofile and level: "); printf("\tprofile and level: ");
switch(p_aac_descriptor->i_profile_and_level) switch(p_aac_descriptor->i_profile_and_level)
...@@ -1328,8 +1338,9 @@ static void DumpAACDescriptor(dvbpsi_aac_dr_t *p_aac_descriptor) ...@@ -1328,8 +1338,9 @@ static void DumpAACDescriptor(dvbpsi_aac_dr_t *p_aac_descriptor)
/***************************************************************************** /*****************************************************************************
* DumpTimeShiftedServiceDescriptor * DumpTimeShiftedServiceDescriptor
*****************************************************************************/ *****************************************************************************/
static void DumpTimeShiftedServiceDescriptor(dvbpsi_tshifted_service_dr_t *p_ts_service) static void DumpTimeShiftedServiceDescriptor(const void *p_descriptor)
{ {
const dvbpsi_tshifted_service_dr_t *p_ts_service = p_descriptor;
printf("Time Shifted Service\n"); printf("Time Shifted Service\n");
printf("\treference service id:%d", p_ts_service->i_ref_service_id); printf("\treference service id:%d", p_ts_service->i_ref_service_id);
} }
...@@ -1337,8 +1348,9 @@ static void DumpTimeShiftedServiceDescriptor(dvbpsi_tshifted_service_dr_t *p_ts_ ...@@ -1337,8 +1348,9 @@ static void DumpTimeShiftedServiceDescriptor(dvbpsi_tshifted_service_dr_t *p_ts_
/***************************************************************************** /*****************************************************************************
* DumpTimeShiftedEventDescriptor * DumpTimeShiftedEventDescriptor
*****************************************************************************/ *****************************************************************************/
static void DumpTimeShiftedEventDescriptor(dvbpsi_tshifted_ev_dr_t *p_ts_event) static void DumpTimeShiftedEventDescriptor(const void *p_descriptor)
{ {
const dvbpsi_tshifted_ev_dr_t *p_ts_event = p_descriptor;
printf("Time Shifted Event"); printf("Time Shifted Event");
printf("\treference service id:%d", p_ts_event->i_ref_service_id); printf("\treference service id:%d", p_ts_event->i_ref_service_id);
printf("\treference event id:%d", p_ts_event->i_ref_event_id); printf("\treference event id:%d", p_ts_event->i_ref_event_id);
...@@ -1348,9 +1360,10 @@ static void DumpTimeShiftedEventDescriptor(dvbpsi_tshifted_ev_dr_t *p_ts_event) ...@@ -1348,9 +1360,10 @@ static void DumpTimeShiftedEventDescriptor(dvbpsi_tshifted_ev_dr_t *p_ts_event)
* DumpCUEIdentifierDescriptor * DumpCUEIdentifierDescriptor
*****************************************************************************/ *****************************************************************************/
#ifdef TS_USE_DVB_CUEI #ifdef TS_USE_DVB_CUEI
static void DumpCUEIDescriptor(dvbpsi_cuei_dr_t* p_cuei_descriptor) static void DumpCUEIDescriptor(const void *p_descriptor)
{ {
const char *cuei_stream_type; const char *cuei_stream_type;
const dvbpsi_cuei_dr_t* p_cuei_descriptor = p_descriptor;
assert(p_cuei_descriptor); assert(p_cuei_descriptor);
...@@ -1490,13 +1503,13 @@ static void handle_SIS(void* p_data, dvbpsi_sis_t* p_sis) ...@@ -1490,13 +1503,13 @@ static void handle_SIS(void* p_data, dvbpsi_sis_t* p_sis)
#endif #endif
/***************************************************************************** /*****************************************************************************
* DumpDescriptors * DumpDescriptor
*****************************************************************************/ *****************************************************************************/
static void DumpDescriptors(const char* str, dvbpsi_descriptor_t* p_descriptor) static void DumpDescriptor(dvbpsi_descriptor_t *p_descriptor)
{ {
while (p_descriptor) const void *p_decoded = NULL;
{ void (*dump_dr_fn)(const void*) = NULL;
printf("%s 0x%02x : ", str, p_descriptor->i_tag);
switch (p_descriptor->i_tag) switch (p_descriptor->i_tag)
{ {
case 0x06: /* data_stream_alignment_descriptor */ case 0x06: /* data_stream_alignment_descriptor */
...@@ -1517,58 +1530,90 @@ static void DumpDescriptors(const char* str, dvbpsi_descriptor_t* p_descriptor) ...@@ -1517,58 +1530,90 @@ static void DumpDescriptors(const char* str, dvbpsi_descriptor_t* p_descriptor)
} }
} }
printf("\" (%s)\n", GetDescriptorName(p_descriptor->i_tag)); printf("\" (%s)\n", GetDescriptorName(p_descriptor->i_tag));
break; return;
case 0x6a: case 0x6a:
printf("\"a52\" (%s)\n", GetDescriptorName(p_descriptor->i_tag)); printf("\"a52\" (%s)\n", GetDescriptorName(p_descriptor->i_tag));
break; return;
case 0x7c: case 0x7c:
DumpAACDescriptor(dvbpsi_DecodeAACDr(p_descriptor)); p_decoded = dvbpsi_DecodeAACDr(p_descriptor);
dump_dr_fn = DumpAACDescriptor;
break; break;
case 0x08: case 0x08:
DumpSystemClockDescriptor(dvbpsi_DecodeSystemClockDr(p_descriptor)); p_decoded = dvbpsi_DecodeSystemClockDr(p_descriptor);
dump_dr_fn = DumpSystemClockDescriptor;
break; break;
#ifdef TS_USE_DVB_CUEI #ifdef TS_USE_DVB_CUEI
case 0x8a: case 0x8a:
DumpCUEIDescriptor(dvbpsi_DecodeCUEIDr(p_descriptor)); p_decoded = dvbpsi_DecodeCUEIDr(p_descriptor);
dump_dr_fn = DumpCUEIDescriptor;
break; break;
#endif #endif
case 0x0e: case 0x0e:
DumpMaxBitrateDescriptor(dvbpsi_DecodeMaxBitrateDr(p_descriptor)); p_decoded = dvbpsi_DecodeMaxBitrateDr(p_descriptor);
dump_dr_fn = DumpMaxBitrateDescriptor;
break; break;
case 0x10: case 0x10:
DumpSmoothingBufferDescriptor(dvbpsi_DecodeSmoothingBufferDr(p_descriptor)); p_decoded = dvbpsi_DecodeSmoothingBufferDr(p_descriptor);
dump_dr_fn = DumpSmoothingBufferDescriptor;
break; break;
case 0x11: case 0x11:
DumpSTDDescriptor(dvbpsi_DecodeSTDDr(p_descriptor)); p_decoded = dvbpsi_DecodeSTDDr(p_descriptor);
dump_dr_fn = DumpSTDDescriptor;
break; break;
case 0x12: case 0x12:
DumpIBPDescriptor(dvbpsi_DecodeIBPDr(p_descriptor)); p_decoded = dvbpsi_DecodeIBPDr(p_descriptor);
dump_dr_fn = DumpIBPDescriptor;
break; break;
case 0x4c: case 0x4c:
DumpTimeShiftedServiceDescriptor(dvbpsi_DecodeTimeShiftedServiceDr(p_descriptor)); p_decoded = dvbpsi_DecodeTimeShiftedServiceDr(p_descriptor);
dump_dr_fn = DumpTimeShiftedServiceDescriptor;
break; break;
case 0x4f: case 0x4f:
DumpTimeShiftedEventDescriptor(dvbpsi_DecodeTimeShiftedEventDr(p_descriptor)); p_decoded = dvbpsi_DecodeTimeShiftedEventDr(p_descriptor);
dump_dr_fn = DumpTimeShiftedEventDescriptor;
break; break;
case 0x52: case 0x52:
DumpStreamIdentifierDescriptor(dvbpsi_DecodeStreamIdentifierDr(p_descriptor)); p_decoded = dvbpsi_DecodeStreamIdentifierDr(p_descriptor);
dump_dr_fn = DumpStreamIdentifierDescriptor;
break; break;
case 0x53: case 0x53:
DumpCAIdentifierDescriptor(dvbpsi_DecodeCAIdentifierDr(p_descriptor)); p_decoded = dvbpsi_DecodeCAIdentifierDr(p_descriptor);
dump_dr_fn = DumpCAIdentifierDescriptor;
break; break;
case 0x54: case 0x54:
DumpContentDescriptor(dvbpsi_DecodeContentDr(p_descriptor)); p_decoded = dvbpsi_DecodeContentDr(p_descriptor);
dump_dr_fn = DumpContentDescriptor;
break; break;
case 0x59: case 0x59:
DumpSubtitleDescriptor(dvbpsi_DecodeSubtitlingDr(p_descriptor)); p_decoded = dvbpsi_DecodeSubtitlingDr(p_descriptor);
dump_dr_fn = DumpSubtitleDescriptor;
break; break;
default: }
if(dump_dr_fn && p_decoded)
{
/* call the dump function if we could decode the descriptor. */
dump_dr_fn(p_decoded);
}
else
{
/* otherwise just dump the raw data. */
printf("\""); printf("\"");
for (int i = 0; i < p_descriptor->i_length; i++) for (int i = 0; i < p_descriptor->i_length; i++)
printf("%c", p_descriptor->p_data[i]); printf("%c", p_descriptor->p_data[i]);
printf("\" (%s)\n", GetDescriptorName(p_descriptor->i_tag)); printf("\" (%s)\n", GetDescriptorName(p_descriptor->i_tag));
break;
} }
}
/*****************************************************************************
* DumpDescriptors
*****************************************************************************/
static void DumpDescriptors(const char* str, dvbpsi_descriptor_t* p_descriptor)
{
while (p_descriptor)
{
printf("%s 0x%02x : ", str, p_descriptor->i_tag);
DumpDescriptor(p_descriptor);
p_descriptor = p_descriptor->p_next; p_descriptor = p_descriptor->p_next;
} }
} }
......
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