mp4parse.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. /* ///////////////////////////////////////////////////////////////////////
  2. //
  3. // INTEL CORPORATION PROPRIETARY INFORMATION
  4. // This software is supplied under the terms of a license agreement or
  5. // nondisclosure agreement with Intel Corporation and may not be copied
  6. // or disclosed except in accordance with the terms of that agreement.
  7. // Copyright (c) 2001-2007 Intel Corporation. All Rights Reserved.
  8. //
  9. // Description: Parses MPEG-4 headers
  10. //
  11. */
  12. #include "mp4def.h"
  13. mp4_Status mp4_Parse_VisualObjectSequence(mp4_Info* pInfo)
  14. {
  15. pInfo->profile_and_level_indication = mp4_GetBits9(pInfo, 8);
  16. if (pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_1 &&
  17. pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_2 &&
  18. pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_3 &&
  19. pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_0 &&
  20. pInfo->profile_and_level_indication != MP4_CORE_PROFILE_LEVEL_1 &&
  21. pInfo->profile_and_level_indication != MP4_CORE_PROFILE_LEVEL_2 &&
  22. pInfo->profile_and_level_indication != MP4_MAIN_PROFILE_LEVEL_2 &&
  23. pInfo->profile_and_level_indication != MP4_MAIN_PROFILE_LEVEL_3 &&
  24. pInfo->profile_and_level_indication != MP4_MAIN_PROFILE_LEVEL_4 &&
  25. pInfo->profile_and_level_indication != MP4_ADVANCED_REAL_TIME_SIMPLE_PROFILE_LEVEL_1 &&
  26. pInfo->profile_and_level_indication != MP4_ADVANCED_REAL_TIME_SIMPLE_PROFILE_LEVEL_2 &&
  27. pInfo->profile_and_level_indication != MP4_ADVANCED_REAL_TIME_SIMPLE_PROFILE_LEVEL_3 &&
  28. pInfo->profile_and_level_indication != MP4_ADVANCED_REAL_TIME_SIMPLE_PROFILE_LEVEL_4 &&
  29. pInfo->profile_and_level_indication != MP4_ADVANCED_CODING_EFFICIENCY_PROFILE_LEVEL_1 &&
  30. pInfo->profile_and_level_indication != MP4_ADVANCED_CODING_EFFICIENCY_PROFILE_LEVEL_2 &&
  31. pInfo->profile_and_level_indication != MP4_ADVANCED_CODING_EFFICIENCY_PROFILE_LEVEL_3 &&
  32. pInfo->profile_and_level_indication != MP4_ADVANCED_CODING_EFFICIENCY_PROFILE_LEVEL_4 &&
  33. pInfo->profile_and_level_indication != MP4_ADVANCED_CORE_PROFILE_LEVEL_1 &&
  34. pInfo->profile_and_level_indication != MP4_ADVANCED_CORE_PROFILE_LEVEL_2 &&
  35. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_0 &&
  36. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_1 &&
  37. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_2 &&
  38. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_3 &&
  39. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_4 &&
  40. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_5 &&
  41. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_3B) {
  42. mp4_Error("Warning: Unsupported profile_and_level_indication");
  43. if (pInfo->strictSyntaxCheck)
  44. return MP4_STATUS_NOTSUPPORT;
  45. }
  46. if (pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_1 &&
  47. pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_2 &&
  48. pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_3 &&
  49. pInfo->profile_and_level_indication != MP4_SIMPLE_PROFILE_LEVEL_0 &&
  50. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_0 &&
  51. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_1 &&
  52. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_2 &&
  53. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_3 &&
  54. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_4 &&
  55. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_5 &&
  56. pInfo->profile_and_level_indication != MP4_ADVANCED_SIMPLE_PROFILE_LEVEL_3B) {
  57. mp4_Error("Warning: Some features of present profile_and_level_indication may be not supported");
  58. }
  59. return MP4_STATUS_OK;
  60. }
  61. mp4_Status mp4_Parse_VisualObject(mp4_Info* pInfo)
  62. {
  63. mp4_VisualObject *VO = &pInfo->VisualObject;
  64. VO->is_identifier = mp4_GetBit(pInfo);
  65. if (VO->is_identifier) {
  66. VO->verid = mp4_GetBits9(pInfo, 4);
  67. if ((VO->verid != 1) && (VO->verid != 2) && (VO->verid != 4) && (VO->verid != 5)) {
  68. VO->verid = 1;
  69. mp4_Error("Warning: Unsupported visual_object_verid");
  70. //f if (pInfo->strictSyntaxCheck)
  71. //f return MP4_STATUS_NOTSUPPORT;
  72. }
  73. VO->priority = mp4_GetBits9(pInfo, 3);
  74. if (VO->priority == 0) {
  75. mp4_Error("Warning: Wrong value of visual_object_priority");
  76. //f if (pInfo->strictSyntaxCheck)
  77. //f return MP4_STATUS_PARSE_ERROR;
  78. }
  79. } else
  80. VO->verid = 1;
  81. VO->type = mp4_GetBits9(pInfo, 4);
  82. if (VO->type != MP4_VISUAL_OBJECT_TYPE_VIDEO) {
  83. mp4_Error("Error: Unsupported object: visual_object_type != video ID");
  84. return MP4_STATUS_NOTSUPPORT;
  85. }
  86. VO->VideoSignalType.video_format = MP4_VIDEO_FORMAT_UNSPECIFIED;
  87. VO->VideoSignalType.video_range = 0;
  88. VO->VideoSignalType.colour_primaries = MP4_VIDEO_COLORS_ITU_R_BT_709;
  89. VO->VideoSignalType.transfer_characteristics = MP4_VIDEO_COLORS_ITU_R_BT_709;
  90. VO->VideoSignalType.matrix_coefficients = MP4_VIDEO_COLORS_ITU_R_BT_709;
  91. if (VO->type == MP4_VISUAL_OBJECT_TYPE_VIDEO || VO->type == MP4_VISUAL_OBJECT_TYPE_TEXTURE) {
  92. VO->VideoSignalType.is_video_signal_type = mp4_GetBit(pInfo);
  93. if (VO->VideoSignalType.is_video_signal_type) {
  94. VO->VideoSignalType.video_format = mp4_GetBits9(pInfo, 3);
  95. if (VO->VideoSignalType.video_format > MP4_VIDEO_FORMAT_UNSPECIFIED) {
  96. mp4_Error("Warning: Wrong value of video_format");
  97. //f if (pInfo->strictSyntaxCheck)
  98. //f return MP4_STATUS_PARSE_ERROR;
  99. }
  100. VO->VideoSignalType.video_range = mp4_GetBit(pInfo);
  101. VO->VideoSignalType.is_colour_description = mp4_GetBit(pInfo);
  102. if (VO->VideoSignalType.is_colour_description) {
  103. VO->VideoSignalType.colour_primaries = mp4_GetBits9(pInfo, 8);
  104. if (VO->VideoSignalType.colour_primaries == MP4_VIDEO_COLORS_FORBIDDEN) {
  105. mp4_Error("Error: Wrong value of colour_primaries");
  106. if (pInfo->strictSyntaxCheck)
  107. return MP4_STATUS_PARSE_ERROR;
  108. }
  109. if (VO->VideoSignalType.colour_primaries > MP4_VIDEO_COLORS_GENERIC_FILM) {
  110. mp4_Error("Warning: Wrong value of colour_primaries");
  111. //f if (pInfo->strictSyntaxCheck)
  112. //f return MP4_STATUS_PARSE_ERROR;
  113. }
  114. VO->VideoSignalType.transfer_characteristics = mp4_GetBits9(pInfo, 8);
  115. if (VO->VideoSignalType.transfer_characteristics == 0) {
  116. mp4_Error("Error: Wrong value of transfer_characteristics");
  117. if (pInfo->strictSyntaxCheck)
  118. return MP4_STATUS_PARSE_ERROR;
  119. }
  120. if (VO->VideoSignalType.transfer_characteristics > 10) {
  121. mp4_Error("Warning: Wrong value of transfer_characteristics");
  122. //f if (pInfo->strictSyntaxCheck)
  123. //f return MP4_STATUS_PARSE_ERROR;
  124. }
  125. VO->VideoSignalType.matrix_coefficients = mp4_GetBits9(pInfo, 8);
  126. if (VO->VideoSignalType.matrix_coefficients == 0) {
  127. mp4_Error("Error: Wrong value of matrix_coefficients");
  128. if (pInfo->strictSyntaxCheck)
  129. return MP4_STATUS_PARSE_ERROR;
  130. }
  131. if (VO->VideoSignalType.matrix_coefficients > 8) {
  132. mp4_Error("Warning: Wrong value of matrix_coefficients");
  133. //f if (pInfo->strictSyntaxCheck)
  134. //f return MP4_STATUS_PARSE_ERROR;
  135. }
  136. }
  137. }
  138. }
  139. return MP4_STATUS_OK;
  140. }
  141. static mp4_Status mp4_Parse_QuantMatrix(mp4_Info* pInfo, uint8_t pQM[64])
  142. {
  143. uint32_t code;
  144. int32_t i;
  145. for (i = 0; i < 64; i ++) {
  146. code = mp4_GetBits9(pInfo, 8);
  147. if (code == 0) break;
  148. pQM[mp4_ClassicalZigzag[i]] = (uint8_t)code;
  149. }
  150. if (i > 0) {
  151. code = pQM[mp4_ClassicalZigzag[i-1]];
  152. for (; i < 64; i ++)
  153. pQM[mp4_ClassicalZigzag[i]] = (uint8_t)code;
  154. } else {
  155. for (i = 1; i < 64; i ++)
  156. pQM[mp4_ClassicalZigzag[i]] = (uint8_t)mp4_ClassicalZigzag[0];
  157. }
  158. return MP4_STATUS_OK;
  159. }
  160. mp4_Status mp4_Parse_VideoObject(mp4_Info* pInfo)
  161. {
  162. uint32_t code;
  163. int32_t i;
  164. mp4_VisualObject *VO = &pInfo->VisualObject;
  165. mp4_VideoObject *VOL = &pInfo->VisualObject.VideoObject;
  166. code = mp4_ShowBits(pInfo, 32);
  167. // check short_video_start_marker
  168. if ((code & (~0x3FF)) == 0x8000) {
  169. VOL->short_video_header = 1;
  170. VOL->quant_precision = 5;
  171. VOL->shape = MP4_SHAPE_TYPE_RECTANGULAR;
  172. VOL->obmc_disable = 1;
  173. VOL->quant_type = 0;
  174. VOL->resync_marker_disable = 1;
  175. VOL->data_partitioned = 0;
  176. VOL->reversible_vlc = 0;
  177. VOL->VideoObjectPlane.rounding_type = 0;
  178. VOL->VideoObjectPlane.fcode_forward = 1;
  179. VOL->VideoObjectPlane.coded = 1;
  180. VOL->interlaced = 0;
  181. VOL->complexity_estimation_disable = 1;
  182. VOL->scalability = 0;
  183. VOL->not_8_bit = 0;
  184. VOL->bits_per_pixel = 8;
  185. VO->VideoSignalType.colour_primaries = 1;
  186. VO->VideoSignalType.transfer_characteristics = 1;
  187. VO->VideoSignalType.matrix_coefficients = 6;
  188. VO->VideoObject.VideoObjectPlaneH263.source_format = (pInfo->bufptr[4] >> 2) & 0x7;
  189. i = VO->VideoObject.VideoObjectPlaneH263.source_format - 1;
  190. if (i < 0 || i > 4) {
  191. mp4_Error("Error: Bad value for VideoPlaneWithShortHeader.source_format");
  192. return MP4_STATUS_PARSE_ERROR;
  193. }
  194. VOL->width = mp4_H263_width[i];
  195. VOL->height = mp4_H263_height[i];
  196. VOL->VideoObjectPlaneH263.num_gobs_in_vop = mp4_H263_gobvop[i];
  197. VOL->VideoObjectPlaneH263.num_macroblocks_in_gob = mp4_H263_mbgob[i];
  198. VOL->VideoObjectPlaneH263.num_rows_in_gob = mp4_H263_rowgob[i];
  199. VOL->vop_time_increment_resolution = 30000;
  200. // VOL->VideoObjectPlane.time_increment = -1001;
  201. VOL->VOLControlParameters.low_delay = 1;
  202. return MP4_STATUS_OK;
  203. }
  204. if (code < 256 + MP4_VIDEO_OBJECT_LAYER_MIN_SC || code > 256 + MP4_VIDEO_OBJECT_LAYER_MAX_SC) {
  205. mp4_Error("Error: Bad start code for VideoObjectLayer");
  206. return MP4_STATUS_PARSE_ERROR;
  207. }
  208. mp4_FlushBits(pInfo, 32);
  209. // video_object_start_code is founded
  210. VOL->id = code & 15;
  211. VOL->short_video_header = 0;
  212. VOL->random_accessible_vol = mp4_GetBit(pInfo);
  213. VOL->type_indication = mp4_GetBits9(pInfo, 8);
  214. if (VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_SIMPLE &&
  215. VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_CORE &&
  216. VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_MAIN &&
  217. VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_ADVANCED_REAL_TIME_SIMPLE &&
  218. VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_ADVANCED_CODING_EFFICIENCY &&
  219. VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_ADVANCED_SIMPLE) {
  220. mp4_Error("Warning: Unsupported video_object_type_indication, some features may be not supported");
  221. //f if (pInfo->strictSyntaxCheck)
  222. //f return MP4_STATUS_NOTSUPPORT;
  223. }
  224. VOL->is_identifier = mp4_GetBit(pInfo);
  225. if (VOL->is_identifier) {
  226. VOL->verid = mp4_GetBits9(pInfo, 4);
  227. if ((VOL->verid != 1) && (VOL->verid != 2) && (VOL->verid != 4) && (VOL->verid != 5)) {
  228. mp4_Error("Warning: Unsupported video_object_layer_verid");
  229. VOL->verid = VO->verid;
  230. //f if (pInfo->strictSyntaxCheck)
  231. //f return MP4_STATUS_NOTSUPPORT;
  232. }
  233. VOL->priority = mp4_GetBits9(pInfo, 3);
  234. if (VOL->priority == 0) {
  235. mp4_Error("Warning: Wrong value of video_object_layer_priority");
  236. //f if (pInfo->strictSyntaxCheck)
  237. //f return MP4_STATUS_PARSE_ERROR;
  238. }
  239. } else
  240. VOL->verid = VO->verid;
  241. VOL->aspect_ratio_info = mp4_GetBits9(pInfo, 4);
  242. if (VOL->aspect_ratio_info == MP4_ASPECT_RATIO_FORBIDDEN) {
  243. mp4_Error("Error: Wrong value of aspect_ratio_info");
  244. if (pInfo->strictSyntaxCheck)
  245. return MP4_STATUS_PARSE_ERROR;
  246. }
  247. if (VOL->aspect_ratio_info > MP4_ASPECT_RATIO_40_33 && VOL->aspect_ratio_info < MP4_ASPECT_RATIO_EXTPAR) {
  248. mp4_Error("Warning: Wrong value of aspect_ratio_info");
  249. //f if (pInfo->strictSyntaxCheck)
  250. //f return MP4_STATUS_PARSE_ERROR;
  251. }
  252. if (VOL->aspect_ratio_info == MP4_ASPECT_RATIO_EXTPAR) {
  253. VOL->aspect_ratio_info_par_width = mp4_GetBits9(pInfo, 8);
  254. if (VOL->aspect_ratio_info_par_width == 0) {
  255. mp4_Error("Error: Wrong value of par_width");
  256. if (pInfo->strictSyntaxCheck)
  257. return MP4_STATUS_PARSE_ERROR;
  258. }
  259. VOL->aspect_ratio_info_par_height = mp4_GetBits9(pInfo, 8);
  260. if (VOL->aspect_ratio_info_par_height == 0) {
  261. mp4_Error("Error: Wrong value of par_height");
  262. if (pInfo->strictSyntaxCheck)
  263. return MP4_STATUS_PARSE_ERROR;
  264. }
  265. }
  266. VOL->is_vol_control_parameters = mp4_GetBit(pInfo);
  267. if (VOL->type_indication == MP4_VIDEO_OBJECT_TYPE_SIMPLE || VOL->type_indication != MP4_VIDEO_OBJECT_TYPE_ADVANCED_REAL_TIME_SIMPLE)
  268. VOL->VOLControlParameters.low_delay = 1;
  269. if (VOL->is_vol_control_parameters) {
  270. VOL->VOLControlParameters.chroma_format = mp4_GetBits9(pInfo, 2);
  271. if (VOL->VOLControlParameters.chroma_format != MP4_CHROMA_FORMAT_420) {
  272. mp4_Error("Error: chroma_format != 4:2:0");
  273. return MP4_STATUS_PARSE_ERROR;
  274. }
  275. VOL->VOLControlParameters.low_delay = mp4_GetBit(pInfo);
  276. VOL->VOLControlParameters.vbv_parameters = mp4_GetBit(pInfo);
  277. if (VOL->VOLControlParameters.vbv_parameters) {
  278. VOL->VOLControlParameters.bit_rate = mp4_GetBits(pInfo, 15) << 15;
  279. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  280. VOL->VOLControlParameters.bit_rate += mp4_GetBits(pInfo, 15);
  281. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  282. if (VOL->VOLControlParameters.bit_rate == 0) {
  283. mp4_Error("Error: vbv_parameters bit_rate == 0");
  284. return MP4_STATUS_PARSE_ERROR;
  285. }
  286. VOL->VOLControlParameters.vbv_buffer_size = mp4_GetBits(pInfo, 15) << 3;
  287. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  288. VOL->VOLControlParameters.vbv_buffer_size += mp4_GetBits9(pInfo, 3);
  289. if (VOL->VOLControlParameters.vbv_buffer_size == 0) {
  290. mp4_Error("Error: vbv_parameters vbv_buffer_size == 0");
  291. return MP4_STATUS_PARSE_ERROR;
  292. }
  293. VOL->VOLControlParameters.vbv_occupancy = mp4_GetBits(pInfo, 11) << 15;
  294. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  295. VOL->VOLControlParameters.vbv_occupancy += mp4_GetBits(pInfo, 15);
  296. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  297. }
  298. }
  299. VOL->shape = mp4_GetBits9(pInfo, 2);
  300. if (VOL->shape != MP4_SHAPE_TYPE_RECTANGULAR) {
  301. mp4_Error("Error: video_object_layer_shape != rectangular (not supported)");
  302. return MP4_STATUS_PARSE_ERROR;
  303. }
  304. if (VOL->verid != 1 && VOL->shape == MP4_SHAPE_TYPE_GRAYSCALE) {
  305. VOL->shape_extension = mp4_GetBits9(pInfo, 4);
  306. if (VOL->shape_extension >= MP4_SHAPE_EXT_NUM) {
  307. mp4_Error("Error: wrong value of video_object_layer_shape_extension");
  308. return MP4_STATUS_PARSE_ERROR;
  309. }
  310. } else
  311. VOL->shape_extension = MP4_SHAPE_EXT_NUM;
  312. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  313. VOL->vop_time_increment_resolution = mp4_GetBits(pInfo, 16);
  314. if (VOL->vop_time_increment_resolution == 0) {
  315. mp4_Error("Error: wrong value of vop_time_increment_resolution");
  316. return MP4_STATUS_PARSE_ERROR;
  317. }
  318. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  319. // define number bits in vop_time_increment_resolution
  320. code = VOL->vop_time_increment_resolution - 1;
  321. i = 0;
  322. do {
  323. code >>= 1;
  324. i ++;
  325. } while (code);
  326. VOL->vop_time_increment_resolution_bits = i;
  327. VOL->fixed_vop_rate = mp4_GetBit(pInfo);
  328. if (VOL->fixed_vop_rate) {
  329. VOL->fixed_vop_time_increment = mp4_GetBits(pInfo, VOL->vop_time_increment_resolution_bits);
  330. if (VOL->fixed_vop_time_increment == 0) {
  331. mp4_Error("Error: wrong value of fixed_vop_time_increment");
  332. return MP4_STATUS_PARSE_ERROR;
  333. }
  334. }
  335. if (VOL->shape != MP4_SHAPE_TYPE_BINARYONLY) {
  336. if (VOL->shape == MP4_SHAPE_TYPE_RECTANGULAR) {
  337. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  338. VOL->width = mp4_GetBits(pInfo, 13);
  339. if (VOL->width == 0) {
  340. mp4_Error("Error: wrong value of video_object_layer_width");
  341. return MP4_STATUS_PARSE_ERROR;
  342. }
  343. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  344. VOL->height = mp4_GetBits(pInfo, 13);
  345. if (VOL->height == 0) {
  346. mp4_Error("Error: wrong value of video_object_layer_height");
  347. return MP4_STATUS_PARSE_ERROR;
  348. }
  349. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  350. }
  351. VOL->interlaced = mp4_GetBit(pInfo);
  352. VOL->obmc_disable = mp4_GetBit(pInfo);
  353. VOL->sprite_enable = mp4_GetBits9(pInfo, VOL->verid != 1 ? 2 : 1);
  354. if (VOL->sprite_enable == MP4_SPRITE_STATIC || VOL->sprite_enable == MP4_SPRITE_GMC) {
  355. if (VOL->sprite_enable == MP4_SPRITE_STATIC) {
  356. VOL->sprite_width = mp4_GetBits(pInfo, 13);
  357. if (VOL->sprite_width == 0) {
  358. mp4_Error("Error: wrong value of sprite_width");
  359. return MP4_STATUS_PARSE_ERROR;
  360. }
  361. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  362. VOL->sprite_height = mp4_GetBits(pInfo, 13);
  363. if (VOL->sprite_height == 0) {
  364. mp4_Error("Error: wrong value of sprite_height");
  365. return MP4_STATUS_PARSE_ERROR;
  366. }
  367. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  368. VOL->sprite_left_coordinate = mp4_GetBits(pInfo, 13);
  369. VOL->sprite_left_coordinate <<= (32 - 13);
  370. VOL->sprite_left_coordinate >>= (32 - 13);
  371. if (VOL->sprite_left_coordinate & 1) {
  372. mp4_Error("Error: sprite_left_coordinate must be divisible by 2");
  373. return MP4_STATUS_PARSE_ERROR;
  374. }
  375. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  376. VOL->sprite_top_coordinate = mp4_GetBits(pInfo, 13);
  377. VOL->sprite_top_coordinate <<= (32 - 13);
  378. VOL->sprite_top_coordinate >>= (32 - 13);
  379. if (VOL->sprite_top_coordinate & 1) {
  380. mp4_Error("Error: sprite_top_coordinate must be divisible by 2");
  381. return MP4_STATUS_PARSE_ERROR;
  382. }
  383. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  384. }
  385. VOL->sprite_warping_points = mp4_GetBits9(pInfo, 6);
  386. if (VOL->sprite_warping_points > 4 || (VOL->sprite_warping_points == 4 && VOL->sprite_enable == MP4_SPRITE_GMC)) {
  387. mp4_Error("Error: bad no_of_sprite_warping_points");
  388. return MP4_STATUS_PARSE_ERROR;
  389. }
  390. VOL->sprite_warping_accuracy = mp4_GetBits9(pInfo, 2);
  391. VOL->sprite_brightness_change = mp4_GetBit(pInfo);
  392. if (VOL->sprite_enable == MP4_SPRITE_GMC) {
  393. if (VOL->sprite_brightness_change) {
  394. mp4_Error("Error: sprite_brightness_change should be 0 for GMC sprites");
  395. return MP4_STATUS_PARSE_ERROR;
  396. }
  397. }
  398. if (VOL->sprite_enable != MP4_SPRITE_GMC) {
  399. VOL->low_latency_sprite_enable = mp4_GetBit(pInfo);
  400. if (VOL->low_latency_sprite_enable) {
  401. mp4_Error("Error: low_latency_sprite is not supported");
  402. return MP4_STATUS_PARSE_ERROR;
  403. }
  404. }
  405. }
  406. if (VOL->verid != 1 && VOL->shape != MP4_SHAPE_TYPE_RECTANGULAR) {
  407. VOL->sadct_disable = mp4_GetBit(pInfo);
  408. if (!VOL->sadct_disable) {
  409. mp4_Error("Error: Shape Adaptive DCT is not supported");
  410. return MP4_STATUS_PARSE_ERROR;
  411. }
  412. }
  413. VOL->not_8_bit = mp4_GetBit(pInfo);
  414. if (VOL->not_8_bit) {
  415. mp4_Error("Error: only 8-bits data is supported");
  416. return MP4_STATUS_PARSE_ERROR;
  417. }
  418. if (VOL->not_8_bit) {
  419. VOL->quant_precision = mp4_GetBits9(pInfo, 4);
  420. if (VOL->quant_precision < 3 || VOL->quant_precision > 9) {
  421. mp4_Error("Error: quant_precision must be in range [3; 9]");
  422. return MP4_STATUS_PARSE_ERROR;
  423. }
  424. VOL->bits_per_pixel = mp4_GetBits9(pInfo, 4);
  425. if (VOL->bits_per_pixel < 4 || VOL->bits_per_pixel > 12) {
  426. mp4_Error("Error: bits_per_pixel must be in range [4; 12]");
  427. return MP4_STATUS_PARSE_ERROR;
  428. }
  429. } else {
  430. VOL->quant_precision = 5;
  431. VOL->bits_per_pixel = 8;
  432. }
  433. if (VOL->shape == MP4_SHAPE_TYPE_GRAYSCALE) {
  434. VOL->no_gray_quant_update = mp4_GetBit(pInfo);
  435. VOL->composition_method = mp4_GetBit(pInfo);
  436. VOL->linear_composition = mp4_GetBit(pInfo);
  437. }
  438. VOL->quant_type = mp4_GetBit(pInfo);
  439. if (VOL->quant_type) {
  440. VOL->load_intra_quant_mat = mp4_GetBit(pInfo);
  441. if (VOL->load_intra_quant_mat) {
  442. if (mp4_Parse_QuantMatrix(pInfo, VOL->intra_quant_mat) != MP4_STATUS_OK)
  443. return MP4_STATUS_PARSE_ERROR;
  444. } else
  445. ippsCopy_8u(mp4_DefaultIntraQuantMatrix, VOL->intra_quant_mat, 64);
  446. VOL->load_nonintra_quant_mat = mp4_GetBit(pInfo);
  447. if (VOL->load_nonintra_quant_mat) {
  448. if (mp4_Parse_QuantMatrix(pInfo, VOL->nonintra_quant_mat) != MP4_STATUS_OK)
  449. return MP4_STATUS_PARSE_ERROR;
  450. } else
  451. ippsCopy_8u(mp4_DefaultNonIntraQuantMatrix, VOL->nonintra_quant_mat, 64);
  452. if (VOL->shape == MP4_SHAPE_TYPE_GRAYSCALE) {
  453. int32_t ac, i;
  454. ac = mp4_aux_comp_count[VOL->shape_extension];
  455. for (i = 0; i < ac; i ++) {
  456. VOL->load_intra_quant_mat_grayscale[i] = mp4_GetBit(pInfo);
  457. if (VOL->load_intra_quant_mat_grayscale[i]) {
  458. if (mp4_Parse_QuantMatrix(pInfo, VOL->intra_quant_mat_grayscale[i]) != MP4_STATUS_OK)
  459. return MP4_STATUS_PARSE_ERROR;
  460. } else
  461. ippsCopy_8u(mp4_DefaultIntraQuantMatrix, VOL->intra_quant_mat_grayscale[i], 64);
  462. VOL->load_nonintra_quant_mat_grayscale[i] = mp4_GetBit(pInfo);
  463. if (VOL->load_nonintra_quant_mat_grayscale[i]) {
  464. if (mp4_Parse_QuantMatrix(pInfo, VOL->nonintra_quant_mat_grayscale[i]) != MP4_STATUS_OK)
  465. return MP4_STATUS_PARSE_ERROR;
  466. } else
  467. ippsCopy_8u(mp4_DefaultNonIntraQuantMatrix, VOL->nonintra_quant_mat_grayscale[i], 64);
  468. }
  469. }
  470. }
  471. if (VOL->verid != 1)
  472. VOL->quarter_sample = mp4_GetBit(pInfo);
  473. VOL->complexity_estimation_disable = mp4_GetBit(pInfo);
  474. if (!VOL->complexity_estimation_disable) {
  475. VOL->ComplexityEstimation.estimation_method = mp4_GetBits9(pInfo, 2);
  476. if (VOL->ComplexityEstimation.estimation_method <= 1) {
  477. VOL->ComplexityEstimation.shape_complexity_estimation_disable = mp4_GetBit(pInfo);
  478. if (!VOL->ComplexityEstimation.shape_complexity_estimation_disable) {
  479. VOL->ComplexityEstimation.opaque = mp4_GetBit(pInfo);
  480. VOL->ComplexityEstimation.transparent = mp4_GetBit(pInfo);
  481. VOL->ComplexityEstimation.intra_cae = mp4_GetBit(pInfo);
  482. VOL->ComplexityEstimation.inter_cae = mp4_GetBit(pInfo);
  483. VOL->ComplexityEstimation.no_update = mp4_GetBit(pInfo);
  484. VOL->ComplexityEstimation.upsampling = mp4_GetBit(pInfo);
  485. }
  486. VOL->ComplexityEstimation.texture_complexity_estimation_set_1_disable = mp4_GetBit(pInfo);
  487. if (!VOL->ComplexityEstimation.texture_complexity_estimation_set_1_disable) {
  488. VOL->ComplexityEstimation.intra_blocks = mp4_GetBit(pInfo);
  489. VOL->ComplexityEstimation.inter_blocks = mp4_GetBit(pInfo);
  490. VOL->ComplexityEstimation.inter4v_blocks = mp4_GetBit(pInfo);
  491. VOL->ComplexityEstimation.not_coded_blocks = mp4_GetBit(pInfo);
  492. }
  493. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  494. VOL->ComplexityEstimation.texture_complexity_estimation_set_2_disable = mp4_GetBit(pInfo);
  495. if (!VOL->ComplexityEstimation.texture_complexity_estimation_set_2_disable) {
  496. VOL->ComplexityEstimation.dct_coefs = mp4_GetBit(pInfo);
  497. VOL->ComplexityEstimation.dct_lines = mp4_GetBit(pInfo);
  498. VOL->ComplexityEstimation.vlc_symbols = mp4_GetBit(pInfo);
  499. VOL->ComplexityEstimation.vlc_bits = mp4_GetBit(pInfo);
  500. }
  501. VOL->ComplexityEstimation.motion_compensation_complexity_disable = mp4_GetBit(pInfo);
  502. if (!VOL->ComplexityEstimation.motion_compensation_complexity_disable) {
  503. VOL->ComplexityEstimation.apm = mp4_GetBit(pInfo);
  504. VOL->ComplexityEstimation.npm = mp4_GetBit(pInfo);
  505. VOL->ComplexityEstimation.interpolate_mc_q = mp4_GetBit(pInfo);
  506. VOL->ComplexityEstimation.forw_back_mc_q = mp4_GetBit(pInfo);
  507. VOL->ComplexityEstimation.halfpel2 = mp4_GetBit(pInfo);
  508. VOL->ComplexityEstimation.halfpel4 = mp4_GetBit(pInfo);
  509. }
  510. }
  511. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  512. if (VOL->ComplexityEstimation.estimation_method == 1) {
  513. // verid != 1
  514. VOL->ComplexityEstimation.version2_complexity_estimation_disable = mp4_GetBit(pInfo);
  515. if (!VOL->ComplexityEstimation.version2_complexity_estimation_disable) {
  516. VOL->ComplexityEstimation.sadct = mp4_GetBit(pInfo);
  517. VOL->ComplexityEstimation.quarterpel = mp4_GetBit(pInfo);
  518. }
  519. }
  520. }
  521. VOL->resync_marker_disable = mp4_GetBit(pInfo);
  522. VOL->data_partitioned = mp4_GetBit(pInfo);
  523. //f GrayScale Shapes does not support data_part
  524. if (VOL->data_partitioned)
  525. VOL->reversible_vlc = mp4_GetBit(pInfo);
  526. if (VOL->verid != 1) {
  527. VOL->newpred_enable = mp4_GetBit(pInfo);
  528. if (VOL->newpred_enable) {
  529. VOL->requested_upstream_message_type = mp4_GetBits9(pInfo, 2);
  530. VOL->newpred_segment_type = mp4_GetBit(pInfo);
  531. mp4_Error("Warning: NEWPRED mode is not fully supported");
  532. //f return MP4_STATUS_PARSE_ERROR;
  533. }
  534. VOL->reduced_resolution_vop_enable = mp4_GetBit(pInfo);
  535. if (VOL->reduced_resolution_vop_enable) {
  536. mp4_Error("Error: Reduced Resolution VOP is not supported");
  537. return MP4_STATUS_PARSE_ERROR;
  538. }
  539. }
  540. VOL->scalability = mp4_GetBit(pInfo);
  541. if (VOL->scalability) {
  542. mp4_Error("Error: VOL scalability is not supported");
  543. return MP4_STATUS_PARSE_ERROR;
  544. }
  545. } else {
  546. if (VOL->verid != 1) {
  547. VOL->scalability = mp4_GetBit(pInfo);
  548. if (VOL->scalability) {
  549. mp4_Error("Error: VOL scalability is not supported");
  550. return MP4_STATUS_PARSE_ERROR;
  551. }
  552. }
  553. VOL->resync_marker_disable = mp4_GetBit(pInfo);
  554. }
  555. VOL->VideoObjectPlane.sprite_transmit_mode = MP4_SPRITE_TRANSMIT_MODE_PIECE;
  556. #if 0
  557. {
  558. uint8_t *sbp = pInfo->bufptr;
  559. int32_t v, b, i;
  560. if (mp4_SeekStartCodeValue(pInfo, MP4_USER_DATA_SC)) {
  561. if (pInfo->bufptr[0] == 'D' && pInfo->bufptr[1] == 'i' && pInfo->bufptr[2] == 'v' && pInfo->bufptr[3] == 'X') {
  562. pInfo->ftype = 2;
  563. v = (pInfo->bufptr[4] - '0') * 100 + (pInfo->bufptr[5] - '0') * 10 + (pInfo->bufptr[6] - '0');
  564. if (v < 503)
  565. pInfo->ftype_f = 1;
  566. else if (v == 503) {
  567. i = 8;
  568. b = 0;
  569. while (pInfo->bufptr[i] != 0) {
  570. if (pInfo->bufptr[i] >= '0' && pInfo->bufptr[i] <= '9')
  571. b = b * 10 + (pInfo->bufptr[i] - '0');
  572. i ++;
  573. }
  574. pInfo->ftype_f = (b < 959) ? 1 : 0;
  575. } else
  576. pInfo->ftype_f = 0;
  577. }
  578. }
  579. pInfo->bufptr = sbp;
  580. }
  581. #else
  582. {
  583. uint8_t *sbp = pInfo->bufptr;
  584. if (mp4_SeekStartCodeValue(pInfo, MP4_USER_DATA_SC)) {
  585. if (pInfo->bufptr[0] == 'D' && pInfo->bufptr[1] == 'i' && pInfo->bufptr[2] == 'v' && pInfo->bufptr[3] == 'X') {
  586. pInfo->ftype = 2;
  587. pInfo->ftype_f = 1;
  588. }
  589. }
  590. pInfo->bufptr = sbp;
  591. }
  592. #endif
  593. return MP4_STATUS_OK;
  594. }
  595. /*static */mp4_Status mp4_Sprite_Trajectory(mp4_Info* pInfo) {
  596. int32_t i, dmv_code, dmv_length, fb;
  597. uint32_t code;
  598. for (i = 0; i < pInfo->VisualObject.VideoObject.sprite_warping_points; i ++) {
  599. code = mp4_ShowBits9(pInfo, 3);
  600. if (code == 7) {
  601. mp4_FlushBits(pInfo, 3);
  602. code = mp4_ShowBits9(pInfo, 9);
  603. fb = 1;
  604. while (code & 256) {
  605. code <<= 1;
  606. fb ++;
  607. }
  608. if (fb > 9) {
  609. mp4_Error("Error when decode sprite_trajectory");
  610. return MP4_STATUS_PARSE_ERROR;
  611. }
  612. dmv_length = fb + 5;
  613. } else {
  614. fb = (code <= 1) ? 2 : 3;
  615. dmv_length = code - 1;
  616. }
  617. mp4_FlushBits(pInfo, fb);
  618. if (dmv_length <= 0)
  619. dmv_code = 0;
  620. else {
  621. dmv_code = mp4_GetBits(pInfo, dmv_length);
  622. if ((dmv_code & (1 << (dmv_length - 1))) == 0)
  623. dmv_code -= (1 << dmv_length) - 1;
  624. }
  625. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  626. pInfo->VisualObject.VideoObject.VideoObjectPlane.warping_mv_code_du[i] = dmv_code;
  627. code = mp4_ShowBits9(pInfo, 3);
  628. if (code == 7) {
  629. mp4_FlushBits(pInfo, 3);
  630. code = mp4_ShowBits9(pInfo, 9);
  631. fb = 1;
  632. while (code & 256) {
  633. code <<= 1;
  634. fb ++;
  635. }
  636. if (fb > 9) {
  637. mp4_Error("Error when decode sprite_trajectory");
  638. return MP4_STATUS_PARSE_ERROR;
  639. }
  640. dmv_length = fb + 5;
  641. } else {
  642. fb = (code <= 1) ? 2 : 3;
  643. dmv_length = code - 1;
  644. }
  645. mp4_FlushBits(pInfo, fb);
  646. if (dmv_length <= 0)
  647. dmv_code = 0;
  648. else {
  649. dmv_code = mp4_GetBits(pInfo, dmv_length);
  650. if ((dmv_code & (1 << (dmv_length - 1))) == 0)
  651. dmv_code -= (1 << dmv_length) - 1;
  652. }
  653. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  654. pInfo->VisualObject.VideoObject.VideoObjectPlane.warping_mv_code_dv[i] = dmv_code;
  655. }
  656. return MP4_STATUS_OK;
  657. }
  658. mp4_Status mp4_Parse_GroupOfVideoObjectPlane(mp4_Info* pInfo)
  659. {
  660. uint32_t hour, min, sec;
  661. hour = mp4_GetBits9(pInfo, 5);
  662. min = mp4_GetBits9(pInfo, 6);
  663. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  664. sec = mp4_GetBits9(pInfo, 6);
  665. pInfo->VisualObject.VideoObject.GroupOfVideoObjectPlane.time_code = sec + min * 60 + hour * 3600;
  666. pInfo->VisualObject.VideoObject.GroupOfVideoObjectPlane.time_code *= pInfo->VisualObject.VideoObject.vop_time_increment_resolution;
  667. pInfo->VisualObject.VideoObject.GroupOfVideoObjectPlane.closed_gov = mp4_GetBit(pInfo);
  668. pInfo->VisualObject.VideoObject.GroupOfVideoObjectPlane.broken_link = mp4_GetBit(pInfo);
  669. return MP4_STATUS_OK;
  670. }
  671. mp4_Status mp4_Parse_VideoObjectPlane(mp4_Info* pInfo)
  672. {
  673. uint32_t code;
  674. mp4_VideoObject *VOL = &pInfo->VisualObject.VideoObject;
  675. mp4_VideoObjectPlane *VOP = &pInfo->VisualObject.VideoObject.VideoObjectPlane;
  676. mp4_VideoObjectPlaneH263 *VOPSH = &pInfo->VisualObject.VideoObject.VideoObjectPlaneH263;
  677. if (VOL->short_video_header) {
  678. code = mp4_GetBits9(pInfo, 6); // read rest bits of short_video_start_marker
  679. VOPSH->temporal_reference = mp4_GetBits9(pInfo, 8);
  680. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  681. code = mp4_GetBit(pInfo); // zero_bit
  682. VOPSH->split_screen_indicator = mp4_GetBit(pInfo);
  683. VOPSH->document_camera_indicator = mp4_GetBit(pInfo);
  684. VOPSH->full_picture_freeze_release = mp4_GetBit(pInfo);
  685. VOPSH->source_format = mp4_GetBits9(pInfo, 3);
  686. if (VOPSH->source_format == 0 || VOPSH->source_format > 5) {
  687. mp4_Error("Error: Bad value for VideoPlaneWithShortHeader.source_format");
  688. return MP4_STATUS_PARSE_ERROR;
  689. }
  690. VOPSH->picture_coding_type = mp4_GetBit(pInfo);
  691. VOP->coding_type = VOPSH->picture_coding_type;
  692. code = mp4_GetBits9(pInfo, 4); // four_reserved_zero_bits
  693. VOPSH->vop_quant = mp4_GetBits9(pInfo, 5);
  694. code = mp4_GetBit(pInfo); // zero_bit
  695. for (;;) {
  696. code = mp4_GetBit(pInfo); // pei
  697. if (!code)
  698. break;
  699. code = mp4_GetBits9(pInfo, 8); // psupp
  700. }
  701. return MP4_STATUS_OK;
  702. }
  703. VOP->coding_type = mp4_GetBits9(pInfo, 2);
  704. if (((VOP->coding_type != MP4_VOP_TYPE_I) && (pInfo->noPVOPs)) || ((VOP->coding_type == MP4_VOP_TYPE_B) && (pInfo->noBVOPs))) {
  705. mp4_Error("Error: Bad vop_coding_type");
  706. return MP4_STATUS_PARSE_ERROR;
  707. }
  708. VOP->modulo_time_base = 0;
  709. do {
  710. code = mp4_GetBit(pInfo);
  711. VOP->modulo_time_base += code;
  712. } while (code);
  713. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  714. if (VOL->vop_time_increment_resolution_bits != 0 ) {
  715. VOP->time_increment = mp4_GetBits(pInfo, VOL->vop_time_increment_resolution_bits);
  716. }
  717. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  718. VOP->coded = mp4_GetBit(pInfo);
  719. if (!VOP->coded)
  720. return MP4_STATUS_OK;
  721. if (VOL->newpred_enable) {
  722. int vop_id_length = VOL->vop_time_increment_resolution_bits + 3;
  723. if (vop_id_length > 15)
  724. vop_id_length = 15;
  725. VOP->vop_id = mp4_GetBits(pInfo, vop_id_length);
  726. VOP->vop_id_for_prediction_indication = mp4_GetBit(pInfo);
  727. if (VOP->vop_id_for_prediction_indication)
  728. VOP->vop_id_for_prediction = mp4_GetBits(pInfo, vop_id_length);
  729. if (!mp4_GetMarkerBit(pInfo))
  730. return MP4_STATUS_PARSE_ERROR;
  731. }
  732. if (VOL->shape != MP4_SHAPE_TYPE_BINARYONLY && (VOP->coding_type == MP4_VOP_TYPE_P ||
  733. (VOP->coding_type == MP4_VOP_TYPE_S && VOL->sprite_enable == MP4_SPRITE_GMC)))
  734. VOP->rounding_type = mp4_GetBit(pInfo);
  735. if (VOL->reduced_resolution_vop_enable && VOL->shape == MP4_SHAPE_TYPE_RECTANGULAR &&
  736. (VOP->coding_type == MP4_VOP_TYPE_I || VOP->coding_type == MP4_VOP_TYPE_P)) {
  737. VOP->reduced_resolution = mp4_GetBit(pInfo);
  738. if (VOP->reduced_resolution) {
  739. mp4_Error("Error: Reduced Resolution VOP is not supported");
  740. return MP4_STATUS_PARSE_ERROR;
  741. }
  742. }
  743. if (VOL->shape != MP4_SHAPE_TYPE_RECTANGULAR) {
  744. if (!(VOL->sprite_enable == MP4_SPRITE_STATIC && VOP->coding_type == MP4_VOP_TYPE_I)) {
  745. VOP->vop_width = mp4_GetBits(pInfo, 13);
  746. if (VOP->vop_width == 0) {
  747. mp4_Error("Error: wrong value of vop_width");
  748. return MP4_STATUS_PARSE_ERROR;
  749. }
  750. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  751. VOP->vop_height = mp4_GetBits(pInfo, 13);
  752. if (VOP->vop_height == 0) {
  753. mp4_Error("Error: wrong value of vop_height");
  754. return MP4_STATUS_PARSE_ERROR;
  755. }
  756. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  757. VOP->vop_horizontal_mc_spatial_ref = mp4_GetBits(pInfo, 13);
  758. VOP->vop_horizontal_mc_spatial_ref <<= (32 - 13);
  759. VOP->vop_horizontal_mc_spatial_ref >>= (32 - 13);
  760. if (VOP->vop_horizontal_mc_spatial_ref & 1) {
  761. mp4_Error("Error: vop_horizontal_mc_spatial_ref must be divisible by 2");
  762. return MP4_STATUS_PARSE_ERROR;
  763. }
  764. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  765. VOP->vop_vertical_mc_spatial_ref = mp4_GetBits(pInfo, 13);
  766. VOP->vop_vertical_mc_spatial_ref <<= (32 - 13);
  767. VOP->vop_vertical_mc_spatial_ref >>= (32 - 13);
  768. if (VOP->vop_vertical_mc_spatial_ref & 1) {
  769. mp4_Error("Error: vop_vertical_mc_spatial_ref must be divisible by 2");
  770. return MP4_STATUS_PARSE_ERROR;
  771. }
  772. if (!mp4_GetMarkerBit(pInfo)) return MP4_STATUS_PARSE_ERROR;
  773. }
  774. //f if ((VOL->shape != MP4_SHAPE_TYPE_BINARYONLY) && VOL->scalability && enhancement_type)
  775. //f background_composition = mp4_GetBit(pInfo);
  776. VOP->change_conv_ratio_disable = mp4_GetBit(pInfo);
  777. VOP->vop_constant_alpha = mp4_GetBit(pInfo);
  778. if (VOP->vop_constant_alpha)
  779. VOP->vop_constant_alpha_value = mp4_GetBits9(pInfo, 8);
  780. else
  781. VOP->vop_constant_alpha_value = 255;
  782. }
  783. if (VOL->shape != MP4_SHAPE_TYPE_BINARYONLY) {
  784. if (!VOL->complexity_estimation_disable) {
  785. if (VOL->ComplexityEstimation.estimation_method == 0) {
  786. if (VOP->coding_type == MP4_VOP_TYPE_I) {
  787. if (VOL->ComplexityEstimation.opaque) VOL->ComplexityEstimation.dcecs_opaque = mp4_GetBits9(pInfo, 8);
  788. if (VOL->ComplexityEstimation.transparent) VOL->ComplexityEstimation.dcecs_transparent = mp4_GetBits9(pInfo, 8);
  789. if (VOL->ComplexityEstimation.intra_cae) VOL->ComplexityEstimation.dcecs_intra_cae = mp4_GetBits9(pInfo, 8);
  790. if (VOL->ComplexityEstimation.inter_cae) VOL->ComplexityEstimation.dcecs_inter_cae = mp4_GetBits9(pInfo, 8);
  791. if (VOL->ComplexityEstimation.no_update) VOL->ComplexityEstimation.dcecs_no_update = mp4_GetBits9(pInfo, 8);
  792. if (VOL->ComplexityEstimation.upsampling) VOL->ComplexityEstimation.dcecs_upsampling = mp4_GetBits9(pInfo, 8);
  793. if (VOL->ComplexityEstimation.intra_blocks) VOL->ComplexityEstimation.dcecs_intra_blocks = mp4_GetBits9(pInfo, 8);
  794. if (VOL->ComplexityEstimation.not_coded_blocks) VOL->ComplexityEstimation.dcecs_not_coded_blocks = mp4_GetBits9(pInfo, 8);
  795. if (VOL->ComplexityEstimation.dct_coefs) VOL->ComplexityEstimation.dcecs_dct_coefs = mp4_GetBits9(pInfo, 8);
  796. if (VOL->ComplexityEstimation.dct_lines) VOL->ComplexityEstimation.dcecs_dct_lines = mp4_GetBits9(pInfo, 8);
  797. if (VOL->ComplexityEstimation.vlc_symbols) VOL->ComplexityEstimation.dcecs_vlc_symbols = mp4_GetBits9(pInfo, 8);
  798. if (VOL->ComplexityEstimation.vlc_bits) VOL->ComplexityEstimation.dcecs_vlc_bits = mp4_GetBits9(pInfo, 4);
  799. if (VOL->ComplexityEstimation.sadct) VOL->ComplexityEstimation.dcecs_sadct = mp4_GetBits9(pInfo, 8);
  800. }
  801. if (VOP->coding_type == MP4_VOP_TYPE_P) {
  802. if (VOL->ComplexityEstimation.opaque) VOL->ComplexityEstimation.dcecs_opaque = mp4_GetBits9(pInfo, 8);
  803. if (VOL->ComplexityEstimation.transparent) VOL->ComplexityEstimation.dcecs_transparent = mp4_GetBits9(pInfo, 8);
  804. if (VOL->ComplexityEstimation.intra_cae) VOL->ComplexityEstimation.dcecs_intra_cae = mp4_GetBits9(pInfo, 8);
  805. if (VOL->ComplexityEstimation.inter_cae) VOL->ComplexityEstimation.dcecs_inter_cae = mp4_GetBits9(pInfo, 8);
  806. if (VOL->ComplexityEstimation.no_update) VOL->ComplexityEstimation.dcecs_no_update = mp4_GetBits9(pInfo, 8);
  807. if (VOL->ComplexityEstimation.upsampling) VOL->ComplexityEstimation.dcecs_upsampling = mp4_GetBits9(pInfo, 8);
  808. if (VOL->ComplexityEstimation.intra_blocks) VOL->ComplexityEstimation.dcecs_intra_blocks = mp4_GetBits9(pInfo, 8);
  809. if (VOL->ComplexityEstimation.not_coded_blocks) VOL->ComplexityEstimation.dcecs_not_coded_blocks = mp4_GetBits9(pInfo, 8);
  810. if (VOL->ComplexityEstimation.dct_coefs) VOL->ComplexityEstimation.dcecs_dct_coefs = mp4_GetBits9(pInfo, 8);
  811. if (VOL->ComplexityEstimation.dct_lines) VOL->ComplexityEstimation.dcecs_dct_lines = mp4_GetBits9(pInfo, 8);
  812. if (VOL->ComplexityEstimation.vlc_symbols) VOL->ComplexityEstimation.dcecs_vlc_symbols = mp4_GetBits9(pInfo, 8);
  813. if (VOL->ComplexityEstimation.vlc_bits) VOL->ComplexityEstimation.dcecs_vlc_bits = mp4_GetBits9(pInfo, 4);
  814. if (VOL->ComplexityEstimation.inter_blocks) VOL->ComplexityEstimation.dcecs_inter_blocks = mp4_GetBits9(pInfo, 8);
  815. if (VOL->ComplexityEstimation.inter4v_blocks) VOL->ComplexityEstimation.dcecs_inter4v_blocks = mp4_GetBits9(pInfo, 8);
  816. if (VOL->ComplexityEstimation.apm) VOL->ComplexityEstimation.dcecs_apm = mp4_GetBits9(pInfo, 8);
  817. if (VOL->ComplexityEstimation.npm) VOL->ComplexityEstimation.dcecs_npm = mp4_GetBits9(pInfo, 8);
  818. if (VOL->ComplexityEstimation.forw_back_mc_q) VOL->ComplexityEstimation.dcecs_forw_back_mc_q = mp4_GetBits9(pInfo, 8);
  819. if (VOL->ComplexityEstimation.halfpel2) VOL->ComplexityEstimation.dcecs_halfpel2 = mp4_GetBits9(pInfo, 8);
  820. if (VOL->ComplexityEstimation.halfpel4) VOL->ComplexityEstimation.dcecs_halfpel4 = mp4_GetBits9(pInfo, 8);
  821. if (VOL->ComplexityEstimation.sadct) VOL->ComplexityEstimation.dcecs_sadct = mp4_GetBits9(pInfo, 8);
  822. if (VOL->ComplexityEstimation.quarterpel) VOL->ComplexityEstimation.dcecs_quarterpel = mp4_GetBits9(pInfo, 8);
  823. }
  824. if (VOP->coding_type == MP4_VOP_TYPE_B) {
  825. if (VOL->ComplexityEstimation.opaque) VOL->ComplexityEstimation.dcecs_opaque = mp4_GetBits9(pInfo, 8);
  826. if (VOL->ComplexityEstimation.transparent) VOL->ComplexityEstimation.dcecs_transparent = mp4_GetBits9(pInfo, 8);
  827. if (VOL->ComplexityEstimation.intra_cae) VOL->ComplexityEstimation.dcecs_intra_cae = mp4_GetBits9(pInfo, 8);
  828. if (VOL->ComplexityEstimation.inter_cae) VOL->ComplexityEstimation.dcecs_inter_cae = mp4_GetBits9(pInfo, 8);
  829. if (VOL->ComplexityEstimation.no_update) VOL->ComplexityEstimation.dcecs_no_update = mp4_GetBits9(pInfo, 8);
  830. if (VOL->ComplexityEstimation.upsampling) VOL->ComplexityEstimation.dcecs_upsampling = mp4_GetBits9(pInfo, 8);
  831. if (VOL->ComplexityEstimation.intra_blocks) VOL->ComplexityEstimation.dcecs_intra_blocks = mp4_GetBits9(pInfo, 8);
  832. if (VOL->ComplexityEstimation.not_coded_blocks) VOL->ComplexityEstimation.dcecs_not_coded_blocks = mp4_GetBits9(pInfo, 8);
  833. if (VOL->ComplexityEstimation.dct_coefs) VOL->ComplexityEstimation.dcecs_dct_coefs = mp4_GetBits9(pInfo, 8);
  834. if (VOL->ComplexityEstimation.dct_lines) VOL->ComplexityEstimation.dcecs_dct_lines = mp4_GetBits9(pInfo, 8);
  835. if (VOL->ComplexityEstimation.vlc_symbols) VOL->ComplexityEstimation.dcecs_vlc_symbols = mp4_GetBits9(pInfo, 8);
  836. if (VOL->ComplexityEstimation.vlc_bits) VOL->ComplexityEstimation.dcecs_vlc_bits = mp4_GetBits9(pInfo, 4);
  837. if (VOL->ComplexityEstimation.inter_blocks) VOL->ComplexityEstimation.dcecs_inter_blocks = mp4_GetBits9(pInfo, 8);
  838. if (VOL->ComplexityEstimation.inter4v_blocks) VOL->ComplexityEstimation.dcecs_inter4v_blocks = mp4_GetBits9(pInfo, 8);
  839. if (VOL->ComplexityEstimation.apm) VOL->ComplexityEstimation.dcecs_apm = mp4_GetBits9(pInfo, 8);
  840. if (VOL->ComplexityEstimation.npm) VOL->ComplexityEstimation.dcecs_npm = mp4_GetBits9(pInfo, 8);
  841. if (VOL->ComplexityEstimation.forw_back_mc_q) VOL->ComplexityEstimation.dcecs_forw_back_mc_q = mp4_GetBits9(pInfo, 8);
  842. if (VOL->ComplexityEstimation.halfpel2) VOL->ComplexityEstimation.dcecs_halfpel2 = mp4_GetBits9(pInfo, 8);
  843. if (VOL->ComplexityEstimation.halfpel4) VOL->ComplexityEstimation.dcecs_halfpel4 = mp4_GetBits9(pInfo, 8);
  844. if (VOL->ComplexityEstimation.interpolate_mc_q) VOL->ComplexityEstimation.dcecs_interpolate_mc_q = mp4_GetBits9(pInfo, 8);
  845. if (VOL->ComplexityEstimation.sadct) VOL->ComplexityEstimation.dcecs_sadct = mp4_GetBits9(pInfo, 8);
  846. if (VOL->ComplexityEstimation.quarterpel) VOL->ComplexityEstimation.dcecs_quarterpel = mp4_GetBits9(pInfo, 8);
  847. }
  848. if (VOP->coding_type == MP4_VOP_TYPE_S && VOL->sprite_enable == MP4_SPRITE_STATIC) {
  849. if (VOL->ComplexityEstimation.intra_blocks) VOL->ComplexityEstimation.dcecs_intra_blocks = mp4_GetBits9(pInfo, 8);
  850. if (VOL->ComplexityEstimation.not_coded_blocks) VOL->ComplexityEstimation.dcecs_not_coded_blocks = mp4_GetBits9(pInfo, 8);
  851. if (VOL->ComplexityEstimation.dct_coefs) VOL->ComplexityEstimation.dcecs_dct_coefs = mp4_GetBits9(pInfo, 8);
  852. if (VOL->ComplexityEstimation.dct_lines) VOL->ComplexityEstimation.dcecs_dct_lines = mp4_GetBits9(pInfo, 8);
  853. if (VOL->ComplexityEstimation.vlc_symbols) VOL->ComplexityEstimation.dcecs_vlc_symbols = mp4_GetBits9(pInfo, 8);
  854. if (VOL->ComplexityEstimation.vlc_bits) VOL->ComplexityEstimation.dcecs_vlc_bits = mp4_GetBits9(pInfo, 4);
  855. if (VOL->ComplexityEstimation.inter_blocks) VOL->ComplexityEstimation.dcecs_inter_blocks = mp4_GetBits9(pInfo, 8);
  856. if (VOL->ComplexityEstimation.inter4v_blocks) VOL->ComplexityEstimation.dcecs_inter4v_blocks = mp4_GetBits(pInfo, 8);
  857. if (VOL->ComplexityEstimation.apm) VOL->ComplexityEstimation.dcecs_apm = mp4_GetBits9(pInfo, 8);
  858. if (VOL->ComplexityEstimation.npm) VOL->ComplexityEstimation.dcecs_npm = mp4_GetBits9(pInfo, 8);
  859. if (VOL->ComplexityEstimation.forw_back_mc_q) VOL->ComplexityEstimation.dcecs_forw_back_mc_q = mp4_GetBits9(pInfo, 8);
  860. if (VOL->ComplexityEstimation.halfpel2) VOL->ComplexityEstimation.dcecs_halfpel2 = mp4_GetBits9(pInfo, 8);
  861. if (VOL->ComplexityEstimation.halfpel4) VOL->ComplexityEstimation.dcecs_halfpel4 = mp4_GetBits(pInfo, 8);
  862. if (VOL->ComplexityEstimation.interpolate_mc_q) VOL->ComplexityEstimation.dcecs_interpolate_mc_q = mp4_GetBits9(pInfo, 8);
  863. }
  864. }
  865. }
  866. VOP->intra_dc_vlc_thr = mp4_GetBits9(pInfo, 3);
  867. if (VOL->interlaced) {
  868. VOP->top_field_first = mp4_GetBit(pInfo);
  869. VOP->alternate_vertical_scan_flag = mp4_GetBit(pInfo);
  870. }
  871. }
  872. if ((VOL->sprite_enable == MP4_SPRITE_STATIC || VOL->sprite_enable == MP4_SPRITE_GMC) && VOP->coding_type == MP4_VOP_TYPE_S) {
  873. if (VOL->sprite_warping_points > 0)
  874. if (mp4_Sprite_Trajectory(pInfo) != MP4_STATUS_OK)
  875. return MP4_STATUS_PARSE_ERROR;
  876. if (VOL->sprite_brightness_change) {
  877. code = mp4_ShowBits9(pInfo, 4);
  878. if (code == 15) {
  879. mp4_FlushBits(pInfo, 4);
  880. VOP->brightness_change_factor = 625 + mp4_GetBits(pInfo, 10);
  881. } else if (code == 14) {
  882. mp4_FlushBits(pInfo, 4);
  883. VOP->brightness_change_factor = 113 + mp4_GetBits9(pInfo, 9);
  884. } else if (code >= 12) {
  885. mp4_FlushBits(pInfo, 3);
  886. code = mp4_GetBits9(pInfo, 7);
  887. VOP->brightness_change_factor = (code < 64) ? code - 112 : code - 15;
  888. } else if (code >= 8) {
  889. mp4_FlushBits(pInfo, 2);
  890. code = mp4_GetBits9(pInfo, 6);
  891. VOP->brightness_change_factor = (code < 32) ? code - 48 : code - 15;
  892. } else {
  893. mp4_FlushBits(pInfo, 1);
  894. code = mp4_GetBits9(pInfo, 5);
  895. VOP->brightness_change_factor = (code < 16) ? code - 16 : code - 15;
  896. }
  897. } else
  898. VOP->brightness_change_factor = 0;
  899. if (VOL->sprite_enable == MP4_SPRITE_STATIC)
  900. return MP4_STATUS_OK;
  901. }
  902. if (VOL->shape != MP4_SHAPE_TYPE_BINARYONLY) {
  903. VOP->quant = mp4_GetBits9(pInfo, VOL->quant_precision);
  904. if (VOL->shape == MP4_SHAPE_TYPE_GRAYSCALE) {
  905. int32_t ac, i;
  906. ac = mp4_aux_comp_count[VOL->shape_extension];
  907. for (i = 0; i < ac; i ++)
  908. VOP->alpha_quant[i] = mp4_GetBits9(pInfo, 6);
  909. }
  910. if (VOP->coding_type != MP4_VOP_TYPE_I) {
  911. VOP->fcode_forward = mp4_GetBits9(pInfo, 3);
  912. if (VOP->fcode_forward == 0) {
  913. mp4_Error("Error: vop_fcode_forward == 0");
  914. return MP4_STATUS_PARSE_ERROR;
  915. }
  916. }
  917. if (VOP->coding_type == MP4_VOP_TYPE_B) {
  918. VOP->fcode_backward = mp4_GetBits9(pInfo, 3);
  919. if (VOP->fcode_backward == 0) {
  920. mp4_Error("Error: vop_fcode_backward == 0");
  921. return MP4_STATUS_PARSE_ERROR;
  922. }
  923. }
  924. if (!VOL->scalability) {
  925. if (VOL->shape != MP4_SHAPE_TYPE_RECTANGULAR && VOP->coding_type != MP4_VOP_TYPE_I)
  926. VOP->shape_coding_type = mp4_GetBit(pInfo);
  927. } else {
  928. //f if (VOL->enhancement_type) {
  929. //f VOP->load_backward_shape = mp4_GetBit(pInfo);
  930. //f if (VOP->load_backward_shape) {
  931. //f shape
  932. //f }
  933. //f }
  934. VOP->ref_select_code = mp4_GetBits9(pInfo, 2);
  935. }
  936. }
  937. return MP4_STATUS_OK;
  938. }
  939. /*
  940. // decode VideoPacket
  941. */
  942. mp4_Status mp4_CheckDecodeVideoPacket(mp4_Info* pInfo, int32_t *found)
  943. {
  944. uint32_t code;
  945. int32_t header_extension_code, rml;
  946. mp4_VideoObject *VOL = &pInfo->VisualObject.VideoObject;
  947. mp4_VideoObjectPlane *VOP = &pInfo->VisualObject.VideoObject.VideoObjectPlane;
  948. *found = 0;
  949. // check stuffing bits
  950. if (mp4_ShowBit(pInfo) != 0)
  951. return MP4_STATUS_OK;
  952. if (mp4_ShowBits9(pInfo, 8 - pInfo->bitoff) != (uint32_t)((1 << (7 - pInfo->bitoff)) - 1))
  953. return MP4_STATUS_OK;
  954. if (VOP->coding_type == MP4_VOP_TYPE_I)
  955. rml = 17;
  956. else if (VOP->coding_type == MP4_VOP_TYPE_B)
  957. rml = 16 + IPP_MAX(VOP->fcode_forward, VOP->fcode_backward);
  958. else
  959. rml = 16 + VOP->fcode_forward;
  960. code = (pInfo->bufptr[1] << 16) | (pInfo->bufptr[2] << 8) | pInfo->bufptr[3];
  961. code >>= 24 - rml;
  962. if (code == 1) { // is resync_marker
  963. mp4_FlushBits(pInfo, rml + 8 - pInfo->bitoff);
  964. header_extension_code = 0;
  965. if (VOL->shape != MP4_SHAPE_TYPE_RECTANGULAR) {
  966. header_extension_code = mp4_GetBit(pInfo);
  967. if (header_extension_code && !(VOL->sprite_enable == MP4_SPRITE_STATIC && VOP->coding_type == MP4_VOP_TYPE_I)) {
  968. VOP->vop_width = mp4_GetBits(pInfo, 13);
  969. if (!mp4_GetBit(pInfo))
  970. if (pInfo->stopOnErr)
  971. goto Err;
  972. VOP->vop_height = mp4_GetBits(pInfo, 13);
  973. if (!mp4_GetBit(pInfo))
  974. if (pInfo->stopOnErr)
  975. goto Err;
  976. VOP->vop_horizontal_mc_spatial_ref = mp4_GetBits(pInfo, 13);
  977. if (!mp4_GetBit(pInfo))
  978. if (pInfo->stopOnErr)
  979. goto Err;
  980. VOP->vop_vertical_mc_spatial_ref = mp4_GetBits(pInfo, 13);
  981. if (!mp4_GetBit(pInfo))
  982. if (pInfo->stopOnErr)
  983. goto Err;
  984. }
  985. }
  986. pInfo->VisualObject.VideoObject.VideoObjectPlane.macroblock_num = mp4_GetBits(pInfo, pInfo->VisualObject.VideoObject.mbns);
  987. if (pInfo->VisualObject.VideoObject.VideoObjectPlane.macroblock_num >= pInfo->VisualObject.VideoObject.MacroBlockPerVOP)
  988. goto Err;
  989. if (VOL->shape != MP4_SHAPE_TYPE_BINARYONLY) {
  990. pInfo->VisualObject.VideoObject.VideoObjectPlane.quant_scale = mp4_GetBits9(pInfo, VOL->quant_precision); // quant_scale
  991. }
  992. if (VOL->shape == MP4_SHAPE_TYPE_RECTANGULAR) {
  993. header_extension_code = mp4_GetBit(pInfo);
  994. }
  995. if (header_extension_code) {
  996. //f ignore modulo_time_base
  997. do {
  998. code = mp4_GetBit(pInfo);
  999. } while (code);
  1000. if (!mp4_GetBit(pInfo))
  1001. if (pInfo->stopOnErr)
  1002. goto Err;
  1003. //f ignore vop_time_increment
  1004. if (VOL->vop_time_increment_resolution_bits != 0 ) {
  1005. code = mp4_GetBits(pInfo, VOL->vop_time_increment_resolution_bits);
  1006. }
  1007. if (!mp4_GetBit(pInfo))
  1008. if (pInfo->stopOnErr)
  1009. goto Err;
  1010. //f ignore vop_coding_type
  1011. code = mp4_GetBits9(pInfo, 2);
  1012. if (VOL->shape != MP4_SHAPE_TYPE_RECTANGULAR) {
  1013. VOP->change_conv_ratio_disable = mp4_GetBit(pInfo);
  1014. if (VOP->coding_type != MP4_VOP_TYPE_I)
  1015. VOP->shape_coding_type = mp4_GetBit(pInfo);
  1016. }
  1017. if (VOL->shape != MP4_SHAPE_TYPE_BINARYONLY) {
  1018. //f ignore intra_dc_vlc_thr
  1019. code = mp4_GetBits9(pInfo, 3);
  1020. if (VOL->sprite_enable == MP4_SPRITE_GMC && VOP->coding_type == MP4_VOP_TYPE_S && VOL->sprite_warping_points > 0)
  1021. if (mp4_Sprite_Trajectory(pInfo) != MP4_STATUS_OK)
  1022. if (pInfo->stopOnErr)
  1023. goto Err;
  1024. //f ignore vop_reduced_resolution
  1025. if (VOL->reduced_resolution_vop_enable && VOL->shape == MP4_SHAPE_TYPE_RECTANGULAR &&
  1026. (VOP->coding_type == MP4_VOP_TYPE_I || VOP->coding_type == MP4_VOP_TYPE_P))
  1027. code = mp4_GetBit(pInfo);
  1028. if (VOP->coding_type != MP4_VOP_TYPE_I)
  1029. VOP->fcode_forward = mp4_GetBits9(pInfo, 3);
  1030. if (VOP->coding_type == MP4_VOP_TYPE_B)
  1031. VOP->fcode_backward = mp4_GetBits9(pInfo, 3);
  1032. }
  1033. }
  1034. if (VOL->newpred_enable) {
  1035. int vop_id_length = VOL->vop_time_increment_resolution_bits + 3;
  1036. if (vop_id_length > 15)
  1037. vop_id_length = 15;
  1038. VOP->vop_id = mp4_GetBits(pInfo, vop_id_length);
  1039. VOP->vop_id_for_prediction_indication = mp4_GetBit(pInfo);
  1040. if (VOP->vop_id_for_prediction_indication)
  1041. VOP->vop_id_for_prediction = mp4_GetBits(pInfo, vop_id_length);
  1042. if (!mp4_GetMarkerBit(pInfo))
  1043. if (pInfo->stopOnErr)
  1044. goto Err;
  1045. }
  1046. *found = 1;
  1047. return MP4_STATUS_OK;
  1048. }
  1049. return MP4_STATUS_OK;
  1050. Err:
  1051. mp4_Error("Error: decoding Video Packet Header");
  1052. return MP4_STATUS_PARSE_ERROR;
  1053. }
  1054. int32_t mp4_CheckDecodeGOB_SVH(mp4_Info* pInfo)
  1055. {
  1056. int32_t code;
  1057. pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.gob_number ++;
  1058. pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.gob_header_empty = 1;
  1059. code = mp4_ShowBits(pInfo, 17); /* check gob_resync_marker */
  1060. if (code != 1) {
  1061. code = mp4_ShowBitsAlign(pInfo, 17); /* check next aligned bits are gob_resync_marker */
  1062. if (code == 1)
  1063. mp4_AlignBits(pInfo);
  1064. }
  1065. if (code == 1) {
  1066. mp4_FlushBits(pInfo, 17);
  1067. pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.gob_header_empty = 0;
  1068. code = mp4_GetBits9(pInfo, 5); /* gob_number */
  1069. pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.gob_frame_id = mp4_GetBits9(pInfo, 2);
  1070. pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.quant_scale = mp4_GetBits9(pInfo, 5);
  1071. // check gob_number is valid
  1072. //if (code > pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.gob_number && code <= pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.num_gobs_in_vop)
  1073. if (code <= pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.num_gobs_in_vop)
  1074. pInfo->VisualObject.VideoObject.VideoObjectPlaneH263.gob_number = code;
  1075. else {
  1076. mp4_Error("Error: bad gob_number in GOB header");
  1077. return MP4_STATUS_ERROR;
  1078. }
  1079. }
  1080. return MP4_STATUS_OK;
  1081. }