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

📄 video_thread.c

📁 davinci lab video playback play video file
💻 C
字号:
/* * video_thread.c *//* Standard Linux headers */#include <stdio.h>		// always include stdio.h#include <stdlib.h>		// always include stdlib.h#include <string.h>             // defines memset and memcpy methods#include <sys/ioctl.h>		// defines ioctl method#include <linux/fb.h>		// defines framebuffer driver methods#include <asm/types.h>          // standard typedefs required by v4l2 header#include <linux/videodev2.h>    // v4l2 driver definitions/* Application header files */#include "debug.h"		// DBG and ERR macros#include "video_thread.h"	// video thread definitions#include "video_osd.h"          // OSD window functions#include "video_output.h" 	// Display device functions/* Video capture and display devices used */#define FBVID_VIDEO "/dev/fb/3"#define FBVID_ATTR "/dev/fb/2"#define FBVID_OSD "/dev/fb/0"/* Input file */#define INPUTFILE "/tmp/video.raw"#define PICTUREFILE "osd.r16"/* Double-buffered display, triple-buffered capture */#define NUM_DISP_BUFS 2/* Other Definitions */#define SCREEN_BPP 16#define D1_WIDTH 720#define D1_HEIGHT 480/* Macro for clearing structures */#define CLEAR(x) memset (&(x), 0, sizeof (x))/****************************************************************************** * video_thread_fxn ******************************************************************************//*  input parameters:                                                         *//*      void *arg  --  a pointer to a video_thread_env structure as           *//*                     defined in video_thread.h                              *//*                                                                            *//*          arg.quit    -- when quit != 0, thread will cleanup and exit       *//*                                                                            *//*  return value:                                                             *//*      void *     --  VIDEO_THREAD_SUCCESS or VIDEO_THREAD_FAILURE as        *//*                     defined in video_thread.h                              *//******************************************************************************/void *video_thread_fxn(void *arg){/* Thread parameters and return value */    video_thread_env *env    = arg;			// see above    void             *status = VIDEO_THREAD_SUCCESS;	// see above/* The levels of initialization for initMask */#define OSDSETUPCOMPLETE	 0x1#define DISPLAYDEVICEINITIALIZED 0x2#define INPUTFILEOPENED          0x4    unsigned int       initMask       = 0x0;/* Capture and display driver variables */    FILE              *inputFile      = NULL;  // input file pointer    int                osdFd	      = 0;     // OSD file descriptor    int                attrFd	      = 0;     // attr window file descriptor    int 	       fbFd 	      = 0;     // video fb driver file desc    unsigned short    *osdDisplay;		// OSD display buffer    unsigned short    *attrDisplay;		// attribute display buffer#define PICTURE_HEIGHT 60#define PICTURE_WIDTH 720    unsigned short     picture[PICTURE_HEIGHT * PICTURE_WIDTH]; // osd picture    char              *displays[NUM_DISP_BUFS]; // display frame pointers    int 	       displayWidth;		// width of a display frame    int		       displayHeight;		// height of a display frame    int 	       displayBufSize;		// bytes in a display frame    int                displayIdx     = 0;	// frame being displayed    int                workingIdx     = 1;	// next frame, being built    char              *dst;			// pointer to working frame    int		       captureSize    = 0;      // size of input frame    /* Thread Setup Phase -- secure and initialize resources */    /*  Initialize video attribute window to fully opaque OSD (0x77)     */    if( video_osd_setup(&osdFd, &attrFd, FBVID_OSD, FBVID_ATTR, 0x00, 			&osdDisplay, &attrDisplay) == VOSD_FAILURE ){	ERR("Failed video_osd_setup in video_thread_function\n");	status = VIDEO_THREAD_FAILURE;	goto cleanup;    }    initMask |= OSDSETUPCOMPLETE;    /* Place a circular alpha-blended OSD frame around video screen */    video_osd_circframe(osdDisplay, attrDisplay, 0xFFFF, 0x44);    /* Open the display picture for OSD */        if((inputFile = fopen(PICTUREFILE, "r")) == NULL) {	ERR("Failed to open input file %s\n", PICTUREFILE);	status = VIDEO_THREAD_FAILURE;	goto cleanup;    }    DBG("Opened file %s with FILE pointer %p\n", PICTUREFILE, inputFile);    /* read in picture */    if(fread(picture, sizeof(short), PICTURE_HEIGHT * PICTURE_WIDTH, inputFile)					< PICTURE_HEIGHT * PICTURE_WIDTH){ 	    ERR("Error reading osd picture from file\n");	    fclose(inputFile);	    goto cleanup;    }    fclose(inputFile);    DBG("OSD Picture read successful, placing picture\n");    video_osd_place(osdDisplay, attrDisplay, picture, 0x77, 				0, 360, PICTURE_WIDTH, PICTURE_HEIGHT);    /* Initialize the video display device */    displayWidth = D1_WIDTH;    displayHeight = D1_HEIGHT;    if( video_output_setup(&fbFd, FBVID_VIDEO, displays, NUM_DISP_BUFS, 			&displayWidth, &displayHeight, ZOOM_1X) 				== VOUT_FAILURE) {        ERR("Failed video_output_setup in video_thread_function\n");	status = VIDEO_THREAD_FAILURE;	goto cleanup;    }    /*  Calculate size of a display buffer in bytes */    displayBufSize = displayWidth * displayHeight * SCREEN_BPP/8;    /* Record that display device was opened in initialization bitmask */    initMask |= DISPLAYDEVICEINITIALIZED;    /* Initialize the video capture device */        if((inputFile = fopen(INPUTFILE, "r")) == NULL) {	ERR("Failed to open input file %s\n", INPUTFILE);	status = VIDEO_THREAD_FAILURE;	goto cleanup;    }    DBG("Opened file %s with FILE pointer %p\n", INPUTFILE, inputFile);    /* Record that cpature device was opened in initialization bitmask */    initMask |= INPUTFILEOPENED;    /* Thread Execute Phase -- perform I/O and processing */    DBG("Entering video_thread_fxn processing loop.\n");    while (!env->quit) {	/*  Read input buffer from video capture device */ 	if(fread(&captureSize, sizeof(captureSize), 1, inputFile) < 1) 	    break;	dst = displays[workingIdx];	if(fread(dst, sizeof(char), captureSize, inputFile) < captureSize)	    break;        /* Flip display buffer and working buffer */        displayIdx = (displayIdx + 1) % NUM_DISP_BUFS;        workingIdx = (workingIdx + 1) % NUM_DISP_BUFS;        flip_display_buffers(fbFd, displayIdx);    }cleanup:    DBG("Exited video_thread_fxn processing loop\n");    DBG("\tStarting video thread cleanup\n");    /* Thread Cleanup Phase -- free resources no longer needed by thread */    /* Uses the init_bitmask to only free resources that were allocated  */    /* Cleanup osd */    if (initMask & OSDSETUPCOMPLETE) {	DBG("Closing FILE ptr %p\n", inputFile);	video_osd_cleanup(osdFd, attrFd, osdDisplay, attrDisplay);        }    /* Close video input file */    if (initMask & INPUTFILEOPENED) {	DBG("Closing FILE ptr %p\n", inputFile);        fclose(inputFile);    }    /* Close video display device */     if (initMask & DISPLAYDEVICEINITIALIZED) {        video_output_cleanup(fbFd, displays, NUM_DISP_BUFS);    }    /* Return the status of thread execution */    DBG("Video thread cleanup complete. Exiting video_thread_fxn\n");    return status;}

⌨️ 快捷键说明

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