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.

308 lines
8.6KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. static int FUNC(filler_payload)
  19. (CodedBitstreamContext *ctx, RWContext *rw,
  20. SEIRawFillerPayload *current, SEIMessageState *state)
  21. {
  22. int err, i;
  23. HEADER("Filler Payload");
  24. #ifdef READ
  25. current->payload_size = state->payload_size;
  26. #endif
  27. for (i = 0; i < current->payload_size; i++)
  28. fixed(8, ff_byte, 0xff);
  29. return 0;
  30. }
  31. static int FUNC(user_data_registered)
  32. (CodedBitstreamContext *ctx, RWContext *rw,
  33. SEIRawUserDataRegistered *current, SEIMessageState *state)
  34. {
  35. int err, i, j;
  36. HEADER("User Data Registered ITU-T T.35");
  37. u(8, itu_t_t35_country_code, 0x00, 0xff);
  38. if (current->itu_t_t35_country_code != 0xff)
  39. i = 1;
  40. else {
  41. u(8, itu_t_t35_country_code_extension_byte, 0x00, 0xff);
  42. i = 2;
  43. }
  44. #ifdef READ
  45. if (state->payload_size < i) {
  46. av_log(ctx->log_ctx, AV_LOG_ERROR,
  47. "Invalid SEI user data registered payload.\n");
  48. return AVERROR_INVALIDDATA;
  49. }
  50. current->data_length = state->payload_size - i;
  51. #endif
  52. allocate(current->data, current->data_length);
  53. for (j = 0; j < current->data_length; j++)
  54. xu(8, itu_t_t35_payload_byte[], current->data[j], 0x00, 0xff, 1, i + j);
  55. return 0;
  56. }
  57. static int FUNC(user_data_unregistered)
  58. (CodedBitstreamContext *ctx, RWContext *rw,
  59. SEIRawUserDataUnregistered *current, SEIMessageState *state)
  60. {
  61. int err, i;
  62. HEADER("User Data Unregistered");
  63. #ifdef READ
  64. if (state->payload_size < 16) {
  65. av_log(ctx->log_ctx, AV_LOG_ERROR,
  66. "Invalid SEI user data unregistered payload.\n");
  67. return AVERROR_INVALIDDATA;
  68. }
  69. current->data_length = state->payload_size - 16;
  70. #endif
  71. for (i = 0; i < 16; i++)
  72. us(8, uuid_iso_iec_11578[i], 0x00, 0xff, 1, i);
  73. allocate(current->data, current->data_length);
  74. for (i = 0; i < current->data_length; i++)
  75. xu(8, user_data_payload_byte[i], current->data[i], 0x00, 0xff, 1, i);
  76. return 0;
  77. }
  78. static int FUNC(mastering_display_colour_volume)
  79. (CodedBitstreamContext *ctx, RWContext *rw,
  80. SEIRawMasteringDisplayColourVolume *current, SEIMessageState *state)
  81. {
  82. int err, c;
  83. HEADER("Mastering Display Colour Volume");
  84. for (c = 0; c < 3; c++) {
  85. ubs(16, display_primaries_x[c], 1, c);
  86. ubs(16, display_primaries_y[c], 1, c);
  87. }
  88. ub(16, white_point_x);
  89. ub(16, white_point_y);
  90. ub(32, max_display_mastering_luminance);
  91. ub(32, min_display_mastering_luminance);
  92. return 0;
  93. }
  94. static int FUNC(content_light_level_info)
  95. (CodedBitstreamContext *ctx, RWContext *rw,
  96. SEIRawContentLightLevelInfo *current, SEIMessageState *state)
  97. {
  98. int err;
  99. HEADER("Content Light Level Information");
  100. ub(16, max_content_light_level);
  101. ub(16, max_pic_average_light_level);
  102. return 0;
  103. }
  104. static int FUNC(alternative_transfer_characteristics)
  105. (CodedBitstreamContext *ctx, RWContext *rw,
  106. SEIRawAlternativeTransferCharacteristics *current,
  107. SEIMessageState *state)
  108. {
  109. int err;
  110. HEADER("Alternative Transfer Characteristics");
  111. ub(8, preferred_transfer_characteristics);
  112. return 0;
  113. }
  114. static int FUNC(message)(CodedBitstreamContext *ctx, RWContext *rw,
  115. SEIRawMessage *current)
  116. {
  117. const SEIMessageTypeDescriptor *desc;
  118. int err, i;
  119. desc = ff_cbs_sei_find_type(ctx, current->payload_type);
  120. if (desc) {
  121. SEIMessageState state = {
  122. .payload_type = current->payload_type,
  123. .payload_size = current->payload_size,
  124. .extension_present = current->extension_bit_length > 0,
  125. };
  126. int start_position, current_position, bits_written;
  127. #ifdef READ
  128. CHECK(ff_cbs_sei_alloc_message_payload(current, desc));
  129. #endif
  130. start_position = bit_position(rw);
  131. CHECK(desc->READWRITE(ctx, rw, current->payload, &state));
  132. current_position = bit_position(rw);
  133. bits_written = current_position - start_position;
  134. if (byte_alignment(rw) || state.extension_present ||
  135. bits_written < 8 * current->payload_size) {
  136. size_t bits_left;
  137. #ifdef READ
  138. GetBitContext tmp = *rw;
  139. int trailing_bits, trailing_zero_bits;
  140. bits_left = 8 * current->payload_size - bits_written;
  141. if (bits_left > 8)
  142. skip_bits_long(&tmp, bits_left - 8);
  143. trailing_bits = get_bits(&tmp, FFMIN(bits_left, 8));
  144. if (trailing_bits == 0) {
  145. // The trailing bits must contain a bit_equal_to_one, so
  146. // they can't all be zero.
  147. return AVERROR_INVALIDDATA;
  148. }
  149. trailing_zero_bits = ff_ctz(trailing_bits);
  150. current->extension_bit_length =
  151. bits_left - 1 - trailing_zero_bits;
  152. #endif
  153. if (current->extension_bit_length > 0) {
  154. allocate(current->extension_data,
  155. (current->extension_bit_length + 7) / 8);
  156. bits_left = current->extension_bit_length;
  157. for (i = 0; bits_left > 0; i++) {
  158. int length = FFMIN(bits_left, 8);
  159. xu(length, reserved_payload_extension_data,
  160. current->extension_data[i],
  161. 0, MAX_UINT_BITS(length), 0);
  162. bits_left -= length;
  163. }
  164. }
  165. fixed(1, bit_equal_to_one, 1);
  166. while (byte_alignment(rw))
  167. fixed(1, bit_equal_to_zero, 0);
  168. }
  169. #ifdef WRITE
  170. current->payload_size = (put_bits_count(rw) - start_position) / 8;
  171. #endif
  172. } else {
  173. uint8_t *data;
  174. allocate(current->payload, current->payload_size);
  175. data = current->payload;
  176. for (i = 0; i < current->payload_size; i++)
  177. xu(8, payload_byte[i], data[i], 0, 255, 1, i);
  178. }
  179. return 0;
  180. }
  181. static int FUNC(message_list)(CodedBitstreamContext *ctx, RWContext *rw,
  182. SEIRawMessageList *current, int prefix)
  183. {
  184. SEIRawMessage *message;
  185. int err, k;
  186. #ifdef READ
  187. for (k = 0;; k++) {
  188. uint32_t payload_type = 0;
  189. uint32_t payload_size = 0;
  190. uint32_t tmp;
  191. while (show_bits(rw, 8) == 0xff) {
  192. fixed(8, ff_byte, 0xff);
  193. payload_type += 255;
  194. }
  195. xu(8, last_payload_type_byte, tmp, 0, 254, 0);
  196. payload_type += tmp;
  197. while (show_bits(rw, 8) == 0xff) {
  198. fixed(8, ff_byte, 0xff);
  199. payload_size += 255;
  200. }
  201. xu(8, last_payload_size_byte, tmp, 0, 254, 0);
  202. payload_size += tmp;
  203. CHECK(ff_cbs_sei_list_add(current));
  204. message = &current->messages[k];
  205. message->payload_type = payload_type;
  206. message->payload_size = payload_size;
  207. CHECK(FUNC(message)(ctx, rw, message));
  208. if (!cbs_h2645_read_more_rbsp_data(rw))
  209. break;
  210. }
  211. #else
  212. for (k = 0; k < current->nb_messages; k++) {
  213. PutBitContext start_state;
  214. uint32_t tmp;
  215. int trace, i;
  216. message = &current->messages[k];
  217. // We write the payload twice in order to find the size. Trace
  218. // output is switched off for the first write.
  219. trace = ctx->trace_enable;
  220. ctx->trace_enable = 0;
  221. start_state = *rw;
  222. for (i = 0; i < 2; i++) {
  223. *rw = start_state;
  224. tmp = message->payload_type;
  225. while (tmp >= 255) {
  226. fixed(8, ff_byte, 0xff);
  227. tmp -= 255;
  228. }
  229. xu(8, last_payload_type_byte, tmp, 0, 254, 0);
  230. tmp = message->payload_size;
  231. while (tmp >= 255) {
  232. fixed(8, ff_byte, 0xff);
  233. tmp -= 255;
  234. }
  235. xu(8, last_payload_size_byte, tmp, 0, 254, 0);
  236. err = FUNC(message)(ctx, rw, message);
  237. ctx->trace_enable = trace;
  238. if (err < 0)
  239. return err;
  240. }
  241. }
  242. #endif
  243. return 0;
  244. }