⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 video_example_bf533.c

📁 BlackFin处理器视频演示代码
💻 C
字号:
/**
 *@file video_example.c
 *@author Zlatan Stanojevic
 *
 *This file contains the example of a possible init procedure and interrupt handlers.
 */

/******************************************************
 
 This file contains several example setups for both
 video input and output. A reference of the used API
 functions can be found in the included Doxygen 
 documentation. Feel free to modify this file.

******************************************************/


#include "blt.h"
#include "analog_video.h"
#include "../../misc/clock_query.h"
#include <stdio.h>
#include <stdlib.h>
#include <gpio_global.h>
#include "video_boards.h"


// SELECT THE VIDEO STANDARD ------------------------
//#define NTSC
#define PAL
// --------------------------------------------------
// SELECT IF INPUT OR OUTPUT IS USED ----------------
//#define _USE_OUTPUT_
#define _USE_INPUT_
// --------------------------------------------------

// *******************************************************************
// ADD THE _USE_TESTPIC_ MACRO TO THE PREPROCESSOR DEFINITIONS WITHIN
// THE PROJECT SETTINGS TO GET A TEST PICTURE ON OUTPUT. OTHERWISE A
// TESTSCREEN WITH RED AND BLUE STRIPES IS SHOWN
// *******************************************************************

#if defined (NTSC)
#define VIDEO_STANDARD		NTSC_443
#define VIDEO_STRUCT		g_pNTSCstd
#define Y_RES				484
#elif defined (PAL)
#define VIDEO_STANDARD		PAL_BGHID
#define VIDEO_STRUCT		g_pPALstd
#define Y_RES				576
#else
#error "video standard not supported"
#endif

#define DEBUG

#if   defined( __ADSPBF533__ )
#define MDMA_CHANNEL ADI_DMA_MDMA_0
#elif defined( __ADSPBF537__ )
#define MDMA_CHANNEL ADI_DMA_MDMA_0
#elif defined( __ADSPBF561__ )
#define MDMA_CHANNEL ADI_DMA_MDMA2_0
#endif

static BLTBufferDesc screen1, screen2, output, testpic;

static char *output_matrix;
static char *input_buffer;


AV_EVENT_HANDLER( Handler_BufferedLoop )
{
#ifdef DEBUG
    printf( "Sync lost!\n" );
#endif
    if( pa_eEvent == AV_EVENT_PPI_FT_ERR )
    {
        av_restart( 0 );
        long loops = querySystemClock() / 20, i;
        for( i = 0; i < loops; i++ )
            asm( "ssync;" );
        if( ! av_input_locked() )
        {
            AV_SRC_FIELD video_source;
            av_stop( 0 );
            while( AV_RESULT_OK != av_find_input( 1, &video_source, EXT_VIDEO_INPUTS, VIDEO_STANDARD ) );
            av_start( 0 );
        }
        return AV_HANDLER_RESULT_NOT_PROCESSED;
    }
    return AV_HANDLER_RESULT_NOT_PROCESSED;
}


void InitVideoExample( void )
{
    AV_RESULT result;
    AV_SRC_FIELD video_source;
    
    blt_init();
    
    result = av_base_init( 12, 13 );
    
#ifdef _USE_INPUT_
    // section to read the video stream into memory ------------------------
    
    result = av_init_input( _PF6, 0, false );
    
    input_buffer = malloc( AV_SIZEOF_VISIBLE_FRAME( VIDEO_STRUCT ) );
    
    while( AV_RESULT_OK != av_find_input( 1, &video_source, EXT_VIDEO_INPUTS, VIDEO_STANDARD ) );
    
    result = av_open( 0, input_buffer, g_pInputStd, 0, 0, 0, 0, Handler_BufferedLoop, 1 );
    
    printf( "Video input can be found at address 0x%08lX\n", (u32)input_buffer );
    
    // ----------------------------------------------------------------------
#endif
    
#ifdef _USE_OUTPUT_
    // uncomment this section to output a standard test screen --------------    
#ifdef _USE_TESTPIC_    
    extern char testpic_array [];
#else    
    // create a testscreen (red and blue stripes) ------------------
    char *test_pic_place = (char *)0x1000000;
    char *test_pic_buffer_start = test_pic_place;
    unsigned short lines;
    unsigned short xpos;
    unsigned short ypos;
    for (ypos=0; ypos<Y_RES; ypos+=16) {
        for (lines=0; lines<8; lines++) {
	    	for (xpos=0;xpos<720;xpos+=2) {
	    	    *test_pic_place=0xef;
	    	    test_pic_place++;
	    	    *test_pic_place=0x2d;
	    	    test_pic_place++;
	    	    *test_pic_place=0x67;
	    	    test_pic_place++;
	    	    *test_pic_place=0x2d;
	    	    test_pic_place++;
	    	}
        }
        for (lines=0; lines<8; lines++) {
	    	for (xpos=0;xpos<720;xpos+=2) {
	    	    *test_pic_place=0x5a;
	    	    test_pic_place++;
	    	    *test_pic_place=0x5c;
	    	    test_pic_place++;
	    	    *test_pic_place=0xf0;
	    	    test_pic_place++;
	    	    *test_pic_place=0x5c;
	    	    test_pic_place++;
	    	}
        }
    }
#endif    
    // ------------------------------------------------------------    
    result = av_init_input( _PF6, 0, true );
    
    result = av_setup_output( 0, 0, VIDEO_STRUCT, false );

    output_matrix = malloc( AV_SIZEOF_TOTAL_FRAME( VIDEO_STRUCT ) );
    
    result = av_init_matrix( output_matrix, &output, VIDEO_STRUCT );
#ifdef _USE_TESTPIC_    
    testpic = blt_makeLinearSurface( testpic_array, 720, Y_RES );
#else    
    testpic = blt_makeLinearSurface( test_pic_buffer_start, 720, Y_RES );
#endif    
    blt( MDMA_CHANNEL, &testpic, &output, 0, 0, 0, 0, 720, Y_RES );
    
    result = av_open( 0, output_matrix, VIDEO_STRUCT, 1, 1, 0, 0, 0, 1 );
    
    // ----------------------------------------------------------------------
#endif
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -