📄 videoinedgedetection_buffers.c
字号:
/*****************************************************************************
Copyright (c) 2006 Analog Devices, Inc. All Rights Reserved.
This software is proprietary and confidential to Analog Devices, Inc.
and its licensors.
*****************************************************************************
$RCSfile: VideoInEdgeDetection_Buffers.c,v $
$Revision: 1.4 $
$Date: 2006/07/28 05:11:05 $
Project: BlackfinSDK (Edge Detection on ITU656 Video In)
Title: Buffer handling functions
Author(s): bmk
Revised by:
Description:
Functions to Handle video input/output buffers used for
Edge Detection on ITU 656 Video Input
References:
None
*****************************************************************************
Tab Setting: 4
Target Processor: ADSP-BF5xx
Target Tools Revision: ADSP VisualDSP++ v4.5
******************************************************************************
Modification History:
====================
$Log: VideoInEdgeDetection_Buffers.c,v $
Revision 1.4 2006/07/28 05:11:05 bmk
modified code for actual NTSC resolution
Previous rev- 720 x 480, now - 720 x 486
Revision 1.3 2006/07/06 07:26:28 bmk
modified project to use video utility file macros
Revision 1.2 2006/07/04 05:33:19 bmk
added Slide-show mode for BF533
Revision 1.1 2006/06/30 01:33:55 bmk
Initial entry
******************************************************************************
Include files
*****************************************************************************/
#include <sobel.h> // Sobel edge detection algorithm includes
#include <VideoInEdgeDetection_System.h> // Video In Edge detection system includes
#include <SDK-ezkitutilities.h> // EZ-Kit utility definitions
/*****************************************************************************
Video Data buffers
*****************************************************************************/
// Define the buffers to handle video data processing
// Because of SDRAM performance, each buffer must be in a different bank.
section("video_sdram_bank0") volatile u8 Video_In_Buf0 [VIDEO_BUF_SIZE];
#if defined(__ADSPBF561__)
section("video_sdram_bank1") volatile u8 Video_In_Buf1 [VIDEO_BUF_SIZE];
#endif
section("video_sdram_bank2") volatile u8 Video_Out_Buf [VIDEO_BUF_SIZE];
// Sobel Edge detection buffers
section("Sobel_In_buf0") volatile u8 Sobel_In_Buf0 [SOBEL_BUF_SIZE];
section("Sobel_In_buf1") volatile u8 Sobel_In_Buf1 [SOBEL_BUF_SIZE];
section("Sobel_Out_buf0") volatile u8 Sobel_Out_Buf0 [SOBEL_BUF_SIZE];
section("Sobel_Out_buf1") volatile u8 Sobel_Out_Buf1 [SOBEL_BUF_SIZE];
#if defined(__ADSPBF561__)
#define VIDEO_BUFFERS 2 // number of 2D (video) buffers used
#elif defined(__ADSPBF533__)
#define VIDEO_BUFFERS 1 // number of 2D (video) buffers used
#else
#error "*** ERROR: Application doesnot support this processor yet ***"
#endif
static ADI_DEV_2D_BUFFER Video_Out_Buffer2D[VIDEO_BUFFERS]; // Video output buffer
static ADI_DEV_2D_BUFFER Video_In_Buffer2D [VIDEO_BUFFERS]; // Video input buffers
/***********************************
MDMA Handels & data
***********************************/
// DMA Stream Handels
ADI_DMA_STREAM_HANDLE MDMA_Handle_Stream0; // MDMA stream for video in buffer to sobel in buffer
ADI_DMA_STREAM_HANDLE MDMA_Handle_Stream1; // MDMA stream for sobel out buffer to video out buffer
// MDMA 2D transfer data type
// structures to define video in buffer to sobel in buffer stream
ADI_DMA_2D_TRANSFER MDMA_Sobel_In_Src;
ADI_DMA_2D_TRANSFER MDMA_Sobel_In_Des;
// structures to define sobel out buffer to video out buffer stream
ADI_DMA_2D_TRANSFER MDMA_Sobel_Out_Src;
ADI_DMA_2D_TRANSFER MDMA_Sobel_Out_Des;
/***********************************
Globals
***********************************/
// Background colour for edge detected output (grey colour-ycbcr format)
static char background[] = {0x89,0x11,0x89,0x11};
// Pointer to some location in Video_In_Bufx - points next block of data for Sobel_In_Bufx
u8 *pVideoInBuf;
// Pointer to some location in Video_Out_Buf - points start address to copy next block of Sobel_Out_Buf
u8 *pVideoOutBuf;
// Temp video in pointer
u8 *tpVideoInBuf;
// Temp video out pointer
u8 *tpVideoOutBuf;
SOBEL_FLAGS SobelFlag; // Flags used to carryout Sobel Edge Detection
u8 SobelInBlockCount; // Number of sobel in blocks processed
u8 SobelOutBlockCount; // Number of sobel out blocks processed
u8 SobelInColumnBlockCount; // Number of sobel in Columns processed
u8 SobelOutColumnBlockCount; // Number of sobel out Columns processed
/***********************************
local function prototypes
***********************************/
static void MDMA_Callback0 (void *AppHandle, u32 Event, void *pArg); // MEMDMA stream callback function (sobel in)
static void MDMA_Callback1 (void *AppHandle, u32 Event, void *pArg); // MEMDMA stream callback function (sobel out)
void MDMA_SobelIn (void); // MDMA Sobel In buffer update - callback routine
void MDMA_SobelOut (void); // MDMA Sobel Out buffer update - callback routine
/*********************************************************************
Function: Format_Video_Out_Frames
Description: Formats Sobel video output frames to specified mode
*********************************************************************/
section("sdram_bank1")
void FormatVideoOutFrames (void)
{
// Check input video frame type
if (SystemFlag.ITU656_Mode == ITU656_PAL)
{
// Pause disabled. format video out buffer for video streaming
// Format memory as PAL interlaced video frame
adi_video_FrameFormat ((char *)Video_Out_Buf,PAL_IL);
// Fill the Video out frame with background color
adi_video_FrameFill ((char *)Video_Out_Buf,PAL_IL,background);
}
else // format a NTSC video frame
{
// Format memory as NTSC interlaced video frame
adi_video_FrameFormat ((char *)Video_Out_Buf,NTSC_IL);
// Fill the Video out frame with background color
adi_video_FrameFill ((char *)Video_Out_Buf,NTSC_IL,background);
}
return;
}
/*********************************************************************
Function: SubmitVideoOutBuffers
Description: Prepares and submits Video Output Buffers (for ADV717x)
*********************************************************************/
section("sdram_bank1")
void SubmitVideoOutBuffers (
){
u8 OutBufCount,i;
OutBufCount = 1; // number of output buffers to be submitted by default
// if sobel is enabled, submit the original sobel video out buffer
if (SystemFlag.SobelEnable == TRUE)
{
Video_Out_Buffer2D[0].Data = (void*)(&Video_Out_Buf[0]); // Video buffer to be displayed
}
#if defined(__ADSPBF561__)
else // display incoming video or paused original frame
{
// check pause flag
if (SystemFlag.Pause_Frame_Capture == TRUE)
{
// Pause is enabled. so submit paused Video In frame to Video out
Video_Out_Buffer2D[0].Data = (void*)(((ADI_DEV_BUFFER *)pPausedBuffer)->TwoD.Data);
}
else // Stream incoming video
{
Video_Out_Buffer2D[0].Data = (void*)(&Video_In_Buf0[0]);// Video buffer to be displayed
Video_Out_Buffer2D[1].Data = (void*)(&Video_In_Buf1[0]);// Video buffer to be displayed
// 2 video in buffers to be submitted for video streaming
OutBufCount = 2;
}
}
#elif defined(__ADSPBF533__)
// if sobel is disabled, display captured video frame
else
{
// submit captured Video In frame to Video out
Video_Out_Buffer2D[0].Data = (void*)(((ADI_DEV_BUFFER *)pPausedBuffer)->TwoD.Data);
}
#endif
for (i=0;i<OutBufCount;i++)
{
// Configure Video Out Buffer
Video_Out_Buffer2D[i].ElementWidth = DMA_BUS_SIZE; // 32 bit transfer for BF561/16 bit transfer for BF533
Video_Out_Buffer2D[i].XModify = DMA_BUS_SIZE; // 4 bytes increment for BF561/2 bytes increment for BF533
Video_Out_Buffer2D[i].XCount = (DataPerLine/DMA_BUS_SIZE); // Video Data per line
Video_Out_Buffer2D[i].YCount = FrameLines; // Total number of lines in a frame
Video_Out_Buffer2D[i].YModify = DMA_BUS_SIZE; // 4 bytes increment for BF561/2 bytes increment for BF533
Video_Out_Buffer2D[i].CallbackParameter = &Video_Out_Buffer2D[i]; // call back parameter
Video_Out_Buffer2D[i].pNext = NULL;
// submit the video output buffer to the system
ezErrorCheck(adi_dev_Write(ADV717xDeviceHandle, ADI_DEV_2D, (ADI_DEV_BUFFER *)&Video_Out_Buffer2D[i]));
}
return;
}
/*********************************************************************
Function: Submit_Video_In_Buffers
Description: Prepares and submits Video Input Buffers (for ADV7183)
*********************************************************************/
section("sdram_bank1")
void SubmitVideoInBuffers (
){
u8 i;
// Configure Video In Buffer(s)
// Video In Buffer 1
Video_In_Buffer2D[0].Data = (void*)(&Video_In_Buf0[0]); // start location of 2D Video In buffer0
#if defined(__ADSPBF561__)
// Video In Buffer 2
Video_In_Buffer2D[1].Data = (void*)(&Video_In_Buf1[0]); // start location of 2D Video In buffer1
#endif
for (i=0; i<VIDEO_BUFFERS; i++)
{
Video_In_Buffer2D[i].ElementWidth = DMA_BUS_SIZE; // 32 bit transfer for BF561/16 bit transfer for BF533
Video_In_Buffer2D[i].XModify = DMA_BUS_SIZE; // 4 bytes increment for BF561/2 bytes increment for BF533
Video_In_Buffer2D[i].XCount = (DataPerLine/DMA_BUS_SIZE); // Video Data per line
Video_In_Buffer2D[i].YCount = FrameLines; // Total number of lines in a frame
Video_In_Buffer2D[i].YModify = DMA_BUS_SIZE; // 4 bytes increment for BF561/2 bytes increment for BF533
Video_In_Buffer2D[i].CallbackParameter = &Video_In_Buffer2D[i]; // call back parameter
Video_In_Buffer2D[i].pNext = NULL; // Submit both buffers independently
// submit video input buffer(s) to the system
ezErrorCheck(adi_dev_Read(ADV7183DeviceHandle, ADI_DEV_2D, (ADI_DEV_BUFFER *)&Video_In_Buffer2D[i]));
}
return;
}
/*********************************************************************
Function: ConfigureMDMA
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -