📄 analog_video.h
字号:
/**
* \file analog_video.h
* \author Zlatan Stanojevic
*
*/
#ifndef ANALOG_VIDEO_H
#define ANALOG_VIDEO_H
#include <services/services.h>
#include "blt.h"
/**
* This contains the information necessary to work with various video standards
* \brief Video standard info
*/
typedef struct
{
long width; ///< active video width
long height; ///< active video height
long pixel_stride; ///< address difference between two neighbouring pixels
long line_stride; ///< address difference between two line starts
long field_stride; ///< address difference between two field starts
long frame_stride; ///< address difference between two frame starts
long active_video1_offset; ///< active video start address offset in first field
long active_video2_offset; ///< active video start address offset in second field
long active_video_line_size; ///< size in bytes of an active video line
long blank_line_size; ///< size in bytes of blanking region in a line
long total_lines; ///< total number of lines (active & blank)
struct
{
long line; ///< line where flags change
u32 flags; ///< new flags or'ed together
} flags[7]; ///< flag change positions
} AVStandard;
extern const AVStandard *g_pInvalidStd; ///< pointer to invalid standard structure
extern const AVStandard *g_pPALstd; ///< pointer to PAL standard structure
extern const AVStandard *g_pNTSCstd; ///< pointer to NTSC standard structure
extern const AVStandard *g_pInputStd; ///< pointer to the standard structure detected at analog input
/**
* \brief Gives size in bytes of the visible portion of a frame
* \param std Pointer to valid \ref AVStandard structure
*/
#define AV_SIZEOF_VISIBLE_FRAME( std ) ( std->width * std->height * 2 )
/**
* \brief Gives size in bytes of a complete frame (inlcuding blanking regions)
* \param std Pointer to valid \ref AVStandard structure
*/
#define AV_SIZEOF_TOTAL_FRAME( std ) ( std->frame_stride )
/**
* \brief Results returned by the av_*** functions
*/
typedef enum
{
AV_RESULT_OK = 0, ///< function exited sucessfully
AV_RESULT_NO_INPUT, ///< no video input found
AV_RESULT_AMBIGUOUS_INPUT_SELECTION, ///< more than one expected analog video input found
AV_RESULT_UNKNOWN_DECODER_DEVICE, ///< decoder device returned unknown ID
AV_RESULT_WRONG_PPI_INDEX, ///< specified PPI index not present
AV_RESULT_PPI_ALREADY_OPENED, ///< specified PPI peripheral is already in use by av
AV_RESULT_PPI_NOT_OPENED, ///< the corresponding PPI peripheral must be opened first
AV_RESULT_NEED_BUFFER_MATRIX, ///< a buffer matrix is required for this mode of operation
AV_RESULT_ADI_INT_ERROR, ///< the adi_int module returned an error
AV_RESULT_PPI_CONFIG_ERROR, ///< the PPIConfig module returned an error
AV_RESULT_INVALID_STANDARD, ///< the specified pointer yields to an invalid standard structure
} AV_RESULT;
/// Composite input at AIN1
#define AV_CVBS_AIN1 0x0001
/// Composite input at AIN2
#define AV_CVBS_AIN2 0x0002
/// Composite input at AIN3
#define AV_CVBS_AIN3 0x0004
/// Composite input at AIN4
#define AV_CVBS_AIN4 0x0008
/// Composite input at AIN5
#define AV_CVBS_AIN5 0x0010
/// Composite input at AIN6
#define AV_CVBS_AIN6 0x0020
/// YC input at AIN1 and AIN4
#define AV_YC_AIN14 0x0040
/// YC input at AIN2 and AIN5
#define AV_YC_AIN25 0x0080
/// YC input at AIN3 and AIN6
#define AV_YC_AIN36 0x0100
/// YPrPb input at AIN1, AIN4 and AIN5
#define AV_YPrPb_AIN145 0x0200
/// YPrPb input at AIN2, AIN3 and AIN6
#define AV_YPrPb_AIN236 0x0400
/// Composite input at AIN7
#define AV_CVBS_AIN7 0x0800
/// Composite input at AIN8
#define AV_CVBS_AIN8 0x1000
/// Composite input at AIN9
#define AV_CVBS_AIN9 0x2000
/// Composite input at AIN10
#define AV_CVBS_AIN10 0x4000
/// Composite input at AIN11
#define AV_CVBS_AIN11 0x8000
/// Mask of all composite inputs
#define AV_CVBS_ALL 0xf83f
/// Mask of all YC inputs
#define AV_YC_ALL 0x01c0
/// Mask of all YPrPb inputs
#define AV_YPrPb_ALL 0x0600
typedef u16 AV_SRC_FIELD; ///< Bitfield for identifying and masking video sources
//typedef int AV_HANDLE;
/**
* \brief Values passed to AV event handlers
*/
typedef enum
{
AV_EVENT_PPI_FT_ERR, ///< PPI frame tracking error
AV_EVENT_FRAME_FINISHED ///< end of one frame - start of the following
} AV_EVENT;
/**
* \brief Values returned by AV event handlers
*/
typedef enum
{
AV_HANDLER_RESULT_PROCESSED, ///< Handler has processed the request
AV_HANDLER_RESULT_NOT_PROCESSED, ///< Handler has not processed the request
} AV_HANDLER_RESULT;
/**
* Input standards codes used during input auto detection
*/
typedef enum
{
NTSC_MJ = 0x00,
NTSC_443 = 0x10,
PAL_M = 0x20,
PAL_60 = 0x30,
PAL_BGHID = 0x40,
SECAM = 0x50,
PAL_N = 0x60,
SECAM_525 = 0x70,
AUTODETECT = 0xff,
} AV_INPUT_TYPE;
/// Event handler function pointer typedef
typedef AV_HANDLER_RESULT (*AV_EVENT_HANDLER_FN)( AV_EVENT pa_eEvent );
/// Declaration/definition macro for AV event handlers
#define AV_EVENT_HANDLER( NAME ) AV_HANDLER_RESULT NAME ( AV_EVENT pa_eEvent )
/**
* \brief Initalizes AV module
* \param pa_nDMAIVG IVG to be used for DMA interrupts
* \param pa_nPPIIVG IVG to be used for PPI-Error interrupts
* \return \ref AV_RESULT_OK, \ref AV_RESULT_ADI_INT_ERROR
*/
AV_RESULT av_base_init( int pa_nDMAIVG, int pa_nPPIIVG );
/**
* \brief Initalizes video decoder
* \param OE_pin Pin connected to OE (see "ppi_global.h"), 0 if not connected
* \param RESET_pin Pin connected to RESET (see "ppi_global.h"), 0 if not connected
* \param pa_bDisable Configure decoder, but disable both its clock and pixel port.
* \return \ref AV_RESULT_OK, \ref AV_RESULT_UNKNOWN_DECODER_DEVICE
*/
AV_RESULT av_init_input( u32 OE_pin, u32 RESET_pin, bool pa_bDisable );
/**
* \brief Finds connected input signals
* \param pa_nTries Tries to find input before giving up
* \param pa_video_detection_result Pointer to buffer, where auto detection result shoud be stored
* \param pa_video_detection_mask Mask of allowed inputs
* \return \ref AV_RESULT_OK, \ref AV_RESULT_NO_INPUT, \ref AV_RESULT_AMBIGUOUS_INPUT_SELECTION
*/
AV_RESULT av_find_input( s16 pa_nTries,
AV_SRC_FIELD *pa_video_detection_result,
AV_SRC_FIELD pa_video_detection_mask,
AV_INPUT_TYPE pa_input_type );
/**
* \brief Configures input to specified signal input
* \param video_source Input video source
* \return \ref AV_RESULT_OK, \ref AV_RESULT_NO_INPUT, \ref AV_RESULT_AMBIGUOUS_INPUT_SELECTION
*/
AV_RESULT av_configure_input( AV_SRC_FIELD video_source,
AV_INPUT_TYPE pa_input_type );
/**
* \brief Checks if video decoder has locked to signal
* \return Nonzero if decoder is locked, zero otherwise
*/
int av_input_locked(void);
/**
* \brief Initializes video encoder
* \param BLANK_pin Pin connected to BLANK (see "ppi_global.h"), 0 if not connected
* \param RESET_pin Pin connected to RESET (see "ppi_global.h"), 0 if not connected
* \param pa_pStd Video standard to use for video output
* \param pa_bPAL_M Output standard should be PAL_M (only relevant if pa_pStd is PAL)
* \return \ref AV_RESULT_OK, \ref AV_RESULT_INVALID_STANDARD
*/
AV_RESULT av_setup_output( u32 BLANK_pin, u32 RESET_pin,
const AVStandard *pa_pStd, bool pa_bPAL_M );
/**
* \brief Resets the encoder's internal timing
* \return \ref AV_RESULT_OK
*/
AV_RESULT av_reset_output_timing();
/**
* \brief Opens a PPI for video transfer
* \param pa_nPPIindex Index of PPI to use
* \param pa_pTargetBuffer Buffer to read from / write to
* \param pa_pStd Video standard to use
* \param pa_bBufferMatrix Work on a buffer matrix
* \param pa_bOutput Open PPI as output
* \param pa_bDoubleBuffer Work on a double buffer
* \param pa_fFrameHandler Handler function for frame synchronisation, 0 for none
* \param pa_fErrorHandler Handler function for PPI errors, 0 for none
* \param pa_bStart Call \ref av_start after configuration
* \return \ref AV_RESULT_OK, \ref AV_RESULT_INVALID_STANDARD, \ref AV_RESULT_WRONG_PPI_INDEX, \ref AV_RESULT_PPI_ALREADY_OPENED
*/
AV_RESULT av_open( u8 pa_nPPIindex,
void *pa_pTargetBuffer,
const AVStandard *pa_pStd,
bool pa_bBufferMatrix,
bool pa_bOutput,
bool pa_bDoubleBuffer,
AV_EVENT_HANDLER_FN pa_fFrameHandler,
AV_EVENT_HANDLER_FN pa_fErrorHandler,
bool pa_bStart );
/**
* \brief Closes previously opened PPI
* \param pa_nPPIindex Index of PPI to close
* \return \ref AV_RESULT_OK, \ref AV_RESULT_WRONG_PPI_INDEX, \ref AV_RESULT_PPI_NOT_OPENED
*/
AV_RESULT av_close( int pa_nPPIindex );
/**
* \brief Starts transfer at specified PPI
* \param pa_nPPIindex Index of PPI to use
* \return \ref AV_RESULT_OK, \ref AV_RESULT_WRONG_PPI_INDEX, \ref AV_RESULT_PPI_NOT_OPENED, \ref AV_RESULT_NEED_BUFFER_MATRIX, \ref AV_RESULT_PPI_CONFIG_ERROR
*/
AV_RESULT av_start( int pa_nPPIindex );
/**
* \brief Stops transfer at specified PPI
* \param pa_nPPIindex Index of PPI to use
* \return \ref AV_RESULT_OK, \ref AV_RESULT_WRONG_PPI_INDEX, \ref AV_RESULT_PPI_NOT_OPENED, \ref AV_RESULT_PPI_CONFIG_ERROR, \ref AV_RESULT_ADI_INT_ERROR
*/
AV_RESULT av_stop( int pa_nPPIindex );
/**
* \brief Restarts transfer at specified PPI
* \param pa_nPPIindex Index of PPI to use
* \return \ref AV_RESULT_OK, \ref AV_RESULT_WRONG_PPI_INDEX, \ref AV_RESULT_PPI_NOT_OPENED
*/
AV_RESULT av_restart( int pa_nPPIindex );
/**
* When using double buffering, this function tells which of the two buffers AV is currently using.
* \brief Tells whics buffer AV is currently using
* \param pa_nPPIindex Index of PPI to query
* \param which Pointer to int where the index of the used buffer is stored
* \return \ref AV_RESULT_OK, \ref AV_RESULT_WRONG_PPI_INDEX
*/
AV_RESULT av_tell( int pa_nPPIindex, int *which );
/**
* \brief Prepares a buffer to be used as a matrix
* \param pa_pTargetBuffer Pointer to buffer
* \param pa_pBufferDesc Pointer to structure that will contain information needed by \ref blt
* \param pa_pStd Video standard to use
* \return \ref AV_RESULT_OK, \ref AV_RESULT_INVALID_STANDARD
*/
AV_RESULT av_init_matrix( void *pa_pBufferAddr, BLTBufferDesc *pa_pBufferDesc,
const AVStandard *pa_pStd );
#endif //ANALOG_VIDEO_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -