void replace_pword(std::ios_base& iob, int idx, const T& x) { iob.register_callback(callback<NewFormat>, idx); NewFormat* new_format(new NewFormat(x)); OldFormat* old_format(static_cast<OldFormat*>(iob.pword(idx))); iob.pword(idx) = new_format; delete old_format; }
void image_format_param_t::set_new_format( double unused) { int w = width_input_->value(); int h = height_input_->value(); float a = aspect_input_->value(); image::format_t new_format( w, h, a); menu_->blockSignals( true); menu_->setCurrentIndex( new_format.preset_index()); menu_->blockSignals( false); param_set()->begin_edit(); set_value( new_format); param_set()->end_edit(); }
int plugin_run(struct playerHandles *ph, char *key, int *totaltime){ size_t size; size_t len; int mret=MPG123_NEED_MORE; int retval=DEC_RET_SUCCESS; struct outputdetail *details=ph->outdetail; unsigned char *out; int outsize; if(mp3Init(ph)<0)return DEC_RET_ERROR; details->totaltime=*totaltime>0?*totaltime:-1; details->percent=-1; ph->dechandle=&h; pthread_mutex_lock(&dechandle_lock); new_format(ph); outsize=mpg123_outblock(h.m); pthread_mutex_unlock(&dechandle_lock); h.tcarry=0; h.total=0; h.accuracy=1000; if(!(out=malloc(sizeof(unsigned char)*outsize))){ fprintf(stderr,"Malloc failed (out decoder buffer)."); plugin_exit(ph); return DEC_RET_ERROR; } do{ /* Read and write until everything is through. */ //if outbuff isn't big enough to hold all decoded data from inbuff, keep going if(mret != MPG123_NEED_MORE){ pthread_mutex_lock(&dechandle_lock); mret=mpg123_read(h.m,out,outsize,&len); pthread_mutex_unlock(&dechandle_lock); } else{ pthread_mutex_lock(&dechandle_lock); mret=mpg123_read(h.m,out,outsize,&len); pthread_mutex_unlock(&dechandle_lock); if(mret==MPG123_DONE || mret==MPG123_ERR){ // EOF (or read error) retval=DEC_RET_SUCCESS; break; } } if(mret==MPG123_NEW_FORMAT){ //fprintf(stderr,"Should have reformatted here."); pthread_mutex_lock(&dechandle_lock); new_format(ph); pthread_mutex_unlock(&dechandle_lock); } if(len==0)continue; size=len; pthread_mutex_lock(&dechandle_lock); details->curtime=h.total; details->percent=(details->curtime*100)/details->totaltime; h.tcarry+=size; if(h.tcarry>=h.samptime){ h.total+=h.tcarry/h.samptime; h.tcarry%=h.samptime; } pthread_mutex_unlock(&dechandle_lock); #if WITH_ALSA==1 if(writei_snd(ph,(char *)out,size/h.framesize)<0)break; #else if(writei_snd(ph,(char *)out,size)<0)break; #endif /* if(metacount++>2000){ printf("1\n"); metacount=0; pthread_mutex_lock(&dechandle_lock); metaret=mpg123_meta_check(h.m); if(metaret & MPG123_NEW_ICY){ mpg123_icy(h.m,&icymeta); printf("%s\n",icymeta); } pthread_mutex_unlock(&dechandle_lock); }*/ if(ph->pflag->exit!=DEC_RET_SUCCESS){ retval=ph->pflag->exit; break; } }while(mret != MPG123_ERR && mret!=MPG123_DONE); if(mret == MPG123_ERR){ fprintf(stderr, "decoder error: %s", mpg123_strerror(h.m)); if(mpg123_errcode(h.m)!=28) // Common error. quick fix retval=DEC_RET_ERROR; } writei_snd(ph,(char *)out,0); // drain sound buffer /* Done decoding, now just clean up and leave. */ plugin_exit(ph); free(out); *totaltime=details->curtime; return retval; }