Go to the documentation of this file.
15 for (
int i=0; i<mx->
extcnt;i++) {
20 if (aavail+vavail)
return ((aavail+vavail));
26 for (
int i=0; i < n; i++)
36 for (
int i=0; i < n; i++) {
42 }
else if(
ptscmp(tmppts, ext[i].
pts) > 0) {
57 LOG(VB_GENERAL, LOG_ERR,
58 "error in peek next video unit");
65 LOG(VB_GENERAL, LOG_DEBUG,
66 QString(
"video index start: %1 stop: %2 (%3) rpos: %4\n")
67 .arg(viu->start).arg(viu->start+viu->length)
81 LOG(VB_GENERAL, LOG_ERR,
82 "error in get next video unit");
89 LOG(VB_GENERAL, LOG_INFO,
90 QString(
"video index start: %1 stop: %2 (%3) rpos: %4\n")
91 .arg(viu->start).arg(viu->start+viu->length)
97 viu->ptsrate = (
uptsdiff(nviu.dts, viu->dts) << 8) / viu->length;
107 LOG(VB_GENERAL, LOG_ERR,
108 "error in peek next video unit");
116 LOG(VB_GENERAL, LOG_DEBUG,
117 QString(
"ext index start: %1 stop: %2 (%3) rpos: %4")
118 .arg(extiu->start).arg(extiu->start+extiu->length)
131 for(j = 0; j < mx->
ext[i].frmperpkt; j++) {
137 LOG(VB_GENERAL, LOG_ERR,
138 "error in get next ext unit");
145 length += piu->length;
158 LOG(VB_GENERAL, LOG_DEBUG,
159 QString(
"ext index start: %1 stop: %2 (%3) rpos: %4")
187 std::array<uint8_t,3000> outbuf {};
194 LOG(VB_GENERAL, LOG_DEBUG,
"writing VIDEO pack");
210 mx->
SCR, mx->
muxr, outbuf.data());
217 LOG(VB_GENERAL, LOG_DEBUG,
" with sequence and gop header");
224 unsigned int length = viu->
length;
225 while (!mx->
is_ts && length < mx->data_size){
228 int old_frame = viu->
frame;
229 uint64_t old_pts = viu->
pts;
230 uint64_t old_dts = viu->
dts;
234 if (!nviu.seq_header || !nviu.gop ||
242 viu->
frame = old_frame;
257 std::vector<uint8_t> gop(8);
258 frame_len=length-frame_len;
268 LOG(VB_GENERAL, LOG_DEBUG,
269 QString(
"EXTRACLOCK2: %1 %2 %3")
271 LOG(VB_GENERAL, LOG_DEBUG, QString(
"EXTRACLOCK2: %1")
282 int nlength = length;
286 mx->
SCR, outbuf.data(), &nlength,
292 mx->
SCR, mx->
muxr, outbuf.data(), &nlength,
308 if (
write(mx->
fd_out, outbuf.data(), written) != written) {
311 if (mx->
error < 10) {
312 LOG(VB_GENERAL, LOG_ERR,
313 QString(
"%1 writes failed: %2")
314 .arg(mx->
error).arg(strerror(errno)));
319 LOG(VB_GENERAL, LOG_DEBUG,
"VPTS");
321 LOG(VB_GENERAL, LOG_DEBUG,
" DTS");
334 std::array<uint8_t,3000> outbuf {};
345 uint64_t adelay = mx->
ext[n].pts_off;
346 uint64_t *apts = &mx->
ext[n].pts;
353 LOG(VB_GENERAL, LOG_DEBUG, QString(
"writing AUDIO%1 pack\n").arg(n));
359 LOG(VB_GENERAL, LOG_DEBUG, QString(
"writing AC3%1 pack\n").arg(n));
374 unsigned int length = aiu->
length;
375 if (length < aiu->framesize){
382 LOG(VB_GENERAL, LOG_DEBUG, QString(
"start: %1 stop: %2 (%3) length %4")
384 .arg(aiu->
length).arg(length));
391 while (!mx->
is_ts && length < mx->data_size + rest_data){
400 length+= aiu->length;
401 if (length < mx->data_size + rest_data)
407 LOG(VB_GENERAL, LOG_DEBUG,
408 QString(
"start: %1 stop: %2 (%3) length %4")
409 .arg(aiu->start).arg(aiu->start+aiu->length)
410 .arg(aiu->length).arg(length));
419 LOG(VB_GENERAL, LOG_ERR,
"error in writeout ext");
424 int nlength = length;
430 outbuf.data(), &nlength, newpts ? 0 :
PTS_ONLY,
442 outbuf.data(), &nlength, newpts ? 0 :
PTS_ONLY,
474 if ((int64_t)*apts < 0)
475 LOG(VB_GENERAL, LOG_DEBUG,
"SCHEISS APTS");
483 LOG(VB_GENERAL, LOG_ERR,
"error in writeout ext");
490 std::array<uint8_t,3000> outbuf {};
492 LOG(VB_GENERAL, LOG_INFO,
"writing PADDING pack");
496 mx->
muxr, outbuf.data());
508 LOG(VB_GENERAL, LOG_ERR,
"error in get next video unit");
522 LOG(VB_GENERAL, LOG_DEBUG,
538 for (
int i=0; i<mx->
extcnt; i++){
540 mx->
ext[i].iu.pts) > 0) {
543 mx->
ext[i].iu.pts) > 0)
549 if (temp_scr > 0.0) {
561 for (
int i=0;i <mx->
extcnt; i++)
571 for (
int i = 0; i < mx->
extcnt; i++){
573 mx->
ext[i].iu.length > 0 &&
582 LOG(VB_GENERAL, LOG_DEBUG,
"SCR");
584 LOG(VB_GENERAL, LOG_DEBUG,
"VDTS");
586 LOG(VB_GENERAL, LOG_DEBUG, QString(
" (%1) EXT").arg(*video_ok));
587 for (
int i = 0; i < mx->
extcnt; i++){
588 LOG(VB_GENERAL, LOG_DEBUG,
589 QString(
"%1:").arg(mx->
ext[i].type));
591 LOG(VB_GENERAL, LOG_DEBUG,
592 QString(
" (%1)").arg(ext_ok[i]));
612 if (!done && !mx->
VBR){
625 std::array<uint8_t,4> mpeg_end { 0x00, 0x00, 0x01, 0xB9 };
651 for (
int i = 0; i < mx->
extcnt; i++){
667 LOG(VB_GENERAL, LOG_ERR,
668 QString(
"close failed: %1")
669 .arg(strerror(errno)));
673 for (
int i=0; i<mx->
extcnt;i++)
682 uint32_t numpkt = (framesize +
PES_H_MIN + 10 + pktdata -1) / pktdata;
683 return pktsize - (((pktsize * numpkt) - framesize + numpkt - 1) / numpkt);
691 for (
int i = 0; i < cnt; i++) {
698 int numpkt = (size + pktdata - 1) / pktdata;
699 int overhead = (pktsize * numpkt - size + numpkt - 1) / numpkt;
700 max = std::max(overhead, max);
702 return pktsize - max;
707 uint64_t video_delay, uint64_t audio_delay,
int fd,
714 uint32_t data_rate = 0;
807 for (mx->
extcnt = 0, data_rate = 0, i = 0;
808 i <
N_AUDIO && exttype[i]; i++){
810 LOG(VB_GENERAL, LOG_ERR,
811 QString(
"Found illegal stream type %1").arg(exttype[i]));
814 mx->
ext[i].type = exttype[i];
815 mx->
ext[i].pts_off = 0;
816 mx->
ext[i].frmperpkt = 1;
817 mx->
ext[i].strmnum = exttypcnt[i];
818 strncpy(mx->
ext[i].language, extframe[i].
language, 4);
846 data_rate += seq_head->
bit_rate *400;
853 LOG(VB_GENERAL, LOG_WARNING,
854 "data rate may be to high for required mux rate");
857 LOG(VB_GENERAL, LOG_INFO, QString(
"Mux rate: %1 Mbit/s")
858 .arg(mx->
muxr*8.0/1000000.0, 0,
'f',2,QChar(
'0')));
860 mx->
SCRinc = 27000000ULL/((uint64_t)mx->
muxr /
868 for (
int i=0; i < mx->
extcnt; i++)
877 mx->
ext[i].iu.pts, mx->
ext[i].pts_off);
885 std::array<uint8_t,2048> outbuf {};
891 std::array<uint8_t,2048> outbuf {};
893 mx->
SCR, mx->
muxr, outbuf.data());
void pts2time(uint64_t pts, uint8_t *buf, int len)
static int get_ts_video_overhead(int pktsize, sequence_t *seq)
static int get_next_ext_unit(multiplex_t *mx, index_unit *extiu, int i)
int write_out_packs(multiplex_t *mx, int video_ok, aok_arr &ext_ok)
static int peek_next_video_unit(multiplex_t *mx, index_unit *viu)
int dummy_init(dummy_buffer *dbuf, int s)
static uint8_t get_ptsdts(multiplex_t *mx, index_unit *viu)
static int fill_buffers(void *r, int finish)
int ring_peek(ringbuffer *rbuf, uint8_t *data, unsigned int count, uint32_t off)
int dummy_delete(dummy_buffer *dbuf, uint64_t time)
uint32_t audio_buffer_size
static void writeout_video(multiplex_t *mx)
def write(text, progress=True)
void write_ts_patpmt(extdata_t *ext, int extcnt, uint8_t prog_num, uint8_t *buf)
int write_video_pes(int pack_size, int extcnt, uint64_t vpts, uint64_t vdts, uint64_t SCR, uint64_t muxr, uint8_t *buf, int *vlength, uint8_t ptsdts, ringbuffer *vrbuffer)
static void ptsinc(uint64_t *pts1, uint64_t pts2)
void printpts(int64_t pts)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void init_multiplex(multiplex_t *mx, sequence_t *seq_head, audio_frame_t *extframe, int *exttype, const int *exttypcnt, uint64_t video_delay, uint64_t audio_delay, int fd, int(*fill_buffers)(void *p, int f), ringbuffer *vrbuffer, ringbuffer *index_vrbuffer, ringbuffer *extrbuffer, ringbuffer *index_extrbuffer, int otype)
std::array< extdata_t, N_AUDIO > ext_arr
int64_t ptsdiff(uint64_t pts1, uint64_t pts2)
static void writeout_ext(multiplex_t *mx, int n)
int write_ac3_pes(int pack_size, int extcnt, int n, uint64_t pts, uint64_t SCR, uint32_t muxr, uint8_t *buf, int *alength, uint8_t ptsdts, int nframes, int ac3_off, ringbuffer *ac3rbuffer)
ringbuffer * index_extrbuffer
static int peek_next_ext_unit(multiplex_t *mx, index_unit *extiu, int i)
void dummy_destroy(dummy_buffer *dbuf)
ringbuffer * index_vrbuffer
int dummy_add(dummy_buffer *dbuf, uint64_t time, uint32_t size)
void check_times(multiplex_t *mx, int *video_ok, aok_arr &ext_ok, int *start)
static int get_next_video_unit(multiplex_t *mx, index_unit *viu)
int finish_mpg(multiplex_t *mx)
static int which_ext(ext_arr &ext, const aok_arr &aok, int n)
static int ring_rpos(ringbuffer *rbuf)
static void writeout_padding(multiplex_t *mx)
uint64_t uptsdiff(uint64_t pts1, uint64_t pts2)
int ring_read(ringbuffer *rbuf, uint8_t *data, int count)
void write_padding_pes(int pack_size, int extcnt, uint64_t SCR, uint64_t muxr, uint8_t *buf)
int write_nav_pack(int pack_size, int extcnt, uint64_t SCR, uint32_t muxr, uint8_t *buf)
static int use_video(uint64_t vpts, ext_arr &ext, const aok_arr &aok, int n)
static unsigned int ring_avail(ringbuffer *rbuf)
int(* fill_buffers)(void *p, int f)
int write_audio_ts(int n, uint64_t pts, uint8_t *buf, int *alength, uint8_t ptsdts, ringbuffer *arbuffer)
static uint32_t dummy_space(dummy_buffer *dbuf)
std::chrono::duration< CHRONO_TYPE, std::ratio< 1, 90000 > > pts
static int get_ts_ext_overhead(int pktsize, audio_frame_t *extframe, extdata_t *ext, int cnt)
void setup_multiplex(multiplex_t *mx)
uint32_t video_buffer_size
int write_audio_pes(int pack_size, int extcnt, int n, uint64_t pts, uint64_t SCR, uint32_t muxr, uint8_t *buf, int *alength, uint8_t ptsdts, ringbuffer *arbuffer)
int ptscmp(uint64_t pts1, uint64_t pts2)
int ring_poke(ringbuffer *rbuf, uint8_t *data, unsigned int count, uint32_t off)
static const iso6937table * d
int write_video_ts(uint64_t vpts, uint64_t vdts, uint64_t SCR, uint8_t *buf, int *vlength, uint8_t ptsdts, ringbuffer *vrbuffer)
int write_ac3_ts(int n, uint64_t pts, uint8_t *buf, int *alength, uint8_t ptsdts, int nframes, ringbuffer *ac3rbuffer)
static int buffers_filled(multiplex_t *mx)
std::array< bool, N_AUDIO > aok_arr