38 unsigned int slots [4] = {12, 144, 0, 0};
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}};
44 uint32_t
freq[4] = {441, 480, 320, 0};
45 static uint64_t
samples[4] = { 384, 1152, 1152, 1536};
46 const char *
frames[3] = {
"I-Frame",
"P-Frame",
"B-Frame"};
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 uint8_t
ac3half[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
74 if (c)
LOG(VB_GENERAL, LOG_INFO,
"fix audio frames %d", c);
81 int64_t newdts = 0, newpts = 0;
86 newdts = ( (fcount-1) *
SEC_PER + *pts);
87 newpts = ((fnum ) *
SEC_PER + *pts);
89 uint64_t extra_time = 0;
91 LOG(VB_GENERAL, LOG_INFO,
"pulldown %d %d",
92 (
int)fcount-1, fnum-1);
100 newdts = (fcount - 1) * 5ULL *
SEC_PER / 4ULL +
101 ((fcount - 1)%2)*extra_time +
108 (fnum -1) * 5ULL *
SEC_PER / 4ULL +
109 ((fnum - 1)%2)*extra_time +
120 uint64_t origdts, uint64_t dts)
134 if (!psig) pdiff = -pdiff;
135 if (!dsig) ddiff = -ddiff;
145 if (!psig) fr = -(int)pframe;
146 else fr = (int)pframe;
147 if (!dsig) fr -= (int)dframe;
148 else fr += (int)dframe;
149 *frame = *frame + fr/2;
150 if (fr/2)
LOG(VB_GENERAL, LOG_INFO,
"fixed video frame %d", (
int)fr/2);
160 h = (uint8_t)(pts/90000)/3600;
161 m = (uint8_t)((pts/90000)%3600)/60;
162 s = (uint8_t)((pts/90000)%3600)%60;
165 if (buf[c] == 0x00 && buf[c+1] == 0x00 && buf[c+2] == 0x01 &&
168 buf[c+4] |= (h & 0x1F) << 2;
169 buf[c+4] |= (m & 0x30) >> 4;
172 buf[c+5] |= (m & 0x0F) << 4;
173 buf[c+5] |= (s & 0x38) >> 3;
176 buf[c+6] |= (s & 0x07) << 5;
181 LOG(VB_GENERAL, LOG_INFO,
"fixed time");
182 LOG(VB_GENERAL, LOG_INFO,
"%02d:%02d:%02d",
183 (
int)((buf[c]>>2)& 0x1F),
184 (
int)(((buf[c]<<4)& 0x30)|((buf[c+1]>>4)& 0x0F)),
185 (
int)(((buf[c+1]<<3)& 0x38)|((buf[c+2]>>5)& 0x07)));
212 if (
ring_peek(rbuf, buf, 150, off) < 0)
return -2;
214 s->
h_size = ((headr[1] &0xF0) >> 4) | (headr[0] << 4);
215 s->
v_size = ((headr[1] &0x0F) << 8) | (headr[2]);
217 sw = (int)((headr[3]&0xF0) >> 4) ;
222 LOG(VB_GENERAL, LOG_INFO,
"Video: aspect ratio: 1:1");
226 LOG(VB_GENERAL, LOG_INFO,
"Video: aspect ratio: 4:3");
230 LOG(VB_GENERAL, LOG_INFO,
"Video: aspect ratio: 16:9");
234 LOG(VB_GENERAL, LOG_INFO,
235 "Video: aspect ratio: 2.21:1");
240 LOG(VB_GENERAL, LOG_INFO,
241 "Video: aspect ratio: reserved");
252 LOG(VB_GENERAL, LOG_DEBUG,
" size = %dx%d",
255 sw = (int)(headr[3]&0x0F);
288 LOG(VB_GENERAL, LOG_DEBUG,
" frame rate: %2.3f fps",
291 s->
bit_rate = (((headr[4] << 10) & 0x0003FC00UL)
292 | ((headr[5] << 2) & 0x000003FCUL) |
293 (((headr[6] & 0xC0) >> 6) & 0x00000003UL));
296 LOG(VB_GENERAL, LOG_DEBUG,
" bit rate: %.2f Mbit/s",
303 s->
vbv_buffer_size = (( headr[7] & 0xF8) >> 3 ) | (( headr[6] & 0x1F )<< 5);
304 s->
flags = ( headr[7] & 0x06);
306 LOG(VB_GENERAL, LOG_DEBUG,
" vbvbuffer %d",
311 s->
flags = ( headr[7] & 0x07);
313 s->
flags |= headr[c+63] & 0x01;
317 (( headr[c-1+i] & 0x01) << 7);
367 if (
b == b1) found = 1;
375 }
else if (
b != b1) found = 0;
379 if (found)
return -2;
416 if (
b == b1) found = 1;
422 }
else if (
b != b1) found = 0;
426 if (found)
return -2;
442 LOG(VB_GENERAL, LOG_ERR,
"Incomplete audio header");
445 LOG(VB_GENERAL, LOG_ERR,
"Error in audio header");
451 if ( af->
layer != ((headr[1] & 0x06) >> 1) ){
452 if ( headr[1] == 0xff){
456 LOG(VB_GENERAL, LOG_ERR,
"Wrong audio layer");
464 LOG(VB_GENERAL, LOG_ERR,
"Wrong audio bit rate");
471 frame = (headr[4]&0x3F);
474 LOG(VB_GENERAL, LOG_ERR,
"Wrong audio bit rate");
479 fr = (headr[4] & 0xc0) >> 6;
482 LOG(VB_GENERAL, LOG_ERR,
"Wrong audio frequency");
506 af->
layer = (headr[1] & 0x06) >> 1;
509 LOG(VB_GENERAL, LOG_DEBUG,
"Audiostream: layer: %d",
517 LOG(VB_GENERAL, LOG_DEBUG,
" Bit rate: free");
519 LOG(VB_GENERAL, LOG_DEBUG,
" BRate: reserved");
521 LOG(VB_GENERAL, LOG_DEBUG,
" BRate: %d kb/s",
525 fr = (headr[2] & 0x0c ) >> 2;
530 LOG(VB_GENERAL, LOG_DEBUG,
" Freq: reserved");
532 LOG(VB_GENERAL, LOG_DEBUG,
" Freq: %2.1f kHz",
540 LOG(VB_GENERAL, LOG_INFO,
" frame size: %d", af->
framesize);
565 LOG(VB_GENERAL, LOG_DEBUG,
"AC3 stream:");
566 frame = (headr[4]&0x3F);
570 LOG(VB_GENERAL, LOG_DEBUG,
" bit rate: %d kb/s",
572 fr = (headr[4] & 0xc0) >> 6;
576 LOG(VB_GENERAL, LOG_DEBUG,
" freq: %d Hz", af->
frequency);
578 switch (headr[4] & 0xc0) {
593 LOG(VB_GENERAL, LOG_DEBUG,
" frame size %d", af->
framesize);
613 LOG(VB_GENERAL, LOG_ERR,
"Error in find_mpg_header");
617 if (
ring_peek(rbuf, buf, 5, off) < 0)
return -2;
620 ext_id = (headr[0]&0xF0) >> 4;
632 if (
ring_peek(rbuf, buf, 10, off) < 0)
return -2;
636 LOG(VB_GENERAL, LOG_DEBUG,
"Sequence Extension:");
637 s->
profile = ((headr[0]&0x0F) << 4) | ((headr[1]&0xF0) >> 4);
640 s->
chroma = (headr[1]&0x06)>>1;
644 LOG(VB_GENERAL, LOG_DEBUG,
" chroma reserved ");
647 LOG(VB_GENERAL, LOG_DEBUG,
" chroma 4:2:0 ");
650 LOG(VB_GENERAL, LOG_DEBUG,
" chroma 4:2:2 ");
653 LOG(VB_GENERAL, LOG_DEBUG,
" chroma 4:4:4 ");
658 hsize = ((headr[1]&0x01)<<12) | ((headr[2]&0x80)<<6);
659 vsize = ((headr[2]&0x60)<<7);
663 LOG(VB_GENERAL, LOG_DEBUG,
" size = %dx%d",
666 bitrate = ((headr[2]& 0x1F) << 25) | (( headr[3] & 0xFE ) << 17);
670 LOG(VB_GENERAL, LOG_DEBUG,
" bit rate: %.2f Mbit/s",
674 vbvb = (headr[4]<<10);
677 LOG(VB_GENERAL, LOG_DEBUG,
" vbvbuffer %d",
679 fr_n = (headr[5] & 0x60) >> 6;
680 fr_d = (headr[5] & 0x1F);
684 LOG(VB_GENERAL, LOG_DEBUG,
" frame rate: %2.3f",
697 if (
ring_peek(rbuf, buf, 10, off) < 0)
return -2;
700 if ( (headr[2]&0x03) != 0x03 )
break;
701 if ( (headr[3]&0x02) ) pulldown = 1;
713 LOG(VB_GENERAL, LOG_DEBUG,
714 "Picture Coding Extension: " 715 "3:2 pulldown detected");
718 LOG(VB_GENERAL, LOG_DEBUG,
719 "Picture Coding Extension: " 720 "2:3 pulldown detected");
724 LOG(VB_GENERAL, INFO_DEBUG,
725 " no pulldown detected");
#define EXTENSION_START_CODE
int get_video_ext_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
int64_t ptsdiff(uint64_t pts1, uint64_t pts2)
static uint64_t samples[4]
uint64_t next_ptsdts_video(uint64_t *pts, sequence_t *s, uint64_t fcount, uint64_t gcount)
#define SEQUENCE_EXTENSION
int get_ac3_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
uint64_t add_pts_audio(uint64_t pts, audio_frame_t *aframe, uint64_t frames)
void printpts(int64_t pts)
#define QUANT_MATRIX_EXTENSION
static uint8_t ac3half[12]
unsigned int ac3_bitrates[32]
int check_audio_header(ringbuffer *rbuf, audio_frame_t *af, int off, int le, int type)
int get_audio_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
int mring_peek(ringbuffer *rbuf, uint8_t *buf, unsigned int l, uint32_t off)
void pts2time(uint64_t pts, uint8_t *buf, int len)
int ring_find_mpg_header(ringbuffer *rbuf, uint8_t head, int off, int le)
#define PICTURE_DISPLAY_EXTENSION
int find_audio_s(uint8_t *rbuf, int off, int type, int le)
int ring_peek(ringbuffer *rbuf, uint8_t *data, unsigned int count, uint32_t off)
#define SEQUENCE_HDR_CODE
#define LOG(_MASK_, _LEVEL_, _STRING_)
void fix_video_count(sequence_t *s, uint64_t *frame, uint64_t origpts, uint64_t pts, uint64_t origdts, uint64_t dts)
unsigned int bitrates[3][16]
uint8_t non_intra_quant[64]
#define PICTURE_CODING_EXTENSION
int find_audio_sync(ringbuffer *rbuf, uint8_t *buf, int off, int type, int le)
int get_video_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
void fix_audio_count(uint64_t *acount, audio_frame_t *aframe, uint64_t origpts, uint64_t pts)
#define SEQUENCE_DISPLAY_EXTENSION