MythTV  master
element.cpp
Go to the documentation of this file.
1 /*
2  * element.c: MPEG ELEMENTARY STREAM functions for replex
3  *
4  *
5  * Copyright (C) 2003 Marcus Metzler <mocm@metzlerbros.de>
6  * Metzler Brothers Systementwicklung GbR
7  * Changes to use MythTV logging
8  * Copyright (C) 2011 Gavin Hurlbut <ghurlbut@mythtv.org>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * General Public License for more details.
20  *
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
26  *
27  */
28 
29 #include <cstdio>
30 #include <cstring>
31 
32 #include "element.h"
33 #include "mpg_common.h"
34 #include "pes.h"
35 
36 #include "mythlogging.h"
37 
38 unsigned int slots [4] = {12, 144, 0, 0};
39 unsigned int bitrates[3][16] =
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}};
43 
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"};
47 
48 unsigned int ac3_bitrates[32] =
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};
52 uint32_t ac3_freq[4] = {480, 441, 320, 0};
53 
54 #define DEBUG true
55 
56 uint64_t add_pts_audio(uint64_t pts, audio_frame_t *aframe, uint64_t frames)
57 {
58  int64_t newpts=0;
59 
60  newpts = (pts + (frames *samples [3-aframe->layer] * 27000000ULL)
61  / aframe->frequency);
62  return newpts>0 ? newpts%MAX_PTS2: MAX_PTS2+newpts;
63 }
64 
65 void fix_audio_count(uint64_t *acount, audio_frame_t *aframe, uint64_t origpts, uint64_t pts)
66 {
67  uint64_t di = (samples [3-aframe->layer] * 27000000ULL);
68  int64_t diff = ptsdiff(origpts,pts);
69  int c=(aframe->frequency * diff+di/2)/di;
70  if (c)
71  LOG(VB_GENERAL, LOG_INFO, QString("fix audio frames %1").arg(c));
72  *acount += c;
73 }
74 
75 
76 uint64_t next_ptsdts_video(uint64_t *pts, sequence_t *s, uint64_t fcount, uint64_t gcount)
77 {
78  int64_t newdts = 0;
79  int64_t newpts = 0;
80  int64_t fnum = s->current_tmpref - gcount + fcount;
81 
82 
83  if ( s->pulldown == NOPULLDOWN ) {
84  newdts = ( (fcount-1) * SEC_PER + *pts);
85  newpts = ((fnum ) * SEC_PER + *pts);
86  } else {
87  uint64_t extra_time = 0;
88 #if 0
89  LOG(VB_GENERAL, LOG_INFO, QString("pulldown %1 %2")
90  .arg(fcount-1).arg(fnum-1));
91 #endif
92 
93  if ( s->pulldown == PULLDOWN32)
94  extra_time = SEC_PER;
95  else
96  extra_time = 3*SEC_PER/2;
97 
98  newdts = (fcount - 1) * 5ULL * SEC_PER / 4ULL +
99  ((fcount - 1)%2)*extra_time +
100  *pts;
101 
102  if ((s->pulldown == PULLDOWN23) && (fcount-1))
103  newdts -= SEC_PER/2;
104 
105  newpts = SEC_PER +
106  (fnum -1) * 5ULL * SEC_PER / 4ULL +
107  ((fnum - 1)%2)*extra_time +
108  *pts;
109 
110  }
111 
112 
113  *pts = newpts >= 0 ? newpts%MAX_PTS2: MAX_PTS2+newpts;
114  return newdts >= 0 ? newdts%MAX_PTS2: MAX_PTS2+newdts;
115 }
116 
117 void fix_video_count(sequence_t *s, uint64_t *frame, uint64_t origpts, uint64_t pts,
118  uint64_t origdts, uint64_t dts)
119 {
120  int64_t pdiff = 0;
121  int64_t ddiff = 0;
122  int64_t pframe = 0;
123  int64_t dframe = 0;
124  int psig=0;
125  int dsig=0;
126  int64_t fr=0;
127 
128  pdiff = ptsdiff(origpts,pts);
129  ddiff = ptsdiff(origdts,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;
134 
135  if ( s->pulldown == NOPULLDOWN ) {
136  dframe = (ddiff+SEC_PER/2ULL) / SEC_PER;
137  pframe = (pdiff+SEC_PER/2ULL) / SEC_PER;
138  } else {
139  dframe = (4ULL*ddiff/5ULL+SEC_PER/2ULL) / SEC_PER;
140  pframe = (4ULL*pdiff/5ULL+SEC_PER/2ULL) / SEC_PER;
141  }
142 
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;
148  if (fr/2)
149  LOG(VB_GENERAL, LOG_INFO,
150  QString("fixed video frame %1").arg(fr/2));
151 }
152 
153 
154 void pts2time(uint64_t pts, uint8_t *buf, int len)
155 {
156  int c = 0;
157 
158  pts = (pts/300)%MAX_PTS;
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;
162 
163  while (c+7 < len){
164  if (buf[c] == 0x00 && buf[c+1] == 0x00 && buf[c+2] == 0x01 &&
165  buf[c+3] == GROUP_START_CODE && (buf[c+5] & 0x08)){
166  buf[c+4] &= ~(0x7F);
167  buf[c+4] |= (h & 0x1F) << 2;
168  buf[c+4] |= (m & 0x30) >> 4;
169 
170  buf[c+5] &= ~(0xF7);
171  buf[c+5] |= (m & 0x0F) << 4;
172  buf[c+5] |= (s & 0x38) >> 3;
173 
174  buf[c+6] &= ~(0xE0);
175  buf[c+6] |= (s & 0x07) << 5;
176 
177 /* 1hhhhhmm|mmmm1sss|sss */
178 #if 0
179  c+=4;
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')));
185 #endif
186  c = len;
187 
188 
189  } else c++;
190  }
191 
192 }
193 
194 
195 int get_video_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
196 {
197  uint8_t buf[150];
198  int form = -1;
199  int c = 0;
200 
201  s->set = 0;
202  s->ext_set = 0;
203  s->pulldown_set = 0;
204  int re = ring_find_mpg_header(rbuf, SEQUENCE_HDR_CODE, off, le);
205  if (re < 0)
206  return re;
207  uint8_t *headr = buf+4;
208  if (ring_peek(rbuf, buf, 150, off) < 0) return -2;
209 
210  s->h_size = ((headr[1] &0xF0) >> 4) | (headr[0] << 4);
211  s->v_size = ((headr[1] &0x0F) << 8) | (headr[2]);
212 
213  int sw = (int)((headr[3]&0xF0) >> 4) ;
214 
215  if (DEBUG){
216  switch( sw ){
217  case 1:
218  LOG(VB_GENERAL, LOG_INFO, "Video: aspect ratio: 1:1");
219  s->aspect_ratio = 100;
220  break;
221  case 2:
222  LOG(VB_GENERAL, LOG_INFO, "Video: aspect ratio: 4:3");
223  s->aspect_ratio = 133;
224  break;
225  case 3:
226  LOG(VB_GENERAL, LOG_INFO, "Video: aspect ratio: 16:9");
227  s->aspect_ratio = 177;
228  break;
229  case 4:
230  LOG(VB_GENERAL, LOG_INFO,
231  "Video: aspect ratio: 2.21:1");
232  s->aspect_ratio = 221;
233  break;
234 
235  case 5 ... 15:
236  LOG(VB_GENERAL, LOG_INFO,
237  "Video: aspect ratio: reserved");
238  s->aspect_ratio = 0;
239  break;
240 
241  default:
242  s->aspect_ratio = 0;
243  return -3;
244  }
245  }
246 
247  if (DEBUG)
248  LOG(VB_GENERAL, LOG_DEBUG,
249  QString(" size = %1x%2").arg(s->h_size).arg(s->v_size));
250 
251  sw = (int)(headr[3]&0x0F);
252 
253  switch ( sw ) {
254  case 1:
255  s->frame_rate = 23976;
256  form = -1;
257  break;
258  case 2:
259  s->frame_rate = 24000;
260  form = -1;
261  break;
262  case 3:
263  s->frame_rate = 25000;
264  form = VIDEO_PAL;
265  break;
266  case 4:
267  s->frame_rate = 29970;
268  form = VIDEO_NTSC;
269  break;
270  case 5:
271  s->frame_rate = 30000;
272  form = VIDEO_NTSC;
273  break;
274  case 6:
275  s->frame_rate = 50000;
276  form = VIDEO_PAL;
277  break;
278  case 7:
279  s->frame_rate = 60000;
280  form = VIDEO_NTSC;
281  break;
282  }
283  if (DEBUG)
284  LOG(VB_GENERAL, LOG_DEBUG, QString(" frame rate: %1 fps")
285  .arg(s->frame_rate/1000.0, 2,'f',3,QChar('0')));
286 
287  s->bit_rate = (((headr[4] << 10) & 0x0003FC00UL)
288  | ((headr[5] << 2) & 0x000003FCUL) |
289  (((headr[6] & 0xC0) >> 6) & 0x00000003UL));
290 
291  if (DEBUG)
292  LOG(VB_GENERAL, LOG_DEBUG, QString(" bit rate: %1 Mbit/s")
293  .arg(400*(s->bit_rate)/1000000.0, 0,'f',2,QChar('0')));
294 
295  s->video_format = form;
296 
297 
298 
299  s->vbv_buffer_size = (( headr[7] & 0xF8) >> 3 ) | (( headr[6] & 0x1F )<< 5);
300  s->flags = ( headr[7] & 0x06);
301  if (DEBUG)
302  LOG(VB_GENERAL, LOG_DEBUG, QString(" vbvbuffer %1")
303  .arg(16*1024*(s->vbv_buffer_size)));
304 
305  c += 8;
306  if ( !(s->flags & INTRAQ_FLAG) )
307  s->flags = ( headr[7] & 0x07);
308  else {
309  s->flags |= headr[c+63] & 0x01;
310  memset(s->intra_quant, 0, 64);
311  for (int i=0;i<64;i++)
312  s->intra_quant[i] |= (headr[c+i] >> 1) |
313  (( headr[c-1+i] & 0x01) << 7);
314 
315  c += 64;
316  }
317  if (s->flags & NONINTRAQ_FLAG){
318  memcpy(s->non_intra_quant, headr+c, 64);
319  c += 64;
320  }
321  s->set=1;
322 
323  return c;
324 }
325 
326 int find_audio_sync(ringbuffer *rbuf, uint8_t *buf, int off, int type, int le)
327 {
328  int found = 0;
329  int l=0;
330 
331  memset(buf,0,7);
332  uint8_t b1 = 0x00;
333  uint8_t b2 = 0x00;
334  uint8_t m2 = 0xFF;
335  switch(type){
336  case AC3:
337  b1 = 0x0B;
338  b2 = 0x77;
339  l = 6;
340  break;
341 
342  case MPEG_AUDIO:
343  b1 = 0xFF;
344  b2 = 0xF8;
345  m2 = 0xF8;
346  l = 4;
347  break;
348 
349  default:
350  return -1;
351  }
352 
353  int c = off;
354  while ( c-off < le){
355  uint8_t b = 0;
356  if (mring_peek(rbuf, &b, 1, c) <0) return -1;
357  switch(found){
358 
359  case 0:
360  if ( b == b1) found = 1;
361  break;
362 
363  case 1:
364  if ( (b&m2) == b2){
365  if (mring_peek(rbuf, buf, l, c-1) < -1)
366  return -2;
367  return c-1-off;
368  } else if ( b != b1) found = 0;
369  }
370  c++;
371  }
372  if (found) return -2;
373  return -1;
374 }
375 
376 int find_audio_s(const uint8_t *rbuf, int off, int type, int le)
377 {
378  int found = 0;
379 
380  uint8_t b1 = 0x00;
381  uint8_t b2 = 0x00;
382  uint8_t m2 = 0xFF;
383  switch(type){
384  case AC3:
385  b1 = 0x0B;
386  b2 = 0x77;
387  break;
388 
389  case MPEG_AUDIO:
390  b1 = 0xFF;
391  b2 = 0xF8;
392  m2 = 0xF8;
393  break;
394 
395  default:
396  return -1;
397  }
398 
399  int c = off;
400  while ( c < le){
401  uint8_t b=rbuf[c];
402  switch(found){
403  case 0:
404  if ( b == b1) found = 1;
405  break;
406 
407  case 1:
408  if ( (b&m2) == b2){
409  return c-1;
410  } else if ( b != b1) found = 0;
411  }
412  c++;
413  }
414  if (found) return -2;
415  return -1;
416 }
417 
418 int check_audio_header(ringbuffer *rbuf, audio_frame_t * af, int off, int le,
419  int type)
420 {
421  uint8_t headr[7];
422  uint8_t frame = 0;
423  int fr = 0;
424  int half = 0;
425  int c=0;
426 
427  if ( (c = find_audio_sync(rbuf, headr, off, type, le))
428  != 0 ) {
429  if (c==-2){
430  LOG(VB_GENERAL, LOG_ERR, "Incomplete audio header");
431  return -2;
432  }
433  LOG(VB_GENERAL, LOG_ERR, "Error in audio header");
434  return -1;
435  }
436  switch (type){
437 
438  case MPEG_AUDIO:
439  if ( af->layer != ((headr[1] & 0x06) >> 1) ){
440  if ( headr[1] == 0xff){
441  return -3;
442  }
443 #ifdef IN_DEBUG
444  LOG(VB_GENERAL, LOG_ERR, "Wrong audio layer");
445 #endif
446  return -1;
447  }
448  if ( af->bit_rate !=
449  (bitrates[(3-af->layer)][(headr[2] >> 4 )]*1000)){
450 #ifdef IN_DEBUG
451  LOG(VB_GENERAL, LOG_ERR, "Wrong audio bit rate");
452 #endif
453  return -1;
454  }
455  break;
456 
457  case AC3:
458  frame = (headr[4]&0x3F);
459  if (af->bit_rate != ac3_bitrates[frame>>1]*1000){
460 #ifdef IN_DEBUG
461  LOG(VB_GENERAL, LOG_ERR, "Wrong audio bit rate");
462 #endif
463  return -1;
464  }
465  half = ac3half[headr[5] >> 3];
466  fr = (headr[4] & 0xc0) >> 6;
467  if (af->frequency != ((ac3_freq[fr] *100) >> half)){
468 #ifdef IN_DEBUG
469  LOG(VB_GENERAL, LOG_ERR, "Wrong audio frequency");
470 #endif
471  return -1;
472  }
473 
474  break;
475 
476  }
477 
478  return 0;
479 }
480 
481 
482 int get_audio_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
483 {
484  int c = 0;
485  int fr =0;
486  uint8_t headr[7];
487 
488  af->set=0;
489 
490  if ( (c = find_audio_sync(rbuf, headr, off, MPEG_AUDIO,le)) < 0 )
491  return c;
492 
493  af->layer = (headr[1] & 0x06) >> 1;
494 
495  if (DEBUG)
496  LOG(VB_GENERAL, LOG_DEBUG, QString("Audiostream: layer: %1")
497  .arg(4-af->layer));
498 
499 
500  af->bit_rate = bitrates[(3-af->layer)][(headr[2] >> 4 )]*1000;
501 
502  if (DEBUG){
503  if (af->bit_rate == 0)
504  LOG(VB_GENERAL, LOG_DEBUG, " Bit rate: free");
505  else if (af->bit_rate == 0xf)
506  LOG(VB_GENERAL, LOG_DEBUG, " BRate: reserved");
507  else
508  LOG(VB_GENERAL, LOG_DEBUG, QString(" BRate: %1 kb/s")
509  .arg(af->bit_rate/1000));
510  }
511 
512  fr = (headr[2] & 0x0c ) >> 2;
513  af->frequency = freq[fr]*100;
514 
515  if (DEBUG){
516  if (af->frequency == 3)
517  LOG(VB_GENERAL, LOG_DEBUG, " Freq: reserved");
518  else
519  LOG(VB_GENERAL, LOG_DEBUG, QString(" Freq: %1 kHz")
520  .arg(af->frequency/1000.0, 2,'f',1,QChar('0')));
521  }
522  af->off = c;
523  af->set = 1;
524 
525  af->frametime = ((samples [3-af->layer] * 27000000ULL) / af->frequency);
526  af->framesize = af->bit_rate *slots [3-af->layer]/ af->frequency;
527  LOG(VB_GENERAL, LOG_INFO, QString(" frame size: %1").arg(af->framesize));
528  printpts(af->frametime);
529 
530  return c;
531 }
532 
533 int get_ac3_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
534 {
535  uint8_t headr[7];
536 
537  af->set=0;
538 
539  int c = find_audio_sync(rbuf, headr, off, AC3, le);
540  if (c < 0)
541  return c;
542 
543  af->off = c;
544 
545  af->layer = 0; // 0 for AC3
546 
547  if (DEBUG)
548  LOG(VB_GENERAL, LOG_DEBUG, "AC3 stream:");
549  uint8_t frame = (headr[4]&0x3F);
550  af->bit_rate = ac3_bitrates[frame>>1]*1000;
551  int half = ac3half[headr[5] >> 3];
552  if (DEBUG)
553  LOG(VB_GENERAL, LOG_DEBUG, QString(" bit rate: %1 kb/s")
554  .arg(af->bit_rate/1000));
555  int fr = (headr[4] & 0xc0) >> 6;
556  af->frequency = (ac3_freq[fr] *100) >> half;
557 
558  if (DEBUG)
559  LOG(VB_GENERAL, LOG_DEBUG,
560  QString(" freq: %1 Hz").arg(af->frequency));
561 
562  switch (headr[4] & 0xc0) {
563  case 0:
564  af->framesize = 4 * af->bit_rate/1000;
565  break;
566 
567  case 0x40:
568  af->framesize = 2 * (320 * af->bit_rate / 147000 + (frame & 1));
569  break;
570 
571  case 0x80:
572  af->framesize = 6 * af->bit_rate/1000;
573  break;
574  }
575 
576  if (DEBUG)
577  LOG(VB_GENERAL, LOG_DEBUG,
578  QString(" frame size %1").arg(af->framesize));
579 
580  af->off = c;
581  af->set = 1;
582 
583  //FIXME calculate frametime
584  af->frametime = 0;
585 
586  return c;
587 }
588 
589 
590 int get_video_ext_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
591 {
592  uint8_t buf[12];
593 
594  int re =ring_find_mpg_header(rbuf, EXTENSION_START_CODE, off, le);
595  if (re < 0) {
596  LOG(VB_GENERAL, LOG_ERR, "Error in find_mpg_header");
597  return re;
598  }
599 
600  if (ring_peek(rbuf, buf, 5, off) < 0) return -2;
601  uint8_t *headr=buf+4;
602 
603  uint8_t ext_id = (headr[0]&0xF0) >> 4;
604 
605  switch (ext_id){
606  case SEQUENCE_EXTENSION:{
607  if (s->ext_set || !s->set) break;
608  if (ring_peek(rbuf, buf, 10, off) < 0) return -2;
609  headr=buf+4;
610 
611  if (DEBUG)
612  LOG(VB_GENERAL, LOG_DEBUG, "Sequence Extension:");
613  s->profile = ((headr[0]&0x0F) << 4) | ((headr[1]&0xF0) >> 4);
614  if (headr[1]&0x08) s->progressive = 1;
615  else s->progressive = 0;
616  s->chroma = (headr[1]&0x06)>>1;
617  if (DEBUG){
618  switch(s->chroma){
619  case 0:
620  LOG(VB_GENERAL, LOG_DEBUG, " chroma reserved ");
621  break;
622  case 1:
623  LOG(VB_GENERAL, LOG_DEBUG, " chroma 4:2:0 ");
624  break;
625  case 2:
626  LOG(VB_GENERAL, LOG_DEBUG, " chroma 4:2:2 ");
627  break;
628  case 3:
629  LOG(VB_GENERAL, LOG_DEBUG, " chroma 4:4:4 ");
630  break;
631  }
632  }
633 
634  uint16_t hsize = ((headr[1]&0x01)<<12) | ((headr[2]&0x80)<<6);
635  uint16_t vsize = ((headr[2]&0x60)<<7);
636  s->h_size |= hsize;
637  s->v_size |= vsize;
638  if (DEBUG)
639  LOG(VB_GENERAL, LOG_DEBUG, QString(" size = %1x%2")
640  .arg(s->h_size).arg(s->v_size));
641 
642  uint32_t bitrate = ((headr[2]& 0x1F) << 25) | (( headr[3] & 0xFE ) << 17);
643  s->bit_rate |= bitrate;
644 
645  if (DEBUG)
646  LOG(VB_GENERAL, LOG_DEBUG, QString(" bit rate: %1 Mbit/s")
647  .arg(400.0*(s->bit_rate)/1000000.0, 0,'f',2,QChar('0')));
648 
649 
650  uint32_t vbvb = (headr[4]<<10);
651  s->vbv_buffer_size |= vbvb;
652  if (DEBUG)
653  LOG(VB_GENERAL, LOG_DEBUG, QString(" vbvbuffer %1")
654  .arg(16*1024*(s->vbv_buffer_size)));
655  uint8_t fr_n = (headr[5] & 0x60) >> 6;
656  uint8_t fr_d = (headr[5] & 0x1F);
657 
658  s->frame_rate = s->frame_rate * (fr_n+1) / (fr_d+1);
659  if (DEBUG)
660  LOG(VB_GENERAL, LOG_DEBUG, QString(" frame rate: %1")
661  .arg(s->frame_rate/1000.0, 2,'f',3,QChar('0')));
662  s->ext_set=1;
663  break;
664  }
665 
667  break;
668 
670  int pulldown = 0;
671 
672  if (!s->set || s->pulldown_set) break;
673  if (ring_peek(rbuf, buf, 10, off) < 0) return -2;
674  headr=buf+4;
675 
676  if ( (headr[2]&0x03) != 0x03 ) break; // not frame picture
677  if ( (headr[3]&0x02) ) pulldown = 1; // repeat flag set => pulldown
678 
679  if (pulldown){
680  if (s->current_tmpref)
681  s->pulldown = PULLDOWN23;
682  else
683  s->pulldown = PULLDOWN32;
684  s->pulldown_set = 1;
685  }
686  if (DEBUG){
687  switch (s->pulldown) {
688  case PULLDOWN32:
689  LOG(VB_GENERAL, LOG_DEBUG,
690  "Picture Coding Extension: "
691  "3:2 pulldown detected");
692  break;
693  case PULLDOWN23:
694  LOG(VB_GENERAL, LOG_DEBUG,
695  "Picture Coding Extension: "
696  "2:3 pulldown detected");
697  break;
698 #if 0
699  default:
700  LOG(VB_GENERAL, INFO_DEBUG,
701  " no pulldown detected");
702 #endif
703  }
704  }
705  break;
706  }
709  break;
710  }
711 
712 
713  return ext_id;
714 }
715 
pts2time
void pts2time(uint64_t pts, uint8_t *buf, int len)
Definition: element.cpp:154
VIDEO_NTSC
@ VIDEO_NTSC
Definition: element.h:64
bitrates
unsigned int bitrates[3][16]
Definition: element.cpp:39
sequence_t::frame_rate
uint32_t frame_rate
Definition: element.h:92
sequence_t::pulldown_set
uint8_t pulldown_set
Definition: element.h:102
pes.h
samples
static uint64_t samples[4]
Definition: element.cpp:45
ring_peek
int ring_peek(ringbuffer *rbuf, uint8_t *data, unsigned int count, uint32_t off)
Definition: ringbuffer.cpp:122
next_ptsdts_video
uint64_t next_ptsdts_video(uint64_t *pts, sequence_t *s, uint64_t fcount, uint64_t gcount)
Definition: element.cpp:76
find_audio_s
int find_audio_s(const uint8_t *rbuf, int off, int type, int le)
Definition: element.cpp:376
ringbuffer
Definition: ringbuffer.h:36
sequence_t
Definition: element.h:86
SEC_PER
#define SEC_PER
Definition: element.h:79
get_video_info
int get_video_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
Definition: element.cpp:195
find_audio_sync
int find_audio_sync(ringbuffer *rbuf, uint8_t *buf, int off, int type, int le)
Definition: element.cpp:326
fix_video_count
void fix_video_count(sequence_t *s, uint64_t *frame, uint64_t origpts, uint64_t pts, uint64_t origdts, uint64_t dts)
Definition: element.cpp:117
get_audio_info
int get_audio_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
Definition: element.cpp:482
AC3
@ AC3
Definition: element.h:83
audio_frame_t::bit_rate
uint32_t bit_rate
Definition: element.h:111
arg
arg(title).arg(filename).arg(doDelete))
PULLDOWN32
#define PULLDOWN32
Definition: element.h:74
get_ac3_info
int get_ac3_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
Definition: element.cpp:533
slots
unsigned int slots[4]
Definition: element.cpp:38
SEQUENCE_EXTENSION
#define SEQUENCE_EXTENSION
Definition: element.h:47
printpts
void printpts(int64_t pts)
Definition: pes.cpp:42
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
fix_audio_count
void fix_audio_count(uint64_t *acount, audio_frame_t *aframe, uint64_t origpts, uint64_t pts)
Definition: element.cpp:65
sequence_t::bit_rate
uint32_t bit_rate
Definition: element.h:93
sequence_t::aspect_ratio
uint8_t aspect_ratio
Definition: element.h:91
NONINTRAQ_FLAG
#define NONINTRAQ_FLAG
Definition: element.h:68
sequence_t::pulldown
uint8_t pulldown
Definition: element.h:103
sequence_t::non_intra_quant
uint8_t non_intra_quant[64]
Definition: element.h:97
sequence_t::set
int set
Definition: element.h:87
check_audio_header
int check_audio_header(ringbuffer *rbuf, audio_frame_t *af, int off, int le, int type)
Definition: element.cpp:418
ptsdiff
int64_t ptsdiff(uint64_t pts1, uint64_t pts2)
Definition: pes.cpp:77
mythlogging.h
mring_peek
int mring_peek(ringbuffer *rbuf, uint8_t *buf, unsigned int l, uint32_t off)
Definition: mpg_common.cpp:168
MAX_PTS2
#define MAX_PTS2
Definition: pes.h:53
QUANT_MATRIX_EXTENSION
#define QUANT_MATRIX_EXTENSION
Definition: element.h:50
sequence_t::h_size
uint16_t h_size
Definition: element.h:89
sequence_t::current_tmpref
uint8_t current_tmpref
Definition: element.h:105
ac3_bitrates
unsigned int ac3_bitrates[32]
Definition: element.cpp:48
INTRAQ_FLAG
#define INTRAQ_FLAG
Definition: element.h:67
mpg_common.h
audio_frame_t::frequency
uint32_t frequency
Definition: element.h:112
sequence_t::profile
uint8_t profile
Definition: element.h:99
audio_frame_t::set
int set
Definition: element.h:109
audio_frame_t::frametime
uint32_t frametime
Definition: element.h:117
element.h
ring_find_mpg_header
int ring_find_mpg_header(ringbuffer *rbuf, uint8_t head, int off, int le)
Definition: mpg_common.cpp:181
sequence_t::flags
uint8_t flags
Definition: element.h:95
add_pts_audio
uint64_t add_pts_audio(uint64_t pts, audio_frame_t *aframe, uint64_t frames)
Definition: element.cpp:56
sequence_t::v_size
uint16_t v_size
Definition: element.h:90
sequence_t::ext_set
int ext_set
Definition: element.h:88
MAX_PTS
#define MAX_PTS
Definition: pes.h:52
MPEG_AUDIO
@ MPEG_AUDIO
Definition: element.h:83
PICTURE_DISPLAY_EXTENSION
#define PICTURE_DISPLAY_EXTENSION
Definition: element.h:51
SEQUENCE_HDR_CODE
#define SEQUENCE_HDR_CODE
Definition: element.h:41
PULLDOWN23
#define PULLDOWN23
Definition: element.h:75
sequence_t::vbv_buffer_size
uint32_t vbv_buffer_size
Definition: element.h:94
sequence_t::video_format
int video_format
Definition: element.h:98
freq
uint32_t freq[4]
Definition: element.cpp:44
sequence_t::intra_quant
uint8_t intra_quant[64]
Definition: element.h:96
VIDEO_PAL
@ VIDEO_PAL
Definition: element.h:64
NOPULLDOWN
#define NOPULLDOWN
Definition: element.h:73
ac3_freq
uint32_t ac3_freq[4]
Definition: element.cpp:52
PICTURE_CODING_EXTENSION
#define PICTURE_CODING_EXTENSION
Definition: element.h:49
ac3half
static uint8_t ac3half[12]
Definition: element.cpp:51
get_video_ext_info
int get_video_ext_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
Definition: element.cpp:590
audio_frame_t::framesize
uint32_t framesize
Definition: element.h:116
uint16_t
unsigned short uint16_t
Definition: iso6937tables.h:1
audio_frame_t
Definition: element.h:108
DEBUG
#define DEBUG
Definition: element.cpp:54
SEQUENCE_DISPLAY_EXTENSION
#define SEQUENCE_DISPLAY_EXTENSION
Definition: element.h:48
audio_frame_t::off
uint32_t off
Definition: element.h:118
audio_frame_t::layer
int layer
Definition: element.h:110
GROUP_START_CODE
#define GROUP_START_CODE
Definition: element.h:45
sequence_t::chroma
uint8_t chroma
Definition: element.h:101
sequence_t::progressive
uint8_t progressive
Definition: element.h:100
EXTENSION_START_CODE
#define EXTENSION_START_CODE
Definition: element.h:43