39 std::array<std::array<unsigned int,16>,3>
bitrates {{
40 {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,0},
41 {0,32,48,56,64,80,96,112,128,160,192,224,256,320,384,0},
42 {0,32,40,48,56,64,80,96,112,128,160,192,224,256,320,0}
45 static const std::array<const uint32_t,4>
freq {441, 480, 320, 0};
46 static const std::array<const uint64_t,4>
samples {384, 1152, 1152, 1536};
49 {32,40,48,56,64,80,96,112,128,160,192,224,256,320,384,448,512,576,640,
50 0,0,0,0,0,0,0,0,0,0,0,0,0};
51 static const std::array<const uint8_t,12>
ac3half {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
52 static const std::array<const uint32_t,4>
ac3_freq {480, 441, 320, 0};
71 LOG(VB_GENERAL, LOG_INFO, QString(
"fix audio frames %1").arg(c));
87 uint64_t extra_time = 0;
89 LOG(VB_GENERAL, LOG_INFO, QString(
"pulldown %1 %2")
90 .arg(fcount-1).arg(fnum-1));
98 newdts = (fcount - 1) * 5ULL *
SEC_PER / 4ULL +
99 ((fcount - 1)%2)*extra_time +
106 (fnum -1) * 5ULL *
SEC_PER / 4ULL +
107 ((fnum - 1)%2)*extra_time +
118 uint64_t origdts, uint64_t dts)
130 psig =
static_cast<int>(pdiff > 0);
131 dsig =
static_cast<int>(ddiff > 0);
132 if (!psig) pdiff = -pdiff;
133 if (!dsig) ddiff = -ddiff;
143 if (!psig) fr = -(int)pframe;
144 else fr = (int)pframe;
145 if (!dsig) fr -= (int)dframe;
146 else fr += (int)dframe;
147 *frame = *frame + fr/2;
149 LOG(VB_GENERAL, LOG_INFO,
150 QString(
"fixed video frame %1").arg(fr/2));
159 uint8_t h = (uint8_t)(
pts/90000)/3600;
160 uint8_t m = (uint8_t)((
pts/90000)%3600)/60;
161 uint8_t s = (uint8_t)((
pts/90000)%3600)%60;
164 if (buf[c] == 0x00 && buf[c+1] == 0x00 && buf[c+2] == 0x01 &&
167 buf[c+4] |= (h & 0x1F) << 2;
168 buf[c+4] |= (m & 0x30) >> 4;
171 buf[c+5] |= (m & 0x0F) << 4;
172 buf[c+5] |= (s & 0x38) >> 3;
175 buf[c+6] |= (s & 0x07) << 5;
180 LOG(VB_GENERAL, LOG_INFO,
"fixed time");
181 LOG(VB_GENERAL, LOG_INFO, QString(
"%1:%2:%3")
182 .arg((
int)((buf[c]>>2)& 0x1F), 2,10,QChar(
'0'))
183 .arg((
int)(((buf[c]<<4)& 0x30)|((buf[c+1]>>4)& 0x0F)), 2,10,QChar(
'0'))
184 .arg((
int)(((buf[c+1]<<3)& 0x38)|((buf[c+2]>>5)& 0x07)), 2,10,QChar(
'0')));
197 std::vector<uint8_t> buf;
208 uint8_t *headr = buf.data()+4;
209 if (
ring_peek(rbuf, buf, off) < 0)
return -2;
211 s->
h_size = ((headr[1] &0xF0) >> 4) | (headr[0] << 4);
212 s->
v_size = ((headr[1] &0x0F) << 8) | (headr[2]);
214 int sw = (int)((headr[3]&0xF0) >> 4) ;
219 LOG(VB_GENERAL, LOG_INFO,
"Video: aspect ratio: 1:1");
223 LOG(VB_GENERAL, LOG_INFO,
"Video: aspect ratio: 4:3");
227 LOG(VB_GENERAL, LOG_INFO,
"Video: aspect ratio: 16:9");
231 LOG(VB_GENERAL, LOG_INFO,
232 "Video: aspect ratio: 2.21:1");
237 LOG(VB_GENERAL, LOG_INFO,
238 "Video: aspect ratio: reserved");
249 LOG(VB_GENERAL, LOG_DEBUG,
250 QString(
" size = %1x%2").arg(s->
h_size).arg(s->
v_size));
252 sw = (int)(headr[3]&0x0F);
285 LOG(VB_GENERAL, LOG_DEBUG, QString(
" frame rate: %1 fps")
286 .arg(s->
frame_rate/1000.0, 2,
'f',3,QChar(
'0')));
288 s->
bit_rate = (((headr[4] << 10) & 0x0003FC00UL)
289 | ((headr[5] << 2) & 0x000003FCUL) |
290 (((headr[6] & 0xC0) >> 6) & 0x00000003UL));
293 LOG(VB_GENERAL, LOG_DEBUG, QString(
" bit rate: %1 Mbit/s")
294 .arg(400*(s->
bit_rate)/1000000.0, 0,
'f',2,QChar(
'0')));
300 s->
vbv_buffer_size = (( headr[7] & 0xF8) >> 3 ) | (( headr[6] & 0x1F )<< 5);
301 s->
flags = ( headr[7] & 0x06);
303 LOG(VB_GENERAL, LOG_DEBUG, QString(
" vbvbuffer %1")
308 s->
flags = ( headr[7] & 0x07);
310 s->
flags |= headr[c+63] & 0x01;
312 for (
int i=0;i<64;i++)
314 (( headr[c-1+i] & 0x01) << 7);
361 if ( b == b1) found = 1;
366 if (
mring_peek(rbuf, buf.data(), l, c-1) < -1)
369 }
else if ( b != b1) found = 0;
373 if (found)
return -2;
405 if ( b == b1) found = 1;
411 }
else if ( b != b1) found = 0;
415 if (found)
return -2;
431 LOG(VB_GENERAL, LOG_ERR,
"Incomplete audio header");
434 LOG(VB_GENERAL, LOG_ERR,
"Error in audio header");
440 if ( af->
layer != ((headr[1] & 0x06) >> 1) ){
441 if ( headr[1] == 0xff){
445 LOG(VB_GENERAL, LOG_ERR,
"Wrong audio layer");
452 LOG(VB_GENERAL, LOG_ERR,
"Wrong audio bit rate");
459 frame = (headr[4]&0x3F);
462 LOG(VB_GENERAL, LOG_ERR,
"Wrong audio bit rate");
467 fr = (headr[4] & 0xc0) >> 6;
470 LOG(VB_GENERAL, LOG_ERR,
"Wrong audio frequency");
494 af->
layer = (headr[1] & 0x06) >> 1;
497 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Audiostream: layer: %1")
505 LOG(VB_GENERAL, LOG_DEBUG,
" Bit rate: free");
507 LOG(VB_GENERAL, LOG_DEBUG,
" BRate: reserved");
509 LOG(VB_GENERAL, LOG_DEBUG, QString(
" BRate: %1 kb/s")
513 fr = (headr[2] & 0x0c ) >> 2;
518 LOG(VB_GENERAL, LOG_DEBUG,
" Freq: reserved");
520 LOG(VB_GENERAL, LOG_DEBUG, QString(
" Freq: %1 kHz")
521 .arg(af->
frequency/1000.0, 2,
'f',1,QChar(
'0')));
528 LOG(VB_GENERAL, LOG_INFO, QString(
" frame size: %1").arg(af->
framesize));
549 LOG(VB_GENERAL, LOG_DEBUG,
"AC3 stream:");
550 uint8_t frame = (headr[4]&0x3F);
552 int half =
ac3half[headr[5] >> 3];
554 LOG(VB_GENERAL, LOG_DEBUG, QString(
" bit rate: %1 kb/s")
556 int fr = (headr[4] & 0xc0) >> 6;
560 LOG(VB_GENERAL, LOG_DEBUG,
561 QString(
" freq: %1 Hz").arg(af->
frequency));
563 switch (headr[4] & 0xc0) {
578 LOG(VB_GENERAL, LOG_DEBUG,
579 QString(
" frame size %1").arg(af->
framesize));
593 std::vector<uint8_t> buf;
598 LOG(VB_GENERAL, LOG_ERR,
"Error in find_mpg_header");
602 if (
ring_peek(rbuf, buf, 5, off) < 0)
return -2;
603 uint8_t *headr=buf.data()+4;
605 uint8_t ext_id = (headr[0]&0xF0) >> 4;
610 if (
ring_peek(rbuf, buf, 10, off) < 0)
return -2;
614 LOG(VB_GENERAL, LOG_DEBUG,
"Sequence Extension:");
615 s->
profile = ((headr[0]&0x0F) << 4) | ((headr[1]&0xF0) >> 4);
618 s->
chroma = (headr[1]&0x06)>>1;
622 LOG(VB_GENERAL, LOG_DEBUG,
" chroma reserved ");
625 LOG(VB_GENERAL, LOG_DEBUG,
" chroma 4:2:0 ");
628 LOG(VB_GENERAL, LOG_DEBUG,
" chroma 4:2:2 ");
631 LOG(VB_GENERAL, LOG_DEBUG,
" chroma 4:4:4 ");
636 uint16_t hsize = ((headr[1]&0x01)<<12) | ((headr[2]&0x80)<<6);
637 uint16_t vsize = ((headr[2]&0x60)<<7);
641 LOG(VB_GENERAL, LOG_DEBUG, QString(
" size = %1x%2")
644 uint32_t bitrate = ((headr[2]& 0x1F) << 25) | (( headr[3] & 0xFE ) << 17);
648 LOG(VB_GENERAL, LOG_DEBUG, QString(
" bit rate: %1 Mbit/s")
649 .arg(400.0*(s->
bit_rate)/1000000.0, 0,
'f',2,QChar(
'0')));
652 uint32_t vbvb = (headr[4]<<10);
655 LOG(VB_GENERAL, LOG_DEBUG, QString(
" vbvbuffer %1")
657 uint8_t fr_n = (headr[5] & 0x60) >> 6;
658 uint8_t fr_d = (headr[5] & 0x1F);
662 LOG(VB_GENERAL, LOG_DEBUG, QString(
" frame rate: %1")
663 .arg(s->
frame_rate/1000.0, 2,
'f',3,QChar(
'0')));
675 if (
ring_peek(rbuf, buf, 10, off) < 0)
return -2;
678 if ( (headr[2]&0x03) != 0x03 )
break;
679 if ( (headr[3]&0x02) ) pulldown = 1;
691 LOG(VB_GENERAL, LOG_DEBUG,
692 "Picture Coding Extension: "
693 "3:2 pulldown detected");
696 LOG(VB_GENERAL, LOG_DEBUG,
697 "Picture Coding Extension: "
698 "2:3 pulldown detected");
702 LOG(VB_GENERAL, INFO_DEBUG,
703 " no pulldown detected");