#ifndef AVFORMAT_PROTECTION_H
#define AVFORMAT_PROTECTION_H

struct AVProtection;
struct AVProtectionSession;
struct AVPacket;

#include "libavformat/avio.h"
#include "libavcodec/avcodec.h"



typedef struct AVProtectionSession{
	struct AVProtection *protection;
	AVIOInterruptCB interrupt; ///<interrupt callback
	void *priv_data; ///<Used by the protection session
} AVProtectionSession;

typedef struct AVProtectionInfo{
	uint8_t *info;
	int size;
} AVProtectionInfo;

#define AVPROTECTION_SCENARIO_OFFLINE 0
#define AVPROTECTION_SCENARIO_STREAMING 1

typedef int (*av_protection_init_session_func)(struct AVProtection *protection, int scenario, AVIOInterruptCB interrupt, AVProtectionSession **session);

typedef int (*av_protection_add_protection_info_func)(AVProtectionSession* session, AVProtectionInfo* *infos, int n_infos, int *error);

typedef int (*av_protection_decrypt_packet_func)(AVProtectionSession* session, uint8_t *data, int data_size, const uint8_t kid[16], const uint8_t iv[16], int iv_size, const short clear[16], const uint32_t encrypted[32], int n_subsamples);

typedef int (*av_protection_get_system_specific_data_func)(AVProtectionSession* session, int id, void **data);

typedef int (*av_protection_close_session_func)(AVProtectionSession* session);

typedef struct AVProtection{
  void* user_data;
  av_protection_init_session_func init_session;
  av_protection_add_protection_info_func add_protection_info;
  av_protection_decrypt_packet_func decrypt_packet;
  av_protection_get_system_specific_data_func get_specific_data;
  av_protection_close_session_func close_session;
} AVProtection;

int av_protection_decrypt_packet(AVProtectionSession *protection, struct AVCodecContext *ctx, struct AVPacket *pkt);
/**
 * Checks a packet to see if it contains PSSH as side data
 * @param protection the AVProtectionSession
 * @param pkt the packet
 * @return < 0 in case of error, 0 if no PSSH data found or the number of decrypt sessions created
 */
int av_protection_check_side_data(AVProtectionSession *protection, struct AVPacket *pkt, int *error);





#endif