INT NS_PREFIX SetStringValue (const char *name, double value) { char buffer[30]; sprintf(buffer,"%-.14g",value); return(SetStringVar(name,buffer)); }
extern int textparse (vlist_t* list, FILE* file, int flags ){ /*** This module just detect language of subtitle file (only eng/rus check) v0.1 beta. Ideas acepting and will be taking with pleasure*/ #define MAX_READ_TRY 128 unsigned char buffer[1024]; unsigned char* pointer; int GT_128=1;/*non ASCII chars count*/ int bin=1; int total=1; int try_count=0; IncStreamCounter(list,'t'); do{ if(try_count>MAX_READ_TRY) break; if(!fread(buffer,1023,1,file)) break; try_count++; buffer[1023]=0; pointer=buffer; while(*pointer){ if(*pointer>128) GT_128++; if(*pointer>128 && *pointer <32 && *pointer!='\x09' && *pointer!='\x0D' && *pointer!='\x0A') bin++; total++; pointer++; } }while(!feof(file)); GT_128++; total++; if(bin>5){ SetStringVar(list,"t1.lang", "binary"); } else{ if(total/GT_128<5){ SetStringVar(list,"t1.lang","non-eng"); } else{ SetStringVar(list,"t1.lang","eng"); } } return 1; }
int ifoparse(vlist_t*list,FILE* file, int s) { /*supported only a vts_xx_0.ifo, video_ts.ifo is not needed for AVInfo*/ char buffer[0x316]; unsigned int video[MAX_STREAMS][VIDEO_INFO_SIZE]; unsigned int audio[MAX_STREAMS][AUDIO_INFO_SIZE]; unsigned int type=0; unsigned int a_c=0; unsigned int s_c=0; unsigned int audio_streams=0; unsigned int subtitle_streams=0; char *lang; memset(video,0,sizeof(video)); memset(audio,0,sizeof(audio)); if(!fread(buffer,0x316,1,file)) return 0; /*if we can not read at least 790 bytes we can not recognize IFO file information*/ if(memcmp(buffer,VTS_SIGNATURE,sizeof(VTS_SIGNATURE))) return 0; /*non VTS IFO or not the IFO*/ /*video (always 1 stream)*/ video[0][V_exist]=1; switch(buffer[0x200]&0xC) { case 0: video[0][V_cc]=FCC_MPG1; break; case 0x40: video[0][V_cc]=FCC_MPG2; break; } type=(buffer[0x200]&0x10)>>4; SetStringVar(list,"v1.type",type?"PAL":"NTSC"); switch(buffer[0x200]&0xC) { case 0: video[0][V_aspectX]=4; video[0][V_aspectY]=3; break; case 0xC: video[0][V_aspectX]=16; video[0][V_aspectY]=9; break; } if(buffer[0x201]&0x20) return 0; /*should not be a 1*/ video[0][V_x]=X_table[(buffer[0x201]&0x18)>>3][type]; video[0][V_y]=Y_table[(buffer[0x201]&0x18)>>3][type]; /*audio (max 8 streams)*/ audio_streams=buffer[0x203]; if(audio_streams>8) audio_streams=8; for(a_c=0; a_c<audio_streams; a_c++) { /* base=104+a_c*8;*/ audio[a_c][A_exist]=1; audio[a_c][A_cc]=Codec_table[(buffer[0x204+a_c*8]&0xE0)>>5]; if(!(buffer[0x205+a_c*8]&0x30)) audio[a_c][A_freq]=48000; lang=malloc(3); audio[a_c][A_ch]=(buffer[0x20B+a_c*7]&0x70)>>4; lang[0]=buffer[0x206+a_c*8]; lang[1]=buffer[0x207+a_c*8]; lang[2]=0; SetIdxStringVar(list,"a%d.lang",a_c+1,lang); /*todo chanels*/ } /*subtitle (max 32 streams, but AVInfo supports only first 9) */ subtitle_streams=buffer[0x254]; if(subtitle_streams>9) subtitle_streams=9; SetNumericVar(list,"stream.t",subtitle_streams); for(s_c=0; s_c<subtitle_streams; s_c++) { lang=malloc(3); lang[0]=buffer[0x258+s_c*6]; lang[1]=buffer[0x257+s_c*6]; lang[2]=0; SetIdxStringVar(list,"t%d.lang",s_c+1,lang); } AddAudioVideo(list,video,audio); return 1; }
int mkvparse(vlist_t *list,FILE* file, int s){ char* buffer=malloc(BUFFER_SIZE+128); unsigned int video[MAX_STREAMS][VIDEO_INFO_SIZE]; unsigned int audio[MAX_STREAMS][AUDIO_INFO_SIZE]; char* lang[MAX_STREAMS][4];/*1 - video, 2 - audio, 3 - text, 0 unused*/ char* codec[MAX_STREAMS][4];/*1 - video, 2 - audio, 3 - text, 0 unused*/ int p; /*pointer in buffer*/ int c,c2; /*counter in some loops*/ int readed_bytes; unsigned int eID; /*element ID*/ int64 eSize; /*Size of element content*/ int offs; char* title=NULL; int64 timescale=1000000; float Duration=0; char* tstr1, *tstr2; /*temp strings*/ int64 DefaultDuration=0; int TrackType=0; int pvt_look_flag=0; int curr_c=-1; int a_c=-1; int v_c=-1; int t_c=-1; int value=0; if(!buffer) return 0; memset(video,0,sizeof(video)); memset(audio,0,sizeof(audio)); memset(lang,0,sizeof(lang)); memset(codec,0,sizeof(codec)); readed_bytes=fread(buffer,1,BUFFER_SIZE,file); /*todo buffer_size,1 ? */ if(!readed_bytes){free(buffer);return 0;} p=0; while(buffer[p]!=MKVID_FILE_BEGIN){ p++; if(p>=readed_bytes){ free(buffer); return 0; } }; /*skip text while EBML begin*/ /*main loop*/ do{ offs=ElementRead(buffer,p,readed_bytes,&eID,&eSize); p+=offs; if(!offs||p>=readed_bytes) break; for(c=0;c<sizeof(MKV_Parse_list)/sizeof(*MKV_Parse_list);c++) if(MKV_Parse_list[c]==eID) { break; } if(c<sizeof(MKV_Parse_list)/sizeof(*MKV_Parse_list)) continue; if(p+eSize>readed_bytes) break; /*TODO - add (if requied) suckup from file to buffer*/ if(eSize==4||eSize==8||eSize==1||eSize==2) value=(int)GetInt(buffer,p,eSize); switch(eID){ case MKVID_TrackType: /*detect a stream type (video/audio/text)*/ TrackType=value; pvt_look_flag=0; switch(TrackType){ case MKV_Track_video: v_c++; if(v_c>MAX_STREAMS) v_c=MAX_STREAMS; video[v_c][V_exist]=1; video[v_c][V_l]=(int)(Duration/1e+9*(float)timescale); curr_c=v_c; break; case MKV_Track_audio: a_c++; if(a_c>MAX_STREAMS) a_c=MAX_STREAMS; audio[a_c][A_exist]=1; audio[a_c][A_l]=(int)(Duration/1e+9*(float)timescale); curr_c=a_c; break; case MKV_Track_subtitle_orig: t_c++; TrackType=MKV_Track_subtitle; /*for normal use in lang array*/ if(t_c>MAX_STREAMS) t_c=MAX_STREAMS; curr_c=t_c; break; } break; case MKVID_DefaultDuration: /*fps detection*/ if(TrackType==MKV_Track_video&&v_c>=0){ DefaultDuration=value; if(DefaultDuration>100){ video[v_c][V_fpsH]=1000000000/DefaultDuration; /*DD in nano sec. fps=1s/DD*/ video[v_c][V_fpsL]=1000000000/(DefaultDuration/100)-100*video[v_c][V_fpsH]; } } break; case MKVID_Language: /*stream language*/ if(curr_c>=0&&TrackType<4&&eSize<MAX_STRING_SIZE) if(lang[curr_c][TrackType]) free(lang[curr_c][TrackType]); lang[curr_c][TrackType]=mkstr(buffer,p,eSize); break; case MKVID_CodecName:/*passtrough*/ case MKVID_CodecID: /*codec detection (if V_MS/VFW/FOURCC - set a fourcc code, else fill a vcodecs value)*/ if(curr_c>=0&&TrackType<4&&eSize<MAX_STRING_SIZE){ if(codec[curr_c][TrackType]) free(codec[curr_c][TrackType]); codec[curr_c][TrackType]=mkstr(buffer,p,eSize); if(!strcmp(codec[curr_c][TrackType],"V_MS/VFW/FOURCC")) pvt_look_flag=1; } break; case MKVID_CodecPrivate: if(pvt_look_flag&&v_c>=0&&eSize>=24){ /*CodecPrivate contains a BITMAPINFOHEADER structure due CodecID==V_MS/VFW/FOURCC*/ pvt_look_flag=0; video[v_c][V_cc]=(buffer[p+16]<<24)+(buffer[p+17]<<16)+(buffer[p+18]<<8)+buffer[p+19]; if(codec[v_c][MKV_Track_video]){ free(codec[v_c][MKV_Track_video]); codec[v_c][MKV_Track_video]=NULL; } } break; case MKVID_PixelWidth: /*pasthough*/ /*bug with aspect differ from 1:1*/ case MKVID_DisplayWidth: if(v_c>=0)video[v_c][V_x]=value; break; case MKVID_PixelHeight: /*pasthough*/ case MKVID_DisplayHeight: if(v_c>=0)video[v_c][V_y]=value; break; case MKVID_TimeCodeScale: timescale=GetInt(buffer,p,eSize); break; case MKVID_Duration: Duration=GetFloat(buffer,p,eSize); break; case MKVID_Channels: if(a_c>=0)audio[a_c][A_ch]=value; break; case MKVID_BitDepth: if(a_c>=0)audio[a_c][A_bits]=value; break; case MKVID_OutputSamplingFrequency: /*pasthough*/ case MKVID_SamplingFrequency: if(a_c>=0) audio[a_c][A_freq]=(int)GetFloat(buffer,p,eSize); break; case MKVID_Title: if(eSize>MAX_STRING_SIZE) break; title=mkstr(buffer,p,eSize); SetNumericVar(list,"stream.d",1); SetNumericVar(list,"d1.num",1); SetStringVar(list,"d11.name","Title"); SetStringVar(list,"d11.value",title); free(title); break; /*TODO case MKVID_Tags:*/ } p+=eSize;/*skip unknown or uninteresting*/ }while(1); AddAudioVideo(list,video,audio); tstr1=strdup("d?.lang"); tstr2=strdup("d?.cc"); if(tstr1&&tstr2){ for(c=0;c<MAX_STREAMS;c++){ for(c2=0;c2<4;c2++){ tstr1[0]=stream_type_letters[c2]; tstr1[1]=c+'0'+1; tstr2[1]=tstr1[1]; tstr2[0]=tstr1[0]; if(lang[c][c2]){ SetStringVar(list,tstr1,lang[c][c2]); free(lang[c][c2]); } if(codec[c][c2]){ SetStringVar(list,tstr2,codec[c][c2]); free(codec[c][c2]); } } } SetNumericVar(list,"stream.t",t_c+1); free(tstr1); free(tstr2); } if(buffer) free(buffer); return 1; }
INT NS_DIM_PREFIX InitUg (int *argcp, char ***argvp) { INT err; #ifdef Debug char buffer[256]; char debugfilename[NAMESIZE]; #endif #ifdef ModelP /* init ppif module */ if ((err = InitPPIF (argcp, argvp)) != PPIF_SUCCESS) { printf ("ERROR in InitParallel while InitPPIF.\n"); printf ("aborting ug\n"); return (1); } #endif /* init the low module */ if ((err = InitLow ()) != 0) { printf ("ERROR in InitUg while InitLow (line %d): called routine line %d\n", (int) HiWrd (err), (int) LoWrd (err)); printf ("aborting ug\n"); return (1); } /* init parallelization module */ #ifdef ModelP PRINTDEBUG (init, 1, ("%d: InitParallel()...\n", me)) if ((err = InitParallel (argcp, argvp)) != 0) { printf ("ERROR in InitUg while InitParallel (line %d): called routine line %d\n", (int) HiWrd (err), (int) LoWrd (err)); printf ("aborting ug\n"); return (1); } #endif /* create struct for configuration parameters */ if (MakeStruct (":conf")) return (__LINE__); if (SetStringVar ("conf:arch", ARCHNAME)) return (__LINE__); /* set variable for parallel modus */ #ifdef ModelP if (SetStringValue ("conf:parallel", 1.0)) return (__LINE__); if (SetStringValue ("conf:procs", (DOUBLE) procs)) return (__LINE__); if (SetStringValue ("conf:me", (DOUBLE) me)) return (__LINE__); #else if (SetStringValue ("conf:parallel", 0.0)) return (__LINE__); if (SetStringValue ("conf:procs", 1.0)) return (__LINE__); if (SetStringValue ("conf:me", 0.0)) return (__LINE__); #endif /* init the devices module */ if ((err = InitDevices (argcp, *argvp)) != 0) { printf ("ERROR in InitUg while InitDevices (line %d): called routine line %d\n", (int) HiWrd (err), (int) LoWrd (err)); printf ("aborting ug\n"); return (1); } #ifdef Debug { int i; for (i = 1; i < *argcp; i++) if (strncmp ((*argvp)[i], "-dbgfile", 8) == 0) break; if ((i < *argcp) && (GetDefaultValue (DEFAULTSFILENAME, UGDEBUGRFILE, buffer) == 0) && (sscanf (buffer, " %s ", debugfilename) == 1)) { if (SetPrintDebugToFile (debugfilename) != 0) { printf ("ERROR while opening debug file '%s'\n", debugfilename); printf ("aborting ug\n"); return (1); } UserWriteF ("debug info is captured to file '%s'\n", debugfilename); } else { SetPrintDebugProc (printf); UserWriteF ("debug info is printed to stdout\n"); } } #endif /* init the domain module */ if ((err = InitDom ()) != 0) { printf ("ERROR in InitDom while InitDom (line %d): called routine line %d\n", (int) HiWrd (err), (int) LoWrd (err)); printf ("aborting ug\n"); return (1); } /* init the gm module */ if ((err = InitGm ()) != 0) { printf ("ERROR in InitUg while InitGm (line %d): called routine line %d\n", (int) HiWrd (err), (int) LoWrd (err)); printf ("aborting ug\n"); return (1); } /* init the numerics module */ if ((err = InitNumerics ()) != 0) { printf ("ERROR in InitUg while InitNumerics (line %d): called routine line %d\n", (int) HiWrd (err), (int) LoWrd (err)); printf ("aborting ug\n"); return (1); } /* init the ui module */ if ((err = InitUi (argcp[0], argvp[0])) != 0) { printf ("ERROR in InitUg while InitUi (line %d): called routine line %d\n", (int) HiWrd (err), (int) LoWrd (err)); printf ("aborting ug\n"); return (1); } /* init the graphics module */ if ((err = InitGraphics ()) != 0) { printf ("ERROR in InitUg while InitGraphics (line %d): called routine line %d\n", (int) HiWrd (err), (int) LoWrd (err)); printf ("aborting ug\n"); return (1); } return (0); }