You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
4.0KB

  1. /*
  2. * HEVC Parameter Set encoding
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "golomb.h"
  21. #include "hevc.h"
  22. #include "put_bits.h"
  23. static void write_ptl_layer(PutBitContext *pb, PTLCommon *ptl)
  24. {
  25. int i;
  26. put_bits(pb, 2, ptl->profile_space);
  27. put_bits(pb, 1, ptl->tier_flag);
  28. put_bits(pb, 5, ptl->profile_idc);
  29. for (i = 0; i < 32; i++)
  30. put_bits(pb, 1, ptl->profile_compatibility_flag[i]);
  31. put_bits(pb, 1, ptl->progressive_source_flag);
  32. put_bits(pb, 1, ptl->interlaced_source_flag);
  33. put_bits(pb, 1, ptl->non_packed_constraint_flag);
  34. put_bits(pb, 1, ptl->frame_only_constraint_flag);
  35. put_bits32(pb, 0); // reserved
  36. put_bits(pb, 12, 0); // reserved
  37. }
  38. static void write_ptl(PutBitContext *pb, PTL *ptl, int max_num_sub_layers)
  39. {
  40. int i;
  41. write_ptl_layer(pb, &ptl->general_ptl);
  42. put_bits(pb, 8, ptl->general_ptl.level_idc);
  43. for (i = 0; i < max_num_sub_layers - 1; i++) {
  44. put_bits(pb, 1, ptl->sub_layer_profile_present_flag[i]);
  45. put_bits(pb, 1, ptl->sub_layer_level_present_flag[i]);
  46. }
  47. if (max_num_sub_layers > 1)
  48. for (i = max_num_sub_layers - 1; i < 8; i++)
  49. put_bits(pb, 2, 0); // reserved
  50. for (i = 0; i < max_num_sub_layers - 1; i++) {
  51. if (ptl->sub_layer_profile_present_flag[i])
  52. write_ptl_layer(pb, &ptl->sub_layer_ptl[i]);
  53. if (ptl->sub_layer_level_present_flag[i])
  54. put_bits(pb, 8, ptl->sub_layer_ptl[i].level_idc);
  55. }
  56. }
  57. int ff_hevc_encode_nal_vps(HEVCVPS *vps, unsigned int id,
  58. uint8_t *buf, int buf_size)
  59. {
  60. PutBitContext pb;
  61. int i;
  62. init_put_bits(&pb, buf, buf_size);
  63. put_bits(&pb, 4, id);
  64. put_bits(&pb, 2, 3); // reserved
  65. put_bits(&pb, 6, vps->vps_max_layers - 1);
  66. put_bits(&pb, 3, vps->vps_max_sub_layers - 1);
  67. put_bits(&pb, 1, vps->vps_temporal_id_nesting_flag);
  68. put_bits(&pb, 16, 0xffff); // reserved
  69. write_ptl(&pb, &vps->ptl, vps->vps_max_sub_layers);
  70. put_bits(&pb, 1, vps->vps_sub_layer_ordering_info_present_flag);
  71. for (i = vps->vps_sub_layer_ordering_info_present_flag ? 0 : vps->vps_max_layers - 1;
  72. i < vps->vps_max_sub_layers; i++) {
  73. set_ue_golomb(&pb, vps->vps_max_dec_pic_buffering[i] - 1);
  74. set_ue_golomb(&pb, vps->vps_num_reorder_pics[i]);
  75. set_ue_golomb(&pb, vps->vps_max_latency_increase[i] + 1);
  76. }
  77. put_bits(&pb, 6, vps->vps_max_layer_id);
  78. set_ue_golomb(&pb, vps->vps_num_layer_sets - 1);
  79. // writing layer_id_included_flag not supported
  80. if (vps->vps_num_layer_sets > 1)
  81. return AVERROR_PATCHWELCOME;
  82. put_bits(&pb, 1, vps->vps_timing_info_present_flag);
  83. if (vps->vps_timing_info_present_flag) {
  84. put_bits32(&pb, vps->vps_num_units_in_tick);
  85. put_bits32(&pb, vps->vps_time_scale);
  86. put_bits(&pb, 1, vps->vps_poc_proportional_to_timing_flag);
  87. if (vps->vps_poc_proportional_to_timing_flag)
  88. set_ue_golomb(&pb, vps->vps_num_ticks_poc_diff_one - 1);
  89. // writing HRD parameters not supported
  90. if (vps->vps_num_hrd_parameters)
  91. return AVERROR_PATCHWELCOME;
  92. }
  93. put_bits(&pb, 1, 0); // extension flag
  94. put_bits(&pb, 1, 1); // stop bit
  95. avpriv_align_put_bits(&pb);
  96. return put_bits_count(&pb) / 8;
  97. }