int main() { double lsa1, lsa2; int sa1=-1, sa1p, sa2=-1, sa2p; double lr; for ( lsa1 = lsa_step; lsa1 <= lsa_max; lsa1 += lsa_step ) { sa1p = (int)exp(lsa1); if ( sa1p == sa1 ) continue; sa1 = sa1p; for ( lsa2 = lsa1; lsa2 <= lsa_max; lsa2 += lsa_step ) { sa2p = (int)exp(lsa2); if ( sa2p == sa2 ) continue; sa2 = sa2p; for ( lr = lr_min; lr <= lr_max; lr += lr_step ) { printpts(exp(lr), sa1, sa2); } } } return 0; }
static void writeout_ext(multiplex_t *mx, int n) { uint8_t outbuf[3000]; int written=0; unsigned int length=0; int nlength=0; uint64_t pts, dpts=0; int newpts=0; int nframes=1; int ac3_off=0; int rest_data = 5; int type = mx->ext[n].type; ringbuffer *airbuffer = &mx->index_extrbuffer[n]; dummy_buffer *dbuf = &mx->ext[n].dbuf; uint64_t adelay = mx->ext[n].pts_off; uint64_t *apts = &mx->ext[n].pts; index_unit *aiu = &mx->ext[n].iu; switch (type){ case MPEG_AUDIO: #ifdef OUT_DEBUG fprintf(stderr,"writing AUDIO%d pack\n",n); #endif break; case AC3: #ifdef OUT_DEBUG fprintf(stderr,"writing AC3%d pack\n",n); #endif rest_data = 1; // 4 bytes AC3 header break; default: return; } if (mx->finish != 2 && dummy_space(dbuf) < mx->data_size + rest_data){ return; } pts = uptsdiff( aiu->pts + mx->audio_delay, adelay ); *apts = pts; length = aiu->length; if (length < aiu->framesize){ newpts = 1; ac3_off = length; } dummy_add(dbuf, pts, aiu->length); #ifdef OUT_DEBUG fprintf(stderr,"start: %d stop: %d (%d) length %d ", aiu->start, (aiu->start+aiu->length), aiu->length, length); printpts(*apts); printpts(aiu->pts); printpts(mx->audio_delay); printpts(adelay); printpts(pts); fprintf(stderr,"\n"); #endif while (!mx->is_ts && length < mx->data_size + rest_data){ if (ring_read(airbuffer, (uint8_t *)aiu, sizeof(index_unit)) > 0){ dpts = uptsdiff(aiu->pts +mx->audio_delay, adelay ); if (newpts){ pts = dpts; newpts=0; } length+= aiu->length; if (length < mx->data_size + rest_data) dummy_add(dbuf, dpts, aiu->length); *apts = dpts; nframes++; #ifdef OUT_DEBUG fprintf(stderr,"start: %d stop: %d (%d) length %d ", aiu->start, (aiu->start+aiu->length), aiu->length, length); printpts(*apts); printpts(aiu->pts); printpts(mx->audio_delay); printpts(adelay); fprintf(stderr,"\n"); #endif } else if (mx->finish){ break; } else if (mx->fill_buffers(mx->priv, mx->finish)< 0) { fprintf(stderr,"error in writeout ext\n"); exit(1); } } nlength = length; switch (type) { case MPEG_AUDIO: if(mx->is_ts) written = write_audio_ts( mx->ext[n].strmnum, pts, outbuf, &nlength, newpts ? 0 : PTS_ONLY, &mx->extrbuffer[n]); else written = write_audio_pes( mx->pack_size, mx->extcnt, mx->ext[n].strmnum, pts, mx->SCR, mx->muxr, outbuf, &nlength, PTS_ONLY, &mx->extrbuffer[n]); break; case AC3: if(mx->is_ts) written = write_ac3_ts(mx->ext[n].strmnum, pts, outbuf, &nlength, newpts ? 0 : PTS_ONLY, mx->ext[n].frmperpkt, &mx->extrbuffer[n]); else written = write_ac3_pes( mx->pack_size, mx->extcnt, mx->ext[n].strmnum, pts, mx->SCR, mx->muxr, outbuf, &nlength, PTS_ONLY, nframes, ac3_off, &mx->extrbuffer[n]); break; } length -= nlength; write(mx->fd_out, outbuf, written); dummy_add(dbuf, dpts, aiu->length-length); aiu->length = length; aiu->start = ring_rpos(&mx->extrbuffer[n]); if (aiu->length == 0){ get_next_ext_unit(mx, aiu, n); } else { //estimate next pts based on bitrate of stream and data written aiu->pts = uptsdiff(aiu->pts + ((nlength*aiu->ptsrate)>>8), 0); } *apts = uptsdiff(aiu->pts + mx->audio_delay, adelay); #ifdef OUT_DEBUG if ((int64_t)*apts < 0) fprintf(stderr,"SCHEISS "); fprintf(stderr,"APTS"); printpts(*apts); printpts(aiu->pts); printpts(mx->audio_delay); printpts(adelay); fprintf(stderr,"\n"); #endif if (mx->fill_buffers(mx->priv, mx->finish)< 0) { fprintf(stderr,"error in writeout ext\n"); exit(1); } }
void check_times( multiplex_t *mx, int *video_ok, int *ext_ok, int *start) { int i; int set_ok = 0; memset(ext_ok, 0, N_AUDIO*sizeof(int)); *video_ok = 0; if (mx->fill_buffers(mx->priv, mx->finish)< 0) { fprintf(stderr,"error in get next video unit\n"); return; } /* increase SCR to next packet */ mx->oldSCR = mx->SCR; if (!*start){ ptsinc(&mx->SCR, mx->SCRinc); } else *start = 0; if (mx->VBR) { #ifdef OUT_DEBUG1 fprintf(stderr,"EXTRACLOCK: %lli ", mx->extra_clock); printpts(mx->extra_clock); fprintf(stderr,"\n"); #endif if (mx->extra_clock > 0.0) { int64_t d = mx->extra_clock/ mx->SCRinc - 1; if (d > 0) mx->extra_clock = d*mx->SCRinc; else mx->extra_clock = 0.0; } if (mx->extra_clock > 0.0) { int64_t temp_scr = mx->extra_clock; for (i=0; i<mx->extcnt; i++){ if (ptscmp(mx->SCR + temp_scr + 100*CLOCK_MS, mx->ext[i].iu.pts) > 0) { while (ptscmp(mx->SCR + temp_scr + 100*CLOCK_MS, mx->ext[i].iu.pts) > 0) temp_scr -= mx->SCRinc; temp_scr += mx->SCRinc; } } if (temp_scr > 0.0) { mx->SCR += temp_scr; mx->extra_clock -= temp_scr; } else mx->extra_clock = 0.0; } } /* clear decoder buffers up to SCR */ dummy_delete(&mx->vdbuf, mx->SCR); for (i=0;i <mx->extcnt; i++) dummy_delete(&mx->ext[i].dbuf, mx->SCR); if (dummy_space(&mx->vdbuf) > mx->vsize && mx->viu.length > 0 && (ptscmp(mx->viu.dts + mx->video_delay, 500*CLOCK_MS +mx->oldSCR)<0) && ring_avail(mx->index_vrbuffer)){ *video_ok = 1; set_ok = 1; } for (i = 0; i < mx->extcnt; i++){ if (dummy_space(&mx->ext[i].dbuf) > mx->extsize && mx->ext[i].iu.length > 0 && ptscmp(mx->ext[i].pts, 500*CLOCK_MS + mx->oldSCR) < 0 && ring_avail(&mx->index_extrbuffer[i])){ ext_ok[i] = 1; set_ok = 1; } } #ifdef OUT_DEBUG if (set_ok) { fprintf(stderr, "SCR"); printpts(mx->oldSCR); fprintf(stderr, "VDTS"); printpts(mx->viu.dts); fprintf(stderr, " (%d)", *video_ok); fprintf(stderr, " EXT"); for (i = 0; i < mx->extcnt; i++){ fprintf(stderr, "%d:", mx->ext[i].type); printpts(mx->ext[i].pts); fprintf(stderr, " (%d)", ext_ok[i]); } fprintf(stderr, "\n"); } #endif }
static void writeout_video(multiplex_t *mx) { uint8_t outbuf[3000]; int written=0; uint8_t ptsdts=0; unsigned int length; int nlength=0; int frame_len=0; index_unit *viu = &mx->viu; #ifdef OUT_DEBUG fprintf(stderr,"writing VIDEO pack\n"); #endif if(viu->frame_start) { ptsdts = get_ptsdts(mx, viu); frame_len = viu->length; } if (viu->frame_start && viu->seq_header && viu->gop && viu->frame == I_FRAME){ if (!mx->startup && mx->is_ts){ write_ts_patpmt(mx->ext, mx->extcnt, 1, outbuf); write(mx->fd_out, outbuf, mx->pack_size*2); ptsinc(&mx->SCR, mx->SCRinc*2); } else if (!mx->startup && mx->navpack){ write_nav_pack(mx->pack_size, mx->extcnt, mx->SCR, mx->muxr, outbuf); write(mx->fd_out, outbuf, mx->pack_size); ptsinc(&mx->SCR, mx->SCRinc); } else mx->startup = 0; #ifdef OUT_DEBUG fprintf (stderr, " with sequence and gop header\n"); #endif } if (mx->finish != 2 && dummy_space(&mx->vdbuf) < mx->data_size){ return; } length = viu->length; while (!mx->is_ts && length < mx->data_size){ index_unit nviu; int old_start = viu->frame_start; int old_frame = viu->frame; uint64_t old_pts = viu->pts; uint64_t old_dts = viu->dts; dummy_add(&mx->vdbuf, uptsdiff(viu->dts+mx->video_delay,0) , viu->length); if ( peek_next_video_unit(mx, &nviu)){ if (!(nviu.seq_header && nviu.gop && nviu.frame == I_FRAME)){ get_next_video_unit(mx, viu); frame_len = viu->length; length += viu->length; if(old_start) { viu->pts = old_pts; viu->dts = old_dts; viu->frame = old_frame; } else { ptsdts = get_ptsdts(mx, viu); } } else break; } else break; } if (viu->frame_start){ viu->frame_start=0; if (viu->gop){ uint8_t gop[8]; frame_len=length-frame_len; ring_peek(mx->vrbuffer, gop, 8, frame_len); pts2time( viu->pts + mx->video_delay, gop, 8); ring_poke(mx->vrbuffer, gop, 8, frame_len); viu->gop=0; } if (mx->VBR) { mx->extra_clock = ptsdiff(viu->dts + mx->video_delay, mx->SCR + 500*CLOCK_MS); #ifdef OUT_DEBUG1 fprintf(stderr,"EXTRACLOCK2: %lli %lli %lli\n", viu->dts, mx->video_delay, mx->SCR); fprintf(stderr,"EXTRACLOCK2: %lli ", mx->extra_clock); printpts(mx->extra_clock); fprintf(stderr,"\n"); #endif if (mx->extra_clock < 0) mx->extra_clock = 0.0; } } nlength = length; if (mx->is_ts) written = write_video_ts( viu->pts+mx->video_delay, viu->dts+mx->video_delay, mx->SCR, outbuf, &nlength, ptsdts, mx->vrbuffer); else written = write_video_pes( mx->pack_size, mx->extcnt, viu->pts+mx->video_delay, viu->dts+mx->video_delay, mx->SCR, mx->muxr, outbuf, &nlength, ptsdts, mx->vrbuffer); length -= nlength; dummy_add(&mx->vdbuf, uptsdiff( viu->dts+mx->video_delay,0) , viu->length-length); viu->length = length; //estimate next pts based on bitrate of this stream and data written viu->dts = uptsdiff(viu->dts + ((nlength*viu->ptsrate)>>8), 0); write(mx->fd_out, outbuf, written); #ifdef OUT_DEBUG fprintf(stderr,"VPTS"); printpts(viu->pts); fprintf(stderr," DTS"); printpts(viu->dts); printpts(mx->video_delay); fprintf(stderr,"\n"); #endif if (viu->length == 0){ get_next_video_unit(mx, viu); } }