📄 videoinedgedetection_callbacks.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_Callbacks.c,v $
$Revision: 1.4 $
$Date: 2006/07/28 05:11:05 $
Project: BlackfinSDK (Edge Detection on ITU656 Video In)
Title: System Service callback routines
Author(s): bmk
Revised by:
Description:
PPI/Pushbutton callback service routines 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_Callbacks.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 <VideoInEdgeDetection_System.h> // Video In Edge Detection system includes
#include <drivers\encoder\adi_adv717x.h> // video encoder driver includes
#include <drivers\decoder\adi_adv7183.h> // video decoder driver includes
#include <SDK-ezkitutilities.h> // EZ-Kit utility definitions
/*********************************************************************
Local function prototypes
*********************************************************************/
void UpdateBufferIDs (void); // Updates Video In/Out buffer IDs
/*********************************************************************
Globals
**********************************************************************
Video parameters
*****************/
// Video data per line (bytes)
u32 DataPerLine;
// Number of lines per ITU656 video frame (bytes)
u32 FrameLines;
// Number of bytes to skip to reach active video data in a single line
u32 ActiveVideoSkip;
// Number of bytes to skip to reach active video frame field1 (odd frame)
u32 Field1Skip;
// Number of bytes to skip to reach active video frame field2 (even frame)
u32 Field2Skip;
// Sobel buffer row size (for valid Edge Detected data only)
u16 SobelRowSize;
// ITU656 video frame - Active field spilt to # number of blocks
u8 SobelFieldBlocks;
// Number of Sobel Blocks for selected video frame
u16 SobelBlockCount;
// System flags for Push Button Trigger status
PB_TRIGGER_FLAGS PBFlag;
// pointer to paused video 2D buffer
volatile u32 *pPausedBuffer;
#if defined(__ADSPBF533__)
#if defined(VIDEO_IN_SLIDE_SHOW) // Conditional compilation macro to enable slide show mode
u32 SlideShowFrameCount; // count to check frame capture frequency
#endif
#endif
/*********************************************************************
Function: VideoOut
Description: Video Out callback service routine
*********************************************************************/
section ("Callback_Code_L1")
void VideoOut(
void *AppHandle,
u32 Event,
void *pArg
){
// Case of (event type)
switch (Event) {
// Case (buffer processed)
case ADI_DEV_EVENT_BUFFER_PROCESSED:
#if defined(__ADSPBF533__)
#if defined(VIDEO_IN_SLIDE_SHOW) // Conditional compilation macro to enable slide show mode
++SlideShowFrameCount; // increment slideshow count
// check if its time to capture a new frame
if (SlideShowFrameCount >= FRAME_CAPTURE_FREQUENCY)
{
// Set Frame capture flag
SystemFlag.Pause_Frame_Capture = TRUE;
// set flag to update buffers
SystemFlag.UpdateVideoOutBufs = TRUE;
}
#endif
#endif
// check UpdateVideoOutBufs flag or UpdateVideoMode flag is set
if (SystemFlag.UpdateVideoOutBufs)
{
// BF561 - Toggle video or Pause video button was pressed or update video mode
// BF533 - Frame capture / toggle video button was pressed
// update the video in/out buffer id's
UpdateBufferIDs();
}
break;
// Case (DMA Error)
case ADI_DEV_EVENT_DMA_ERROR_INTERRUPT:
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
default: // other events
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
}
}
/*********************************************************************
Function: VideoIn
Description: Video In callback service routine
*********************************************************************/
section ("Callback_Code_L1")
void VideoIn(
void *AppHandle,
u32 Event,
void *pArg
){
// Case of (event type)
switch (Event) {
// Case (buffer processed)
case ADI_DEV_EVENT_BUFFER_PROCESSED: // a video frame has been captured
#if defined(__ADSPBF561__)
// check if UpdateBufs_VideoIn falg is set
if (SystemFlag.UpdateVideoInBufs)
{
// if so, user has pressed Pause Video button and pause is enabled this time
// retrive the address of present video in buffer which is selected to pause
pPausedBuffer = (u32 *)pArg;
// update the video in/out buffer id's
UpdateBufferIDs();
}
// check if sobel video out is enabled (for edge detected video streaming)
if (SystemFlag.SobelEnable)
{
// check if Sobel buffers are ready to take next frame
if (SystemFlag.SobelDone)
{
// Initialise Video In to Sobel In data streaming
// address of video in buffer that generated callback is passed as pArg
SobelInInit ((u32 *)pArg);
// clear the flag to start sobel conversion for next frame
SystemFlag.SobelDone = FALSE;
}
}
#elif defined(__ADSPBF533__)
// retrive the address of present video in buffer that has the captured frame
pPausedBuffer = (u32 *)pArg;
// BF533 - A Video frame has been captured
// Disable Video In dataflow
EnableVideoIn (FALSE);
// Close ADV7183
ezErrorCheck(adi_dev_Close(ADV7183DeviceHandle));
// copy captured video buf field to avoid interleave problem
if (SystemFlag.ITU656_Mode == ITU656_NTSC)
{
// Incoming video stream is NTSC
// Arguments - pointer to video frame start location, frame type, field source, active data only
adi_video_CopyField((char *)(((ADI_DEV_BUFFER *)pPausedBuffer)->TwoD.Data), NTSC_IL,2, TRUE);
}
else if (SystemFlag.ITU656_Mode == ITU656_PAL)
{
// Incoming video stream is PAL
// Arguments - pointer to video frame start location, frame type, field source, active data only
adi_video_CopyField((char *)(((ADI_DEV_BUFFER *)pPausedBuffer)->TwoD.Data), PAL_IL, 2, TRUE);
}
// Initialise Sobel edge detection for the new frame
SobelInInit ((u32 *) pPausedBuffer);
// clear the flag to indicate a new frame is available for edge detection
SystemFlag.SobelDone = FALSE;
// enable video encoder (ADV7171) in BF533 Ez-kit
ezEnableVideoEncoder ();
// Instal Video Encoder (video output - ADV717x)
InstallVideoEncoder ();
// Enable Video Out dataflow
EnableVideoOut (TRUE);
#endif
break;
// Case DMA Error
case ADI_DEV_EVENT_DMA_ERROR_INTERRUPT:
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
default: // other events
// turn on all LEDs and wait for help
ezTurnOnAllLEDs();
while (1) ;
}
}
/*********************************************************************
Function: ButtonPressed
Description: Ez-Kit button press callback service routine
*********************************************************************/
section ("Callback_Code_L1")
void ButtonPressed (
void *AppHandle,
u32 Event,
void *pArg
){
int i;
// Case of (event type)
switch (Event) {
// Case (flag interrupt occurred)
case ADI_FLAG_EVENT_CALLBACK:
// check if terminate application button was been pressed
if ((int)pArg == TERMINATE_BUTTON)
{
// if so, clear the KeepRunningFlag
SystemFlag.KeepRunningFlag = FALSE;
}
#if defined(__ADSPBF561__)
// check for Update Video Mode button press
// Video update will start only after this button gets released
else if ((int)pArg == UPDATE_VIDEO_MODE_BUTTON)
{
// Check Pause Button system status flag
if (PBFlag.Video_Mode)
{
// if the flag is set, then the button was previously pressed & just released
// Update Video Mode button has been pressed & released. change trigger status to wait for next button press
ezErrorCheck(adi_flag_SetTrigger(UPDATE_VIDEO_MODE_BUTTON,ADI_FLAG_TRIGGER_RISING_EDGE));
// set the Update Video Mode button system flag to indicate the button has been released
PBFlag.Video_Mode = FALSE;
// ignore multiple button press as only one button should be serviced at a time
// check Update flags and even if one of them is set, ignore this button press
if (!(SystemFlag.UpdateVideoInBufs || SystemFlag.UpdateVideoOutBufs || SystemFlag.UpdateVideoMode))
{
// set flag to update video mode
SystemFlag.UpdateVideoMode = TRUE;
// update video mode in video out callback
SystemFlag.UpdateVideoOutBufs = TRUE;
}
}
else // Update Video Mode button is in pressed state
{
// Update Video Mode button has been pressed. change trigger status to wait until its released
ezErrorCheck(adi_flag_SetTrigger(UPDATE_VIDEO_MODE_BUTTON,ADI_FLAG_TRIGGER_FALLING_EDGE));
// set the Update Video Mode button system flag to indicate the button has been pressed
PBFlag.Video_Mode = TRUE;
}
}
// check for Pause Video button press
else if ((int)pArg == PAUSE_FRAME_CAPTURE_BUTTON)
{
// ignore multiple button press as only one button should be serviced at a time
// check Update flags and even if one of them is set, ignore this button press
if (!(SystemFlag.UpdateVideoInBufs || SystemFlag.UpdateVideoOutBufs || SystemFlag.UpdateVideoMode))
{
SystemFlag.Pause_Frame_Capture ^= 1; // toggle pause video flag
// check pause flag
if (SystemFlag.Pause_Frame_Capture == TRUE)
{
// if this is a pause enable operation, buffer update should be done only in Video In Callback
SystemFlag.UpdateVideoInBufs = TRUE;
}
else
{
// this is to enable video stream(disable pause), can be done only in Video Out callback
// because video in will be off during pause enable mode
SystemFlag.UpdateVideoOutBufs = TRUE;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -