hardware/intel/intel-driver
修订版 | 896316a21f72c9599f2bc4cd504b9256cb6649fb (tree) |
---|---|
时间 | 2015-03-24 13:05:25 |
作者 | Olivier Crete <olivier.crete@coll...> |
Commiter | Xiang, Haihao |
gen7_mfd: Optimise start code search
Code inspired from GStreamer
See https://bugs.freedesktop.org/show_bug.cgi?id=89507
Signed-off-by: Olivier Crete <olivier.crete@collabora.com>
@@ -1043,21 +1043,29 @@ uint32_t mpeg2_get_slice_data_length(dri_bo *slice_data_bo, VASliceParameterBuff | ||
1043 | 1043 | uint8_t *buf; |
1044 | 1044 | uint32_t buf_offset = slice_param->slice_data_offset + (slice_param->macroblock_offset >> 3); |
1045 | 1045 | uint32_t buf_size = slice_param->slice_data_size - (slice_param->macroblock_offset >> 3); |
1046 | - uint32_t i; | |
1046 | + uint32_t i = 0; | |
1047 | 1047 | |
1048 | 1048 | dri_bo_map(slice_data_bo, 0); |
1049 | 1049 | buf = (uint8_t *)slice_data_bo->virtual + buf_offset; |
1050 | 1050 | |
1051 | - for (i = 3; i < buf_size; i++) { | |
1052 | - if (buf[i - 3] && | |
1053 | - !buf[i - 2] && | |
1054 | - !buf[i - 1] && | |
1055 | - !buf[i]) { | |
1056 | - dri_bo_unmap(slice_data_bo); | |
1057 | - return i - 3 + 1; | |
1058 | - } | |
1051 | + if (buf_size < 4) | |
1052 | + return buf_size; | |
1053 | + | |
1054 | + while (i <= (buf_size - 4)) { | |
1055 | + if (buf[i + 2] > 1) { | |
1056 | + i += 3; | |
1057 | + } else if (buf[i + 1]) { | |
1058 | + i += 2; | |
1059 | + } else if (buf[i] || buf[i + 2] != 1) { | |
1060 | + i++; | |
1061 | + } else { | |
1062 | + break; | |
1063 | + } | |
1059 | 1064 | } |
1060 | 1065 | |
1066 | + if (i <= (buf_size - 4)) | |
1067 | + buf_size = i; | |
1068 | + | |
1061 | 1069 | dri_bo_unmap(slice_data_bo); |
1062 | 1070 | return buf_size; |
1063 | 1071 | } |