| 50 | } DiracParseContext; |
| 51 | |
| 52 | static int find_frame_end(DiracParseContext *pc, |
| 53 | const uint8_t *buf, int buf_size) |
| 54 | { |
| 55 | uint32_t state = pc->state; |
| 56 | int i = 0; |
| 57 | |
| 58 | if (!pc->is_synced) { |
| 59 | for (i = 0; i < buf_size; i++) { |
| 60 | state = (state << 8) | buf[i]; |
| 61 | if (state == DIRAC_PARSE_INFO_PREFIX) { |
| 62 | state = -1; |
| 63 | pc->is_synced = 1; |
| 64 | pc->header_bytes_needed = 9; |
| 65 | pc->sync_offset = i; |
| 66 | break; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if (pc->is_synced) { |
| 72 | pc->sync_offset = 0; |
| 73 | for (; i < buf_size; i++) { |
| 74 | if (state == DIRAC_PARSE_INFO_PREFIX) { |
| 75 | if ((buf_size-i) >= pc->header_bytes_needed) { |
| 76 | pc->state = -1; |
| 77 | return i + pc->header_bytes_needed; |
| 78 | } else { |
| 79 | pc->header_bytes_needed = 9-(buf_size-i); |
| 80 | break; |
| 81 | } |
| 82 | } else |
| 83 | state = (state << 8) | buf[i]; |
| 84 | } |
| 85 | } |
| 86 | pc->state = state; |
| 87 | return -1; |
| 88 | } |
| 89 | |
| 90 | typedef struct DiracParseUnit |
| 91 | { |