/**
 * Labgency Player
 *
 * Copyright (c) 2012 Labgency
 *
 * All rights reserved
 *
 */


#ifndef _H_AVDRM
#define _H_AVDRM

#include <stdlib.h>

#ifdef __cplusplus
extern "C"{
#endif // __cplusplus

#define AVDRM_PLAYREADY   1
#define AVDRM_WMDRM10     2
#define AVDRM_VMX 	3 


/**
 * \ingroup LgyPlayer
 */
/*@{*/
   
/**
* DRM structure
*/
typedef struct {
    /**
     * Allocates a new DRM context
     * @param context user data
     * @param drmType specifies the type of the DRM header (either AVDRM_PLAYREADY or DRM_WMDRM10)
     * @param data pointer to the DRM header
     * @param dataLength length of the buffer containing the DRM header
     * @return the drm instance context, must me freed with the release function
     */
    void *  (*alloc) (void *context, int drmType, const unsigned char *  data, int dataLength);
    /**
     * Releases a drm instance context
     * @param context user data
     * @param drm the drm instance context to release
     */
    void  (*release) (void *context, void *  drm);
    /**
     * Sets the IV for the next call to decrypt packet
     * @param context user data
     * @param drm the drm instance context
     * @param aIv pointer to a buffer containing the IV
     * @param aIvSize size of the IV (should be either 8 or 16). When using 8, the 8 remaining bytes are filled with zeros
     */
    void  (*set_iv) (void *context, void *  drm, unsigned char *  aIv, int  aIvSize);
    /**
     * Decrypts a packet
     * @param context user data
     * @param drm the drm instance context
     * @param aPacket buffer containing the data to decrypt
     * @param aPacketSize size of the buffer 
     * @return a result code, 0 if all went well
     */
    int  (*decrypt_packet) (void *context, void *  drm, unsigned char *  aPacket, int  aPacketSize);
    /**
     * Validates environment
     * @param context user data
     * @return 0 if DRM can be used (checks the DRM certificates), another value otherwise
     */
    int  (*validate_environment)(void *context);

    /**
     * Allocates a new DRM context
     * @param context user data
     * @param drmType specifies the type of the DRM header (either AVDRM_PLAYREADY or AVDRM_WMDRM10)
     * @param data pointer to the DRM header for Playready/WMDRM10. For Verymatrix, this is the url of the key
     * @param dataLength length of the buffer containing the DRM header/key url
     * @param user_agent user agent to use during http/https requests
     * @param result will contain an error code in case of error (if return == NULL)
     * @return the drm instance context, must me freed with the release function
     */
    void *  (*alloc2) (void *context, int drmType, const unsigned char *  data, int dataLength, const char* user_agent, int *result);
} avplayer_drm;


/*@}*/

#ifdef __cplusplus
} // end extern "C"
#endif // __cplusplus


#endif 

// EOF!

