39std::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}
45static const std::array<const uint32_t,4>
freq {441, 480, 320, 0};
46static 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};
51static const std::array<const uint8_t,12>
ac3half {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
52static 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')));
199 std::vector<uint8_t> buf;
210 uint8_t *headr = buf.data()+4;
211 if (
ring_peek(rbuf, buf, off) < 0)
return -2;
213 s->
h_size = ((headr[1] &0xF0) >> 4) | (headr[0] << 4);
214 s->
v_size = ((headr[1] &0x0F) << 8) | (headr[2]);
216 int sw = ((headr[3]&0xF0) >> 4) ;
221 LOG(VB_GENERAL, LOG_INFO,
"Video: aspect ratio: 1:1");
225 LOG(VB_GENERAL, LOG_INFO,
"Video: aspect ratio: 4:3");
229 LOG(VB_GENERAL, LOG_INFO,
"Video: aspect ratio: 16:9");
233 LOG(VB_GENERAL, LOG_INFO,
234 "Video: aspect ratio: 2.21:1");
239 LOG(VB_GENERAL, LOG_INFO,
240 "Video: aspect ratio: reserved");
251 LOG(VB_GENERAL, LOG_DEBUG,
252 QString(
" size = %1x%2").arg(s->
h_size).arg(s->
v_size));
254 sw = (int)(headr[3]&0x0F);
287 LOG(VB_GENERAL, LOG_DEBUG, QString(
" frame rate: %1 fps")
288 .arg(s->
frame_rate/1000.0, 2,
'f',3,QChar(
'0')));
290 s->
bit_rate = (((headr[4] << 10) & 0x0003FC00UL)
291 | ((headr[5] << 2) & 0x000003FCUL) |
292 (((headr[6] & 0xC0) >> 6) & 0x00000003UL));
295 LOG(VB_GENERAL, LOG_DEBUG, QString(
" bit rate: %1 Mbit/s")
296 .arg(400*(s->
bit_rate)/1000000.0, 0,
'f',2,QChar(
'0')));
302 s->
vbv_buffer_size = (( headr[7] & 0xF8) >> 3 ) | (( headr[6] & 0x1F )<< 5);
303 s->
flags = ( headr[7] & 0x06);
305 LOG(VB_GENERAL, LOG_DEBUG, QString(
" vbvbuffer %1")
310 s->
flags = ( headr[7] & 0x07);
312 s->
flags |= headr[c+63] & 0x01;
314 for (
int i=0;i<64;i++)
316 (( headr[c-1+i] & 0x01) << 7);
363 if ( b == b1) found = 1;
368 if (
mring_peek(rbuf, buf.data(), l, c-1) < -1)
371 }
else if ( b != b1) {
377 if (found)
return -2;
409 if ( b == b1) found = 1;
415 }
else if ( b != b1) {
421 if (found)
return -2;
436 LOG(VB_GENERAL, LOG_ERR,
"Incomplete audio header");
439 LOG(VB_GENERAL, LOG_ERR,
"Error in audio header");
445 if ( af->
layer != ((headr[1] & 0x06) >> 1) ){
446 if ( headr[1] == 0xff){
450 LOG(VB_GENERAL, LOG_ERR,
"Wrong audio layer");
457 LOG(VB_GENERAL, LOG_ERR,
"Wrong audio bit rate");
464 frame = (headr[4]&0x3F);
467 LOG(VB_GENERAL, LOG_ERR,
"Wrong audio bit rate");
472 fr = (headr[4] & 0xc0) >> 6;
475 LOG(VB_GENERAL, LOG_ERR,
"Wrong audio frequency");
499 af->
layer = (headr[1] & 0x06) >> 1;
502 LOG(VB_GENERAL, LOG_DEBUG, QString(
"Audiostream: layer: %1")
510 LOG(VB_GENERAL, LOG_DEBUG,
" Bit rate: free");
512 LOG(VB_GENERAL, LOG_DEBUG,
" BRate: reserved");
514 LOG(VB_GENERAL, LOG_DEBUG, QString(
" BRate: %1 kb/s")
518 fr = (headr[2] & 0x0c ) >> 2;
523 LOG(VB_GENERAL, LOG_DEBUG,
" Freq: reserved");
525 LOG(VB_GENERAL, LOG_DEBUG, QString(
" Freq: %1 kHz")
526 .arg(af->
frequency/1000.0, 2,
'f',1,QChar(
'0')));
533 LOG(VB_GENERAL, LOG_INFO, QString(
" frame size: %1").arg(af->
framesize));
554 LOG(VB_GENERAL, LOG_DEBUG,
"AC3 stream:");
555 uint8_t frame = (headr[4]&0x3F);
557 int half =
ac3half[headr[5] >> 3];
559 LOG(VB_GENERAL, LOG_DEBUG, QString(
" bit rate: %1 kb/s")
561 int fr = (headr[4] & 0xc0) >> 6;
565 LOG(VB_GENERAL, LOG_DEBUG,
566 QString(
" freq: %1 Hz").arg(af->
frequency));
568 switch (headr[4] & 0xc0) {
583 LOG(VB_GENERAL, LOG_DEBUG,
584 QString(
" frame size %1").arg(af->
framesize));
598 std::vector<uint8_t> buf;
603 LOG(VB_GENERAL, LOG_ERR,
"Error in find_mpg_header");
607 if (
ring_peek(rbuf, buf, 5, off) < 0)
return -2;
608 uint8_t *headr=buf.data()+4;
610 uint8_t ext_id = (headr[0]&0xF0) >> 4;
615 if (
ring_peek(rbuf, buf, 10, off) < 0)
return -2;
619 LOG(VB_GENERAL, LOG_DEBUG,
"Sequence Extension:");
620 s->
profile = ((headr[0]&0x0F) << 4) | ((headr[1]&0xF0) >> 4);
623 s->
chroma = (headr[1]&0x06)>>1;
627 LOG(VB_GENERAL, LOG_DEBUG,
" chroma reserved ");
630 LOG(VB_GENERAL, LOG_DEBUG,
" chroma 4:2:0 ");
633 LOG(VB_GENERAL, LOG_DEBUG,
" chroma 4:2:2 ");
636 LOG(VB_GENERAL, LOG_DEBUG,
" chroma 4:4:4 ");
641 uint16_t hsize = ((headr[1]&0x01)<<12) | ((headr[2]&0x80)<<6);
642 uint16_t vsize = ((headr[2]&0x60)<<7);
646 LOG(VB_GENERAL, LOG_DEBUG, QString(
" size = %1x%2")
649 uint32_t bitrate = ((headr[2]& 0x1F) << 25) | (( headr[3] & 0xFE ) << 17);
653 LOG(VB_GENERAL, LOG_DEBUG, QString(
" bit rate: %1 Mbit/s")
654 .arg(400.0*(s->
bit_rate)/1000000.0, 0,
'f',2,QChar(
'0')));
657 uint32_t vbvb = (headr[4]<<10);
660 LOG(VB_GENERAL, LOG_DEBUG, QString(
" vbvbuffer %1")
662 uint8_t fr_n = (headr[5] & 0x60) >> 6;
663 uint8_t fr_d = (headr[5] & 0x1F);
667 LOG(VB_GENERAL, LOG_DEBUG, QString(
" frame rate: %1")
668 .arg(s->
frame_rate/1000.0, 2,
'f',3,QChar(
'0')));
680 if (
ring_peek(rbuf, buf, 10, off) < 0)
return -2;
683 if ( (headr[2]&0x03) != 0x03 )
break;
684 if ( (headr[3]&0x02) ) pulldown = 1;
696 LOG(VB_GENERAL, LOG_DEBUG,
697 "Picture Coding Extension: "
698 "3:2 pulldown detected");
701 LOG(VB_GENERAL, LOG_DEBUG,
702 "Picture Coding Extension: "
703 "2:3 pulldown detected");
707 LOG(VB_GENERAL, INFO_DEBUG,
708 " no pulldown detected");
int get_audio_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
static const std::array< const uint32_t, 4 > freq
uint64_t add_pts_audio(uint64_t pts, audio_frame_t *aframe, uint64_t frames)
static const std::array< const uint16_t, 32 > ac3_bitrates
int find_audio_sync(ringbuffer *rbuf, audio_sync_buf &buf, int off, int type, int le)
void fix_audio_count(uint64_t *acount, audio_frame_t *aframe, uint64_t origpts, uint64_t pts)
int get_ac3_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
int find_audio_s(const uint8_t *rbuf, int off, int type, int le)
uint64_t next_ptsdts_video(uint64_t *pts, sequence_t *s, uint64_t fcount, uint64_t gcount)
static const std::array< const uint32_t, 4 > ac3_freq
int get_video_ext_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
static const std::array< const uint8_t, 12 > ac3half
int get_video_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
void pts2time(uint64_t pts, uint8_t *buf, int len)
int check_audio_header(ringbuffer *rbuf, audio_frame_t *af, int off, int le, int type)
std::array< std::array< unsigned int, 16 >, 3 > bitrates
std::array< unsigned int, 4 > slotsPerLayer
static const std::array< const uint64_t, 4 > samples
void fix_video_count(sequence_t *s, uint64_t *frame, uint64_t origpts, uint64_t pts, uint64_t origdts, uint64_t dts)
#define SEQUENCE_DISPLAY_EXTENSION
#define SEQUENCE_EXTENSION
#define PICTURE_CODING_EXTENSION
#define EXTENSION_START_CODE
std::array< uint8_t, 7 > audio_sync_buf
#define QUANT_MATRIX_EXTENSION
#define PICTURE_DISPLAY_EXTENSION
#define SEQUENCE_HDR_CODE
int mring_peek(ringbuffer *rbuf, uint8_t *buf, unsigned int l, uint32_t off)
int ring_find_mpg_header(ringbuffer *rbuf, uint8_t head, int off, int le)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
std::chrono::duration< CHRONO_TYPE, std::ratio< 1, 90000 > > pts
void printpts(int64_t pts)
int64_t ptsdiff(uint64_t pts1, uint64_t pts2)
int ring_peek(ringbuffer *rbuf, uint8_t *data, unsigned int count, uint32_t off)
uint8_t non_intra_quant[64]