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

📄 main.c

📁 TI workshop 培训资料。 是关于如何创建DAVINCI平台下codec engine
💻 C
字号:
/* * main.c * * ============================================================================ * Copyright (c) Texas Instruments Inc 2005 * * Use of this software is controlled by the terms and conditions found in the * license agreement under which this software has been supplied or provided. * ============================================================================ *//* Standard Linux headers */#include <stdio.h>	//  Always include this header#include <stdlib.h>	//  Always include this header#include <signal.h>	//  Defines signal-handling functions (i.e. trap Ctrl-C)#include <unistd.h>	//  Defines sleep function#include <pthread.h>    // be sure this is nptl header w/ proper -I in Makefile!/* Application headers */#include "debug.h"#include "audio_thread.h"#include "video_thread.h"/* Codec Engine headers */#include <xdc/std.h>			// xdc base definitions. Must come 1st#include <ti/sdo/ce/CERuntime.h>	// defines CERuntime_init/* The codec engine to use in this application */#define ENGINE_NAME     "encodedecode"	// as defined in engine .cfg file/* Global thread environments */audio_thread_env audio_env = {0, NULL};video_thread_env video_env = {0, NULL};/* Callback called when SIGINT is sent to the process (Ctrl-C). */void signal_handler(int sig){    DBG("Ctrl-C pressed, cleaning up and exiting..\n");    audio_env.quit = 1;/*  If we're in debug mode, pause for a second to give the audio thread time *//*          complete it's cleanup so that feedback from two threads don't    *//*          become interleaved                                               */#ifdef _DEBUG_    sleep(1);#endif    video_env.quit = 1;}/****************************************************************************** * main ******************************************************************************/int main(int argc, char *argv[]){/* The levels of initialization for initMask */#define AUDIOTHREADATTRSCREATED 0x1#define AUDIOTHREADCREATED 0x2#define VIDEOTHREADATTRSCREATED 0x4#define VIDEOTHREADCREATED 0x8    unsigned int    initMask  = 0;    int             status    = EXIT_SUCCESS;    pthread_t       audioThread, videoThread;    pthread_attr_t  audioThreadAttrs, videoThreadAttrs;    struct sched_param audioThreadParams, videoThreadParams;    void *audioThreadReturn;    void *videoThreadReturn;    /* Set the signal callback for Ctrl-C */    signal(SIGINT, signal_handler);    /* Always call CERuntime_init before using any CE methods */    CERuntime_init();    /* Initialize audio and video thread attributes structures */    if(pthread_attr_init(&audioThreadAttrs)){	ERR("audioThreadAttrs initialization failed\n");        status = EXIT_FAILURE;	goto cleanup;    }    initMask |= AUDIOTHREADATTRSCREATED;    if(pthread_attr_init(&videoThreadAttrs)){	ERR("videoThreadAttrs initialization failed\n");        status = EXIT_FAILURE;	goto cleanup;    }    initMask |= VIDEOTHREADATTRSCREATED;    /* This library defaults to inherited scheduling characteristics!   */    /* If you don't set the inheritance, no changes will take place!    */    if(pthread_attr_setinheritsched(&audioThreadAttrs, PTHREAD_EXPLICIT_SCHED)){	ERR("audioThreadAttrs set scheduler inheritance failed\n");        status = EXIT_FAILURE;	goto cleanup;    }    if(pthread_attr_setinheritsched(&videoThreadAttrs, PTHREAD_EXPLICIT_SCHED)){	ERR("videoThreadAttrs set scheduler inheritance failed\n");	status = EXIT_FAILURE;	goto cleanup;    }    /* Set audio thread scheduling policy to real-time & video to time-slice */    /* SCHED_RR available only to threads running with superuser permission  */    if(pthread_attr_setschedpolicy(&audioThreadAttrs, SCHED_RR)){	ERR("pthread_attr_setschedpolicy failed for audioThreadAttrs\n");        status = EXIT_FAILURE;	goto cleanup;    }    if(pthread_attr_setschedpolicy(&videoThreadAttrs, SCHED_OTHER)){	ERR("pthread_attr_setschedpolicy failed for videoThreadAttrs\n");        status = EXIT_FAILURE;	goto cleanup;    }    /* Set audio and video thread priorities */    audioThreadParams.sched_priority = sched_get_priority_max(SCHED_RR);    if(pthread_attr_setschedparam(&audioThreadAttrs, &audioThreadParams)){	ERR("pthread_attr_setschedparam failed for audioThreadAttrs\n");        status = EXIT_FAILURE;	goto cleanup;    }     videoThreadParams.sched_priority = sched_get_priority_max(SCHED_OTHER);    if(pthread_attr_setschedparam(&videoThreadAttrs, &videoThreadParams)){	ERR("pthread_attr_setschedparam failed for videoThreadAttrs\n");        status = EXIT_FAILURE;	goto cleanup;    }    /*  Create a thread for audio loopthru        */    audio_env.engineName = ENGINE_NAME;    DBG("Creating audio thread\n");    DBG("\tthread priority = %d\n", audioThreadParams.sched_priority);    if (pthread_create(&audioThread, &audioThreadAttrs, audio_thread_fxn, 					(void *) &audio_env)) {        ERR("Failed to create audio thread\n");        status = EXIT_FAILURE;	video_env.quit = 1;	goto cleanup;    }    initMask |= AUDIOTHREADCREATED;    /*  Create a second thread for video loopthru */    /* If we're in debug mode, pause for a second to give audio thread */    /*      time to initialize. This keeps the initialization output   */    /*      from getting interleaved between the two threads.          */#ifdef _DEBUG_    sleep(1);#endif    /*  Create a second thread for video loopthru */    video_env.engineName = ENGINE_NAME;    DBG("Creating video thread\n");    DBG("\tpriority = %d\n", videoThreadParams.sched_priority);    if (pthread_create(&videoThread, &videoThreadAttrs, video_thread_fxn, 					(void *) &video_env)) {        ERR("Failed to create video thread\n");        status = EXIT_FAILURE;	audio_env.quit = 1;	goto cleanup;    }    initMask |= VIDEOTHREADCREATED;cleanup:    /* Free the audio and video attributes structures */    if (initMask & AUDIOTHREADATTRSCREATED)	pthread_attr_destroy(&audioThreadAttrs);        if (initMask & VIDEOTHREADATTRSCREATED)	pthread_attr_destroy(&videoThreadAttrs);    /* Main thread will wait here until audio and video threads terminate */    /* If we're in debug mode, pause for a second to give video thread    */    /*      time to initialize. Before displaying message                 */#ifdef _DEBUG_    sleep(1);#endif    printf("All application threads started\n");    printf("\tPress Ctrl-C to exit\n");    /* Wait until the audio thread terminates */    if (initMask & AUDIOTHREADCREATED) {	pthread_join(audioThread, &audioThreadReturn);	if( audioThreadReturn == AUDIO_THREAD_FAILURE )	    DBG("audio thread exited with FAILURE status\n");	else	    DBG("audio thread exited with SUCCESS status\n");    }    /* Wait until the video thread terminates */    if (initMask & VIDEOTHREADCREATED) {        pthread_join(videoThread, &videoThreadReturn);	if( videoThreadReturn == VIDEO_THREAD_FAILURE )	    DBG("video thread exited with FAILURE status\n");	else	    DBG("video thread exited with SUCCESS status\n");    }    exit(status);}

⌨️ 快捷键说明

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