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.

125 lines
4.1KB

  1. /*
  2. * HEVC Supplementary Enhancement Information messages
  3. *
  4. * Copyright (C) 2012 - 2013 Guillaume Martres
  5. * Copyright (C) 2012 - 2013 Gildas Cocherel
  6. * Copyright (C) 2013 Vittorio Giovara
  7. *
  8. * This file is part of Libav.
  9. *
  10. * Libav is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * Libav is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with Libav; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include "golomb.h"
  25. #include "hevc.h"
  26. static void decode_nal_sei_decoded_picture_hash(HEVCContext *s,
  27. int payload_size)
  28. {
  29. int cIdx, i;
  30. GetBitContext *gb = &s->HEVClc.gb;
  31. uint8_t hash_type = get_bits(gb, 8);
  32. for (cIdx = 0; cIdx < 3; cIdx++) {
  33. if (hash_type == 0) {
  34. s->is_md5 = 1;
  35. for (i = 0; i < 16; i++)
  36. s->md5[cIdx][i] = get_bits(gb, 8);
  37. } else if (hash_type == 1) {
  38. // picture_crc = get_bits(gb, 16);
  39. skip_bits(gb, 16);
  40. } else if (hash_type == 2) {
  41. // picture_checksum = get_bits(gb, 32);
  42. skip_bits(gb, 32);
  43. }
  44. }
  45. }
  46. static void decode_nal_sei_frame_packing_arrangement(HEVCLocalContext *lc)
  47. {
  48. GetBitContext *gb = &lc->gb;
  49. int cancel, type, quincunx;
  50. get_ue_golomb(gb); // frame_packing_arrangement_id
  51. cancel = get_bits1(gb); // frame_packing_cancel_flag
  52. if (cancel == 0) {
  53. type = get_bits(gb, 7); // frame_packing_arrangement_type
  54. quincunx = get_bits1(gb); // quincunx_sampling_flag
  55. skip_bits(gb, 6); // content_interpretation_type
  56. // the following skips spatial_flipping_flag frame0_flipped_flag
  57. // field_views_flag current_frame_is_frame0_flag
  58. // frame0_self_contained_flag frame1_self_contained_flag
  59. skip_bits(gb, 6);
  60. if (quincunx == 0 && type != 5)
  61. skip_bits(gb, 16); // frame[01]_grid_position_[xy]
  62. skip_bits(gb, 8); // frame_packing_arrangement_reserved_byte
  63. skip_bits1(gb); // frame_packing_arrangement_persistance_flag
  64. }
  65. skip_bits1(gb); // upsampled_aspect_ratio_flag
  66. }
  67. static int decode_nal_sei_message(HEVCContext *s)
  68. {
  69. GetBitContext *gb = &s->HEVClc.gb;
  70. int payload_type = 0;
  71. int payload_size = 0;
  72. int byte = 0xFF;
  73. av_log(s->avctx, AV_LOG_DEBUG, "Decoding SEI\n");
  74. while (byte == 0xFF) {
  75. byte = get_bits(gb, 8);
  76. payload_type += byte;
  77. }
  78. byte = 0xFF;
  79. while (byte == 0xFF) {
  80. byte = get_bits(gb, 8);
  81. payload_size += byte;
  82. }
  83. if (s->nal_unit_type == NAL_SEI_PREFIX) {
  84. if (payload_type == 256)
  85. decode_nal_sei_decoded_picture_hash(s, payload_size);
  86. else if (payload_type == 45)
  87. decode_nal_sei_frame_packing_arrangement(&s->HEVClc);
  88. else {
  89. av_log(s->avctx, AV_LOG_DEBUG, "Skipped PREFIX SEI %d\n", payload_type);
  90. skip_bits(gb, 8 * payload_size);
  91. }
  92. } else { /* nal_unit_type == NAL_SEI_SUFFIX */
  93. if (payload_type == 132)
  94. decode_nal_sei_decoded_picture_hash(s, payload_size);
  95. else {
  96. av_log(s->avctx, AV_LOG_DEBUG, "Skipped SUFFIX SEI %d\n", payload_type);
  97. skip_bits(gb, 8 * payload_size);
  98. }
  99. }
  100. return 0;
  101. }
  102. static int more_rbsp_data(GetBitContext *gb)
  103. {
  104. return get_bits_left(gb) > 0 && show_bits(gb, 8) != 0x80;
  105. }
  106. int ff_hevc_decode_nal_sei(HEVCContext *s)
  107. {
  108. do {
  109. decode_nal_sei_message(s);
  110. } while (more_rbsp_data(&s->HEVClc.gb));
  111. return 0;
  112. }