/*
 *  Copyright (C) 2005-2026 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "cores/VideoPlayer/Interface/DemuxPacket.h"

#include <chrono>
#include <span>
#include <string>
#include <vector>

struct AVChapter;
struct AVPacket;

struct ChapterFFmpeg
{
  bool operator==(const ChapterFFmpeg&) const = default;

  std::chrono::milliseconds m_startPts;
  std::chrono::milliseconds m_endPts;
  std::string m_name;
};

class CDVDDemuxUtils
{
public:
  //! How far in a first chapter may start and still count as starting at zero: longer than a
  //! keyframe interval, shorter than anything worth seeking to.
  static constexpr std::chrono::milliseconds KEYFRAME_OFFSET_LIMIT{1000};

  static void FreeDemuxPacket(DemuxPacket* pPacket);
  static DemuxPacket* AllocateDemuxPacket(int iDataSize = 0);
  static DemuxPacket* AllocateDemuxPacket(unsigned int iDataSize,
                                          unsigned int encryptedSubsampleCount);
  static void StoreSideData(DemuxPacket* pkt, AVPacket* src);
  static std::vector<ChapterFFmpeg> LoadChapters(std::span<AVChapter*> chapters);
};
