/*
 *******************************************************************************
 *  Copyright (c) 2010-2022 VATICS(KNERON) Inc. All rights reserved.
 *
 *  +-----------------------------------------------------------------+
 *  | THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED |
 *  | AND COPIED IN ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH  |
 *  | A LICENSE AND WITH THE INCLUSION OF THE THIS COPY RIGHT NOTICE. |
 *  | THIS SOFTWARE OR ANY OTHER COPIES OF THIS SOFTWARE MAY NOT BE   |
 *  | PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON. THE   |
 *  | OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED.        |
 *  |                                                                 |
 *  | THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT   |
 *  | ANY PRIOR NOTICE AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY |
 *  | VATICS(KNERON) INC.                                             |
 *  +-----------------------------------------------------------------+
 *
 *******************************************************************************
 */

#ifndef VIDEO_ENCODER_OUTPUT_SCM_H
#define VIDEO_ENCODER_OUTPUT_SCM_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>

#include "vmf/video_encoder.h"
#include "SharedCompactMemory/shared_compact_memory.h"
#include "comm/frame_info.h"
#include "comm/vmf_log.h"

#ifdef __cplusplus
extern "C" {
#endif

#define VENC_SCM_TAG "VENC_SCM"

typedef struct
{
	const char *szScmName;		//! string of SCM name.
	uint32_t dwBufSize;			//! SCM buffer size. Please use bigger than 2*(check size). Recommend 2.5*(check size).
	uint32_t dwChkSize;			//! SCM buffer check size, including bitstream and SRB header.
                                //! Every time SCM writer will make sure this size for writing buffer.
	bool bBlock;				//! SCM block mode. True: Writer will waiting reader if buffer is not enough.
                                //!                 False: Writer will remove the oldest data in buffer if buffer is not enough.
	bool bLimit;				//! SCM limit mode. True: SCM handle will only hold the maximum 16 data logs in handle.
                                //!                 False: SCM handle will not limit the amount of data logs in handle.
} VMF_VENC_OUT_SCM_INITOPT_T;

typedef struct
{
	SCM_HANDLE_T *ptScmHandle;	//! The pointer to SRB handle.
	SCM_BUFFER_T tScmBuf;		//! SCM buffer structure.
	uint32_t dwBsBufSize;

	// For bitrate profiling
	uint32_t dwFrameCount;		//! the encode frame number on GoP interval
	uint32_t dwEncodeBytes;		//! the totoal encode byte on GoP interval
	uint32_t dwMaxEncodeBytes;	//! the max encode bytes on current bitstream
} VMF_VENC_OUT_SCM_T;

int VMF_VENC_OUT_SCM_Init(VMF_VENC_OUT_SCM_T **, VMF_VENC_OUT_SCM_INITOPT_T *);
int VMF_VENC_OUT_SCM_Release(VMF_VENC_OUT_SCM_T **);
int VMF_VENC_OUT_SCM_SetOutput(uint8_t **, uint8_t **, uint32_t * , void *);
int VMF_VENC_OUT_SCM_Header(VMF_VENC_ENCODE_INFO_T *, void *, void *);
int VMF_VENC_OUT_SCM_Data(VMF_VENC_ENCODE_INFO_T *, uint8_t *, uint32_t, void *);
int VMF_VENC_OUT_SCM_Setup_Config(VMF_VENC_CONFIG_T *, VMF_VENC_CODEC_TYPE, void *, void *);

#ifdef __cplusplus
}
#endif


#endif //! guard
