// this thread is responsible for decoding and inserting buffers of decoded // audio into each sink static void *decode_thread(void *arg) { struct GroovePlaylistPrivate *p = arg; struct GroovePlaylist *playlist = &p->externals; while (!p->abort_request) { pthread_mutex_lock(&p->decode_head_mutex); // if we don't have anything to decode, wait until we do if (!p->decode_head) { if (!p->sent_end_of_q) { every_sink_signal_end(playlist); p->sent_end_of_q = 1; } pthread_cond_wait(&p->decode_head_cond, &p->decode_head_mutex); pthread_mutex_unlock(&p->decode_head_mutex); continue; } p->sent_end_of_q = 0; // if all sinks are filled up, no need to read more if (every_sink_full(playlist)) { pthread_cond_wait(&p->sink_drain_cond, &p->decode_head_mutex); pthread_mutex_unlock(&p->decode_head_mutex); continue; } struct GrooveFile *file = p->decode_head->file; p->volume = p->decode_head->gain * playlist->volume; if (decode_one_frame(playlist, file) < 0) { p->decode_head = p->decode_head->next; // seek to beginning of next song if (p->decode_head) { struct GrooveFile *next_file = p->decode_head->file; struct GrooveFilePrivate *next_f = (struct GrooveFilePrivate *) next_file; pthread_mutex_lock(&next_f->seek_mutex); next_f->seek_pos = 0; next_f->seek_flush = 0; pthread_mutex_unlock(&next_f->seek_mutex); } } pthread_mutex_unlock(&p->decode_head_mutex); } return NULL; }
int videoinfoload(const char *path) { strcpy(filename, path); pFormatCtx = avformat_alloc_context(); if (avformat_open_input(&pFormatCtx, filename, NULL, NULL) != 0) { LOGI("Couldn't open input stream."); return -1; } if (avformat_find_stream_info(pFormatCtx, NULL) < 0) { LOGI("Couldn't find stream information."); return -1; } int i; for (i = 0; i < pFormatCtx->nb_streams; i++) { switch (pFormatCtx->streams[i]->codec->codec_type) { case AVMEDIA_TYPE_VIDEO: videoStream = i; video_st = pFormatCtx->streams[i]; video_ctx = video_st->codec; break; case AVMEDIA_TYPE_AUDIO: audioStream = i; audio_st = pFormatCtx->streams[i]; audio_ctx = audio_st->codec; break; default: break; } } video_codec = avcodec_find_decoder(video_ctx->codec_id); if (video_codec == NULL) { LOGI("Codec not found.\n"); return -1; } if (avcodec_open2(video_ctx, video_codec, NULL) < 0) { LOGI("Could not open codec.\n"); return -1; } VideoDecodeInit(video_ctx); decode_one_frame(); return 0; }
int main(int argc, char **argv) { int Flag = TRUE; //long ftell_position;//, expected_slice_type; //int ret; NALU_t *nalu; h264_decoder* dec_params; char *ptr; ptr = ( char*)malloc(10 * sizeof(char)); if ((dec_params = ( h264_decoder*)h264_malloc(1 * sizeof(h264_decoder)))==NULL) // if ((dec_params = ( h264_decoder*)h264_malloc(1 * 100))==NULL) { Flag=FALSE; } if ((dec_params->input = (InputParameters *)h264_malloc(1 * sizeof(InputParameters)))==NULL) { printf("main: input"); exit(0); } if ((dec_params->img = (ImageParameters *)h264_malloc(1 * sizeof(ImageParameters)))==NULL) { printf("main: img"); exit(0); } ////////// ADDED INITIALIZATIONS ////// dec_params->active_sps = NULL; dec_params->active_pps = NULL; dec_params->Co_located = NULL; dec_params->dec_picture = NULL; dec_params->global_init_done = 0; dec_params->dpb.init_done = 0; dec_params->img->DeblockCall = 0; // dec_params->img->structure = 0; dec_params->MapUnitToSliceGroupMap = NULL; dec_params->MbToSliceGroupMap = NULL; dec_params->img->errorConcealmentFlag = 0; // ERROR CONCEALMENT FLAG SET TO ZERO , NO ERROR CONCEALMENT dec_params->img->no_output_of_prior_pics_flag = -1; /////////////////////////////////////// Initializations(dec_params); Configure ( argc, argv,dec_params ); init_old_slice(dec_params); switch (dec_params->input->FileFormat) { case 0: OpenBitstreamFile (dec_params->input->infile,dec_params); break; case 1: OpenRTPFile (dec_params->input->infile,dec_params); break; default: printf ("Unsupported file format %d, exit\n", dec_params->input->FileFormat); } // Allocate Slice data struct malloc_slice(dec_params->input,dec_params->img,dec_params); init(dec_params->img,dec_params); dec_params->dec_picture = NULL; dec_params->dpb.init_done = 0; //dec_params->g_nFrame = 0; // init_out_buffer(dec_params); //dec_params->img->idr_psnr_number=dec_params->input->ref_offset; //dec_params->img->psnr_number=0; dec_params->img->number=0; dec_params->img->type = I_SLICE; dec_params->img->dec_ref_pic_marking_buffer = NULL; // B pictures dec_params->Bframe_ctr=0; // time for total decoding session dec_params->tot_time = 0; dec_params->nalu = AllocNALU(MAX_CODED_FRAME_SIZE,dec_params); nalu = dec_params->nalu; dec_params->dp = AllocPartition(1, dec_params,1024); dec_params->sps = AllocSPS(); dec_params->pps = AllocPPS(); { while ( decode_one_frame( dec_params ) != EOS ); } //report( dec_params->input, dec_params->img, dec_params->snr,dec_params,); report( dec_params->input, dec_params->img,dec_params); free_slice( dec_params->input,dec_params->img); FreeNALU(dec_params->nalu); FreePartition (dec_params->dp, 1); FreeSPS (dec_params->sps); if (dec_params->PicParSet[dec_params->pps->pic_parameter_set_id].Valid == TRUE && dec_params->PicParSet[dec_params->pps->pic_parameter_set_id].slice_group_id != NULL) { h264_free (dec_params->PicParSet[dec_params->pps->pic_parameter_set_id].slice_group_id); dec_params->PicParSet[dec_params->pps->pic_parameter_set_id].slice_group_id = NULL; } // IF FMO PRESENT if (dec_params->active_pps->num_slice_groups_minus1) { FmoFinit(dec_params); } FreePPS (dec_params->pps); free_global_buffers_baseline(dec_params); flush_dpb(dec_params); #ifdef PAIR_FIELDS_IN_OUTPUT flush_pending_output(dec_params->p_out); #endif CloseBitstreamFile(dec_params); //close(dec_params->p_out); fclose (dec_params->f_out); // fclose(p_out2); #if TRACE fclose(p_trace); #endif //ercClose(dec_params->erc_errorVar,dec_params); ercClose(dec_params); free_dpb(dec_params); // uninit_out_buffer(dec_params); free_colocated(dec_params); if(dec_params->dec_picture != NULL) { free (dec_params->dec_picture); dec_params->dec_picture = NULL; } if(dec_params->input != NULL) { h264_free (dec_params->input); dec_params->input = NULL; } if(dec_params->img != NULL) { h264_free (dec_params->img); dec_params->img = NULL; } if(dec_params != NULL) { h264_free (dec_params); dec_params = NULL; } return 0; }
//int ldecod(/*int argc, char **argv*/) //int ldecod(char * cfg_file) //int ldecod(char * cfg_file, unsigned char * bitstream) //int ldecod(char * cfg_file, unsigned char * bitstream, unsigned int length) int ldecod(unsigned char * bitstream, unsigned int length) #endif { // allocate memory for the structures if (Frame_cnt == 0) { if ((input = (struct inp_par *)calloc(1, sizeof(struct inp_par)))==NULL) no_mem_exit("main: input"); if ((snr = (struct snr_par *)calloc(1, sizeof(struct snr_par)))==NULL) no_mem_exit("main: snr"); if ((img = (struct img_par *)calloc(1, sizeof(struct img_par)))==NULL) no_mem_exit("main: img"); } // Read Configuration File /* if (argc != 2) { snprintf(errortext, ET_SIZE, "Usage: %s <config.dat> \n\t<config.dat> defines decoder parameters",argv[0]); error(errortext, 300); } */ Bitstream_leng = length; //init_conf(input, cfg_file);// read cfg & init init_conf2(input);// read cfg & init g_new_frame=1; switch (input->FileFormat) { case 0: //OpenBitstreamFile (input->infile);//Load bitsteam: master_read() OpenBitstreamFile2 (bitstream);//Load bitsteam: master_read() break; case 1: OpenRTPFile (input->infile); break; default: printf ("Unsupported file format %d, exit\n", input->FileFormat); } // Allocate Slice data struct malloc_slice(input,img); init(img); dec_picture = NULL; dpb.init_done = 0; // init_dpb(input); init_out_buffer(); img->idr_psnr_number=0; img->psnr_number=0; img->number=0; img->type = I_SLICE; img->tr_old = -1; // WYK: Oct. 8, 2001, for detection of a new frame img->dec_ref_pic_marking_buffer = NULL; // B pictures Bframe_ctr=0; // time for total decoding session tot_time = 0; #ifdef ESLSC tb_hls_cavld_p = (tb_hls_cavld*)tb; #endif // one clock cycle for one frame //printf("[%d]",Frame_cnt); //cout<< "-->start_time:"<<sc_time_stamp() << endl; while (decode_one_frame(img, input, snr) != EOS) { //flush_one_dpb();//cylin num_pending_frame++; if(!flag_start_dump_frame){ //cout<< sc_time_stamp() <<"\t"<<" ldecode().event_dump_one_frame_req.notify"<<endl; flag_start_dump_frame = 1; event_dump_one_frame_req.notify(5*CLK_CYCLES, CLK_UNIT);//CYLin:define in "global.h" } } //if(flag_start_dump_frame && num_pending_frame >= FRAME_BUFFER_SIZE) if(num_pending_frame >= FRAME_BUFFER_SIZE) wait(event_dump_one_frame_end);//CYLin:waiting pre-frame __report(input, img, snr); if(Frame_cnt == 60) { //if(flag_start_dump_frame) while(num_pending_frame){ wait(event_dump_one_frame_end);//CYLin:waiting pre-frame } free_slice(input,img); FmoFinit(); free_global_buffers(input, img); //printf("******** flush_dpb() ***********\n");//cylin.debug flush_dpb(); //CloseBitstreamFile(); CloseBitstreamFile2(); // fclose(p_out); // fclose(p_out2); if (p_ref) fclose(p_ref); #if TRACE fclose(p_trace); #endif ercClose(erc_errorVar); free_dpb(); uninit_out_buffer(); free (input); free (snr); free (img); } //while( !kbhit() ); return 0; }
/*! *********************************************************************** * \brief * main function for TML decoder *********************************************************************** */ int main(int argc, char **argv) { // allocate memory for the structures if ((input = (struct inp_par *)calloc(1, sizeof(struct inp_par)))==NULL) no_mem_exit("main: input"); if ((snr = (struct snr_par *)calloc(1, sizeof(struct snr_par)))==NULL) no_mem_exit("main: snr"); if ((img = (struct img_par *)calloc(1, sizeof(struct img_par)))==NULL) no_mem_exit("main: img"); // Read Configuration File if (argc != 2) { snprintf(errortext, ET_SIZE, "Usage: %s <config.dat> \n\t<config.dat> defines decoder parameters",argv[0]); error(errortext, 300); } init_conf(input, argv[1]); init_old_slice(); switch (input->FileFormat) { case 0: OpenBitstreamFile (input->infile); break; case 1: OpenRTPFile (input->infile); break; default: printf ("Unsupported file format %d, exit\n", input->FileFormat); } // Allocate Slice data struct malloc_slice(input,img); init(img); dec_picture = NULL; dpb.init_done = 0; g_nFrame = 0; // init_dpb(input); init_out_buffer(); img->idr_psnr_number=input->ref_offset; img->psnr_number=0; img->number=0; img->type = I_SLICE; img->dec_ref_pic_marking_buffer = NULL; // B pictures Bframe_ctr=0; // time for total decoding session tot_time = 0; while (decode_one_frame(img, input, snr) != EOS) ; report(input, img, snr); free_slice(input,img); FmoFinit(); free_global_buffers(); flush_dpb(); #ifdef PAIR_FIELDS_IN_OUTPUT flush_pending_output(p_out); #endif CloseBitstreamFile(); fclose(p_out); // fclose(p_out2); if (p_ref) fclose(p_ref); #if TRACE fclose(p_trace); #endif ercClose(erc_errorVar); free_dpb(); uninit_out_buffer(); free_collocated(Co_located); free (input); free (snr); free (img); //while( !kbhit() ); return 0; }
/*! *********************************************************************** * \brief * main function for TML decoder *********************************************************************** */ int main2(int argc, char **argv) { int i; // allocate memory for the structures if ((input = (struct inp_par *)calloc(1, sizeof(struct inp_par)))==NULL) no_mem_exit("main: input"); if ((snr = (struct snr_par *)calloc(1, sizeof(struct snr_par)))==NULL) no_mem_exit("main: snr"); if ((img = (struct img_par *)calloc(1, sizeof(struct img_par)))==NULL) no_mem_exit("main: img"); Configure (argc, argv); init_old_slice(); switch (input->FileFormat) { case 0: OpenBitstreamFile (input->infile); break; case 1: OpenRTPFile (input->infile); break; default: printf ("Unsupported file format %d, exit\n", input->FileFormat); } // Allocate Slice data struct malloc_slice(input,img); init(img); #ifdef ADAPTIVE_FILTER InitAdaptiveFilter(); #endif #ifdef MV_COMPETITION init_MV_Competition(); #endif dec_picture = NULL; dpb.init_done = 0; g_nFrame = 0; init_out_buffer(); img->idr_psnr_number=input->ref_offset; img->psnr_number=0; img->number=0; img->type = I_SLICE; img->dec_ref_pic_marking_buffer = NULL; // B pictures Bframe_ctr=snr->frame_ctr=0; // time for total decoding session tot_time = 0; // reference flag initialization for(i=0; i<17; i++) { ref_flag[i]=1; } while (decode_one_frame(img, input, snr) != EOS) ; report(input, img, snr); free_slice(input,img); FmoFinit(); free_global_buffers(); flush_dpb(); #ifdef PAIR_FIELDS_IN_OUTPUT flush_pending_output(p_out); #endif CloseBitstreamFile(); close(p_out); // fclose(p_out2); if (p_ref!=-1) close(p_ref); #if TRACE fclose(p_trace); #endif #ifdef MV_COMPETITION close_MV_Competition(); #endif ercClose(erc_errorVar); free_dpb(); uninit_out_buffer(); free_colocated(Co_located); free (input); free (snr); free (img); //while( !kbhit() ); return 0; }
jint Java_org_kreal_ccffmpeg_ccFFmpeg_decoderOne(JNIEnv *env, jobject instance) { return decode_one_frame(); }