uint8_t MpegMuxer::open(char *filename, uint32_t vbitrate, uint32_t fps1000, WAVHeader *audioheader,float need) { double fps; uint32_t abitrate,frequency; PackStream *pack=NULL; int bytes_needed,samples_needed; float bn,sn; fps=fps1000; fps/=1000.; // lookup audio info from wavheader abitrate=audioheader->byterate*8; this->frequency=frequency=audioheader->frequency; audioBitrate=(audioheader->byterate*8)/1000; switch(audioheader->encoding) { case WAV_MP2: audioType=AUDIO_ID_MP2;break; case WAV_AC3: audioType=AUDIO_ID_AC3;break; default: GUI_Error_HIG(QT_TR_NOOP("Incompatible audio"), QT_TR_NOOP("For DVD, audio must be MP2 or AC3.")); return 0; } pack=mux_open(filename,(int)vbitrate,fps,(int)abitrate,(int)frequency,audioType); if(!pack) { GUI_Error_HIG(QT_TR_NOOP("lvemux init failed"), NULL); return 0; } packStream=(void *)pack; printf("Lvemux successfully initialized with :\n fq=%lu audio bitrate" " %lu video bitrate %lu framerate :%f id:%lu",frequency,abitrate,vbitrate,fps,audioType); sn=audioheader->frequency*1000.0; sn/=fps1000; samples_needed = (int)floor(sn+0.5); // pcm sample per frame bn=1000./fps1000; bn*=audioheader->byterate; bytes_needed=(int)floor(bn+0.5); printf("Sample per frame : %d %f, bytes per frame :%d %f\n",samples_needed,sn,bytes_needed,bn); //_packSize=bytes_needed; _packSize=pack->audio_encoded_fs; printf("Pack size:%d\n",_packSize); needPerFrame=need; printf("Will take %f bytes per frame\n",needPerFrame); return 1; }
int mux_write_data(int type, void *pbuf, unsigned long size, unsigned long timestamp, int nIsIFrame) { int ret = 0; if (hMedia == AK_NULL || close_flag == 1 || stop_record_flag == 1) { return 0; } #if 0 MediaLib_Mux_GetInfo(hMedia, &mux_info); if(ReachLimit(mux_info.m_ulFileBytes, mux_info.m_ulTotalTime_ms)) { mux_close(); times--; if( times == 0 ) { printf("Record over \n"); CloseRecordManager(); Recordflag = 0; return -1; } else { mux_open( &mux_input ); } } #endif if (type == 0) ret = mux_addAudio(pbuf, size, timestamp); else ret = mux_addVideo(pbuf, size, timestamp, nIsIFrame); return ret; }
int start_record( int cycrecord ) { signed long long DiskSize = 0; T_S64 DiskSizeTenth = 0; T_S32 bavail, bsize; int format; int wid; #if 1 DiskFreeSize( "/mnt", &bavail, &bsize); DiskSize = (T_S64)(T_U32)(bavail) * (T_S64)(T_U32)(bsize); printf("avail= %ld, bsize = %ld, DiskSize = %lld\n", bavail, bsize, DiskSize); while(DiskSize < (T_S64)MIN_LIMIT_FREE_SPACE_SIZE) { delete_oldest_file(); DiskFreeSize( "/mnt", &bavail, &bsize); DiskSize = (T_S64)(T_U32)(bavail) * (T_S64)(T_U32)(bsize); printf("avail= %ld, bsize = %ld, DiskSize = %lld\n", bavail, bsize, DiskSize); } /* if (DiskSize < (T_S64)MIN_LIMIT_FREE_SPACE_SIZE) { printf( "get %s disk size full!\n", "/mnt" ); return -1; } */ DiskSizeTenth = DiskSize /10; if ( DiskSizeTenth > MIN_LIMIT_FREE_SPACE_SIZE_CALC ) { SetMinRecordLimit( MIN_LIMIT_FREE_SPACE_SIZE_CALC ); }else if ( ( DiskSizeTenth < MIN_LIMIT_FREE_SPACE_SIZE ) && ( DiskSize > MIN_LIMIT_FREE_SPACE_SIZE ) ) { SetMinRecordLimit( MIN_LIMIT_FREE_SPACE_SIZE ); }else if ( DiskSizeTenth > MIN_LIMIT_FREE_SPACE_SIZE ) { SetMinRecordLimit( DiskSizeTenth ); }else { printf("the %s is disk size is %lldM is too less!", "/mnt/", DiskSize); return -1; } #endif IniSetting_init(); struct recoder_info * recoder = IniSetting_GetRecordInfo(); T_S32 video_index = atoi(recoder->video_index); T_S32 leng = atoi(recoder->length); T_S32 time = atoi(recoder->time); if (leng <= 0) leng = 3; if (time <= 0) time = 1; times = (time*3600)/(leng*60); if (times <= 0) times = 1; IniSetting_destroy(); T_U32 bitsrate; if (1 == video_index) bitsrate = (T_U32)BRTable_h264[0].nBitsRate; else if (2 == video_index) { switch (parse.format2) { case 0: format = 0; break; case 1: format = 1; break; default: format = 0; } switch (parse.width2) { case 720: wid = 0; break; case 640: wid = 1; break; case 320: wid = 2; break; default: wid = 1; } if (format == 0) bitsrate = BRTable_h264[wid].nBitsRate; else bitsrate = BRTable[wid].nBitsRate; } if (0 > recmgr_open("/mnt", bitsrate, leng*60*1000, cycrecord)) { printf("open record manager error \n"); return -1; } T_MUX_INPUT mux_input1; mux_input1.m_MediaRecType = MEDIALIB_REC_AVI_NORMAL; if (video_index == 1) { //mux video if(parse.format1 == 0) mux_input1.m_eVideoType = MEDIALIB_VIDEO_H264; else if(parse.format1 == 1) mux_input1.m_eVideoType = MEDIALIB_VIDEO_MJPEG; mux_input1.m_nWidth = parse.width; mux_input1.m_nHeight = parse.height; } else { //mux video if (parse.format2 == 0) mux_input1.m_eVideoType = MEDIALIB_VIDEO_H264; else if (parse.format2 == 1) mux_input1.m_eVideoType = MEDIALIB_VIDEO_MJPEG; mux_input1.m_nWidth = parse.width2; mux_input1.m_nHeight = parse.height2; } //mux audio mux_input1.m_bCaptureAudio = 1; mux_input1.m_eAudioType = MEDIALIB_AUDIO_AAC; mux_input1.m_nSampleRate = 8000; // mux_input1.abitsrate = 0; // mux_input1.pfile1 = AK_NULL; // mux_input1.pfile2 = AK_NULL; if (mux_open(&mux_input1) < 0) { printf("open mux err \n"); return -1; } close_flag = 0; g_mux_exit = 0; pthread_attr_t SchedAttr; struct sched_param SchedParam; memset(&SchedAttr, 0, sizeof(pthread_attr_t)); memset(&SchedParam, 0, sizeof(SchedParam)); pthread_attr_init( &SchedAttr ); SchedParam.sched_priority = 60; pthread_attr_setschedparam( &SchedAttr, &SchedParam ); pthread_attr_setschedpolicy( &SchedAttr, SCHED_RR ); if (pthread_create(&ThredMuxID, &SchedAttr, thread_enc, NULL ) != 0 ) { pthread_attr_destroy(&SchedAttr); // printf( "unable to create a thread for osd = %d!\n" ); return -1; } pthread_attr_destroy(&SchedAttr); setled_record_start(video_index-1); return 0; }