-
-
Save 4lehandro/2059a4d3385d67102e0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //-------------------------------------------// | |
| //INCLUDES // | |
| //-------------------------------------------// | |
| #include <sys/time.h> | |
| #include <gst/gst.h> | |
| #include <glib.h> | |
| #include <sys/param.h> | |
| #include <sys/user.h> | |
| #include <sys/sysctl.h> | |
| #include <unistd.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| // communication include files | |
| #include <Msg_Def.h> | |
| #include <cmem.h> | |
| #include <sys/mman.h> | |
| #include <sys/ioctl.h> | |
| #include <Playback_Msg_Def.h> | |
| // pthread include files | |
| #include <pthread.h> | |
| #include "gst_player.h" | |
| // signal interrupt message | |
| #include <unistd.h> | |
| #include <signal.h> | |
| // Process Priority | |
| #include <sys/resource.h> | |
| // share memory | |
| #include <sys/shm.h> | |
| #define RRET__SUCCESS (0) | |
| #define RRET__FAIL (RRET__SUCCESS - 1000) | |
| //-------------------------------------------// | |
| //GLOBALS // | |
| //-------------------------------------------// | |
| int Msgqid=0,gStopFlag=FALSE, gThreadFlag=FALSE, s32InitFlag=FALSE; | |
| int gSampleRate=0, gErrProduceFlag=FALSE, gExecRst=0, gs32CodeType=0; | |
| char gCodeType[16] = ""; | |
| gridChoice_t *gParamPtr = NULL; | |
| //-------------------------------------------// | |
| //Pototypes and Macro // | |
| //-------------------------------------------// | |
| enum{eNULL, eOnlyVdo, eMulawAdo, eMpegAdo}; | |
| enum{eNoSupCode, eH264, eMPEG4}; | |
| enum{eFMTPASS, eErrFMT}; | |
| // loop waiting for bus message | |
| static void event_loop (GstElement * pipe); | |
| void vMsg_pThreadFunction(GstElement * pipe); | |
| void vRelease_Msg_pThread(); | |
| int Msg_Init(int msgKey); | |
| int AssayFile(char *FI_FileString); | |
| int SetPreviewFreeze(int enable); | |
| void vExitMsgProgram(); | |
| void VideoplaybackStopAck(void); | |
| void VIDEO_SetCursorBusy(void); | |
| //-------------------------------------------// | |
| //FUNCTIONS // | |
| //-------------------------------------------// | |
| /** | |
| * @Justin CMEM MMAP | |
| * @param none | |
| * @return pointer to cmem address | |
| */ | |
| extern int cmem_fd; | |
| void *CMEM_MMAP( unsigned long physp, int size ) | |
| { | |
| void *userp; | |
| if (cmem_fd == -1) { | |
| printf("[%s:%d]allocPool: You must initialize CMEM before making API calls.\n",__FILE__,__LINE__); | |
| return NULL; | |
| } | |
| /* Map the physical address to user space */ | |
| userp = mmap(0, // Preferred start address | |
| size, // Length to be mapped | |
| PROT_WRITE | PROT_READ, // Read and write access | |
| MAP_SHARED, // Shared memory | |
| cmem_fd, // File descriptor | |
| physp); // The byte offset from fd | |
| if (userp == MAP_FAILED) { | |
| printf("[%s:%d]allocPool: Failed to mmap buffer at physical address %#lx\n", | |
| __FILE__,__LINE__,physp); | |
| ioctl(cmem_fd, CMEM_IOCFREE, &physp); | |
| return NULL; | |
| } | |
| return userp; | |
| } | |
| //==========================// | |
| // Share memory functons // | |
| //==========================// | |
| int ShareMemInit(int key,int size) | |
| { | |
| int sharemid; | |
| sharemid = shmget(key, size, IPC_CREAT | 0660); | |
| if(sharemid < 0) | |
| { | |
| printf("Cannot get share memory:%d\n",sharemid); | |
| return -1; | |
| } | |
| return sharemid; | |
| } | |
| void* ShareMemMap(int sharemid) | |
| { | |
| char *psrc; | |
| if(sharemid < 0) | |
| return (void*)NULL; | |
| psrc = shmat(sharemid,0,0); | |
| return (void*)psrc; | |
| } | |
| int ShareUnMap(void *buf) | |
| { | |
| shmdt(buf); | |
| return 0; | |
| } | |
| #if 0 | |
| void timeStart(diffTime_t *timeRec) | |
| { | |
| struct timeval tv; | |
| if (gettimeofday(&tv, NULL) >= 0) | |
| timeRec->start = tv.tv_sec * 1000 + tv.tv_usec/1000; | |
| } | |
| void timeEnd(diffTime_t *timeRec) | |
| { | |
| struct timeval tv; | |
| if (gettimeofday(&tv, NULL) >= 0) | |
| timeRec->end = tv.tv_sec * 1000 + tv.tv_usec/1000; | |
| } | |
| double timeDiff(diffTime_t *timeRec) | |
| { | |
| return (double)(timeRec->end-timeRec->start)/1000; | |
| } | |
| #endif | |
| void exit_progream(int sig) | |
| { | |
| printf("Catched signal: %d !!\n", sig); | |
| vExitMsgProgram(); | |
| signal(SIGINT, SIG_DFL); | |
| } | |
| void WaitExecPlayback(void) | |
| { | |
| int s32Flag=1, msg_size = 0,msg_cnt=0; | |
| MSG_BUF msgbuf; | |
| while(s32Flag) | |
| { | |
| msg_size = msgrcv( Msgqid, &msgbuf, sizeof(msgbuf)-sizeof(long), MSG_TYPE_MSG13, 0); | |
| if (msg_size < 0) | |
| { | |
| } | |
| else | |
| { | |
| msgbuf.ret = 0; | |
| switch(msgbuf.cmd) | |
| { | |
| case MSG_CMD_PLAYBACK_ShowLogo: | |
| s32Flag = 0; | |
| msgbuf.ret = 1; | |
| s32InitFlag = TRUE; | |
| break; | |
| case MSG_CMD_PLAYBACK_PLAYING: | |
| s32Flag = 0; | |
| msgbuf.ret = 1; | |
| break; | |
| case MSG_CMD_VIDPLYBACK_INIT: | |
| if (gParamPtr == NULL) | |
| { | |
| CMEM_init(); | |
| gParamPtr = CMEM_MMAP(msgbuf.mem_info.addr, msgbuf.mem_info.size); | |
| printf("[%s:%d]gGridChoice->outRes=%d \n",__FILE__,__LINE__,gParamPtr->outRes); | |
| CMEM_exit(); | |
| } | |
| msgbuf.ret = 1; | |
| break; | |
| default: | |
| if (msg_cnt > 3) | |
| { | |
| sleep(1); | |
| msg_cnt=0; | |
| gErrProduceFlag = TRUE; | |
| printf("[%s:%d]inactive command: %d \n",__FILE__,__LINE__,msgbuf.cmd); | |
| }else{ | |
| msg_cnt++; | |
| } | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| void GetResolution(char *ResType, char *OutMode) | |
| { | |
| if (gParamPtr != NULL) | |
| { | |
| switch(gParamPtr->outRes) | |
| { | |
| case eXGA: | |
| strcpy(ResType, "XGA"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| case eD1_NTSC: | |
| strcpy(ResType,"D1_NTSC"); | |
| strcpy(OutMode, "COMPOSITE"); | |
| break; | |
| case e720P: | |
| strcpy(ResType,"720P"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| case eSXGA: | |
| strcpy(ResType,"SXGA"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| case eWXGA: | |
| strcpy(ResType,"WXGA"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| case eUXGA: | |
| strcpy(ResType,"UXGA"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| case e1080p: | |
| strcpy(ResType,"1080P"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| case eXGA_HF: | |
| strcpy(ResType, "XGA"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| default: | |
| strcpy(ResType,"SXGA"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| } | |
| } | |
| } | |
| int main (int argc, char *argv[]){ | |
| GstElement *bin = NULL; | |
| GstElement *filesrc = NULL; | |
| GError *error = NULL; | |
| gchar *GstCMDStr = NULL; | |
| ITEM_SETTING *SysInfoPtr = NULL; | |
| pthread_t Msg_pThread; | |
| GstState state=0,pending=0; | |
| int s32FileType = 0; | |
| int SysInfoShmemID= 0; | |
| char strOutRes[16] = ""; | |
| char strOutMod[12] = ""; | |
| char *LogoFilePath = "/opt/ipnc/Logo.avi"; | |
| char UserLogoPath[128]=""; | |
| strcpy (UserLogoPath, DF_LogoDir); | |
| strcat (UserLogoPath, DF_UserLogoFIle); | |
| strcat (UserLogoPath, ".avi"); | |
| SysInfoShmemID = ShareMemInit(ITEM_SETTING_MSG_KEY,sizeof(ITEM_SETTING)); | |
| SysInfoPtr =(ITEM_SETTING*)ShareMemMap(SysInfoShmemID); | |
| setpriority(PRIO_PROCESS, 0, 0); | |
| signal(SIGINT, exit_progream); | |
| //Messages communictaion Initial | |
| if (!Msgqid) | |
| Msgqid = Msg_Init(MSG_KEY); | |
| //gstreamer initial | |
| gst_init (&argc, &argv); | |
| #if 0 | |
| if (argc < 2) | |
| { | |
| g_print ("usage: %s <avi file> <option>\n", argv[0]); | |
| return 0; | |
| } | |
| #endif | |
| while(TRUE) | |
| { | |
| gExecRst=RRET__SUCCESS; | |
| WaitExecPlayback(); | |
| gs32CodeType = eNoSupCode; | |
| if (s32InitFlag == TRUE) | |
| { | |
| printf("--Info--[%s:%d] Display_Logo \n",__FILE__,__LINE__); | |
| GetResolution(strOutRes, strOutMod); | |
| if (SysInfoPtr->cUserLogoOn) | |
| { | |
| s32FileType = AssayFile(UserLogoPath); | |
| } | |
| else | |
| { | |
| s32FileType = AssayFile(LogoFilePath); | |
| } | |
| if ((s32FileType == eNULL)||(gs32CodeType == eNoSupCode)) | |
| { | |
| printf("--Error--[%s:%d] FileType = NULL !!!\n",__FILE__,__LINE__); | |
| s32InitFlag = FALSE; | |
| gExecRst=RRET__FAIL; | |
| VideoplaybackStopAck(); | |
| continue; | |
| } | |
| // Setting av_server status = Freeze | |
| SetPreviewFreeze(eReleaseDisMem); | |
| printf("--Info--[%s:%d]Release Display Memory finish \n",__FILE__,__LINE__); | |
| VIDEO_SetCursorBusy(); | |
| printf("--Info--[%s:%d]Set Cursor Icon finish \n",__FILE__,__LINE__); | |
| } | |
| else | |
| { | |
| printf("--Info--[%s:%d] Display_avi FilePath:%s \n",__FILE__,__LINE__,gParamPtr->filePath); | |
| GetResolution(strOutRes, strOutMod); | |
| s32FileType = AssayFile(gParamPtr->filePath); | |
| if ((s32FileType == eNULL)||(gs32CodeType == eNoSupCode)) | |
| { | |
| gExecRst=RRET__FAIL; | |
| VideoplaybackStopAck(); | |
| continue; | |
| } | |
| } | |
| //printf("[%s:%d] FilePath:%s Resolution:%s \n",__FILE__,__LINE__,gParamPtr->filePath,strOutRes); | |
| switch(s32FileType) | |
| { | |
| case eNULL: | |
| gExecRst=RRET__FAIL; | |
| continue; | |
| case eOnlyVdo: | |
| GstCMDStr = g_strdup_printf ("filesrc name=my_filesrc ! avidemux name=demux demux.video_00 ! TIViddec2 engineName=decode codecName=\"%s\" numOutputBufs=3 genTimeStamps=true gcloseloop=false ! TIDmaiVideoSink videoStd=\"%s\" videoOutput=\"%s\" resizer=TRUE",gCodeType,strOutRes,strOutMod); | |
| bin = (GstElement *) gst_parse_launch (GstCMDStr, &error); | |
| break; | |
| case eMulawAdo: | |
| GstCMDStr = g_strdup_printf ("filesrc name=my_filesrc ! avidemux name=demux demux.video_00 ! TIViddec2 engineName=decode codecName=\"%s\" numOutputBufs=3 genTimeStamps=true gcloseloop=true ! TIDmaiVideoSink videoStd=\"%s\" videoOutput=\"%s\" resizer=TRUE demux.audio_00 ! queue max-size-buffers=1600 max-size-time=0 max-size-bytes=0 ! decodebin ! queue ! audio/x-raw-int, rate=\"%d\" ! alsasink",gCodeType,strOutRes,strOutMod,gSampleRate); | |
| bin = (GstElement *) gst_parse_launch (GstCMDStr, &error); | |
| break; | |
| case eMpegAdo: | |
| GstCMDStr = g_strdup_printf ("filesrc name=my_filesrc ! avidemux name=demux demux.video_00 ! TIViddec2 engineName=decode codecName=\"%s\" numOutputBufs=3 genTimeStamps=true gcloseloop=false ! TIDmaiVideoSink videoStd=\"%s\" videoOutput=\"%s\" resizer=TRUE ",gCodeType,strOutRes,strOutMod); | |
| //GstCMDStr = g_strdup_printf ("filesrc name=my_filesrc ! avidemux name=demux demux.video_00 ! TIViddec2 engineName=decode codecName=\"%s\" numOutputBufs=3 genTimeStamps=true gcloseloop=false ! TIDmaiVideoSink videoStd=\"%s\" videoOutput=\"%s\" resizer=TRUE demux.audio_00 ! queue max-size-buffers=1600 max-size-time=0 max-size-bytes=0 ! mad ! queue ! audio/x-raw-int, rate=\"%d\" ! alsasink provide-clock=true",gCodeType,strOutRes,strOutMod,gSampleRate); | |
| bin = (GstElement *) gst_parse_launch (GstCMDStr, &error); | |
| break; | |
| } | |
| if (!bin) | |
| { | |
| printf("--Error--[%s:%d] Parse error: %s \n",__FILE__,__LINE__,error->message); | |
| } | |
| filesrc = gst_bin_get_by_name (GST_BIN (bin), "my_filesrc"); | |
| if (s32InitFlag == TRUE) | |
| { | |
| if (SysInfoPtr->cUserLogoOn) | |
| { | |
| g_object_set (G_OBJECT (filesrc), "location", UserLogoPath, NULL); | |
| } | |
| else | |
| { | |
| g_object_set (G_OBJECT (filesrc), "location", LogoFilePath, NULL); | |
| } | |
| } | |
| else | |
| { | |
| g_object_set (G_OBJECT (filesrc), "location", gParamPtr->filePath, NULL); | |
| } | |
| printf("--Info--[%s:%d] Setting file location finish \n",__FILE__,__LINE__); | |
| gst_element_set_state (bin, GST_STATE_READY); | |
| // Setting av_server status = Freeze | |
| if (!s32InitFlag) | |
| { | |
| SetPreviewFreeze(eReleaseDisMem); | |
| VIDEO_SetCursorBusy(); | |
| } | |
| gst_element_set_state (bin, GST_STATE_PLAYING); | |
| usleep(100000); | |
| //create receiver control message of pthread | |
| pthread_create(&Msg_pThread, NULL, (void *) vMsg_pThreadFunction, bin); | |
| pthread_detach(Msg_pThread); | |
| /* Run event loop listening for bus messages until EOS or ERROR */ | |
| event_loop (bin); | |
| /* stop the bin */ | |
| //gst_element_get_state (bin, &state, &pending, GST_CLOCK_TIME_NONE); | |
| if (!gStopFlag) | |
| { | |
| printf("--Info--[%s:%d]Setting pipeline to PAUSED ...\n",__FILE__,__LINE__); | |
| gst_element_set_state (bin, GST_STATE_PAUSED); | |
| //gst_element_get_state (bin, &state, &pending, GST_CLOCK_TIME_NONE); | |
| //iterate mainloop to process pending stuff | |
| while (g_main_context_iteration (NULL, FALSE)); | |
| } | |
| else | |
| gStopFlag = FALSE; | |
| printf("--Info--[%s:%d]Setting pipeline to READY ...\n",__FILE__,__LINE__); | |
| gst_element_get_state (bin, &state, &pending, GST_CLOCK_TIME_NONE); | |
| if (state == GST_STATE_PAUSED) | |
| gst_element_set_state (bin, GST_STATE_READY); | |
| printf("--Info--[%s:%d] set gst pipeline status to NULL \n",__FILE__,__LINE__); | |
| gst_element_set_state (bin, GST_STATE_NULL); | |
| gst_object_unref (GST_OBJECT (bin)); | |
| while(gThreadFlag){usleep(100000);} | |
| // Setting av_server status = Freeze | |
| printf("--Info--[%s:%d] Setting av_server into unFreeze status \n",__FILE__,__LINE__); | |
| SetPreviewFreeze(eAllocateMem); | |
| VideoplaybackStopAck(); | |
| s32InitFlag = FALSE; | |
| } | |
| return 0; | |
| } | |
| //! loop waiting for bus message | |
| static void event_loop (GstElement * pipe) | |
| { | |
| GstBus *bus = NULL ; | |
| GstMessage *message = NULL ; | |
| GError *gerror = NULL ; | |
| gchar *debug = NULL ; | |
| gboolean bLoop ; | |
| char ch=0; | |
| bLoop = TRUE ; | |
| bus = gst_element_get_bus (GST_ELEMENT (pipe)); | |
| printf("event_loop ... start \n"); | |
| while (bLoop) | |
| { | |
| ch = 0; | |
| message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1); | |
| //g_assert (message != NULL); | |
| if (message == NULL) | |
| continue; | |
| //printf("Processing message: %d \n", message->type); | |
| switch (message->type) | |
| { | |
| case GST_MESSAGE_EOS: | |
| gst_message_unref (message); | |
| vRelease_Msg_pThread(); | |
| bLoop = FALSE ; | |
| break ; | |
| case GST_MESSAGE_STATE_CHANGED: | |
| { | |
| GstState old, new, pending; | |
| gst_message_parse_state_changed (message, &old, &new, &pending); | |
| /* we only care about pipeline state change messages */ | |
| if (GST_MESSAGE_SRC (message) != GST_OBJECT_CAST (pipe)) | |
| break; | |
| /* dump graph for pipeline state changes */ | |
| { | |
| gchar *dump_name = g_strdup_printf ("gst-launch.%s_%s", | |
| gst_element_state_get_name (old), | |
| gst_element_state_get_name (new)); | |
| printf("[%s:%d] %s \n",__FILE__,__LINE__,dump_name); | |
| GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipe), | |
| GST_DEBUG_GRAPH_SHOW_ALL, dump_name); | |
| g_free (dump_name); | |
| } | |
| /* | |
| // ignore when we are buffering since then we mess with the states ourselves. | |
| if (buffering) { | |
| PRINT (_("Prerolled, waiting for buffering to finish...\n")); | |
| break; | |
| } | |
| // if we reached the final target state, exit | |
| if (target_state == GST_STATE_PAUSED && new == target_state) | |
| goto exit; | |
| */ | |
| /* else not an interesting message */ | |
| break; | |
| } | |
| //case GST_MESSAGE_WARNING: | |
| case GST_MESSAGE_ERROR: | |
| gst_message_parse_error (message, &gerror, &debug); | |
| gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); | |
| gst_message_unref (message); | |
| vRelease_Msg_pThread(); | |
| g_error_free (gerror); | |
| g_free (debug); | |
| bLoop = FALSE; | |
| gExecRst=RRET__FAIL; | |
| break; | |
| case GST_MESSAGE_NEW_CLOCK: | |
| { | |
| GstClock *clock; | |
| gst_message_parse_new_clock (message, &clock); | |
| printf("New clock: %s\n", (clock ? GST_OBJECT_NAME (clock) : "NULL")); | |
| break; | |
| } | |
| default: | |
| if (gStopFlag == TRUE) | |
| bLoop = FALSE; | |
| gst_message_unref (message); | |
| break; | |
| } | |
| } | |
| } | |
| void vMsg_pThreadFunction(GstElement * pipe) | |
| { | |
| int s32Flag=1, msg_size = 0, msg_cnt=0; | |
| MSG_BUF msgbuf; | |
| gThreadFlag = TRUE; | |
| GstState state, pending; | |
| while(s32Flag) | |
| { | |
| msg_size = msgrcv( Msgqid, &msgbuf, sizeof(msgbuf)-sizeof(long), MSG_TYPE_MSG13, 0); | |
| if (msg_size < 0) | |
| { | |
| } | |
| else | |
| { | |
| switch( msgbuf.cmd ) | |
| { | |
| case MSG_CMD_PLAYBACK_PLAYING: | |
| gst_element_set_state (pipe, GST_STATE_PLAYING); | |
| break; | |
| case MSG_CMD_PLAYBACK_PAUSED: | |
| printf("[%s:%d] \n",__FILE__,__LINE__); | |
| gst_element_set_state (pipe, GST_STATE_PAUSED); | |
| break; | |
| case MSG_CMD_PLAYBACK_STOP: | |
| gStopFlag = TRUE; | |
| printf("--Info--[%s:%d]Setting Playback to Stop ...\n",__FILE__,__LINE__); | |
| gst_element_get_state (pipe, &state, &pending, GST_CLOCK_TIME_NONE); | |
| if (state == GST_STATE_PLAYING) | |
| gst_element_set_state (pipe, GST_STATE_PAUSED); | |
| else | |
| gst_element_set_state (pipe, GST_STATE_READY); | |
| // iterate mainloop to process pending stuff | |
| //while (g_main_context_iteration (NULL, FALSE)); | |
| s32Flag = 0; | |
| break; | |
| case MSG_CMD_PLAYBACK_EOS: | |
| s32Flag = 0; | |
| break; | |
| default: | |
| if (msg_cnt > 3) | |
| { | |
| sleep(1); | |
| msg_cnt=0; | |
| printf("--Info--[%s:%d]inactive command: %d \n",__FILE__,__LINE__,msgbuf.cmd); | |
| }else{ | |
| msg_cnt++; | |
| } | |
| break; | |
| } | |
| } | |
| } | |
| gThreadFlag = FALSE; | |
| pthread_exit("Msg_pThread exit !"); | |
| } | |
| //-------------------------------------------// | |
| // Author: Jaison // | |
| // Create: 2010.02.03 // | |
| // Discription: IPC message initial // | |
| //-------------------------------------------// | |
| int Msg_Init( int msgKey ) | |
| { | |
| int qid; | |
| key_t key = msgKey; | |
| qid = msgget(key,0); | |
| if( qid < 0 ) | |
| { | |
| qid = msgget(key,IPC_CREAT|0666); | |
| } | |
| return qid; | |
| } | |
| void vRelease_Msg_pThread() | |
| { | |
| MSG_BUF msgbuf; | |
| memset(&msgbuf,0,sizeof(msgbuf)); | |
| msgbuf.Des = MSG_TYPE_MSG13; | |
| msgbuf.Src = MSG_TYPE_MSG13; | |
| msgbuf.cmd = MSG_CMD_PLAYBACK_EOS; | |
| msgbuf.mem_info.addr = 0; | |
| msgbuf.mem_info.size = 0; | |
| if (gErrProduceFlag) | |
| printf("[%s:%d] sned by self !!!\n",__FILE__,__LINE__); | |
| msgsnd( Msgqid, &msgbuf, sizeof(msgbuf)-sizeof(long), 0);//send msg1 | |
| // msgrcv( Msgqid, &msgbuf, sizeof(msgbuf)-sizeof(long), MSG_TYPE_MSG13, 0); | |
| // return msgbuf.ret; | |
| } | |
| void VideoplaybackStopAck(void) | |
| { | |
| MSG_BUF msgbuf; | |
| memset(&msgbuf,0,sizeof(msgbuf)); | |
| msgbuf.Des = MSG_TYPE_MSG14; | |
| msgbuf.Src = 0; | |
| msgbuf.cmd = MSG_CMD_PLAYBACK_STOP; | |
| msgbuf.mem_info.addr = 0; | |
| msgbuf.mem_info.size = 0; | |
| msgbuf.ret = gExecRst; | |
| if (gErrProduceFlag) | |
| printf("[%s:%d] sned by self !!!\n",__FILE__,__LINE__); | |
| printf("[%s:%d] VideoplaybackStopAck \n",__FILE__,__LINE__); | |
| msgsnd( Msgqid, &msgbuf, sizeof(msgbuf)-sizeof(long), 0);//send msg1 | |
| } | |
| void vExitMsgProgram() | |
| { | |
| MSG_BUF msgbuf; | |
| memset(&msgbuf,0,sizeof(msgbuf)); | |
| msgbuf.Des = MSG_TYPE_MSG13; | |
| msgbuf.Src = MSG_TYPE_MSG13; | |
| msgbuf.cmd = MSG_CMD_PLAYBACK_STOP; | |
| msgbuf.mem_info.addr = 0; | |
| msgbuf.mem_info.size = 0; | |
| if (gErrProduceFlag) | |
| printf("[%s:%d] sned by self !!!\n",__FILE__,__LINE__); | |
| msgsnd( Msgqid, &msgbuf, sizeof(msgbuf)-sizeof(long), 0);//send msg1 | |
| } | |
| void printFourcc(FOURCC fcc) | |
| { | |
| int i; | |
| DWORD mask = 0xff, chr = 0x0; | |
| for(i=0;i<4;i++){ | |
| chr=(fcc&(mask<<(8*i)))>>i*8; | |
| printf("%c",chr); | |
| } | |
| printf("\n"); | |
| } | |
| int matchStreamType(FOURCC sType) | |
| { | |
| if(sType == vids_fcc) return 0; | |
| if(sType == auds_fcc) return 1; | |
| if(sType == txts_fcc) return 2; | |
| if(sType == odml_fcc) return 3; | |
| return -1; | |
| } | |
| int readFileInfo(FILE *fp, struct AVIDATA* aviData) | |
| { | |
| int i; | |
| /*** read riff header information ***/ | |
| fread(&aviData->riffHeader, sizeof(struct RIFFHEADER), 1, fp); | |
| if (aviData->riffHeader.fcc != RIFF_fcc) | |
| return eErrFMT; | |
| /*** read LIST 0 information ***/ | |
| fread(&aviData->list1, sizeof(struct LIST), 1, fp); | |
| /*** read AVI Main header ***/ | |
| fread(&aviData->aviMainHeader, sizeof(struct AVIMAINHEADER), 1, fp); | |
| for(i=0;i<aviData->aviMainHeader.dwStreams;i++){ | |
| /*** read sub list info. ***/ | |
| fread(&aviData->subList[i], sizeof(struct LIST), 1, fp); | |
| /*** read AVI Stream Header ***/ | |
| fread(&aviData->aviStreamHeader[i], sizeof(struct AVISTREAMHEADER), 1, fp); | |
| switch(matchStreamType(aviData->aviStreamHeader[i].fccType)){ | |
| case 0: /* vids */ | |
| /* read bitmap header */ | |
| fread(&aviData->bitmapInfoHeader, sizeof(struct BITMAPINFOHEADER), 1, fp); | |
| /*== jump to next sublist ==*/ | |
| /* back to the front of current list */ | |
| /* 12 bytes for LIST */ | |
| /* n bytes for BITMAPINFOHEADER */ | |
| /* jump to next list */ | |
| /* 4 bytes for 'LIST' */ | |
| /* 4 bytes for the variable subList[i].cb */ | |
| /* n bytes for current whole list structure (sizeOfSubList[i]) */ | |
| fseek(fp, sizeofFCC+sizeofCB+aviData->subList[i].cb-(sizeof(struct BITMAPINFOHEADER)+sizeof(struct LIST)+sizeof(struct AVISTREAMHEADER)), SEEK_CUR); | |
| if(i == 0){ | |
| aviData->vidsIDb = x0db_fcc; | |
| aviData->vidsIDc = x0dc_fcc; | |
| }else{ | |
| aviData->vidsIDb = x1db_fcc; | |
| aviData->vidsIDc = x1dc_fcc; | |
| } | |
| if (aviData->aviStreamHeader[i].fccHandler == H264_fcc) | |
| { | |
| gs32CodeType = eH264; | |
| strcpy(gCodeType, "h264dec\0"); | |
| } | |
| if (aviData->aviStreamHeader[i].fccHandler == FMP4_fcc) | |
| { | |
| gs32CodeType = eMPEG4; | |
| strcpy(gCodeType, "mpeg4dec\0"); | |
| } | |
| break; | |
| case 1: /* auds */ | |
| fread(&aviData->waveFormatex, sizeof(struct WAVEFORMATEX), 1, fp); | |
| /*== jump to next sublist ==*/ | |
| /* back to the front of current list */ | |
| /* 12 bytes for LIST */ | |
| /* n bytes for WAVEFORMATEX */ | |
| /* jump to next list */ | |
| /* 4 bytes for 'LIST' */ | |
| /* 4 bytes for the variable subList[i].cb */ | |
| /* n bytes for current whole list structure (sizeOfSubList[i]) */ | |
| fseek(fp, sizeofFCC+sizeofCB+aviData->subList[i].cb-(sizeof(struct WAVEFORMATEX)+sizeof(struct LIST)+sizeof(struct AVISTREAMHEADER)), SEEK_CUR); | |
| if(i == 0){ | |
| aviData->audsID = x0wb_fcc; | |
| }else{ | |
| aviData->audsID = x1wb_fcc; | |
| } | |
| break; | |
| case 2: /* txts */ | |
| break; | |
| case 3: /* odml */ | |
| break; | |
| default: | |
| printf("Sorry! This program can't recogize the stream type %d %#x:", i,aviData->aviStreamHeader[i].fccType); | |
| printFourcc(aviData->aviStreamHeader[i].fccType); | |
| break; | |
| } | |
| } | |
| /*== jump to the end of list 1 ==*/ | |
| /* 12 bytes for RIFFHEADER */ | |
| /* 4 bytes for 'LIST' */ | |
| /* 4 bytes for the variable list1.cb */ | |
| /* n bytes for the whole LIST 1 structrue (sizeOfList1) */ | |
| fseek(fp, sizeof(struct RIFFHEADER)+sizeofFCC+sizeofCB+aviData->list1.cb, SEEK_SET); | |
| /*** JUNK chunk checking until we reached the 'movi' ***/ | |
| fread(&aviData->list2, sizeof(struct LIST), 1, fp); | |
| while(aviData->list2.subFcc != movi_fcc){ | |
| /*** cause we alread read extra 4 bytes, so we need to minus 4 bytes when we jump ***/ | |
| fseek(fp, -sizeofFCC+aviData->list2.cb, SEEK_CUR); | |
| fread(&aviData->list2, sizeof(struct LIST), 1, fp); | |
| } | |
| /*** record current position ***/ | |
| aviData->posOfFirstDataBlock = ftell(fp); | |
| #if 0 | |
| /*** check if the video has index ***/ | |
| if((aviData->aviMainHeader.dwFlags & AVIF_HASINDEX)){ | |
| /*** jump to the end of List 2 ***/ | |
| fseek(fp,-sizeofFCC+aviData->list2.cb, SEEK_CUR); /* minus 4 bytes for current position ('movi') */ | |
| fread(&aviData->avioldIndex, sizeof(struct AVIOLDINDEX), 1, fp); | |
| /* JUNK checking */ | |
| while(aviData->avioldIndex.fcc != idx1_fcc){ | |
| fseek(fp, aviData->avioldIndex.cb, SEEK_CUR); | |
| fread(&aviData->avioldIndex, sizeof(struct AVIOLDINDEX), 1, fp); | |
| } | |
| /*** the total index item is total index size divide each element size (sizeof(struct AVIOLDINDEX_ENTRY)) */ | |
| aviData->numOfIndexItem = aviData->avioldIndex.cb/sizeof(struct AVIOLDINDEX_ENTRY); | |
| aviData->indexEntry = (struct AVIOLDINDEX_ENTRY*)calloc(aviData->numOfIndexItem, sizeof(struct AVIOLDINDEX_ENTRY)); | |
| fread(aviData->indexEntry, sizeof(struct AVIOLDINDEX_ENTRY), aviData->numOfIndexItem, fp); | |
| /*** check the dwOffset error ***/ | |
| aviData->posError = aviData->posOfFirstDataBlock-aviData->indexEntry[0].dwOffset; | |
| }else{ | |
| printf("Sorry! This program don't support the video without index information!"); | |
| exit(EXIT_FAILURE); | |
| } | |
| #endif | |
| return eFMTPASS; | |
| } | |
| int AssayFile(char *FI_FileString) | |
| { | |
| FILE *fp; | |
| struct AVIDATA* aviData; | |
| int s32TmpType=0; | |
| aviData = (struct AVIDATA*)calloc(1, sizeof(struct AVIDATA)); | |
| /** open avi video ***/ | |
| if((fp = fopen(FI_FileString, "rb")) == NULL){ | |
| printf("Fail to open %s \n!", FI_FileString); | |
| free(aviData); | |
| return eNULL; | |
| } | |
| if (readFileInfo(fp, aviData) == eErrFMT) | |
| { | |
| printf("\n it's not support avi format 0x%x \n", aviData->riffHeader.fcc); | |
| goto ErrExit; | |
| } | |
| gSampleRate = aviData->waveFormatex.nSamplesPerSec; | |
| s32TmpType = aviData->aviMainHeader.dwStreams; | |
| if (s32TmpType > 1) | |
| { | |
| if (aviData->waveFormatex.nChannels == 1) | |
| return eMulawAdo; | |
| else | |
| return eMpegAdo; | |
| } | |
| free(aviData->indexEntry); | |
| free(aviData); | |
| fclose(fp); | |
| return eOnlyVdo; | |
| ErrExit: | |
| free(aviData->indexEntry); | |
| free(aviData); | |
| fclose(fp); | |
| return eNULL; | |
| } | |
| int SetPreviewFreeze(int enable) | |
| { | |
| MSG_BUF msgbuf; | |
| int* ptr; | |
| memset(&msgbuf,0,sizeof(msgbuf)); | |
| msgbuf.Des = MSG_TYPE_MSG1; | |
| msgbuf.Src = MSG_TYPE_MSG13; | |
| msgbuf.cmd = MSG_CMD_SET_FREEZE; | |
| ptr = (int*)&msgbuf.mem_info; | |
| *ptr = enable; | |
| if (gErrProduceFlag) | |
| printf("[%s:%d] sned by self !!!\n",__FILE__,__LINE__); | |
| msgsnd( Msgqid, &msgbuf,sizeof(msgbuf)-sizeof(long),0);/*send msg1*/ | |
| msgrcv( Msgqid, &msgbuf,sizeof(msgbuf)-sizeof(long), MSG_TYPE_MSG13, 0); | |
| usleep(100); | |
| return msgbuf.ret; | |
| } | |
| //-------------------------------------------// | |
| // Author: Jaison // | |
| // Data : 2010.06.03 // | |
| // Destribution: // | |
| //-------------------------------------------// | |
| #if 1 | |
| extern int Msgqid; | |
| void VIDEO_SetCursorBusy(void) | |
| { | |
| MSG_BUF msgbuf; | |
| memset(&msgbuf, 0, sizeof(msgbuf)); | |
| msgbuf.Des = MSG_TYPE_MSG14; | |
| msgbuf.Src = 0; | |
| msgbuf.cmd = MSG_CMD_SETCursorBusy; | |
| msgsnd( Msgqid,&msgbuf,sizeof(msgbuf)-sizeof(long),0);//send msg1 | |
| } | |
| #endif | |
| /* | |
| pid_t getProcessId(const char * csProcessName) | |
| { | |
| struct kinfo_proc *sProcesses = NULL, *sNewProcesses; | |
| pid_t iCurrentPid; | |
| int aiNames[4]; | |
| size_t iNamesLength; | |
| int i, iRetCode, iNumProcs; | |
| size_t iSize; | |
| iSize = 0; | |
| aiNames[0] = CTL_KERN; | |
| aiNames[1] = KERN_PROC; | |
| aiNames[2] = KERN_PROC_ALL; | |
| aiNames[3] = 0; | |
| iNamesLength = 3; | |
| iRetCode = sysctl(aiNames, iNamesLength, NULL, &iSize, NULL, 0); | |
| //Allocate memory and populate info in the processes structure | |
| do { | |
| iSize += iSize / 10; | |
| sNewProcesses = realloc(sProcesses, iSize); | |
| if (sNewProcesses == 0) { | |
| if (sProcesses) | |
| free(sProcesses); | |
| errx(1, "could not reallocate memory"); | |
| } | |
| sProcesses = sNewProcesses; | |
| iRetCode = sysctl(aiNames, iNamesLength, sProcesses, &iSize, NULL, 0); | |
| } while (iRetCode == -1 && errno == ENOMEM); | |
| iNumProcs = iSize / sizeof(struct kinfo_proc); | |
| //Search for the given process name and return its pid. | |
| for (i = 0; i < iNumProcs; i++) { | |
| iCurrentPid = sProcesses[i].kp_proc.p_pid; | |
| if( strncmp(csProcessName, sProcesses[i].kp_proc.p_comm, MAXCOMLEN) == 0 ) { | |
| free(sProcesses); | |
| return iCurrentPid; | |
| } | |
| } | |
| //Clean up and return -1 because the given proc name was not found | |
| free(sProcesses); | |
| return (-1); | |
| } // end of getProcessId() | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //-------------------------------------------// | |
| //INCLUDES // | |
| //-------------------------------------------// | |
| #include <sys/time.h> | |
| #include <gst/gst.h> | |
| #include <glib.h> | |
| #include <sys/param.h> | |
| #include <sys/user.h> | |
| #include <sys/sysctl.h> | |
| #include <unistd.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| // communication include files | |
| #include <Msg_Def.h> | |
| #include <cmem.h> | |
| #include <sys/mman.h> | |
| #include <sys/ioctl.h> | |
| #include <Playback_Msg_Def.h> | |
| // pthread include files | |
| #include <pthread.h> | |
| #include "gst_player.h" | |
| // signal interrupt message | |
| #include <unistd.h> | |
| #include <signal.h> | |
| // Process Priority | |
| #include <sys/resource.h> | |
| // share memory | |
| #include <sys/shm.h> | |
| #define RRET__SUCCESS (0) | |
| #define RRET__FAIL (RRET__SUCCESS - 1000) | |
| //-------------------------------------------// | |
| //GLOBALS // | |
| //-------------------------------------------// | |
| int Msgqid=0,gStopFlag=FALSE, gThreadFlag=FALSE, s32InitFlag=FALSE; | |
| int gSampleRate=0, gErrProduceFlag=FALSE, gExecRst=0, gs32CodeType=0; | |
| char gCodeType[16] = ""; | |
| gridChoice_t *gParamPtr = NULL; | |
| //-------------------------------------------// | |
| //Pototypes and Macro // | |
| //-------------------------------------------// | |
| enum{eNULL, eOnlyVdo, eMulawAdo, eMpegAdo}; | |
| enum{eNoSupCode, eH264, eMPEG4}; | |
| enum{eFMTPASS, eErrFMT}; | |
| // loop waiting for bus message | |
| static void event_loop (GstElement * pipe); | |
| void vMsg_pThreadFunction(GstElement * pipe); | |
| void vRelease_Msg_pThread(); | |
| int Msg_Init(int msgKey); | |
| int AssayFile(char *FI_FileString); | |
| int SetPreviewFreeze(int enable); | |
| void vExitMsgProgram(); | |
| void VideoplaybackStopAck(void); | |
| void VIDEO_SetCursorBusy(void); | |
| //-------------------------------------------// | |
| //FUNCTIONS // | |
| //-------------------------------------------// | |
| /** | |
| * @Justin CMEM MMAP | |
| * @param none | |
| * @return pointer to cmem address | |
| */ | |
| extern int cmem_fd; | |
| void *CMEM_MMAP( unsigned long physp, int size ) | |
| { | |
| void *userp; | |
| if (cmem_fd == -1) { | |
| printf("[%s:%d]allocPool: You must initialize CMEM before making API calls.\n",__FILE__,__LINE__); | |
| return NULL; | |
| } | |
| /* Map the physical address to user space */ | |
| userp = mmap(0, // Preferred start address | |
| size, // Length to be mapped | |
| PROT_WRITE | PROT_READ, // Read and write access | |
| MAP_SHARED, // Shared memory | |
| cmem_fd, // File descriptor | |
| physp); // The byte offset from fd | |
| if (userp == MAP_FAILED) { | |
| printf("[%s:%d]allocPool: Failed to mmap buffer at physical address %#lx\n", | |
| __FILE__,__LINE__,physp); | |
| ioctl(cmem_fd, CMEM_IOCFREE, &physp); | |
| return NULL; | |
| } | |
| return userp; | |
| } | |
| //==========================// | |
| // Share memory functons // | |
| //==========================// | |
| int ShareMemInit(int key,int size) | |
| { | |
| int sharemid; | |
| sharemid = shmget(key, size, IPC_CREAT | 0660); | |
| if(sharemid < 0) | |
| { | |
| printf("Cannot get share memory:%d\n",sharemid); | |
| return -1; | |
| } | |
| return sharemid; | |
| } | |
| void* ShareMemMap(int sharemid) | |
| { | |
| char *psrc; | |
| if(sharemid < 0) | |
| return (void*)NULL; | |
| psrc = shmat(sharemid,0,0); | |
| return (void*)psrc; | |
| } | |
| int ShareUnMap(void *buf) | |
| { | |
| shmdt(buf); | |
| return 0; | |
| } | |
| #if 0 | |
| void timeStart(diffTime_t *timeRec) | |
| { | |
| struct timeval tv; | |
| if (gettimeofday(&tv, NULL) >= 0) | |
| timeRec->start = tv.tv_sec * 1000 + tv.tv_usec/1000; | |
| } | |
| void timeEnd(diffTime_t *timeRec) | |
| { | |
| struct timeval tv; | |
| if (gettimeofday(&tv, NULL) >= 0) | |
| timeRec->end = tv.tv_sec * 1000 + tv.tv_usec/1000; | |
| } | |
| double timeDiff(diffTime_t *timeRec) | |
| { | |
| return (double)(timeRec->end-timeRec->start)/1000; | |
| } | |
| #endif | |
| void exit_progream(int sig) | |
| { | |
| printf("Catched signal: %d !!\n", sig); | |
| vExitMsgProgram(); | |
| signal(SIGINT, SIG_DFL); | |
| } | |
| void WaitExecPlayback(void) | |
| { | |
| int s32Flag=1, msg_size = 0,msg_cnt=0; | |
| MSG_BUF msgbuf; | |
| while(s32Flag) | |
| { | |
| msg_size = msgrcv( Msgqid, &msgbuf, sizeof(msgbuf)-sizeof(long), MSG_TYPE_MSG13, 0); | |
| if (msg_size < 0) | |
| { | |
| } | |
| else | |
| { | |
| msgbuf.ret = 0; | |
| switch(msgbuf.cmd) | |
| { | |
| case MSG_CMD_PLAYBACK_ShowLogo: | |
| s32Flag = 0; | |
| msgbuf.ret = 1; | |
| s32InitFlag = TRUE; | |
| break; | |
| case MSG_CMD_PLAYBACK_PLAYING: | |
| s32Flag = 0; | |
| msgbuf.ret = 1; | |
| break; | |
| case MSG_CMD_VIDPLYBACK_INIT: | |
| if (gParamPtr == NULL) | |
| { | |
| CMEM_init(); | |
| gParamPtr = CMEM_MMAP(msgbuf.mem_info.addr, msgbuf.mem_info.size); | |
| printf("[%s:%d]gGridChoice->outRes=%d \n",__FILE__,__LINE__,gParamPtr->outRes); | |
| CMEM_exit(); | |
| } | |
| msgbuf.ret = 1; | |
| break; | |
| default: | |
| if (msg_cnt > 3) | |
| { | |
| sleep(1); | |
| msg_cnt=0; | |
| gErrProduceFlag = TRUE; | |
| printf("[%s:%d]inactive command: %d \n",__FILE__,__LINE__,msgbuf.cmd); | |
| }else{ | |
| msg_cnt++; | |
| } | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| void GetResolution(char *ResType, char *OutMode) | |
| { | |
| if (gParamPtr != NULL) | |
| { | |
| switch(gParamPtr->outRes) | |
| { | |
| case eXGA: | |
| strcpy(ResType, "XGA"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| case eD1_NTSC: | |
| strcpy(ResType,"D1_NTSC"); | |
| strcpy(OutMode, "COMPOSITE"); | |
| break; | |
| case e720P: | |
| strcpy(ResType,"720P"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| case eSXGA: | |
| strcpy(ResType,"SXGA"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| case eWXGA: | |
| strcpy(ResType,"WXGA"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| case eUXGA: | |
| strcpy(ResType,"UXGA"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| case e1080p: | |
| strcpy(ResType,"1080P"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| case eXGA_HF: | |
| strcpy(ResType, "XGA"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| default: | |
| strcpy(ResType,"SXGA"); | |
| strcpy(OutMode, "DIGITAL"); | |
| break; | |
| } | |
| } | |
| } | |
| int main (int argc, char *argv[]){ | |
| GstElement *bin = NULL; | |
| GstElement *filesrc = NULL; | |
| GError *error = NULL; | |
| gchar *GstCMDStr = NULL; | |
| ITEM_SETTING *SysInfoPtr = NULL; | |
| pthread_t Msg_pThread; | |
| GstState state=0,pending=0; | |
| int s32FileType = 0; | |
| int SysInfoShmemID= 0; | |
| char strOutRes[16] = ""; | |
| char strOutMod[12] = ""; | |
| char *LogoFilePath = "/opt/ipnc/Logo.avi"; | |
| char UserLogoPath[128]=""; | |
| strcpy (UserLogoPath, DF_LogoDir); | |
| strcat (UserLogoPath, DF_UserLogoFIle); | |
| strcat (UserLogoPath, ".avi"); | |
| SysInfoShmemID = ShareMemInit(ITEM_SETTING_MSG_KEY,sizeof(ITEM_SETTING)); | |
| SysInfoPtr =(ITEM_SETTING*)ShareMemMap(SysInfoShmemID); | |
| setpriority(PRIO_PROCESS, 0, 0); | |
| signal(SIGINT, exit_progream); | |
| //Messages communictaion Initial | |
| if (!Msgqid) | |
| Msgqid = Msg_Init(MSG_KEY); | |
| //gstreamer initial | |
| gst_init (&argc, &argv); | |
| #if 0 | |
| if (argc < 2) | |
| { | |
| g_print ("usage: %s <avi file> <option>\n", argv[0]); | |
| return 0; | |
| } | |
| #endif | |
| while(TRUE) | |
| { | |
| gExecRst=RRET__SUCCESS; | |
| WaitExecPlayback(); | |
| gs32CodeType = eNoSupCode; | |
| if (s32InitFlag == TRUE) | |
| { | |
| printf("--Info--[%s:%d] Display_Logo \n",__FILE__,__LINE__); | |
| GetResolution(strOutRes, strOutMod); | |
| if (SysInfoPtr->cUserLogoOn) | |
| { | |
| s32FileType = AssayFile(UserLogoPath); | |
| } | |
| else | |
| { | |
| s32FileType = AssayFile(LogoFilePath); | |
| } | |
| if ((s32FileType == eNULL)||(gs32CodeType == eNoSupCode)) | |
| { | |
| printf("--Error--[%s:%d] FileType = NULL !!!\n",__FILE__,__LINE__); | |
| s32InitFlag = FALSE; | |
| gExecRst=RRET__FAIL; | |
| VideoplaybackStopAck(); | |
| continue; | |
| } | |
| // Setting av_server status = Freeze | |
| SetPreviewFreeze(eReleaseDisMem); | |
| printf("--Info--[%s:%d]Release Display Memory finish \n",__FILE__,__LINE__); | |
| VIDEO_SetCursorBusy(); | |
| printf("--Info--[%s:%d]Set Cursor Icon finish \n",__FILE__,__LINE__); | |
| } | |
| else | |
| { | |
| printf("--Info--[%s:%d] Display_avi FilePath:%s \n",__FILE__,__LINE__,gParamPtr->filePath); | |
| GetResolution(strOutRes, strOutMod); | |
| s32FileType = AssayFile(gParamPtr->filePath); | |
| if ((s32FileType == eNULL)||(gs32CodeType == eNoSupCode)) | |
| { | |
| gExecRst=RRET__FAIL; | |
| VideoplaybackStopAck(); | |
| continue; | |
| } | |
| } | |
| //printf("[%s:%d] FilePath:%s Resolution:%s \n",__FILE__,__LINE__,gParamPtr->filePath,strOutRes); | |
| switch(s32FileType) | |
| { | |
| case eNULL: | |
| gExecRst=RRET__FAIL; | |
| continue; | |
| case eOnlyVdo: | |
| GstCMDStr = g_strdup_printf ("filesrc name=my_filesrc ! avidemux name=demux demux.video_00 ! TIViddec2 engineName=decode codecName=\"%s\" numOutputBufs=3 genTimeStamps=true gcloseloop=false ! TIDmaiVideoSink videoStd=\"%s\" videoOutput=\"%s\" resizer=TRUE",gCodeType,strOutRes,strOutMod); | |
| bin = (GstElement *) gst_parse_launch (GstCMDStr, &error); | |
| break; | |
| case eMulawAdo: | |
| GstCMDStr = g_strdup_printf ("filesrc name=my_filesrc ! avidemux name=demux demux.video_00 ! TIViddec2 engineName=decode codecName=\"%s\" numOutputBufs=3 genTimeStamps=true gcloseloop=true ! TIDmaiVideoSink videoStd=\"%s\" videoOutput=\"%s\" resizer=TRUE demux.audio_00 ! queue max-size-buffers=1600 max-size-time=0 max-size-bytes=0 ! decodebin ! queue ! audio/x-raw-int, rate=\"%d\" ! alsasink",gCodeType,strOutRes,strOutMod,gSampleRate); | |
| bin = (GstElement *) gst_parse_launch (GstCMDStr, &error); | |
| break; | |
| case eMpegAdo: | |
| GstCMDStr = g_strdup_printf ("filesrc name=my_filesrc ! avidemux name=demux demux.video_00 ! TIViddec2 engineName=decode codecName=\"%s\" numOutputBufs=3 genTimeStamps=true gcloseloop=false ! TIDmaiVideoSink videoStd=\"%s\" videoOutput=\"%s\" resizer=TRUE ",gCodeType,strOutRes,strOutMod); | |
| //GstCMDStr = g_strdup_printf ("filesrc name=my_filesrc ! avidemux name=demux demux.video_00 ! TIViddec2 engineName=decode codecName=\"%s\" numOutputBufs=3 genTimeStamps=true gcloseloop=false ! TIDmaiVideoSink videoStd=\"%s\" videoOutput=\"%s\" resizer=TRUE demux.audio_00 ! queue max-size-buffers=1600 max-size-time=0 max-size-bytes=0 ! mad ! queue ! audio/x-raw-int, rate=\"%d\" ! alsasink provide-clock=true",gCodeType,strOutRes,strOutMod,gSampleRate); | |
| bin = (GstElement *) gst_parse_launch (GstCMDStr, &error); | |
| break; | |
| } | |
| if (!bin) | |
| { | |
| printf("--Error--[%s:%d] Parse error: %s \n",__FILE__,__LINE__,error->message); | |
| } | |
| filesrc = gst_bin_get_by_name (GST_BIN (bin), "my_filesrc"); | |
| if (s32InitFlag == TRUE) | |
| { | |
| if (SysInfoPtr->cUserLogoOn) | |
| { | |
| g_object_set (G_OBJECT (filesrc), "location", UserLogoPath, NULL); | |
| } | |
| else | |
| { | |
| g_object_set (G_OBJECT (filesrc), "location", LogoFilePath, NULL); | |
| } | |
| } | |
| else | |
| { | |
| g_object_set (G_OBJECT (filesrc), "location", gParamPtr->filePath, NULL); | |
| } | |
| printf("--Info--[%s:%d] Setting file location finish \n",__FILE__,__LINE__); | |
| gst_element_set_state (bin, GST_STATE_READY); | |
| // Setting av_server status = Freeze | |
| if (!s32InitFlag) | |
| { | |
| SetPreviewFreeze(eReleaseDisMem); | |
| VIDEO_SetCursorBusy(); | |
| } | |
| gst_element_set_state (bin, GST_STATE_PLAYING); | |
| usleep(100000); | |
| //create receiver control message of pthread | |
| pthread_create(&Msg_pThread, NULL, (void *) vMsg_pThreadFunction, bin); | |
| pthread_detach(Msg_pThread); | |
| /* Run event loop listening for bus messages until EOS or ERROR */ | |
| event_loop (bin); | |
| /* stop the bin */ | |
| //gst_element_get_state (bin, &state, &pending, GST_CLOCK_TIME_NONE); | |
| if (!gStopFlag) | |
| { | |
| printf("--Info--[%s:%d]Setting pipeline to PAUSED ...\n",__FILE__,__LINE__); | |
| gst_element_set_state (bin, GST_STATE_PAUSED); | |
| //gst_element_get_state (bin, &state, &pending, GST_CLOCK_TIME_NONE); | |
| //iterate mainloop to process pending stuff | |
| while (g_main_context_iteration (NULL, FALSE)); | |
| } | |
| else | |
| gStopFlag = FALSE; | |
| printf("--Info--[%s:%d]Setting pipeline to READY ...\n",__FILE__,__LINE__); | |
| gst_element_get_state (bin, &state, &pending, GST_CLOCK_TIME_NONE); | |
| if (state == GST_STATE_PAUSED) | |
| gst_element_set_state (bin, GST_STATE_READY); | |
| printf("--Info--[%s:%d] set gst pipeline status to NULL \n",__FILE__,__LINE__); | |
| gst_element_set_state (bin, GST_STATE_NULL); | |
| gst_object_unref (GST_OBJECT (bin)); | |
| while(gThreadFlag){usleep(100000);} | |
| // Setting av_server status = Freeze | |
| printf("--Info--[%s:%d] Setting av_server into unFreeze status \n",__FILE__,__LINE__); | |
| SetPreviewFreeze(eAllocateMem); | |
| VideoplaybackStopAck(); | |
| s32InitFlag = FALSE; | |
| } | |
| return 0; | |
| } | |
| //! loop waiting for bus message | |
| static void event_loop (GstElement * pipe) | |
| { | |
| GstBus *bus = NULL ; | |
| GstMessage *message = NULL ; | |
| GError *gerror = NULL ; | |
| gchar *debug = NULL ; | |
| gboolean bLoop ; | |
| char ch=0; | |
| bLoop = TRUE ; | |
| bus = gst_element_get_bus (GST_ELEMENT (pipe)); | |
| printf("event_loop ... start \n"); | |
| while (bLoop) | |
| { | |
| ch = 0; | |
| message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1); | |
| //g_assert (message != NULL); | |
| if (message == NULL) | |
| continue; | |
| //printf("Processing message: %d \n", message->type); | |
| switch (message->type) | |
| { | |
| case GST_MESSAGE_EOS: | |
| gst_message_unref (message); | |
| vRelease_Msg_pThread(); | |
| bLoop = FALSE ; | |
| break ; | |
| case GST_MESSAGE_STATE_CHANGED: | |
| { | |
| GstState old, new, pending; | |
| gst_message_parse_state_changed (message, &old, &new, &pending); | |
| /* we only care about pipeline state change messages */ | |
| if (GST_MESSAGE_SRC (message) != GST_OBJECT_CAST (pipe)) | |
| break; | |
| /* dump graph for pipeline state changes */ | |
| { | |
| gchar *dump_name = g_strdup_printf ("gst-launch.%s_%s", | |
| gst_element_state_get_name (old), | |
| gst_element_state_get_name (new)); | |
| printf("[%s:%d] %s \n",__FILE__,__LINE__,dump_name); | |
| GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipe), | |
| GST_DEBUG_GRAPH_SHOW_ALL, dump_name); | |
| g_free (dump_name); | |
| } | |
| /* | |
| // ignore when we are buffering since then we mess with the states ourselves. | |
| if (buffering) { | |
| PRINT (_("Prerolled, waiting for buffering to finish...\n")); | |
| break; | |
| } | |
| // if we reached the final target state, exit | |
| if (target_state == GST_STATE_PAUSED && new == target_state) | |
| goto exit; | |
| */ | |
| /* else not an interesting message */ | |
| break; | |
| } | |
| //case GST_MESSAGE_WARNING: | |
| case GST_MESSAGE_ERROR: | |
| gst_message_parse_error (message, &gerror, &debug); | |
| gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); | |
| gst_message_unref (message); | |
| vRelease_Msg_pThread(); | |
| g_error_free (gerror); | |
| g_free (debug); | |
| bLoop = FALSE; | |
| gExecRst=RRET__FAIL; | |
| break; | |
| case GST_MESSAGE_NEW_CLOCK: | |
| { | |
| GstClock *clock; | |
| gst_message_parse_new_clock (message, &clock); | |
| printf("New clock: %s\n", (clock ? GST_OBJECT_NAME (clock) : "NULL")); | |
| break; | |
| } | |
| default: | |
| if (gStopFlag == TRUE) | |
| bLoop = FALSE; | |
| gst_message_unref (message); | |
| break; | |
| } | |
| } | |
| } | |
| void vMsg_pThreadFunction(GstElement * pipe) | |
| { | |
| int s32Flag=1, msg_size = 0, msg_cnt=0; | |
| MSG_BUF msgbuf; | |
| gThreadFlag = TRUE; | |
| GstState state, pending; | |
| while(s32Flag) | |
| { | |
| msg_size = msgrcv( Msgqid, &msgbuf, sizeof(msgbuf)-sizeof(long), MSG_TYPE_MSG13, 0); | |
| if (msg_size < 0) | |
| { | |
| } | |
| else | |
| { | |
| switch( msgbuf.cmd ) | |
| { | |
| case MSG_CMD_PLAYBACK_PLAYING: | |
| gst_element_set_state (pipe, GST_STATE_PLAYING); | |
| break; | |
| case MSG_CMD_PLAYBACK_PAUSED: | |
| printf("[%s:%d] \n",__FILE__,__LINE__); | |
| gst_element_set_state (pipe, GST_STATE_PAUSED); | |
| break; | |
| case MSG_CMD_PLAYBACK_STOP: | |
| gStopFlag = TRUE; | |
| printf("--Info--[%s:%d]Setting Playback to Stop ...\n",__FILE__,__LINE__); | |
| gst_element_get_state (pipe, &state, &pending, GST_CLOCK_TIME_NONE); | |
| if (state == GST_STATE_PLAYING) | |
| gst_element_set_state (pipe, GST_STATE_PAUSED); | |
| else | |
| gst_element_set_state (pipe, GST_STATE_READY); | |
| // iterate mainloop to process pending stuff | |
| //while (g_main_context_iteration (NULL, FALSE)); | |
| s32Flag = 0; | |
| break; | |
| case MSG_CMD_PLAYBACK_EOS: | |
| s32Flag = 0; | |
| break; | |
| default: | |
| if (msg_cnt > 3) | |
| { | |
| sleep(1); | |
| msg_cnt=0; | |
| printf("--Info--[%s:%d]inactive command: %d \n",__FILE__,__LINE__,msgbuf.cmd); | |
| }else{ | |
| msg_cnt++; | |
| } | |
| break; | |
| } | |
| } | |
| } | |
| gThreadFlag = FALSE; | |
| pthread_exit("Msg_pThread exit !"); | |
| } | |
| //-------------------------------------------// | |
| // Author: Jaison // | |
| // Create: 2010.02.03 // | |
| // Discription: IPC message initial // | |
| //-------------------------------------------// | |
| int Msg_Init( int msgKey ) | |
| { | |
| int qid; | |
| key_t key = msgKey; | |
| qid = msgget(key,0); | |
| if( qid < 0 ) | |
| { | |
| qid = msgget(key,IPC_CREAT|0666); | |
| } | |
| return qid; | |
| } | |
| void vRelease_Msg_pThread() | |
| { | |
| MSG_BUF msgbuf; | |
| memset(&msgbuf,0,sizeof(msgbuf)); | |
| msgbuf.Des = MSG_TYPE_MSG13; | |
| msgbuf.Src = MSG_TYPE_MSG13; | |
| msgbuf.cmd = MSG_CMD_PLAYBACK_EOS; | |
| msgbuf.mem_info.addr = 0; | |
| msgbuf.mem_info.size = 0; | |
| if (gErrProduceFlag) | |
| printf("[%s:%d] sned by self !!!\n",__FILE__,__LINE__); | |
| msgsnd( Msgqid, &msgbuf, sizeof(msgbuf)-sizeof(long), 0);//send msg1 | |
| // msgrcv( Msgqid, &msgbuf, sizeof(msgbuf)-sizeof(long), MSG_TYPE_MSG13, 0); | |
| // return msgbuf.ret; | |
| } | |
| void VideoplaybackStopAck(void) | |
| { | |
| MSG_BUF msgbuf; | |
| memset(&msgbuf,0,sizeof(msgbuf)); | |
| msgbuf.Des = MSG_TYPE_MSG14; | |
| msgbuf.Src = 0; | |
| msgbuf.cmd = MSG_CMD_PLAYBACK_STOP; | |
| msgbuf.mem_info.addr = 0; | |
| msgbuf.mem_info.size = 0; | |
| msgbuf.ret = gExecRst; | |
| if (gErrProduceFlag) | |
| printf("[%s:%d] sned by self !!!\n",__FILE__,__LINE__); | |
| printf("[%s:%d] VideoplaybackStopAck \n",__FILE__,__LINE__); | |
| msgsnd( Msgqid, &msgbuf, sizeof(msgbuf)-sizeof(long), 0);//send msg1 | |
| } | |
| void vExitMsgProgram() | |
| { | |
| MSG_BUF msgbuf; | |
| memset(&msgbuf,0,sizeof(msgbuf)); | |
| msgbuf.Des = MSG_TYPE_MSG13; | |
| msgbuf.Src = MSG_TYPE_MSG13; | |
| msgbuf.cmd = MSG_CMD_PLAYBACK_STOP; | |
| msgbuf.mem_info.addr = 0; | |
| msgbuf.mem_info.size = 0; | |
| if (gErrProduceFlag) | |
| printf("[%s:%d] sned by self !!!\n",__FILE__,__LINE__); | |
| msgsnd( Msgqid, &msgbuf, sizeof(msgbuf)-sizeof(long), 0);//send msg1 | |
| } | |
| void printFourcc(FOURCC fcc) | |
| { | |
| int i; | |
| DWORD mask = 0xff, chr = 0x0; | |
| for(i=0;i<4;i++){ | |
| chr=(fcc&(mask<<(8*i)))>>i*8; | |
| printf("%c",chr); | |
| } | |
| printf("\n"); | |
| } | |
| int matchStreamType(FOURCC sType) | |
| { | |
| if(sType == vids_fcc) return 0; | |
| if(sType == auds_fcc) return 1; | |
| if(sType == txts_fcc) return 2; | |
| if(sType == odml_fcc) return 3; | |
| return -1; | |
| } | |
| int readFileInfo(FILE *fp, struct AVIDATA* aviData) | |
| { | |
| int i; | |
| /*** read riff header information ***/ | |
| fread(&aviData->riffHeader, sizeof(struct RIFFHEADER), 1, fp); | |
| if (aviData->riffHeader.fcc != RIFF_fcc) | |
| return eErrFMT; | |
| /*** read LIST 0 information ***/ | |
| fread(&aviData->list1, sizeof(struct LIST), 1, fp); | |
| /*** read AVI Main header ***/ | |
| fread(&aviData->aviMainHeader, sizeof(struct AVIMAINHEADER), 1, fp); | |
| for(i=0;i<aviData->aviMainHeader.dwStreams;i++){ | |
| /*** read sub list info. ***/ | |
| fread(&aviData->subList[i], sizeof(struct LIST), 1, fp); | |
| /*** read AVI Stream Header ***/ | |
| fread(&aviData->aviStreamHeader[i], sizeof(struct AVISTREAMHEADER), 1, fp); | |
| switch(matchStreamType(aviData->aviStreamHeader[i].fccType)){ | |
| case 0: /* vids */ | |
| /* read bitmap header */ | |
| fread(&aviData->bitmapInfoHeader, sizeof(struct BITMAPINFOHEADER), 1, fp); | |
| /*== jump to next sublist ==*/ | |
| /* back to the front of current list */ | |
| /* 12 bytes for LIST */ | |
| /* n bytes for BITMAPINFOHEADER */ | |
| /* jump to next list */ | |
| /* 4 bytes for 'LIST' */ | |
| /* 4 bytes for the variable subList[i].cb */ | |
| /* n bytes for current whole list structure (sizeOfSubList[i]) */ | |
| fseek(fp, sizeofFCC+sizeofCB+aviData->subList[i].cb-(sizeof(struct BITMAPINFOHEADER)+sizeof(struct LIST)+sizeof(struct AVISTREAMHEADER)), SEEK_CUR); | |
| if(i == 0){ | |
| aviData->vidsIDb = x0db_fcc; | |
| aviData->vidsIDc = x0dc_fcc; | |
| }else{ | |
| aviData->vidsIDb = x1db_fcc; | |
| aviData->vidsIDc = x1dc_fcc; | |
| } | |
| if (aviData->aviStreamHeader[i].fccHandler == H264_fcc) | |
| { | |
| gs32CodeType = eH264; | |
| strcpy(gCodeType, "h264dec\0"); | |
| } | |
| if (aviData->aviStreamHeader[i].fccHandler == FMP4_fcc) | |
| { | |
| gs32CodeType = eMPEG4; | |
| strcpy(gCodeType, "mpeg4dec\0"); | |
| } | |
| break; | |
| case 1: /* auds */ | |
| fread(&aviData->waveFormatex, sizeof(struct WAVEFORMATEX), 1, fp); | |
| /*== jump to next sublist ==*/ | |
| /* back to the front of current list */ | |
| /* 12 bytes for LIST */ | |
| /* n bytes for WAVEFORMATEX */ | |
| /* jump to next list */ | |
| /* 4 bytes for 'LIST' */ | |
| /* 4 bytes for the variable subList[i].cb */ | |
| /* n bytes for current whole list structure (sizeOfSubList[i]) */ | |
| fseek(fp, sizeofFCC+sizeofCB+aviData->subList[i].cb-(sizeof(struct WAVEFORMATEX)+sizeof(struct LIST)+sizeof(struct AVISTREAMHEADER)), SEEK_CUR); | |
| if(i == 0){ | |
| aviData->audsID = x0wb_fcc; | |
| }else{ | |
| aviData->audsID = x1wb_fcc; | |
| } | |
| break; | |
| case 2: /* txts */ | |
| break; | |
| case 3: /* odml */ | |
| break; | |
| default: | |
| printf("Sorry! This program can't recogize the stream type %d %#x:", i,aviData->aviStreamHeader[i].fccType); | |
| printFourcc(aviData->aviStreamHeader[i].fccType); | |
| break; | |
| } | |
| } | |
| /*== jump to the end of list 1 ==*/ | |
| /* 12 bytes for RIFFHEADER */ | |
| /* 4 bytes for 'LIST' */ | |
| /* 4 bytes for the variable list1.cb */ | |
| /* n bytes for the whole LIST 1 structrue (sizeOfList1) */ | |
| fseek(fp, sizeof(struct RIFFHEADER)+sizeofFCC+sizeofCB+aviData->list1.cb, SEEK_SET); | |
| /*** JUNK chunk checking until we reached the 'movi' ***/ | |
| fread(&aviData->list2, sizeof(struct LIST), 1, fp); | |
| while(aviData->list2.subFcc != movi_fcc){ | |
| /*** cause we alread read extra 4 bytes, so we need to minus 4 bytes when we jump ***/ | |
| fseek(fp, -sizeofFCC+aviData->list2.cb, SEEK_CUR); | |
| fread(&aviData->list2, sizeof(struct LIST), 1, fp); | |
| } | |
| /*** record current position ***/ | |
| aviData->posOfFirstDataBlock = ftell(fp); | |
| #if 0 | |
| /*** check if the video has index ***/ | |
| if((aviData->aviMainHeader.dwFlags & AVIF_HASINDEX)){ | |
| /*** jump to the end of List 2 ***/ | |
| fseek(fp,-sizeofFCC+aviData->list2.cb, SEEK_CUR); /* minus 4 bytes for current position ('movi') */ | |
| fread(&aviData->avioldIndex, sizeof(struct AVIOLDINDEX), 1, fp); | |
| /* JUNK checking */ | |
| while(aviData->avioldIndex.fcc != idx1_fcc){ | |
| fseek(fp, aviData->avioldIndex.cb, SEEK_CUR); | |
| fread(&aviData->avioldIndex, sizeof(struct AVIOLDINDEX), 1, fp); | |
| } | |
| /*** the total index item is total index size divide each element size (sizeof(struct AVIOLDINDEX_ENTRY)) */ | |
| aviData->numOfIndexItem = aviData->avioldIndex.cb/sizeof(struct AVIOLDINDEX_ENTRY); | |
| aviData->indexEntry = (struct AVIOLDINDEX_ENTRY*)calloc(aviData->numOfIndexItem, sizeof(struct AVIOLDINDEX_ENTRY)); | |
| fread(aviData->indexEntry, sizeof(struct AVIOLDINDEX_ENTRY), aviData->numOfIndexItem, fp); | |
| /*** check the dwOffset error ***/ | |
| aviData->posError = aviData->posOfFirstDataBlock-aviData->indexEntry[0].dwOffset; | |
| }else{ | |
| printf("Sorry! This program don't support the video without index information!"); | |
| exit(EXIT_FAILURE); | |
| } | |
| #endif | |
| return eFMTPASS; | |
| } | |
| int AssayFile(char *FI_FileString) | |
| { | |
| FILE *fp; | |
| struct AVIDATA* aviData; | |
| int s32TmpType=0; | |
| aviData = (struct AVIDATA*)calloc(1, sizeof(struct AVIDATA)); | |
| /** open avi video ***/ | |
| if((fp = fopen(FI_FileString, "rb")) == NULL){ | |
| printf("Fail to open %s \n!", FI_FileString); | |
| free(aviData); | |
| return eNULL; | |
| } | |
| if (readFileInfo(fp, aviData) == eErrFMT) | |
| { | |
| printf("\n it's not support avi format 0x%x \n", aviData->riffHeader.fcc); | |
| goto ErrExit; | |
| } | |
| gSampleRate = aviData->waveFormatex.nSamplesPerSec; | |
| s32TmpType = aviData->aviMainHeader.dwStreams; | |
| if (s32TmpType > 1) | |
| { | |
| if (aviData->waveFormatex.nChannels == 1) | |
| return eMulawAdo; | |
| else | |
| return eMpegAdo; | |
| } | |
| free(aviData->indexEntry); | |
| free(aviData); | |
| fclose(fp); | |
| return eOnlyVdo; | |
| ErrExit: | |
| free(aviData->indexEntry); | |
| free(aviData); | |
| fclose(fp); | |
| return eNULL; | |
| } | |
| int SetPreviewFreeze(int enable) | |
| { | |
| MSG_BUF msgbuf; | |
| int* ptr; | |
| memset(&msgbuf,0,sizeof(msgbuf)); | |
| msgbuf.Des = MSG_TYPE_MSG1; | |
| msgbuf.Src = MSG_TYPE_MSG13; | |
| msgbuf.cmd = MSG_CMD_SET_FREEZE; | |
| ptr = (int*)&msgbuf.mem_info; | |
| *ptr = enable; | |
| if (gErrProduceFlag) | |
| printf("[%s:%d] sned by self !!!\n",__FILE__,__LINE__); | |
| msgsnd( Msgqid, &msgbuf,sizeof(msgbuf)-sizeof(long),0);/*send msg1*/ | |
| msgrcv( Msgqid, &msgbuf,sizeof(msgbuf)-sizeof(long), MSG_TYPE_MSG13, 0); | |
| usleep(100); | |
| return msgbuf.ret; | |
| } | |
| //-------------------------------------------// | |
| // Author: Jaison // | |
| // Data : 2010.06.03 // | |
| // Destribution: // | |
| //-------------------------------------------// | |
| #if 1 | |
| extern int Msgqid; | |
| void VIDEO_SetCursorBusy(void) | |
| { | |
| MSG_BUF msgbuf; | |
| memset(&msgbuf, 0, sizeof(msgbuf)); | |
| msgbuf.Des = MSG_TYPE_MSG14; | |
| msgbuf.Src = 0; | |
| msgbuf.cmd = MSG_CMD_SETCursorBusy; | |
| msgsnd( Msgqid,&msgbuf,sizeof(msgbuf)-sizeof(long),0);//send msg1 | |
| } | |
| #endif | |
| /* | |
| pid_t getProcessId(const char * csProcessName) | |
| { | |
| struct kinfo_proc *sProcesses = NULL, *sNewProcesses; | |
| pid_t iCurrentPid; | |
| int aiNames[4]; | |
| size_t iNamesLength; | |
| int i, iRetCode, iNumProcs; | |
| size_t iSize; | |
| iSize = 0; | |
| aiNames[0] = CTL_KERN; | |
| aiNames[1] = KERN_PROC; | |
| aiNames[2] = KERN_PROC_ALL; | |
| aiNames[3] = 0; | |
| iNamesLength = 3; | |
| iRetCode = sysctl(aiNames, iNamesLength, NULL, &iSize, NULL, 0); | |
| //Allocate memory and populate info in the processes structure | |
| do { | |
| iSize += iSize / 10; | |
| sNewProcesses = realloc(sProcesses, iSize); | |
| if (sNewProcesses == 0) { | |
| if (sProcesses) | |
| free(sProcesses); | |
| errx(1, "could not reallocate memory"); | |
| } | |
| sProcesses = sNewProcesses; | |
| iRetCode = sysctl(aiNames, iNamesLength, sProcesses, &iSize, NULL, 0); | |
| } while (iRetCode == -1 && errno == ENOMEM); | |
| iNumProcs = iSize / sizeof(struct kinfo_proc); | |
| //Search for the given process name and return its pid. | |
| for (i = 0; i < iNumProcs; i++) { | |
| iCurrentPid = sProcesses[i].kp_proc.p_pid; | |
| if( strncmp(csProcessName, sProcesses[i].kp_proc.p_comm, MAXCOMLEN) == 0 ) { | |
| free(sProcesses); | |
| return iCurrentPid; | |
| } | |
| } | |
| //Clean up and return -1 because the given proc name was not found | |
| free(sProcesses); | |
| return (-1); | |
| } // end of getProcessId() | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment