| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: ts_packet.c $ |
|---|
| 11 | * $brcm_Revision: 1 $ |
|---|
| 12 | * $brcm_Date: 2/7/05 11:29p $ |
|---|
| 13 | * |
|---|
| 14 | * [File Description:] |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /BSEAV/lib/mpeg2_ts_parse/ts_packet.c $ |
|---|
| 19 | * |
|---|
| 20 | * 1 2/7/05 11:29p dlwin |
|---|
| 21 | * Merge down for release 2005_REFSW_MERGETOMAIN: |
|---|
| 22 | * |
|---|
| 23 | * Irvine_BSEAVSW_Devel/2 2/4/04 9:56a erickson |
|---|
| 24 | * PR9217: converted BDBG_ASSERT calls to CHECK calls. Don't assert on bad |
|---|
| 25 | * data. |
|---|
| 26 | * |
|---|
| 27 | * Irvine_BSEAVSW_Devel/1 8/29/03 5:05p marcusk |
|---|
| 28 | * Initial Version. |
|---|
| 29 | * |
|---|
| 30 | ***************************************************************************/ |
|---|
| 31 | #include "bstd.h" |
|---|
| 32 | #include "ts_packet.h" |
|---|
| 33 | #include "psip_priv.h" |
|---|
| 34 | BDBG_MODULE(ts_packet); |
|---|
| 35 | |
|---|
| 36 | void TS_parseTsPacket( const uint8_t *buf, TS_packet *p_packet ) |
|---|
| 37 | { |
|---|
| 38 | CHECK( buf[0] == 0x47 ); |
|---|
| 39 | p_packet->transport_error_indicator = (buf[1]>>7)&1; |
|---|
| 40 | p_packet->payload_unit_start_indicator = (buf[1]>>6)&1; |
|---|
| 41 | p_packet->transport_priority = (buf[1]>>5)&1; |
|---|
| 42 | p_packet->PID = (uint16_t)(TS_READ_16(&buf[1]) & 0x1FFF); |
|---|
| 43 | p_packet->transport_scambling_control = (uint8_t)((buf[3]>>6)&3); |
|---|
| 44 | p_packet->adaptation_field_control = (uint8_t)((buf[3]>>4)&3); |
|---|
| 45 | p_packet->continuity_counter = (uint8_t)(buf[3]&0xF); |
|---|
| 46 | |
|---|
| 47 | if( p_packet->adaptation_field_control & 0x2 ) |
|---|
| 48 | { |
|---|
| 49 | int byteOffset = 6; |
|---|
| 50 | |
|---|
| 51 | p_packet->adaptation_field.discontinuity_indicator = (buf[5]>>7)&1; |
|---|
| 52 | p_packet->adaptation_field.random_access_indicator = (buf[5]>>6)&1; |
|---|
| 53 | p_packet->adaptation_field.elementary_stream_priority_indicator = (buf[5]>>5)&1; |
|---|
| 54 | p_packet->adaptation_field.PCR_flag = (buf[5]>>4)&1; |
|---|
| 55 | p_packet->adaptation_field.OPCR_flag = (buf[5]>>3)&1; |
|---|
| 56 | p_packet->adaptation_field.splicing_point_flag = (buf[5]>>2)&1; |
|---|
| 57 | p_packet->adaptation_field.transport_private_data_flag = (buf[5]>>1)&1; |
|---|
| 58 | p_packet->adaptation_field.adaptation_field_extension_flag = buf[5]&1; |
|---|
| 59 | |
|---|
| 60 | if( p_packet->adaptation_field.PCR_flag ) |
|---|
| 61 | { |
|---|
| 62 | p_packet->adaptation_field.program_clock_reference_base = TS_READ_64( &buf[byteOffset] )>>31; |
|---|
| 63 | p_packet->adaptation_field.program_clock_reference_extension = (uint16_t)(TS_READ_16( &buf[byteOffset+4] ) & 0x1FF); |
|---|
| 64 | byteOffset += 6; |
|---|
| 65 | } |
|---|
| 66 | if( p_packet->adaptation_field.OPCR_flag ) |
|---|
| 67 | { |
|---|
| 68 | p_packet->adaptation_field.original_program_clock_reference_base = TS_READ_64( &buf[byteOffset] )>>31; |
|---|
| 69 | p_packet->adaptation_field.original_program_clock_reference_extension = (uint16_t)(TS_READ_16( &buf[byteOffset+4] ) & 0x1FF); |
|---|
| 70 | byteOffset += 6; |
|---|
| 71 | } |
|---|
| 72 | if( p_packet->adaptation_field.splicing_point_flag ) |
|---|
| 73 | { |
|---|
| 74 | p_packet->adaptation_field.splice_countdown = buf[byteOffset]; |
|---|
| 75 | byteOffset += 1; |
|---|
| 76 | } |
|---|
| 77 | if( p_packet->adaptation_field.transport_private_data_flag ) |
|---|
| 78 | { |
|---|
| 79 | p_packet->adaptation_field.transport_private_data_length = buf[byteOffset]; |
|---|
| 80 | p_packet->adaptation_field.p_private_data_byte = &buf[byteOffset+1]; |
|---|
| 81 | byteOffset += 1 + p_packet->adaptation_field.transport_private_data_length; |
|---|
| 82 | } |
|---|
| 83 | if( p_packet->adaptation_field.adaptation_field_extension_flag ) |
|---|
| 84 | { |
|---|
| 85 | byteOffset += 1; |
|---|
| 86 | p_packet->adaptation_field.ltw_flag = (buf[byteOffset]>>7)&1; |
|---|
| 87 | p_packet->adaptation_field.piecewise_rate_flag = (buf[byteOffset]>>6)&1; |
|---|
| 88 | p_packet->adaptation_field.seamless_splice_flag = (buf[byteOffset]>>5)&1; |
|---|
| 89 | |
|---|
| 90 | byteOffset += 1; |
|---|
| 91 | if( p_packet->adaptation_field.ltw_flag ) |
|---|
| 92 | { |
|---|
| 93 | p_packet->adaptation_field.ltw_valid_flag = (buf[byteOffset]>>7)&1; |
|---|
| 94 | p_packet->adaptation_field.ltw_offset = (uint16_t)(TS_READ_16( &buf[byteOffset+1] ) & 0x7FFF); |
|---|
| 95 | byteOffset += 2; |
|---|
| 96 | } |
|---|
| 97 | if( p_packet->adaptation_field.piecewise_rate_flag ) |
|---|
| 98 | { |
|---|
| 99 | p_packet->adaptation_field.piecewise_rate = (TS_READ_32( &buf[byteOffset] )>>8) & 0x3FFFFF; |
|---|
| 100 | byteOffset += 3; |
|---|
| 101 | } |
|---|
| 102 | if( p_packet->adaptation_field.seamless_splice_flag ) |
|---|
| 103 | { |
|---|
| 104 | p_packet->adaptation_field.splice_type = (uint8_t)((buf[byteOffset]>>4)&0xF); |
|---|
| 105 | // p_packet->adaptation_field.DTS_next_AU = ; |
|---|
| 106 | byteOffset += 5; |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | if(p_packet->adaptation_field_control & 0x3) |
|---|
| 112 | { |
|---|
| 113 | if( p_packet->adaptation_field_control & 0x2 ) |
|---|
| 114 | { |
|---|
| 115 | p_packet->p_data_byte = &buf[5+buf[4]]; |
|---|
| 116 | p_packet->data_size = (uint8_t)(188-(5+buf[4])); |
|---|
| 117 | } |
|---|
| 118 | else |
|---|
| 119 | { |
|---|
| 120 | p_packet->p_data_byte = &buf[4]; |
|---|
| 121 | p_packet->data_size = 188-4; |
|---|
| 122 | } |
|---|
| 123 | } |
|---|
| 124 | else |
|---|
| 125 | { |
|---|
| 126 | p_packet->p_data_byte = NULL; |
|---|
| 127 | p_packet->data_size = 0; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | |
|---|