PageRenderTime 30ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/H264Dec/source/h264bsd_nal_unit.c

http://github.com/mbebenita/Broadway
C | 117 lines | 32 code | 19 blank | 66 comment | 27 complexity | 2b2dc8865030a1f72b3778d40f005f12 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /*
  2. * Copyright (C) 2009 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*------------------------------------------------------------------------------
  17. Table of contents
  18. 1. Include headers
  19. 2. External compiler flags
  20. 3. Module defines
  21. 4. Local function prototypes
  22. 5. Functions
  23. h264bsdDecodeNalUnit
  24. ------------------------------------------------------------------------------*/
  25. /*------------------------------------------------------------------------------
  26. 1. Include headers
  27. ------------------------------------------------------------------------------*/
  28. #include "h264bsd_nal_unit.h"
  29. #include "h264bsd_util.h"
  30. /*------------------------------------------------------------------------------
  31. 2. External compiler flags
  32. --------------------------------------------------------------------------------
  33. --------------------------------------------------------------------------------
  34. 3. Module defines
  35. ------------------------------------------------------------------------------*/
  36. /*------------------------------------------------------------------------------
  37. 4. Local function prototypes
  38. ------------------------------------------------------------------------------*/
  39. /*------------------------------------------------------------------------------
  40. Function name: h264bsdDecodeNalUnit
  41. Functional description:
  42. Decode NAL unit header information
  43. Inputs:
  44. pStrmData pointer to stream data structure
  45. Outputs:
  46. pNalUnit NAL unit header information is stored here
  47. Returns:
  48. HANTRO_OK success
  49. HANTRO_NOK invalid NAL unit header information
  50. ------------------------------------------------------------------------------*/
  51. u32 h264bsdDecodeNalUnit(strmData_t *pStrmData, nalUnit_t *pNalUnit)
  52. {
  53. /* Variables */
  54. u32 tmp;
  55. /* Code */
  56. ASSERT(pStrmData);
  57. ASSERT(pNalUnit);
  58. ASSERT(pStrmData->bitPosInWord == 0);
  59. /* forbidden_zero_bit (not checked to be zero, errors ignored) */
  60. tmp = h264bsdGetBits(pStrmData, 1);
  61. /* Assuming that NAL unit starts from byte boundary ­> don't have to check
  62. * following 7 bits for END_OF_STREAM */
  63. if (tmp == END_OF_STREAM)
  64. return(HANTRO_NOK);
  65. tmp = h264bsdGetBits(pStrmData, 2);
  66. pNalUnit->nalRefIdc = tmp;
  67. tmp = h264bsdGetBits(pStrmData, 5);
  68. pNalUnit->nalUnitType = (nalUnitType_e)tmp;
  69. /* data partitioning NAL units not supported */
  70. if ( (tmp == 2) || (tmp == 3) || (tmp == 4) )
  71. {
  72. return(HANTRO_NOK);
  73. }
  74. /* nal_ref_idc shall not be zero for these nal_unit_types */
  75. if ( ( (tmp == NAL_SEQ_PARAM_SET) || (tmp == NAL_PIC_PARAM_SET) ||
  76. (tmp == NAL_CODED_SLICE_IDR) ) && (pNalUnit->nalRefIdc == 0) )
  77. {
  78. return(HANTRO_NOK);
  79. }
  80. /* nal_ref_idc shall be zero for these nal_unit_types */
  81. else if ( ( (tmp == NAL_SEI) || (tmp == NAL_ACCESS_UNIT_DELIMITER) ||
  82. (tmp == NAL_END_OF_SEQUENCE) || (tmp == NAL_END_OF_STREAM) ||
  83. (tmp == NAL_FILLER_DATA) ) && (pNalUnit->nalRefIdc != 0) )
  84. {
  85. return(HANTRO_NOK);
  86. }
  87. return(HANTRO_OK);
  88. }