/* called by video capture every 10 sec for checking disk free space*/ gboolean FreeDiskCheck_timer(gpointer data) { struct ALL_DATA * all_data = (struct ALL_DATA *) data; struct vdIn *videoIn = all_data->videoIn; struct GLOBAL *global = all_data->global; struct GWIDGET *gwidget = all_data->gwidget; __LOCK_MUTEX(__VMUTEX); gboolean capVid = videoIn->capVid; __UNLOCK_MUTEX(__VMUTEX); if (capVid) { if(!DiskSupervisor(data)) { g_printerr("Stopping video Capture\n"); /*stop video capture*/ if(global->debug) g_print("setting video toggle to FALSE\n"); if(!global->no_display) { //gdk_threads_enter(); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(gwidget->CapVidButt), FALSE); gdk_flush(); //gdk_threads_leave(); } else capture_vid(NULL, all_data); } else return(TRUE); /*keeps the timer*/ } return (FALSE);/*destroys the timer*/ }
/* called by video capture from start timer */ gboolean timer_callback(gpointer data) { struct ALL_DATA * all_data = (struct ALL_DATA *) data; struct vdIn *videoIn = all_data->videoIn; struct GLOBAL *global = all_data->global; struct GWIDGET *gwidget = all_data->gwidget; __LOCK_MUTEX(__VMUTEX); gboolean capVid = videoIn->capVid; __UNLOCK_MUTEX(__VMUTEX); if(!capVid) return (FALSE);/*destroys the timer*/ /*stop video capture*/ if(global->debug) g_print("setting video toggle to FALSE\n"); if(!global->no_display) { //gdk_threads_enter(); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(gwidget->CapVidButt), FALSE); gdk_flush(); //gdk_threads_leave(); } else { capture_vid(NULL, all_data); } global->Capture_time=0; //if exit_on_close then shutdown if(global->exit_on_close) shutd (0, data); return (FALSE);/*destroys the timer*/ }
static int initVideoFile(struct ALL_DATA *all_data) { struct GWIDGET *gwidget = all_data->gwidget; struct paRecordData *pdata = all_data->pdata; struct GLOBAL *global = all_data->global; struct vdIn *videoIn = all_data->videoIn; struct VideoFormatData *videoF = all_data->videoF; const char *compression= get_vid4cc(global->VidCodec); videoF->vcodec = get_vcodec_id(global->VidCodec); videoF->acodec = CODEC_ID_NONE; videoF->keyframe = 0; int ret = 0; __LOCK_MUTEX(__VMUTEX); gboolean capVid = videoIn->capVid; __UNLOCK_MUTEX(__VMUTEX); /*alloc video ring buffer*/ alloc_videoBuff(all_data); switch (global->VidFormat) { case AVI_FORMAT: if(videoF->AviOut != NULL) { g_free(videoF->AviOut); videoF->AviOut = NULL; } videoF->AviOut = g_new0(struct avi_t, 1); if(AVI_open_output_file(videoF->AviOut, videoIn->VidFName)<0) { g_printerr("Error: Couldn't create Video.\n"); capVid = FALSE; /*don't start video capture*/ __LOCK_MUTEX(__VMUTEX); videoIn->capVid = capVid; __UNLOCK_MUTEX(__VMUTEX); pdata->capVid = capVid; return(-1); } else { AVI_set_video(videoF->AviOut, global->width, global->height, global->fps, compression); /* start video capture*/ capVid = TRUE; __LOCK_MUTEX(__VMUTEX); videoIn->capVid = capVid; __UNLOCK_MUTEX(__VMUTEX); pdata->capVid = capVid; /* start sound capture*/ if(global->Sound_enable > 0) { /*get channels and sample rate*/ set_sound(global, pdata); /*set audio header for avi*/ AVI_set_audio(videoF->AviOut, global->Sound_NumChan, global->Sound_SampRate, get_aud_bit_rate(get_ind_by4cc(global->Sound_Format)), /*bit rate*/ get_aud_bits(get_ind_by4cc(global->Sound_Format)), /*sample size - only used for PCM*/ global->Sound_Format); /* Initialize sound (open stream)*/ if(init_sound (pdata)) { g_printerr("Audio initialization error\n"); global->Sound_enable=0; if(!(global->no_display)) { gdk_threads_enter(); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gwidget->SndEnable),0); gdk_flush(); gdk_threads_leave(); } else capture_vid(NULL, all_data); } } } break; case MKV_FORMAT: if(global->Sound_enable > 0) { /*set channels, sample rate and allocate buffers*/ set_sound(global, pdata); } if(init_FormatContext((void *) all_data)<0) { capVid = FALSE; __LOCK_MUTEX(__VMUTEX); videoIn->capVid = capVid; __UNLOCK_MUTEX(__VMUTEX); pdata->capVid = capVid; return (-1); } videoF->old_apts = 0; videoF->apts = 0; videoF->vpts = 0; /* start video capture*/ capVid = TRUE; __LOCK_MUTEX(__VMUTEX); videoIn->capVid = capVid; __UNLOCK_MUTEX(__VMUTEX); pdata->capVid = capVid; /* start sound capture*/ if(global->Sound_enable > 0) { /* Initialize sound (open stream)*/ if(init_sound (pdata)) { g_printerr("Audio initialization error\n"); global->Sound_enable=0; if(!(global->no_display)) { /*will this work with the checkbox disabled?*/ gdk_threads_enter(); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gwidget->SndEnable),0); gdk_flush(); gdk_threads_leave(); } else capture_vid(NULL, all_data); } } break; //WebM = MKV + WebVTT //add META data capture case WEBM_FORMAT: if(global->Sound_enable > 0) { /*set channels, sample rate and allocate buffers*/ set_sound(global, pdata); } if(init_FormatContext((void *) all_data)<0) { capVid = FALSE; __LOCK_MUTEX(__VMUTEX); videoIn->capVid = capVid; __UNLOCK_MUTEX(__VMUTEX); pdata->capVid = capVid; return (-1); } videoF->old_apts = 0; videoF->apts = 0; videoF->vpts = 0; /* start video capture*/ capVid = TRUE; __LOCK_MUTEX(__VMUTEX); videoIn->capVid = capVid; __UNLOCK_MUTEX(__VMUTEX); pdata->capVid = capVid; /* start sound capture*/ if(global->Sound_enable > 0) { /* Initialize sound (open stream)*/ if(init_sound (pdata)) { g_printerr("Audio initialization error\n"); global->Sound_enable=0; if(!(global->no_display)) { /*will this work with the checkbox disabled?*/ gdk_threads_enter(); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gwidget->SndEnable),0); gdk_flush(); gdk_threads_leave(); } else capture_vid(NULL, all_data); } } break; default: break; } return (ret); }
static int write_audio_frame (struct ALL_DATA *all_data) { struct paRecordData *pdata = all_data->pdata; struct GLOBAL *global = all_data->global; struct VideoFormatData *videoF = all_data->videoF; struct GWIDGET *gwidget = all_data->gwidget; int ret =0; __THREAD_TYPE press_butt_thread; switch (global->VidFormat) { case AVI_FORMAT: if(!(global->VidButtPress)) //if this is set AVI reached it's limit size ret = compress_audio_frame(all_data); if (ret) { if (AVI_getErrno () == AVI_ERR_SIZELIM) { if (!(global->VidButtPress)) { global->VidButtPress = TRUE; /*avi file limit reached - must end capture close file and start new one*/ if( __THREAD_CREATE(&press_butt_thread, split_avi, all_data)) //should be created detachable { /*thread failed to start - stop video capture */ /*can't restart since we need IO thread to stop */ g_printerr("split avi: thread creation failed\n"); printf("stoping video capture\n"); if(!(global->no_display)) { gdk_threads_enter(); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(gwidget->CapVidButt), FALSE); gdk_flush(); gdk_threads_leave(); } else capture_vid(NULL, all_data); } //split_avi(all_data);/*blocking call*/ g_print("AVI file size limit reached - restarted capture on new file\n"); } } else { g_printerr ("write error on avi out \n"); } } break; case MKV_FORMAT: __LOCK_MUTEX( __AMUTEX ); //why do we need this ??? /*set pts*/ videoF->apts = pdata->audio_buff[pdata->br_ind][pdata->r_ind].time_stamp; /*write audio chunk*/ ret = compress_audio_frame(all_data); __UNLOCK_MUTEX( __AMUTEX ); break; default: break; } return (0); }
static int write_video_frame (struct ALL_DATA *all_data, void *jpeg_struct, void *lavc_data, VidBuff *proc_buff) { struct GLOBAL *global = all_data->global; struct GWIDGET *gwidget = all_data->gwidget; __THREAD_TYPE press_butt_thread; int ret=0; switch (global->VidFormat) { case AVI_FORMAT: /*all video controls are now disabled so related values cannot be changed*/ if(!(global->VidButtPress)) //if this is set AVI reached it's limit size ret = compress_frame(all_data, jpeg_struct, lavc_data, proc_buff); if (ret) { if (AVI_getErrno () == AVI_ERR_SIZELIM) { if (!(global->VidButtPress)) { global->VidButtPress = TRUE; /*avi file limit reached - must end capture close file and start new one*/ if( __THREAD_CREATE(&press_butt_thread, split_avi, all_data)) //should be created detachable { /*thread failed to start - stop video capture */ /*can't restart since we need IO thread to stop */ g_printerr("split avi: thread creation failed\n"); printf("stoping video capture\n"); if(!(global->no_display)) { gdk_threads_enter(); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(gwidget->CapVidButt), FALSE); gdk_flush(); gdk_threads_leave(); } else capture_vid(NULL, all_data); } g_print("AVI file size limit reached - restarted capture on new file\n"); } } else { g_printerr ("write error on avi out \n"); } } break; case MKV_FORMAT: //global->framecount++; ret = compress_frame(all_data, jpeg_struct, lavc_data, proc_buff); break; case WEBM_FORMAT: //global->framecount++; ret = compress_frame(all_data, jpeg_struct, lavc_data, proc_buff); break; default: break; } return (0); }