UINT CSoundFile::Read( LPVOID lpBuffer, UINT cbBuffer ) { mpcpplog(); if ( !mod ) { return 0; } mpcpplog(); if ( !lpBuffer ) { return 0; } mpcpplog(); if ( cbBuffer <= 0 ) { return 0; } mpcpplog(); if ( get_samplerate() <= 0 ) { return 0; } mpcpplog(); if ( get_sample_size() != 1 && get_sample_size() != 2 && get_sample_size() != 4 ) { return 0; } mpcpplog(); if ( get_num_channels() != 1 && get_num_channels() != 2 && get_num_channels() != 4 ) { return 0; } mpcpplog(); std::memset( lpBuffer, 0, cbBuffer ); const std::size_t frames_torender = cbBuffer / get_frame_size(); std::int16_t * out = (std::int16_t*)lpBuffer; std::vector<std::int16_t> tmpbuf; if ( get_sample_size() == 1 || get_sample_size() == 4 ) { tmpbuf.resize( frames_torender * get_num_channels() ); out = &tmpbuf[0]; } mod->set_render_param( openmpt::module::RENDER_INTERPOLATIONFILTER_LENGTH, get_filter_length() ); std::size_t frames_rendered = 0; if ( get_num_channels() == 1 ) { frames_rendered = mod->read( get_samplerate(), frames_torender, out ); } else if ( get_num_channels() == 4 ) { frames_rendered = mod->read_interleaved_quad( get_samplerate(), frames_torender, out ); } else { frames_rendered = mod->read_interleaved_stereo( get_samplerate(), frames_torender, out ); } if ( get_sample_size() == 1 ) { std::uint8_t * dst = (std::uint8_t*)lpBuffer; for ( std::size_t sample = 0; sample < frames_rendered * get_num_channels(); ++sample ) { dst[sample] = ( tmpbuf[sample] / 0x100 ) + 0x80; } } else if ( get_sample_size() == 4 ) { std::int32_t * dst = (std::int32_t*)lpBuffer; for ( std::size_t sample = 0; sample < frames_rendered * get_num_channels(); ++sample ) { dst[sample] = tmpbuf[sample] << (32-16-1-MIXING_ATTENUATION); } } return frames_rendered * get_frame_size(); }
int initial_frame_pointer_offset (int DEPTH) { int size; size = get_frame_size(); return size; }
static void moxie_compute_frame (void) { /* For aligning the local variables. */ int stack_alignment = STACK_BOUNDARY / BITS_PER_UNIT; int padding_locals; int regno; /* Padding needed for each element of the frame. */ cfun->machine->local_vars_size = get_frame_size (); /* Align to the stack alignment. */ padding_locals = cfun->machine->local_vars_size % stack_alignment; if (padding_locals) padding_locals = stack_alignment - padding_locals; cfun->machine->local_vars_size += padding_locals; cfun->machine->callee_saved_reg_size = 0; /* Save callee-saved registers. */ for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) if (df_regs_ever_live_p (regno) && (! call_used_regs[regno])) cfun->machine->callee_saved_reg_size += 4; cfun->machine->size_for_adjusting_sp = crtl->args.pretend_args_size + cfun->machine->local_vars_size + (ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0); }
/* Create an emit instructions for a functions epilogue. */ void lm32_expand_epilogue (void) { rtx ra_rtx = gen_rtx_REG (Pmode, RA_REGNUM); lm32_compute_frame_size (get_frame_size ()); if (current_frame_info.total_size > 0) { /* Prevent stack code from being reordered. */ emit_insn (gen_blockage ()); /* Restore callee save registers. */ if (current_frame_info.reg_save_mask != 0) expand_save_restore (¤t_frame_info, 1); /* Deallocate stack. */ stack_adjust (current_frame_info.total_size); /* Return to calling function. */ emit_jump_insn (gen_return_internal (ra_rtx)); } else { /* Return to calling function. */ emit_jump_insn (gen_return_internal (ra_rtx)); } }
HOST_WIDE_INT lm32_compute_initial_elimination_offset (int from, int to) { HOST_WIDE_INT offset = 0; switch (from) { case ARG_POINTER_REGNUM: switch (to) { case FRAME_POINTER_REGNUM: offset = 0; break; case STACK_POINTER_REGNUM: offset = lm32_compute_frame_size (get_frame_size ()) - current_frame_info.pretend_size; break; default: gcc_unreachable (); } break; default: gcc_unreachable (); } return offset; }
/* Returns the number of bytes offset between FROM_REG and TO_REG for the current function. As a side effect it fills in the current_frame_info structure, if the data is available. */ unsigned int fr30_compute_frame_size (int from_reg, int to_reg) { int regno; unsigned int return_value; unsigned int var_size; unsigned int args_size; unsigned int pretend_size; unsigned int reg_size; unsigned int gmask; var_size = WORD_ALIGN (get_frame_size ()); args_size = WORD_ALIGN (current_function_outgoing_args_size); pretend_size = current_function_pretend_args_size; reg_size = 0; gmask = 0; /* Calculate space needed for registers. */ for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno ++) { if (MUST_SAVE_REGISTER (regno)) { reg_size += UNITS_PER_WORD; gmask |= 1 << regno; } } current_frame_info.save_fp = MUST_SAVE_FRAME_POINTER; current_frame_info.save_rp = MUST_SAVE_RETURN_POINTER; reg_size += (current_frame_info.save_fp + current_frame_info.save_rp) * UNITS_PER_WORD; /* Save computed information. */ current_frame_info.pretend_size = pretend_size; current_frame_info.var_size = var_size; current_frame_info.args_size = args_size; current_frame_info.reg_size = reg_size; current_frame_info.frame_size = args_size + var_size; current_frame_info.total_size = args_size + var_size + reg_size + pretend_size; current_frame_info.gmask = gmask; current_frame_info.initialised = reload_completed; /* Calculate the required distance. */ return_value = 0; if (to_reg == STACK_POINTER_REGNUM) return_value += args_size + var_size; if (from_reg == ARG_POINTER_REGNUM) return_value += reg_size; return return_value; }
void msp430_function_begin_epilogue (FILE * file) { if (cfun->machine->is_OS_task) fprintf (file, "\n\t/* epilogue: empty, task functions never return */\n"); else if (cfun->machine->is_naked) fprintf (file, "\n\t/* epilogue: naked */\n"); else if (msp430_empty_epilogue ()) fprintf (file, "\n\t/* epilogue: not required */\n"); else fprintf (file, "\n\t/* epilogue: frame size = %d */\n", (unsigned)get_frame_size()); }
void OutPort::connect(InPort & other, uint32_t signal_buffer_id) { assert(get_Ts() > 0.0); assert(get_type() != empty); assert(get_frame_size() > 0); if (other.get_Ts() > 0 && get_Ts() != other.get_Ts()) { throw SampleTimesMismatchException(other.get_owner_block_name()+"::"+other.get_name()); } if (other.get_type() != empty && get_type() != other.get_type()) { throw SignalTypesMismatchException(other.get_owner_block_name()+"::"+other.get_name()); } if (other.get_frame_size() > 0 && get_frame_size() != other.get_frame_size()) { throw FrameSizesMismatchException(other.get_owner_block_name()+"::"+other.get_name()); } assert(get_owner_block_name() != ""); other.set_Ts(get_Ts()); other.set_type(get_type()); other.set_frame_size(get_frame_size()); PB_DEBUG_MESSAGE(" " << get_owner_block_name() << ".connect(): port '" << get_name() << "' propagating signal type: " << get_type()) PB_DEBUG_MESSAGE(" " << get_owner_block_name() << ".connect(): port '" << get_name() << "' propagating sample time: " << get_Ts()) PB_DEBUG_MESSAGE(" " << get_owner_block_name() << ".connect(): port '" << get_name() << "' propagating frame size: " << get_frame_size()) set_signal_buffer_id(signal_buffer_id); send = std::tr1::bind(&InPort::receive, std::tr1::ref(other), get_signal_buffer_id()); }
/* Return nonzero if this function is known to have a null epilogue. This allows the optimizer to omit jumps to jumps if no stack was created. */ int lm32_can_use_return (void) { if (!reload_completed) return 0; if (df_regs_ever_live_p (RA_REGNUM) || crtl->profile) return 0; if (lm32_compute_frame_size (get_frame_size ()) != 0) return 0; return 1; }
/* Functions related to activation records could be empty in this level, but we have * chosen to define activation records completely and hence, functions have been * defined fully.*/ int initial_elimination_offset(int from, int to) { if(from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM) { return (get_frame_size()); } else if(from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM) { return -(3+registers_to_be_saved())*4; } else if(from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM) { return ((3+registers_to_be_saved())*4+get_frame_size()); } else if(from == HARD_FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM) { return ((3+registers_to_be_saved())*4+get_frame_size()); } else printf("\nIt should not come here... Trying to eliminate non-eliminable register!\n"); return 0; }
/* command socket callback */ gboolean socket_callback(GSocketService * service, GSocketConnection * conn, GObject * source_object, gpointer user_data) { video_server_t * server = (video_server_t *)user_data; gchar message[128]; guint64 value; GInputStream * istream = g_io_stream_get_input_stream(G_IO_STREAM(conn)); g_input_stream_read(istream, message, 128, NULL, NULL); /* Supported commands: * * "b 5000" set bitrate to 5 Mbps * "i 3000" set I-frame interval in msec * "f 30" set framerate in frames/sec * "s 640x360" set frame size */ gchar **cmd_str = g_strsplit(message, " ", 0); if (g_strv_length(cmd_str) != 2) { fprintf(stderr, "Incorrect command syntax: %s", message); return FALSE; } switch (cmd_str[0][0]) { case 'b': value = g_ascii_strtoull(cmd_str[1], NULL, 0); video_server_set_bitrate(server, (unsigned int) value); break; case 'i': value = g_ascii_strtoull(cmd_str[1], NULL, 0); video_server_set_iframe_period(server, (unsigned int) value); break; case 'f': value = g_ascii_strtoull(cmd_str[1], NULL, 0); video_server_set_framerate(server, (unsigned int) value); break; case 's': get_frame_size(cmd_str[1], server->conf); video_server_reset_frame_size(server); break; } g_strfreev(cmd_str); return FALSE; }
void c54x_expand_epilogue() { int r; emit_insn(gen_frame(gen_rtx_REG (QImode, STACK_POINTER_REGNUM), gen_rtx_CONST_INT(VOIDmode, -get_frame_size()))); for(r = FIRST_PSEUDO_REGISTER - 1; r > 0; r--) { if(c54x_save_register_p(r)) { emit_insn(gen_popqi(gen_rtx_REG(QImode, r))); } } emit_insn(gen_return()); }
void Player::mix_events(MessageQueue &queue, int samples) { assert(model); long long target = queue.read_samples + ((long long)samples<<32); while (queue.write_samples < target) { // send status package queue.status_msg(); mix_frame(queue); long long framesize = get_frame_size(); queue.write_samples += framesize; queue.position++; if (model->enable_loop && (queue.position == model->loop.get_end())) { queue.position = model->loop.get_begin(); } } }
void c54x_expand_prologue() { int r; for(r = 0; r < FIRST_PSEUDO_REGISTER; r++) { if(c54x_save_register_p(r)) { emit_insn(gen_pushqi(gen_rtx_REG(QImode, r))); } } if(frame_pointer_needed) { emit_move_insn(gen_rtx_REG (QImode, FRAME_POINTER_REGNUM), gen_rtx_REG (QImode, STACK_POINTER_REGNUM)); } emit_insn(gen_frame(gen_rtx_REG (QImode, STACK_POINTER_REGNUM), gen_rtx_CONST_INT(VOIDmode, get_frame_size()))); }
void AsyncConnection::handle_buffer() { switch (state_) { case kReadFrameSize: if (bytes_recv_ >= sizeof(uint32_t)) { //got the frame length get_frame_size(); if (frame_size_ >= kMaxFrameSize || frame_size_ == 0) { GlobalOutput.printf("illegal frame size: %u", frame_size_); return; } //fall through to "case kReadFrame" //the buffer may contains a complete frame, or a partial frame state_ = kReadFrame; } else { //continue to read start_recv(false); break; } case kReadFrame: if (bytes_recv_ >= frame_size_+sizeof(uint32_t)) { //got a complete frame, handle it input_buffer_->resetBuffer(&recv_buffer_[0], frame_size_+sizeof(uint32_t)); output_buffer_->resetBuffer(); on_handle_frame(); } else { //continue to read start_recv(false); } break; } }
cst_utterance *asis_to_pm(cst_utterance *utt) { /* Copy the PM structure from the units unchanged */ cst_item *u; cst_lpcres *target_lpcres; int unit_start, unit_end; int utt_pms, utt_size, i; cst_sts_list *sts_list; sts_list = val_sts_list(utt_feat_val(utt,"sts_list")); target_lpcres = new_lpcres(); /* Pass one to find the size */ utt_pms = utt_size = 0; for (u=relation_head(utt_relation(utt,"Unit")); u; u=item_next(u)) { unit_start = item_feat_int(u,"unit_start"); unit_end = item_feat_int(u,"unit_end"); utt_size += get_unit_size(sts_list,unit_start,unit_end); utt_pms += unit_end - unit_start; item_set_int(u,"target_end",utt_size); } lpcres_resize_frames(target_lpcres,utt_pms); /* Pass two to fill in the values */ utt_pms = utt_size = 0; for (u=relation_head(utt_relation(utt,"Unit")); u; u=item_next(u)) { unit_start = item_feat_int(u,"unit_start"); unit_end = item_feat_int(u,"unit_end"); for (i=unit_start; i<unit_end; i++,utt_pms++) { utt_size += get_frame_size(sts_list, i); target_lpcres->times[utt_pms] = utt_size; } } utt_set_feat(utt,"target_lpcres",lpcres_val(target_lpcres)); return utt; }
void msp430_function_end_prologue (FILE * file) { HOST_WIDE_INT frameSize = get_frame_size(); rtx functionExp = DECL_RTL (current_function_decl); const char *functionName = XSTR (XEXP (functionExp, 0), 0); if (cfun->machine->is_naked) { fprintf (file, "\t/* prologue: naked */\n"); fprintf (file, ".L__FrameSize_%s=0x%x\n", functionName, (unsigned)frameSize); } else { int offset = initial_elimination_offset (ARG_POINTER_REGNUM, STACK_POINTER_REGNUM) - 2; fprintf (file, "\t/* prologue ends here (frame size = %d) */\n", (unsigned)frameSize); fprintf (file, ".L__FrameSize_%s=0x%x\n", functionName, (unsigned)frameSize); fprintf (file, ".L__FrameOffset_%s=0x%x\n", functionName, (unsigned)offset); } }
static void crx_compute_frame (void) { /* For aligning the local variables. */ int stack_alignment = STACK_BOUNDARY / BITS_PER_UNIT; int padding_locals; /* Padding needed for each element of the frame. */ local_vars_size = get_frame_size (); /* Align to the stack alignment. */ padding_locals = local_vars_size % stack_alignment; if (padding_locals) padding_locals = stack_alignment - padding_locals; local_vars_size += padding_locals; size_for_adjusting_sp = local_vars_size + (ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0); }
/* Create and emit instructions for a functions prologue. */ void lm32_expand_prologue (void) { rtx insn; lm32_compute_frame_size (get_frame_size ()); if (current_frame_info.total_size > 0) { /* Add space on stack new frame. */ stack_adjust (-current_frame_info.total_size); /* Save callee save registers. */ if (current_frame_info.reg_save_mask != 0) expand_save_restore (¤t_frame_info, 0); /* Setup frame pointer if it's needed. */ if (frame_pointer_needed == 1) { /* Move sp to fp. */ insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx); RTX_FRAME_RELATED_P (insn) = 1; /* Add offset - Don't use total_size, as that includes pretend_size, which isn't part of this frame? */ insn = emit_add (frame_pointer_rtx, frame_pointer_rtx, GEN_INT (current_frame_info.args_size + current_frame_info.callee_size + current_frame_info.locals_size)); RTX_FRAME_RELATED_P (insn) = 1; } /* Prevent prologue from being scheduled into function body. */ emit_insn (gen_blockage ()); } }
static int msm_dai_q6_afe_rtproxy_hw_params(struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { struct msm_dai_q6_dai_data *dai_data = dev_get_drvdata(dai->dev); dai_data->rate = params_rate(params); dai_data->port_config.rtproxy.num_ch = params_channels(params); pr_debug("channel %d entered,dai_id: %d,rate: %d\n", dai_data->port_config.rtproxy.num_ch, dai->id, dai_data->rate); dai_data->port_config.rtproxy.bitwidth = 16; /* Q6 only supports 16 */ dai_data->port_config.rtproxy.interleaved = 1; dai_data->port_config.rtproxy.frame_sz = get_frame_size(dai_data->rate, dai_data->port_config.rtproxy.num_ch); dai_data->port_config.rtproxy.jitter = dai_data->port_config.rtproxy.frame_sz/2; dai_data->port_config.rtproxy.lw_mark = 0; dai_data->port_config.rtproxy.hw_mark = 0; dai_data->port_config.rtproxy.rsvd = 0; return 0; }
void *audio_getpackage_loop(void *args) { int ret; aml_audio_dec_t *audec; audio_decoder_operations_t *adec_ops; int nNextFrameSize=0;//next read frame size int inlen = 0;//real data size in in_buf int nInBufferSize=0;//full buffer size char *inbuf = NULL;//real buffer int rlen = 0;//read buffer ret size int nAudioFormat; adec_print("adec_getpackage_loop start!\n"); audec = (aml_audio_dec_t *)args; adec_ops=audec->adec_ops; nAudioFormat=audec->format; inlen=0; nNextFrameSize=adec_ops->nInBufSize; while (1){ exit_decode_loop: /*detect quit condition*/ if(exit_decode_thread) { if(inbuf) free(inbuf); package_list_free(); break; } /*step 2 get read buffer size*/ nNextFrameSize=get_frame_size(nAudioFormat); //adec_print("==get frame size:%d \n",nNextFrameSize); if(nNextFrameSize==-1) nNextFrameSize=adec_ops->nInBufSize; else if(nNextFrameSize==0) { usleep(1000); continue; } /*step 3 read buffer*/ nInBufferSize = nNextFrameSize; if (inbuf != NULL) { free(inbuf); inbuf = NULL; } inbuf = malloc(nInBufferSize); int nNextReadSize=nInBufferSize; int nRet=0; int nReadErrCount=0; int nCurrentReadCount=0; int nReadSizePerTime=1*1024; rlen=0; while(nNextReadSize>0) { if(exit_decode_thread) goto exit_decode_loop; if(nNextReadSize<=nReadSizePerTime) nReadSizePerTime=nNextReadSize; nRet = read_buffer(inbuf+rlen, nReadSizePerTime);//read 10K per time if(nRet<=0) { usleep(1000); continue; } rlen+=nRet; nNextReadSize-=nRet; } nCurrentReadCount=rlen; rlen += inlen; while(package_add(inbuf,rlen)) { //add failed if(exit_decode_thread) goto exit_decode_loop; usleep(1000); } inbuf=NULL; } QUIT: adec_print("Exit adec_getpackage_loop Thread!"); pthread_exit(NULL); return NULL; }
config_t *config_create(int argc, char *argv[]) { config_t *conf = malloc(sizeof(config_t)); /* add sensible defaults */ conf->device = g_strdup("/dev/video0"); conf->width = 1280; conf->height = 720; conf->framerate = 24; conf->bitrate = 3000; conf->iframe_period = 10000; conf->udp_host = g_strdup("localhost"); conf->udp_port = 4000; conf->cmd_port = 4242; /* parse command line options */ int opt, val; while ((opt = getopt(argc, argv, "d:s:f:b:i:a:p:h")) != -1) { switch (opt) { case 'd': g_free(conf->device); conf->device = g_strdup(optarg); break; case 's': get_frame_size(optarg, conf); break; case 'f': val = atoi(optarg); conf->framerate = get_closest_framerate(val); break; case 'b': val = atoi(optarg); if (val >= 50 && val <= 15000) conf->bitrate = val; else goto help; break; case 'i': val = atoi(optarg); if (val >= 1000 && val <= 60000) conf->iframe_period = val; else goto help; break; case 'a': g_free(conf->udp_host); conf->udp_host = g_strdup(optarg); break; case 'p': val = atoi(optarg); if (val >= 0 && val <= 65535) conf->udp_port = val; else goto help; break; case 'c': val = atoi(optarg); if (val >= 0 && val <= 65535) conf->cmd_port = val; else goto help; case 'h': goto help; break; default: break; } } return conf; help: show_help(); config_destroy(conf); exit(EXIT_FAILURE); }
static int audio_decoder_init( #ifndef WIN32 audio_decoder_operations_t *adec_ops, #endif char *outbuf, int *outlen, char *inbuf, int inlen, long *inbuf_consumed) { unsigned long samplerate; unsigned char channels; int ret; NeAACDecConfigurationPtr config = NULL; char *in_buf; int inbuf_size; in_buf = inbuf; inbuf_size = inlen; int nReadLen=0; FaadContext *gFaadCxt = (FaadContext*)adec_ops->pdecoder; int islatm = 0; if(!in_buf || !inbuf_size ||!outbuf){ audio_codec_print(" input/output buffer null or input len is 0 \n"); } retry: //fixed to LATM aac frame header sync to speed up seek speed #if 1 if(adec_ops->nAudioDecoderType == ACODEC_FMT_AAC_LATM){ islatm = 1; int nSeekNum = AACFindLATMSyncWord(in_buf,inbuf_size); if(nSeekNum == (inbuf_size-2)){ audio_codec_print("[%s]%d bytes data not found latm sync header \n",__FUNCTION__,nSeekNum); } else{ audio_codec_print("[%s]latm seek sync header cost %d,total %d,left %d \n",__FUNCTION__,nSeekNum,inbuf_size,inbuf_size - nSeekNum); } inbuf_size = inbuf_size - nSeekNum; if(inbuf_size < (get_frame_size(gFaadCxt)+FRAME_SIZE_MARGIN)/*AAC_INPUTBUF_SIZE/2*/){ audio_codec_print("[%s]input size %d at least %d ,need more data \n",__FUNCTION__,inbuf_size,(get_frame_size(gFaadCxt)+FRAME_SIZE_MARGIN)); *inbuf_consumed = inlen-inbuf_size; return AAC_ERROR_NO_ENOUGH_DATA; } } #endif gFaadCxt->hDecoder = NeAACDecOpen(); config = NeAACDecGetCurrentConfiguration(gFaadCxt->hDecoder); config->defObjectType = LC; config->outputFormat = FAAD_FMT_16BIT; config->downMatrix = 0x01; config->useOldADTSFormat = 0; //config->dontUpSampleImplicitSBR = 1; NeAACDecSetConfiguration(gFaadCxt->hDecoder, config); if ((ret = NeAACDecInit(gFaadCxt->hDecoder, in_buf,inbuf_size, &samplerate, &channels,islatm)) < 0) { in_buf += RSYNC_SKIP_BYTES; inbuf_size -= RSYNC_SKIP_BYTES; NeAACDecClose(gFaadCxt->hDecoder); gFaadCxt->hDecoder=NULL; if(inbuf_size < 0) inbuf_size = 0; audio_codec_print("init fail,inbuf_size %d \n",inbuf_size); if(inbuf_size < (get_frame_size(gFaadCxt)+FRAME_SIZE_MARGIN)/*AAC_INPUTBUF_SIZE/2*/){ audio_codec_print("input size %d at least %d ,need more data \n",inbuf_size,(get_frame_size(gFaadCxt)+FRAME_SIZE_MARGIN)); *inbuf_consumed = inlen-inbuf_size; return AAC_ERROR_NO_ENOUGH_DATA; } goto retry; } audio_codec_print("init sucess cost %d\n",ret); in_buf += ret; inbuf_size -= ret; *inbuf_consumed = inlen- inbuf_size; NeAACDecStruct* hDecoder = (NeAACDecStruct*)(gFaadCxt->hDecoder); gFaadCxt->init_flag=1; gFaadCxt->gChannels=channels; gFaadCxt->gSampleRate=samplerate; audio_codec_print("[%s] Init OK adif_present :%d adts_present:%d latm_present:%d,sr %d,ch %d\n",__FUNCTION__,hDecoder->adif_header_present,hDecoder->adts_header_present,hDecoder->latm_header_present,samplerate,channels); return 0; }
int audio_dec_decode( #ifndef WIN32 audio_decoder_operations_t *adec_ops, #endif char *outbuf, int *outlen, char *inbuf, int inlen) { unsigned long samplerate; unsigned char channels; void *sample_buffer; NeAACDecFrameInfo frameInfo; int outmaxlen = 0; char *dec_buf; int dec_bufsize; int inbuf_consumed=0; int ret = 0; FaadContext *gFaadCxt = (FaadContext*)adec_ops->pdecoder; dec_bufsize = inlen; dec_buf = inbuf; outmaxlen = *outlen ; *outlen = 0; if(!outbuf ||!inbuf || !inlen){ audio_codec_print("decoder parameter error,check \n"); goto exit; } if(gFaadCxt->init_start_flag == 0){ audio_codec_print("MyFaadDecoder init first in \n"); gFaadCxt->starttime = gettime(); gFaadCxt->init_start_flag = 1; } if (!gFaadCxt->init_flag) { gFaadCxt->error_count= 0; audio_codec_print("begin audio_decoder_init,buf size %d \n",dec_bufsize); ret = audio_decoder_init(adec_ops,outbuf,outlen,dec_buf,dec_bufsize,&inbuf_consumed); if(ret == AAC_ERROR_NO_ENOUGH_DATA){ audio_codec_print("decoder buf size %d,cost %d byte input data ,but initiation failed.^_^ \n",inlen,inbuf_consumed); dec_bufsize -= inbuf_consumed; goto exit; } gFaadCxt->init_flag = 1; dec_buf += inbuf_consumed; dec_bufsize -= inbuf_consumed; gFaadCxt->init_cost += inbuf_consumed; gFaadCxt->endtime = gettime(); audio_codec_print(" MyFaadDecoder decoder init finished total cost %d bytes,consumed time %lld ms \n",gFaadCxt->init_cost,(gFaadCxt->endtime-gFaadCxt->starttime)/1000); gFaadCxt->init_cost = 0; if(dec_bufsize < 0) dec_bufsize = 0; } NeAACDecStruct* hDecoder = (NeAACDecStruct*)(gFaadCxt->hDecoder); //TODO .fix to LATM aac decoder when ffmpeg parser return LATM aac type #if 0 if(adec_ops->nAudioDecoderType == ACODEC_FMT_AAC_LATM) hDecoder->latm_header_present = 1; #endif if(hDecoder->adts_header_present) { int nSeekNum = AACFindADTSSyncWord(dec_buf,dec_bufsize); if(nSeekNum == (dec_bufsize-1)){ audio_codec_print("%d bytes data not found adts sync header \n",nSeekNum); } dec_bufsize = dec_bufsize - nSeekNum; if(dec_bufsize < (get_frame_size(gFaadCxt)+FRAME_SIZE_MARGIN)/*AAC_INPUTBUF_SIZE/2*/){ goto exit; } } if(hDecoder->latm_header_present){ int nSeekNum = AACFindLATMSyncWord(dec_buf,dec_bufsize); if(nSeekNum == (dec_bufsize-2)){ audio_codec_print("%d bytes data not found latm sync header \n",nSeekNum); } dec_bufsize = dec_bufsize - nSeekNum; if(dec_bufsize < (get_frame_size(gFaadCxt)+FRAME_SIZE_MARGIN)/*AAC_INPUTBUF_SIZE/2*/){ goto exit; } } sample_buffer = NeAACDecDecode(gFaadCxt->hDecoder, &frameInfo, dec_buf, dec_bufsize); dec_bufsize -= frameInfo.bytesconsumed; if(frameInfo.error == 0 && sample_buffer == NULL && hDecoder->latm_header_present){ dec_bufsize -= 3; goto exit; } if ((frameInfo.error == 0) && (frameInfo.samples > 0) && sample_buffer!=NULL ) { store_frame_size(gFaadCxt,frameInfo.bytesconsumed); gFaadCxt->gSampleRate=frameInfo.samplerate; gFaadCxt->gChannels=frameInfo.channels; //code to mute first 1 s ??? #define MUTE_S 0.2 if(gFaadCxt->muted_samples == 0){ gFaadCxt->muted_samples = gFaadCxt->gSampleRate*gFaadCxt->gChannels*MUTE_S; } if(gFaadCxt->muted_count < gFaadCxt->muted_samples){ memset(sample_buffer,0,2*frameInfo.samples); gFaadCxt->muted_count += frameInfo.samples; } if( (outmaxlen-(*outlen)) >= (2*frameInfo.samples)){ memcpy(outbuf+(*outlen), sample_buffer, 2*frameInfo.samples); *outlen+=2*frameInfo.samples; gFaadCxt->error_count = 0; }else{ audio_codec_print("[%s %d]WARNING: no enough space used for pcm!\n",__FUNCTION__,__LINE__); } } if (frameInfo.error > 0)//failed seek to the head { if(frameInfo.error != 34 &&frameInfo.error != 35 ){ dec_bufsize -= RSYNC_SKIP_BYTES; audio_codec_print( "Error: %s,inlen %d\n", NeAACDecGetErrorMessage(frameInfo.error),inlen); } // sr/ch changed info happened 5 times always,some times error maybe,skip bytes else if(frameInfo.error == 34 && gFaadCxt->error_count > 5){ dec_bufsize -= RSYNC_SKIP_BYTES; audio_codec_print("%s,,inlen %d\n", NeAACDecGetErrorMessage(frameInfo.error),inlen); } gFaadCxt->error_count++; //err 34,means aac profile changed , PS.SBR,LC ....,normally happens when switch audio source if(gFaadCxt->error_count >= ERROR_RESET_COUNT ||frameInfo.error == 34){ if( gFaadCxt->hDecoder){ NeAACDecClose(gFaadCxt->hDecoder); gFaadCxt->hDecoder=NULL; } gFaadCxt->init_flag = 0; gFaadCxt->init_start_flag = 0; } } exit: if(dec_bufsize < 0) dec_bufsize = 0; if(gFaadCxt->init_flag == 0) gFaadCxt->init_cost += (inlen - dec_bufsize); return inlen - dec_bufsize; }
void expand_prologue (void) { int i; int main_p = MAIN_NAME_P (DECL_NAME (current_function_decl)); int stack_reserve = 0; int offset; int save_prologue_p = msp430_save_prologue_function_p (current_function_decl); int num_saved_regs; HOST_WIDE_INT size = get_frame_size(); rtx insn; /* Last generated instruction */ return_issued = 0; last_insn_address = 0; jump_tables_size = 0; prologue_size = 0; cfun->machine->is_naked = msp430_naked_function_p (current_function_decl); cfun->machine->is_interrupt = interrupt_function_p (current_function_decl); cfun->machine->is_OS_task = msp430_task_function_p (current_function_decl); cfun->machine->is_noint_hwmul = noint_hwmul_function_p (current_function_decl); cfun->machine->is_critical = msp430_critical_function_p(current_function_decl); cfun->machine->is_reenterant = msp430_reentrant_function_p(current_function_decl); cfun->machine->is_wakeup = wakeup_function_p (current_function_decl); cfun->machine->is_signal = signal_function_p (current_function_decl); /* check attributes compatibility */ if ((cfun->machine->is_critical && cfun->machine->is_reenterant) || (cfun->machine->is_reenterant && cfun->machine->is_interrupt)) { warning (OPT_Wattributes, "attribute 'reentrant' ignored"); cfun->machine->is_reenterant = 0; } if (cfun->machine->is_critical && cfun->machine->is_interrupt) { warning (OPT_Wattributes, "attribute 'critical' ignored"); cfun->machine->is_critical = 0; } if (cfun->machine->is_signal && !cfun->machine->is_interrupt) { warning (OPT_Wattributes, "attribute 'signal' has no meaning on MSP430 without 'interrupt' attribute."); cfun->machine->is_signal = 0; } /* naked function discards everything */ if (cfun->machine->is_naked) return; stack_reserve = msp430_get_stack_reserve(); offset = initial_elimination_offset (ARG_POINTER_REGNUM, STACK_POINTER_REGNUM) - 2; msp430_current_frame_offset = offset; if (cfun->machine->is_signal && cfun->machine->is_interrupt) { prologue_size += 1; insn = emit_insn (gen_enable_interrupt()); /* fprintf (file, "\teint\t; enable nested interrupt\n"); */ } if (main_p) { if (TARGET_NO_STACK_INIT) { if (size || stack_reserve) { /* fprintf (file, "\tsub\t#%d, r1\t", size + stack_reserve); */ msp430_fh_sub_sp_const(size + stack_reserve); } if (frame_pointer_needed) { /* fprintf (file, "\tmov\tr1,r%d\n", FRAME_POINTER_REGNUM); */ insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx); RTX_FRAME_RELATED_P (insn) = 1; prologue_size += 1; } if (size) prologue_size += 2; if (size == 1 || size == 2 || size == 4 || size == 8) prologue_size--; } else { /*fprintf (file, "\tmov\t#(%s-%d), r1\n", msp430_init_stack, size + stack_reserve);*/ msp430_fh_load_sp_with_sym_plus_off(msp430_init_stack, -(size + stack_reserve)); if (frame_pointer_needed) { /* fprintf (file, "\tmov\tr1,r%d\n", FRAME_POINTER_REGNUM); */ insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx); RTX_FRAME_RELATED_P (insn) = 1; prologue_size += 1; } prologue_size += 2; } if ((ACCUMULATE_OUTGOING_ARGS) && (!cfun->machine->is_leaf || cfun->calls_alloca) && crtl->outgoing_args_size) msp430_fh_sub_sp_const(crtl->outgoing_args_size); } else /* not a main() function */ { /* Here, we've got a chance to jump to prologue saver */ num_saved_regs = msp430_func_num_saved_regs (); if (!cfun->machine->is_interrupt && cfun->machine->is_critical) { prologue_size += 3; /*fprintf (file, "\tpush\tr2\n"); fprintf (file, "\tdint\n"); if (!size) fprintf (file, "\tnop\n");*/ insn = emit_insn (gen_push_sreg()); /* Pushing R2 using normal push creates a faulty INSN */ RTX_FRAME_RELATED_P (insn) = 1; insn = emit_insn (gen_disable_interrupt()); if (!size) insn = emit_insn (gen_nop()); } if ((TARGET_SAVE_PROLOGUE || save_prologue_p) && !cfun->machine->is_interrupt && !arg_register_used[12] && num_saved_regs > 4) { /* TODO: Expand this as a separate INSN called "call prologue saver", having a meaning of pushing the registers and decreasing SP, so that the debug info generation code will handle this correctly */ /*fprintf (file, "\tsub\t#16, r1\n"); fprintf (file, "\tmov\tr0, r12\n"); fprintf (file, "\tadd\t#8, r12\n"); fprintf (file, "\tbr\t#__prologue_saver+%d\n", (8 - num_saved_regs) * 4);*/ msp430_fh_sub_sp_const(16); msp430_fh_gen_mov_pc_to_reg(12); msp430_fh_add_reg_const(12, 8); msp430_fh_br_to_symbol_plus_offset("__prologue_saver", (8 - num_saved_regs) * 4); if (cfun->machine->is_critical && 8 - num_saved_regs) { int n = 16 - num_saved_regs * 2; /*fprintf (file, "\tadd\t#%d, r1\n", n);*/ msp430_fh_add_sp_const(n); if (n != 0 && n != 1 && n != 2 && n != 4 && n != 8) prologue_size += 1; } else size -= 16 - num_saved_regs * 2; prologue_size += 7; } else if(!cfun->machine->is_OS_task) { for (i = 15; i >= 4; i--) { if ((df_regs_ever_live_p(i) && (!call_used_regs[i] || cfun->machine->is_interrupt)) || (!cfun->machine->is_leaf && (call_used_regs[i] && (cfun->machine->is_interrupt)))) { /*fprintf (file, "\tpush\tr%d\n", i);*/ msp430_fh_emit_push_reg(i); prologue_size += 1; } } } if (size) { /* The next is a hack... I do not understand why, but if there ARG_POINTER_REGNUM and FRAME/STACK are different, the compiler fails to compute corresponding displacement */ if (!optimize && !optimize_size && df_regs_ever_live_p(ARG_POINTER_REGNUM)) { int o = initial_elimination_offset (ARG_POINTER_REGNUM, STACK_POINTER_REGNUM) - size; /* fprintf (file, "\tmov\tr1, r%d\n", ARG_POINTER_REGNUM); fprintf (file, "\tadd\t#%d, r%d\n", o, ARG_POINTER_REGNUM); */ insn = emit_move_insn (arg_pointer_rtx, stack_pointer_rtx); RTX_FRAME_RELATED_P (insn) = 1; msp430_fh_add_reg_const(ARG_POINTER_REGNUM, o); prologue_size += 2; if (o != 0 && o != 1 && o != 2 && o != 4 && o != 8) prologue_size += 1; } /* adjust frame ptr... */ if (size < 0) { int subtracted = (size + 1) & ~1; /*fprintf (file, "\tsub\t#%d, r1\t; %d, fpn %d\n", subtracted, size, frame_pointer_needed);*/ msp430_fh_sub_sp_const(subtracted); } else { int added; size = -size; added = (size + 1) & ~1; /*fprintf (file, "\tadd\t#%d, r1\t; %d, fpn %d\n", (size + 1) & ~1, size, frame_pointer_needed);*/ msp430_fh_add_sp_const(added); } if (size == 1 || size == 2 || size == 4 || size == 8) prologue_size += 1; else prologue_size += 2; } if (frame_pointer_needed) { /*fprintf (file, "\tmov\tr1,r%d\n", FRAME_POINTER_REGNUM);*/ insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx); RTX_FRAME_RELATED_P (insn) = 1; prologue_size += 1; } if ((ACCUMULATE_OUTGOING_ARGS) && (!cfun->machine->is_leaf || cfun->calls_alloca) && crtl->outgoing_args_size) msp430_fh_sub_sp_const(crtl->outgoing_args_size); /* disable interrupt for reentrant function */ if (!cfun->machine->is_interrupt && cfun->machine->is_reenterant) { prologue_size += 1; /*fprintf (file, "\tdint\n");*/ insn = emit_insn (gen_disable_interrupt()); } } /*fprintf (file, "\t/ * prologue end (size=%d) * /\n\n", prologue_size);*/ }
void expand_epilogue (void) { int i; int interrupt_func_p = cfun->machine->is_interrupt; int main_p = MAIN_NAME_P (DECL_NAME (current_function_decl)); int wakeup_func_p = cfun->machine->is_wakeup; int cfp = cfun->machine->is_critical; int ree = cfun->machine->is_reenterant; int save_prologue_p = msp430_save_prologue_function_p (current_function_decl); /*int function_size;*/ HOST_WIDE_INT size = get_frame_size(); rtx insn; last_insn_address = 0; jump_tables_size = 0; epilogue_size = 0; /*function_size = (INSN_ADDRESSES (INSN_UID (get_last_insn ())) - INSN_ADDRESSES (INSN_UID (get_insns ())));*/ if (cfun->machine->is_OS_task || cfun->machine->is_naked) { emit_jump_insn (gen_return ()); /* Otherwise, epilogue with 0 instruction causes a segmentation fault */ return; } if (msp430_empty_epilogue ()) { if (!return_issued) { /*fprintf (file, "\t%s\n", msp430_emit_return (NULL, NULL, NULL));*/ emit_jump_insn (gen_return ()); epilogue_size++; } /*fprintf (file, "\n\t/ * epilogue: not required * /\n");*/ goto done_epilogue; } if ((cfp || interrupt_func_p) && ree) ree = 0; if (cfp && interrupt_func_p) cfp = 0; /*fprintf (file, "\n\t/ * epilogue : frame size = %d * /\n", size);*/ if (main_p) { int totalsize = (size + 1) & ~1; if ((ACCUMULATE_OUTGOING_ARGS) && (!cfun->machine->is_leaf || cfun->calls_alloca) && crtl->outgoing_args_size) totalsize += crtl->outgoing_args_size; if (totalsize) { msp430_fh_add_sp_const(totalsize); /*fprintf (file, "\tadd\t#%d, r1\n", (size + 1) & ~1);*/ } /*fprintf (file, "\tbr\t#%s\n", msp430_endup);*/ msp430_fh_br_to_symbol_plus_offset(msp430_endup, 0); epilogue_size += 4; if (size == 1 || size == 2 || size == 4 || size == 8) epilogue_size--; } else { int totalsize = (size + 1) & ~1; if ((ACCUMULATE_OUTGOING_ARGS) && (!cfun->machine->is_leaf || cfun->calls_alloca) && crtl->outgoing_args_size) totalsize += crtl->outgoing_args_size; if (ree) { /*fprintf (file, "\teint\n");*/ insn = emit_insn (gen_enable_interrupt()); epilogue_size += 1; } if (totalsize) { /*fprintf (file, "\tadd\t#%d, r1\n", (size + 1) & ~1);*/ msp430_fh_add_sp_const(totalsize); if (size == 1 || size == 2 || size == 4 || size == 8) epilogue_size += 1; else epilogue_size += 2; } if ((TARGET_SAVE_PROLOGUE || save_prologue_p) && !interrupt_func_p && msp430_func_num_saved_regs () > 2) { /*fprintf (file, "\tbr\t#__epilogue_restorer+%d\n",(8 - msp430_func_num_saved_regs ()) * 2);*/ msp430_fh_br_to_symbol_plus_offset("__epilogue_restorer", (8 - msp430_func_num_saved_regs ()) * 2); epilogue_size += 2; } else if ((TARGET_SAVE_PROLOGUE || save_prologue_p) && interrupt_func_p) { /*fprintf (file, "\tbr\t#__epilogue_restorer_intr+%d\n", (12 - msp430_func_num_saved_regs ()) * 2);*/ msp430_fh_br_to_symbol_plus_offset("__epilogue_restorer_intr", (12 - msp430_func_num_saved_regs ()) * 2); } else { for (i = 4; i < 16; i++) { if ((df_regs_ever_live_p(i) && (!call_used_regs[i] || interrupt_func_p)) || (!cfun->machine->is_leaf && (call_used_regs[i] && interrupt_func_p))) { /*fprintf (file, "\tpop\tr%d\n", i);*/ msp430_fh_emit_pop_reg(i); epilogue_size += 1; } } if (interrupt_func_p && wakeup_func_p) { /*fprintf (file, "\tbic\t#0xf0,0(r1)\n");*/ msp430_fh_bic_deref_sp(0xF0); epilogue_size += 3; } emit_jump_insn (gen_return ()); /*fprintf (file, "\tret\n");*/ epilogue_size += 1; } } /*fprintf (file, "\t/ * epilogue end (size=%d) * /\n", epilogue_size);*/ done_epilogue: /*fprintf (file, "\t/ * function %s size %d (%d) * /\n", current_function_name, prologue_size + function_size + epilogue_size, function_size);*/ msp430_commands_in_file += prologue_size + /*function_size +*/ epilogue_size; msp430_commands_in_prologues += prologue_size; msp430_commands_in_epilogues += epilogue_size; }