| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2011, 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: budp_jp3dparse.c $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/3 $ |
|---|
| 12 | * $brcm_Date: 1/18/11 1:28p $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: /magnum/commonutils/udp/budp_jp3dparse.c $ |
|---|
| 19 | * |
|---|
| 20 | * Hydra_Software_Devel/3 1/18/11 1:28p darnstein |
|---|
| 21 | * SW7405-4817: add new Stereo_Video_Format_Type values, per N11462. |
|---|
| 22 | * |
|---|
| 23 | * Hydra_Software_Devel/2 10/28/10 3:59p darnstein |
|---|
| 24 | * SW3548-2364: trivial implementation of _isr functions for parsing. |
|---|
| 25 | * |
|---|
| 26 | * Hydra_Software_Devel/1 10/7/10 10:27a darnstein |
|---|
| 27 | * SW7405-4817: Parser for the Dpa 3D signaling message used in Japan. |
|---|
| 28 | * |
|---|
| 29 | ***************************************************************************/ |
|---|
| 30 | |
|---|
| 31 | /* For debugging */ |
|---|
| 32 | /* #define BUDP_P_GETUD_DUMP 1 */ |
|---|
| 33 | #ifdef BUDP_P_GETUD_DUMP |
|---|
| 34 | static const char* BUDP_P_Getud_Filename = "userdata.getud"; |
|---|
| 35 | #include <stdio.h> |
|---|
| 36 | #endif |
|---|
| 37 | |
|---|
| 38 | #include "bstd.h" |
|---|
| 39 | #include "bavc.h" |
|---|
| 40 | #include "bdbg.h" |
|---|
| 41 | #include "budp.h" |
|---|
| 42 | #include "budp_jp3dparse.h" |
|---|
| 43 | |
|---|
| 44 | BDBG_MODULE(BUDP); |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | /*************************************************************************** |
|---|
| 48 | * Forward declarations of static (private) functions |
|---|
| 49 | ***************************************************************************/ |
|---|
| 50 | |
|---|
| 51 | static size_t FindJp3dStart ( |
|---|
| 52 | const uint8_t* userdata, size_t length); |
|---|
| 53 | |
|---|
| 54 | #ifdef BUDP_P_GETUD_DUMP |
|---|
| 55 | static void dump_getud ( |
|---|
| 56 | const BAVC_USERDATA_info* pUserdata_info, size_t offset); |
|---|
| 57 | #endif |
|---|
| 58 | |
|---|
| 59 | /*************************************************************************** |
|---|
| 60 | * Static data (tables, etc.) |
|---|
| 61 | ***************************************************************************/ |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | /*************************************************************************** |
|---|
| 65 | * Implementation of "BUDP_JP3Dparse_" API functions |
|---|
| 66 | ***************************************************************************/ |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | /*************************************************************************** |
|---|
| 70 | * |
|---|
| 71 | */ |
|---|
| 72 | BERR_Code BUDP_JP3Dstart_isr ( |
|---|
| 73 | const BAVC_USERDATA_info* pUserdata_info, |
|---|
| 74 | size_t offset, |
|---|
| 75 | size_t* pBytesParsed |
|---|
| 76 | ) |
|---|
| 77 | { |
|---|
| 78 | size_t bytesParsedSub; |
|---|
| 79 | size_t length; |
|---|
| 80 | uint8_t* userdata; |
|---|
| 81 | |
|---|
| 82 | BDBG_ENTER(BUDP_JP3Dstart_isr); |
|---|
| 83 | |
|---|
| 84 | /* Check for obvious errors from user */ |
|---|
| 85 | if ((pUserdata_info == 0x0) || |
|---|
| 86 | (pBytesParsed == 0x0) ) |
|---|
| 87 | { |
|---|
| 88 | return BERR_INVALID_PARAMETER; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | /* Programming note: all function parameters are now validated */ |
|---|
| 92 | |
|---|
| 93 | #ifdef BUDP_P_GETUD_DUMP |
|---|
| 94 | dump_getud (pUserdata_info, offset); |
|---|
| 95 | #endif |
|---|
| 96 | |
|---|
| 97 | /* Take care of a special case */ |
|---|
| 98 | userdata = (uint8_t*)(pUserdata_info->pUserDataBuffer) + offset; |
|---|
| 99 | length = pUserdata_info->ui32UserDataBufSize - offset; |
|---|
| 100 | if (length < 8) |
|---|
| 101 | { |
|---|
| 102 | *pBytesParsed = length; |
|---|
| 103 | return BERR_BUDP_NO_DATA; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | /* jump past the first SEI userdata start code */ |
|---|
| 107 | bytesParsedSub = FindJp3dStart (userdata, length); |
|---|
| 108 | *pBytesParsed = bytesParsedSub; |
|---|
| 109 | length -= bytesParsedSub; |
|---|
| 110 | /* userdata += bytesParsedSub; */ |
|---|
| 111 | |
|---|
| 112 | /* If we did not find a start code, bail out now */ |
|---|
| 113 | if (length == 0) |
|---|
| 114 | { |
|---|
| 115 | return BERR_BUDP_NO_DATA; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | BDBG_LEAVE(BUDP_JP3Dstart_isr); |
|---|
| 119 | return BERR_SUCCESS; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | BERR_Code BUDP_JP3Dparse_isr ( |
|---|
| 124 | const BAVC_USERDATA_info* pUserdata_info, |
|---|
| 125 | size_t offset, |
|---|
| 126 | size_t* pBytesParsed, |
|---|
| 127 | uint16_t* sigtype |
|---|
| 128 | ) |
|---|
| 129 | { |
|---|
| 130 | size_t length; |
|---|
| 131 | uint8_t* userdata; |
|---|
| 132 | uint8_t val8; |
|---|
| 133 | uint16_t val16; |
|---|
| 134 | |
|---|
| 135 | BDBG_ENTER(BUDP_JP3Dparse_isr); |
|---|
| 136 | |
|---|
| 137 | /* Check for obvious errors from user */ |
|---|
| 138 | if ((pUserdata_info == 0x0) || |
|---|
| 139 | (pBytesParsed == 0x0) || |
|---|
| 140 | (sigtype == 0x0) ) |
|---|
| 141 | { |
|---|
| 142 | return BERR_INVALID_PARAMETER; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | /* Programming note: all function parameters are now validated */ |
|---|
| 146 | |
|---|
| 147 | /* Take care of a special case */ |
|---|
| 148 | userdata = (uint8_t*)(pUserdata_info->pUserDataBuffer) + offset; |
|---|
| 149 | length = pUserdata_info->ui32UserDataBufSize - offset; |
|---|
| 150 | if (length < 4) |
|---|
| 151 | { |
|---|
| 152 | *pBytesParsed = length; |
|---|
| 153 | return BERR_BUDP_NO_DATA; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | /* Stereo_Video_Format_Signaling_Length */ |
|---|
| 157 | if ((*userdata++) != 3) |
|---|
| 158 | { |
|---|
| 159 | *pBytesParsed = 1; |
|---|
| 160 | return BERR_BUDP_PARSE_ERROR; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | /* Reserved (bit) and Stereo_Video_Format_Signaling_Type */ |
|---|
| 164 | val8 = *userdata++; |
|---|
| 165 | if ((val8 & 0x80) == 0) |
|---|
| 166 | { |
|---|
| 167 | *pBytesParsed = 2; |
|---|
| 168 | return BERR_BUDP_PARSE_ERROR; |
|---|
| 169 | } |
|---|
| 170 | val8 &= 0x7F; |
|---|
| 171 | switch (val8) |
|---|
| 172 | { |
|---|
| 173 | case 0x03: |
|---|
| 174 | case 0x04: |
|---|
| 175 | case 0x08: |
|---|
| 176 | break; |
|---|
| 177 | default: |
|---|
| 178 | *pBytesParsed = 2; |
|---|
| 179 | return BERR_BUDP_PARSE_ERROR; |
|---|
| 180 | break; |
|---|
| 181 | } |
|---|
| 182 | /* The heart of the matter */ |
|---|
| 183 | *sigtype = val8; |
|---|
| 184 | |
|---|
| 185 | /* Reserved (2 bytes) */ |
|---|
| 186 | val16 = (*userdata++) << 8; |
|---|
| 187 | val16 |= *userdata++; |
|---|
| 188 | *pBytesParsed = 4; |
|---|
| 189 | if (val16 != 0x04FF) |
|---|
| 190 | { |
|---|
| 191 | return BERR_BUDP_PARSE_ERROR; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | BDBG_LEAVE(BUDP_JP3Dparse_isr); |
|---|
| 195 | return BERR_SUCCESS; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | static size_t FindJp3dStart ( |
|---|
| 200 | const uint8_t* userdata, size_t length) |
|---|
| 201 | { |
|---|
| 202 | uint8_t saved[8]; |
|---|
| 203 | size_t count = 0; |
|---|
| 204 | |
|---|
| 205 | /* Special case (failure) */ |
|---|
| 206 | if (length < 8) |
|---|
| 207 | return length; |
|---|
| 208 | |
|---|
| 209 | /* Initialize */ |
|---|
| 210 | saved[1] = *userdata++; |
|---|
| 211 | saved[2] = *userdata++; |
|---|
| 212 | saved[3] = *userdata++; |
|---|
| 213 | saved[4] = *userdata++; |
|---|
| 214 | saved[5] = *userdata++; |
|---|
| 215 | saved[6] = *userdata++; |
|---|
| 216 | saved[7] = *userdata++; |
|---|
| 217 | |
|---|
| 218 | while (length >= 8) |
|---|
| 219 | { |
|---|
| 220 | /* Read in another byte */ |
|---|
| 221 | saved[0] = saved[1]; |
|---|
| 222 | saved[1] = saved[2]; |
|---|
| 223 | saved[2] = saved[3]; |
|---|
| 224 | saved[3] = saved[4]; |
|---|
| 225 | saved[4] = saved[5]; |
|---|
| 226 | saved[5] = saved[6]; |
|---|
| 227 | saved[6] = saved[7]; |
|---|
| 228 | saved[7] = *userdata++; |
|---|
| 229 | |
|---|
| 230 | if ((saved[0] == 0x00) && |
|---|
| 231 | (saved[1] == 0x00) && |
|---|
| 232 | (saved[2] == 0x01) && |
|---|
| 233 | (saved[3] == 0xb2) && |
|---|
| 234 | (saved[4] == 0x4a) && |
|---|
| 235 | (saved[5] == 0x50) && |
|---|
| 236 | (saved[6] == 0x33) && |
|---|
| 237 | (saved[7] == 0x44) ) |
|---|
| 238 | { |
|---|
| 239 | /* Found it! */ |
|---|
| 240 | break; |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | /* proceed to the next byte */ |
|---|
| 244 | --length; |
|---|
| 245 | ++count; |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | if (length >= 8) |
|---|
| 249 | { |
|---|
| 250 | /* found the pattern before the end of stream */ |
|---|
| 251 | return count + 8; |
|---|
| 252 | } |
|---|
| 253 | else |
|---|
| 254 | { |
|---|
| 255 | /* Didn't find any start code */ |
|---|
| 256 | return count + 7; |
|---|
| 257 | } |
|---|
| 258 | } |
|---|