#include "media/sei_injector.hpp"
namespace smartcut::media {
std::vector<std::uint8_t> make_hevc_prefix_sei_t35(std::span<const std::uint8_t> payload) {
  // av_dynamic_hdr_plus_to_t35() begins at application_mode and deliberately
  // excludes the 48-bit SMPTE ST 2094-40 registration header.
  std::vector<std::uint8_t> body{0xB5, 0x00, 0x3C, 0x00, 0x01, 0x04};
  body.insert(body.end(), payload.begin(), payload.end());
  std::vector<std::uint8_t> rbsp;
  unsigned zero_count = 0;
  for (const auto byte : body) { if (zero_count >= 2 && byte <= 3) { rbsp.push_back(3); zero_count = 0; } rbsp.push_back(byte); zero_count = byte == 0 ? zero_count + 1 : 0; }
  std::vector<std::uint8_t> nal{0, 0, 0, 1, static_cast<std::uint8_t>(39u << 1u), 1};
  const auto payload_type = static_cast<std::size_t>(4);
  std::size_t remaining = payload_type; while (remaining >= 255) { nal.push_back(255); remaining -= 255; } nal.push_back(static_cast<std::uint8_t>(remaining));
  remaining = rbsp.size(); while (remaining >= 255) { nal.push_back(255); remaining -= 255; } nal.push_back(static_cast<std::uint8_t>(remaining));
  nal.insert(nal.end(), rbsp.begin(), rbsp.end()); nal.push_back(0x80); return nal;
}
}
