/***************************************************************************** * dvbpsi_GatherCATSections ***************************************************************************** * Callback for the PSI decoder. *****************************************************************************/ void dvbpsi_GatherCATSections(dvbpsi_decoder_t* p_decoder, dvbpsi_psi_section_t* p_section) { dvbpsi_cat_decoder_t* p_cat_decoder = (dvbpsi_cat_decoder_t*)p_decoder->p_private_decoder; int b_append = 1; int b_reinit = 0; unsigned int i; DVBPSI_DEBUG_ARG("CAT decoder", "Table version %2d, " "i_extension %5d, " "section %3d up to %3d, " "current %1d", p_section->i_version, p_section->i_extension, p_section->i_number, p_section->i_last_number, p_section->b_current_next); if(p_section->i_table_id != 0x01) { /* Invalid table_id value */ DVBPSI_ERROR_ARG("CAT decoder", "invalid section (table_id == 0x%02x)", p_section->i_table_id); b_append = 0; } if(b_append && !p_section->b_syntax_indicator) { /* Invalid section_syntax_indicator */ DVBPSI_ERROR("CAT decoder", "invalid section (section_syntax_indicator == 0)"); b_append = 0; } if(b_append) { /* TS discontinuity check */ if(p_decoder->b_discontinuity) { b_reinit = 1; p_decoder->b_discontinuity = 0; } else { /* Perform some few sanity checks */ if(p_cat_decoder->p_building_cat) { if(p_cat_decoder->p_building_cat->i_version != p_section->i_version) { /* version_number */ DVBPSI_ERROR("CAT decoder", "'version_number' differs" " whereas no discontinuity has occured"); b_reinit = 1; } else if(p_cat_decoder->i_last_section_number != p_section->i_last_number) { /* last_section_number */ DVBPSI_ERROR("CAT decoder", "'last_section_number' differs" " whereas no discontinuity has occured"); b_reinit = 1; } } else { if( (p_cat_decoder->b_current_valid) && (p_cat_decoder->current_cat.i_version == p_section->i_version) && (p_cat_decoder->current_cat.b_current_next == p_section->b_current_next)) { /* Don't decode since this version is already decoded */ b_append = 0; } } } } /* Reinit the decoder if wanted */ if(b_reinit) { /* Force redecoding */ p_cat_decoder->b_current_valid = 0; /* Free structures */ if(p_cat_decoder->p_building_cat) { free(p_cat_decoder->p_building_cat); p_cat_decoder->p_building_cat = NULL; } /* Clear the section array */ for(i = 0; i <= 255; i++) { if(p_cat_decoder->ap_sections[i] != NULL) { dvbpsi_DeletePSISections(p_cat_decoder->ap_sections[i]); p_cat_decoder->ap_sections[i] = NULL; } } } /* Append the section to the list if wanted */ if(b_append) { int b_complete; /* Initialize the structures if it's the first section received */ if(!p_cat_decoder->p_building_cat) { p_cat_decoder->p_building_cat = (dvbpsi_cat_t*)malloc(sizeof(dvbpsi_cat_t)); dvbpsi_InitCAT(p_cat_decoder->p_building_cat, p_section->i_version, p_section->b_current_next); p_cat_decoder->i_last_section_number = p_section->i_last_number; } /* Fill the section array */ if(p_cat_decoder->ap_sections[p_section->i_number] != NULL) { DVBPSI_DEBUG_ARG("CAT decoder", "overwrite section number %d", p_section->i_number); dvbpsi_DeletePSISections(p_cat_decoder->ap_sections[p_section->i_number]); } p_cat_decoder->ap_sections[p_section->i_number] = p_section; /* Check if we have all the sections */ b_complete = 0; for(i = 0; i <= p_cat_decoder->i_last_section_number; i++) { if(!p_cat_decoder->ap_sections[i]) break; if(i == p_cat_decoder->i_last_section_number) b_complete = 1; } if(b_complete) { /* Save the current information */ p_cat_decoder->current_cat = *p_cat_decoder->p_building_cat; p_cat_decoder->b_current_valid = 1; /* Chain the sections */ if(p_cat_decoder->i_last_section_number) { for(i = 0; (int)i <= p_cat_decoder->i_last_section_number - 1; i++) p_cat_decoder->ap_sections[i]->p_next = p_cat_decoder->ap_sections[i + 1]; } /* Decode the sections */ dvbpsi_DecodeCATSections(p_cat_decoder->p_building_cat, p_cat_decoder->ap_sections[0]); /* Delete the sections */ dvbpsi_DeletePSISections(p_cat_decoder->ap_sections[0]); /* signal the new CAT */ p_cat_decoder->pf_callback(p_cat_decoder->p_cb_data, p_cat_decoder->p_building_cat); /* Reinitialize the structures */ p_cat_decoder->p_building_cat = NULL; for(i = 0; i <= p_cat_decoder->i_last_section_number; i++) p_cat_decoder->ap_sections[i] = NULL; } } else { dvbpsi_DeletePSISections(p_section); } }
/***************************************************************************** * dvbpsi_GatherPMTSections ***************************************************************************** * Callback for the PSI decoder. *****************************************************************************/ void DMA_dvbpsi_GatherPMTSections(dvbpsi_decoder_t* p_decoder, dvbpsi_psi_section_t* p_section) { dvbpsi_pmt_decoder_t* p_pmt_decoder = (dvbpsi_pmt_decoder_t*)p_decoder->p_private_decoder; int b_append = 1; int b_reinit = 0; unsigned int i; #if 0 DVBPSI_DEBUG_ARG("PMT decoder", "Table version %2d, " "i_extension %5d, " "section %3d up to %3d, " "current %1d", p_section->i_version, p_section->i_extension, p_section->i_number, p_section->i_last_number, p_section->b_current_next); #endif if(p_section->i_table_id != 0x02) { /* Invalid table_id value */ #if 0 DVBPSI_ERROR_ARG("PMT decoder", "invalid section (table_id == 0x%02x)", p_section->i_table_id); #endif b_append = 0; } if(b_append && !p_section->b_syntax_indicator) { /* Invalid section_syntax_indicator */ #if 0 DMA_DVBPSI_ERROR("PMT decoder", "invalid section (section_syntax_indicator == 0)"); #endif b_append = 0; } /* Now if b_append is true then we have a valid PMT section */ if(b_append && (p_pmt_decoder->i_program_number != p_section->i_extension)) { /* Invalid program_number */ #if 0 DMA_DMA_DVBPSI_ERROR("PMT decoder", "'program_number' don't match"); #endif b_append = 0; } if(b_append) { /* TS discontinuity check */ if(p_decoder->b_discontinuity) { b_reinit = 1; p_decoder->b_discontinuity = 0; } else { /* Perform some few sanity checks */ if(p_pmt_decoder->p_building_pmt) { if(p_pmt_decoder->p_building_pmt->i_version != p_section->i_version) { /* version_number */ #if 0 DMA_DMA_DVBPSI_ERROR("PMT decoder", "'version_number' differs" " whereas no discontinuity has occured"); #endif b_reinit = 1; } else if(p_pmt_decoder->i_last_section_number != p_section->i_last_number) { /* last_section_number */ #if 0 DVBPSI_ERROR("PMT decoder", "'last_section_number' differs" " whereas no discontinuity has occured"); #endif b_reinit = 1; } } else { if( (p_pmt_decoder->b_current_valid) && (p_pmt_decoder->current_pmt.i_version == p_section->i_version)) { /* Signal a new PMT if the previous one wasn't active */ if( (!p_pmt_decoder->current_pmt.b_current_next) && (p_section->b_current_next)) { dvbpsi_pmt_t* p_pmt = (dvbpsi_pmt_t*)malloc(sizeof(dvbpsi_pmt_t)); p_pmt_decoder->current_pmt.b_current_next = 1; *p_pmt = p_pmt_decoder->current_pmt; p_pmt_decoder->pf_callback(p_pmt_decoder->p_cb_data, p_pmt); } /* Don't decode since this version is already decoded */ b_append = 0; } } } } /* Reinit the decoder if wanted */ if(b_reinit) { /* Force redecoding */ p_pmt_decoder->b_current_valid = 0; /* Free structures */ if(p_pmt_decoder->p_building_pmt) { free(p_pmt_decoder->p_building_pmt); p_pmt_decoder->p_building_pmt = NULL; } /* Clear the section array */ for(i = 0; i <= 255; i++) { if(p_pmt_decoder->ap_sections[i] != NULL) { DMA_dvbpsi_DeletePSISections(p_pmt_decoder->ap_sections[i]); p_pmt_decoder->ap_sections[i] = NULL; } } } /* Append the section to the list if wanted */ if(b_append) { int b_complete; /* Initialize the structures if it's the first section received */ if(!p_pmt_decoder->p_building_pmt) { p_pmt_decoder->p_building_pmt = (dvbpsi_pmt_t*)malloc(sizeof(dvbpsi_pmt_t)); DMA_dvbpsi_InitPMT(p_pmt_decoder->p_building_pmt, p_pmt_decoder->i_program_number, p_section->i_version, p_section->b_current_next, ((unsigned short)(p_section->p_payload_start[0] & 0x1f) << 8) | p_section->p_payload_start[1]); p_pmt_decoder->i_last_section_number = p_section->i_last_number; } /* Fill the section array */ if(p_pmt_decoder->ap_sections[p_section->i_number] != NULL) { #if 0 DMA_DVBPSI_DEBUG_ARG("PMT decoder", "overwrite section number %d", p_section->i_number); #endif DMA_dvbpsi_DeletePSISections(p_pmt_decoder->ap_sections[p_section->i_number]); } p_pmt_decoder->ap_sections[p_section->i_number] = p_section; /* Check if we have all the sections */ b_complete = 0; for(i = 0; i <= p_pmt_decoder->i_last_section_number; i++) { if(!p_pmt_decoder->ap_sections[i]) break; if(i == p_pmt_decoder->i_last_section_number) b_complete = 1; } if(b_complete) { /* Save the current information */ p_pmt_decoder->current_pmt = *p_pmt_decoder->p_building_pmt; p_pmt_decoder->b_current_valid = 1; /* Chain the sections */ if(p_pmt_decoder->i_last_section_number) { for(i = 0; i <= p_pmt_decoder->i_last_section_number - 1; i++) p_pmt_decoder->ap_sections[i]->p_next = p_pmt_decoder->ap_sections[i + 1]; } /* Decode the sections */ DMA_dvbpsi_DecodePMTSections(p_pmt_decoder->p_building_pmt, p_pmt_decoder->ap_sections[0]); /* Delete the sections */ DMA_dvbpsi_DeletePSISections(p_pmt_decoder->ap_sections[0]); /* signal the new PMT */ p_pmt_decoder->pf_callback(p_pmt_decoder->p_cb_data, p_pmt_decoder->p_building_pmt); /* Reinitialize the structures */ p_pmt_decoder->p_building_pmt = NULL; for(i = 0; i <= p_pmt_decoder->i_last_section_number; i++) p_pmt_decoder->ap_sections[i] = NULL; } } else { DMA_dvbpsi_DeletePSISections(p_section); } }