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 initVideoFile(struct ALL_DATA *all_data, void* lav_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; io_Stream *vstream, *astream; struct lavcData **lavc_data = (struct lavcData **) lav_data; videoF->vcodec = get_vcodec_id(global->VidCodec); videoF->acodec = get_acodec_id(global->AudCodec); videoF->keyframe = 0; int ret = 0; __LOCK_MUTEX(__VMUTEX); gboolean capVid = videoIn->capVid; __UNLOCK_MUTEX(__VMUTEX); /*alloc video ring buffer*/ alloc_videoBuff(all_data); if(isLavcCodec(global->VidCodec)) *lavc_data = init_lavc(global->width, global->height, global->fps_num, global->fps, global->VidCodec); switch (global->VidFormat) { case AVI_FORMAT: if(videoF->avi != NULL) { avi_destroy_context(videoF->avi); videoF->avi = NULL; } videoF->avi = avi_create_context(videoIn->VidFName); if(!videoF->avi) { g_printerr("Error: Couldn't create AVI context.\n"); capVid = FALSE; /*don't start video capture*/ __LOCK_MUTEX(__VMUTEX); videoIn->capVid = capVid; __UNLOCK_MUTEX(__VMUTEX); pdata->capVid = capVid; return(-1); } vstream = avi_add_video_stream(videoF->avi, global->width, global->height, global->fps, videoF->vcodec, get_vid4cc(global->VidCodec)); if(videoF->vcodec == AV_CODEC_ID_THEORA) { vstream->extra_data = (BYTE*) (*lavc_data)->codec_context->extradata; vstream->extra_data_size = (*lavc_data)->codec_context->extradata_size; } if(global->Sound_enable > 0) { /*get channels and sample rate*/ set_sound(global, pdata); /*sample size - only used for PCM*/ int32_t a_bits = get_aud_bits(global->AudCodec); /*bit rate (compressed formats)*/ int32_t b_rate = get_aud_bit_rate(global->AudCodec); astream = avi_add_audio_stream(videoF->avi, global->Sound_NumChan, global->Sound_SampRate, a_bits, b_rate, videoF->acodec, global->Sound_Format); if(videoF->acodec == AV_CODEC_ID_VORBIS) { astream->extra_data = (BYTE*) pdata->lavc_data->codec_context->extradata; astream->extra_data_size = pdata->lavc_data->codec_context->extradata_size; } } /* add first riff header */ avi_add_new_riff(videoF->avi); /* 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 && init_sound (pdata)) { //FIXME: enable capture button g_printerr("Audio initialization error\n"); global->Sound_enable=0; } break; case WEBM_FORMAT: case MKV_FORMAT: if(videoF->mkv != NULL) { mkv_destroy_context(videoF->mkv); videoF->mkv = NULL; } videoF->mkv = mkv_create_context(videoIn->VidFName, global->VidFormat); if(!videoF->mkv) { g_printerr("Error: Couldn't create MKV context.\n"); capVid = FALSE; /*don't start video capture*/ __LOCK_MUTEX(__VMUTEX); videoIn->capVid = capVid; __UNLOCK_MUTEX(__VMUTEX); pdata->capVid = capVid; return(-1); } vstream = mkv_add_video_stream(videoF->mkv, global->width, global->height, videoF->vcodec); vstream->extra_data_size = set_mkvCodecPriv(global->VidCodec, global->width, global->height, *lavc_data); if(vstream->extra_data_size > 0) vstream->extra_data = get_mkvCodecPriv(global->VidCodec); if(global->Sound_enable > 0) { /*get channels and sample rate*/ set_sound(global, pdata); /*sample size - only used for PCM*/ int32_t a_bits = get_aud_bits(global->AudCodec); /*bit rate (compressed formats)*/ int32_t b_rate = get_aud_bit_rate(global->AudCodec); astream = mkv_add_audio_stream( videoF->mkv, pdata->channels, pdata->samprate, a_bits, b_rate, videoF->acodec, global->Sound_Format); astream->extra_data_size = set_mkvACodecPriv( global->AudCodec, pdata->samprate, pdata->channels, pdata->lavc_data); if(astream->extra_data_size > 0) astream->extra_data = get_mkvACodecPriv(global->AudCodec); } /** write the file header */ mkv_write_header(videoF->mkv); /* 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 && init_sound (pdata)) { //FIXME: enable capture button g_printerr("Audio initialization error\n"); global->Sound_enable=0; } break; default: break; } return (ret); }