11 int vavail=0, aavail=0, i;
15 for (i=0; i<mx->
extcnt;i++){
20 if (aavail+vavail)
return ((aavail+vavail));
28 if(aok[i] &&
ptscmp(vpts,ext[i].pts) > 0)
44 }
else if(
ptscmp(tmppts, ext[i].pts) > 0) {
58 LOG(VB_GENERAL, LOG_ERR,
59 "error in peek next video unit");
65 LOG(VB_GENERAL, LOG_DEBUG,
66 "video index start: %d stop: %d (%d) rpos: %d\n",
81 LOG(VB_GENERAL, LOG_ERR,
82 "error in get next video unit");
88 LOG(VB_GENERAL, LOG_INFO,
89 "video index start: %d stop: %d (%d) rpos: %d\n",
106 LOG(VB_GENERAL, LOG_ERR,
107 "error in peek next video unit");
114 LOG(VB_GENERAL, LOG_DEBUG,
115 "ext index start: %d stop: %d (%d) rpos: %d",
133 LOG(VB_GENERAL, LOG_ERR,
134 "error in get next ext unit");
153 LOG(VB_GENERAL, LOG_DEBUG,
154 "ext index start: %d stop: %d (%d) rpos: %d",
166 if (viu->
frame == I_FRAME || viu->
frame == P_FRAME)
173 if (viu->
frame == I_FRAME)
182 uint8_t outbuf[3000];
191 LOG(VB_GENERAL, LOG_DEBUG,
"writing VIDEO pack");
200 viu->
frame == I_FRAME){
212 LOG(VB_GENERAL, LOG_DEBUG,
" with sequence and gop header");
220 while (!mx->
is_ts && length < mx->data_size){
223 int old_frame = viu->
frame;
224 uint64_t old_pts = viu->
pts;
225 uint64_t old_dts = viu->
dts;
230 nviu.
frame == I_FRAME)){
237 viu->
frame = old_frame;
249 frame_len=length-frame_len;
257 mx->
SCR + 500*CLOCK_MS);
259 LOG(VB_GENERAL, LOG_DEBUG,
260 "EXTRACLOCK2: %lli %lli %lli",
262 LOG(VB_GENERAL, LOG_DEBUG,
"EXTRACLOCK2: %lli",
277 mx->
SCR, outbuf, &nlength,
283 mx->
SCR, mx->
muxr, outbuf, &nlength,
301 LOG(VB_GENERAL, LOG_DEBUG,
"VPTS");
303 LOG(VB_GENERAL, LOG_DEBUG,
" DTS");
316 uint8_t outbuf[3000];
318 unsigned int length=0;
320 uint64_t pts, dpts=0;
330 uint64_t *apts = &mx->
ext[
n].
pts;
337 LOG(VB_GENERAL, LOG_DEBUG,
"writing AUDIO%d pack\n", n);
343 LOG(VB_GENERAL, LOG_DEBUG,
"writing AC3%d pack\n", n);
359 if (length < aiu->framesize){
366 LOG(VB_GENERAL, LOG_DEBUG,
"start: %d stop: %d (%d) length %d",
375 while (!mx->
is_ts && length < mx->data_size + rest_data){
385 if (length < mx->data_size + rest_data)
391 LOG(VB_GENERAL, LOG_DEBUG,
392 "start: %d stop: %d (%d) length %d",
403 LOG(VB_GENERAL, LOG_ERR,
"error in writeout ext");
414 outbuf, &nlength, newpts ? 0 : PTS_ONLY,
419 mx->
muxr, outbuf, &nlength, PTS_ONLY,
425 outbuf, &nlength, newpts ? 0 : PTS_ONLY,
430 mx->
muxr, outbuf, &nlength, PTS_ONLY,
456 if ((int64_t)*apts < 0)
457 LOG(VB_GENERAL, LOG_DEBUG,
"SCHEISS APTS");
465 LOG(VB_GENERAL, LOG_ERR,
"error in writeout ext");
472 uint8_t outbuf[3000];
474 LOG(VB_GENERAL, LOG_INFO,
"writing PADDING pack");
487 memset(ext_ok, 0, N_AUDIO*
sizeof(
int));
491 LOG(VB_GENERAL, LOG_ERR,
"error in get next video unit");
503 LOG(VB_GENERAL, LOG_DEBUG,
"EXTRACLOCK: %lli", mx->
extra_clock);
518 for (i=0; i<mx->
extcnt; i++){
519 if (
ptscmp(mx->
SCR + temp_scr + 100*CLOCK_MS,
529 if (temp_scr > 0.0) {
540 for (i=0;i <mx->
extcnt; i++)
550 for (i = 0; i < mx->
extcnt; i++){
561 LOG(VB_GENERAL, LOG_DEBUG,
"SCR");
563 LOG(VB_GENERAL, LOG_DEBUG,
"VDTS");
565 LOG(VB_GENERAL, LOG_DEBUG,
" (%d) EXT", *video_ok);
566 for (i = 0; i < mx->
extcnt; i++){
567 LOG(VB_GENERAL, LOG_DEBUG,
"%d:", mx->
ext[i].
type);
569 LOG(VB_GENERAL, LOG_DEBUG,
" (%d)", ext_ok[i]);
588 if (!done && !mx->
VBR){
601 uint8_t mpeg_end[4] = { 0x00, 0x00, 0x01, 0xB9 };
603 memset(ext_ok, 0, N_AUDIO*
sizeof(
int));
627 for (i = 0; i < mx->
extcnt; i++){
637 if (mx->
otype == REPLEX_MPEG2)
641 for (i=0; i<mx->
extcnt;i++)
649 int pktdata = pktsize - TS_HEADER_MIN;
651 numpkt = (framesize + PES_H_MIN + 10 + pktdata -1) / pktdata;
652 return pktsize- ((pktsize * numpkt) - framesize + numpkt - 1) / numpkt;
659 int pktdata = pktsize - TS_HEADER_MIN;
660 for (i = 0; i < cnt; i++) {
661 int size, numpkt, overhead;
668 numpkt = (size + pktdata - 1) / pktdata;
669 overhead = (pktsize * numpkt - size + numpkt - 1) / numpkt;
673 return pktsize - max;
678 uint64_t video_delay, uint64_t audio_delay,
int fd,
777 for (mx->
extcnt = 0, data_rate = 0, i = 0;
778 i < N_AUDIO && exttype[i]; i++){
780 LOG(VB_GENERAL, LOG_ERR,
"Found illegal stream type %d",
816 data_rate += seq_head->
bit_rate *400;
823 LOG(VB_GENERAL, LOG_WARNING,
824 "data rate may be to high for required mux rate");
827 LOG(VB_GENERAL, LOG_INFO,
"Mux rate: %.2f Mbit/s",
828 mx->
muxr*8.0/1000000.0);
830 mx->
SCRinc = 27000000ULL/((uint64_t)mx->
muxr /
840 for (i=0; i < mx->
extcnt; i++)
856 uint8_t outbuf[2048];
862 uint8_t outbuf[2048];