H264NalUnit.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*------------------------------------------------------------------------------
  2. -- --
  3. -- This software is confidential and proprietary and may be used --
  4. -- only as expressly authorized by a licensing agreement from --
  5. -- --
  6. -- Hantro Products Oy. --
  7. -- --
  8. -- (C) COPYRIGHT 2006 HANTRO PRODUCTS OY --
  9. -- ALL RIGHTS RESERVED --
  10. -- --
  11. -- The entire notice above must be reproduced --
  12. -- on all copies and should not be removed. --
  13. -- --
  14. --------------------------------------------------------------------------------
  15. --
  16. -- Abstract : NAL unit handling
  17. --
  18. ------------------------------------------------------------------------------*/
  19. /*------------------------------------------------------------------------------
  20. 1. Include headers
  21. ------------------------------------------------------------------------------*/
  22. #include "enccommon.h"
  23. #include "H264NalUnit.h"
  24. /*------------------------------------------------------------------------------
  25. 2. External compiler flags
  26. --------------------------------------------------------------------------------
  27. --------------------------------------------------------------------------------
  28. 3. Module defines
  29. ------------------------------------------------------------------------------*/
  30. /*------------------------------------------------------------------------------
  31. 4. Local function prototypes
  32. ------------------------------------------------------------------------------*/
  33. /*------------------------------------------------------------------------------
  34. H264NalUnit
  35. ------------------------------------------------------------------------------*/
  36. void H264NalUnitHdr(stream_s * stream, i32 nalRefIdc, nalUnitType_e nalUnitType,
  37. true_e byteStream)
  38. {
  39. if(byteStream == ENCHW_YES)
  40. {
  41. H264PutBits(stream, 0, 8);
  42. COMMENT("BYTE STREAM: leadin_zero_8bits");
  43. H264PutBits(stream, 0, 8);
  44. COMMENT("BYTE STREAM: Start_code_prefix");
  45. H264PutBits(stream, 0, 8);
  46. COMMENT("BYTE STREAM: Start_code_prefix");
  47. H264PutBits(stream, 1, 8);
  48. COMMENT("BYTE STREAM: Start_code_prefix");
  49. }
  50. H264PutBits(stream, 0, 1);
  51. COMMENT("forbidden_zero_bit");
  52. H264PutBits(stream, nalRefIdc, 2);
  53. COMMENT("nal_ref_idc");
  54. H264PutBits(stream, (i32) nalUnitType, 5);
  55. COMMENT("nal_unit_type");
  56. stream->zeroBytes = 0; /* we start new counter for zero bytes */
  57. }
  58. /*------------------------------------------------------------------------------
  59. H264NalUnitHdrMvcExtension
  60. ------------------------------------------------------------------------------*/
  61. void H264NalUnitHdrMvcExtension(stream_s * stream, mvc_s * mvc)
  62. {
  63. H264PutBits(stream, !mvc->anchorPicFlag, 1);
  64. COMMENT("non_idr_flag");
  65. H264PutBits(stream, mvc->priorityId, 6);
  66. COMMENT("priority_id");
  67. H264PutBits(stream, mvc->viewId, 10);
  68. COMMENT("view_id");
  69. H264PutBits(stream, mvc->temporalId, 3);
  70. COMMENT("temporal_id");
  71. H264PutBits(stream, mvc->anchorPicFlag, 1);
  72. COMMENT("anchor_pic_flag");
  73. H264PutBits(stream, mvc->interViewFlag, 1);
  74. COMMENT("inter_view_flag");
  75. H264PutBits(stream, 1, 1);
  76. COMMENT("reserved_one_bit");
  77. stream->zeroBytes = 0; /* we start new counter for zero bytes */
  78. }
  79. /*------------------------------------------------------------------------------
  80. H264NalUnitTrailinBits
  81. ------------------------------------------------------------------------------*/
  82. void H264NalUnitTrailinBits(stream_s * stream, true_e byteStream)
  83. {
  84. H264RbspTrailingBits(stream);
  85. if(byteStream == ENCHW_YES)
  86. {
  87. #if 0 /* system model has removed this */
  88. H264PutBits(stream, 0, 8);
  89. COMMENT("BYTE STREAM: trailing_zero_8bits");
  90. #endif
  91. }
  92. return;
  93. }
  94. u32 H264FillerNALU(stream_s * sp, i32 cnt, true_e byteStream)
  95. {
  96. i32 i = cnt;
  97. u32 nal_size;
  98. nal_size = sp->byteCnt;
  99. ASSERT(sp != NULL);
  100. H264NalUnitHdr(sp, 0, FILLERDATA, byteStream);
  101. for(; i > 0; i--)
  102. {
  103. H264NalBits(sp, 0xFF, 8);
  104. COMMENT("filler ff_byte");
  105. }
  106. H264RbspTrailingBits(sp);
  107. nal_size = sp->byteCnt - nal_size;
  108. return nal_size;
  109. }