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 std::array<unsigned int,4> _slots {12, 144, 0, 0};
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}
43 }};
44 
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};
47 
48 static const std::array<const uint16_t,32> ac3_bitrates
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};
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  std::vector<uint8_t> buf;
198  buf.resize(150);
199  int form = -1;
200  int c = 0;
201 
202  s->set = 0;
203  s->ext_set = 0;
204  s->pulldown_set = 0;
205  int re = ring_find_mpg_header(rbuf, SEQUENCE_HDR_CODE, off, le);
206  if (re < 0)
207  return re;
208  uint8_t *headr = buf.data()+4;
209  if (ring_peek(rbuf, buf, off) < 0) return -2;
210 
211  s->h_size = ((headr[1] &0xF0) >> 4) | (headr[0] << 4);
212  s->v_size = ((headr[1] &0x0F) << 8) | (headr[2]);
213 
214  int sw = (int)((headr[3]&0xF0) >> 4) ;
215 
216  if (DEBUG){
217  switch( sw ){
218  case 1:
219  LOG(VB_GENERAL, LOG_INFO, "Video: aspect ratio: 1:1");
220  s->aspect_ratio = 100;
221  break;
222  case 2:
223  LOG(VB_GENERAL, LOG_INFO, "Video: aspect ratio: 4:3");
224  s->aspect_ratio = 133;
225  break;
226  case 3:
227  LOG(VB_GENERAL, LOG_INFO, "Video: aspect ratio: 16:9");
228  s->aspect_ratio = 177;
229  break;
230  case 4:
231  LOG(VB_GENERAL, LOG_INFO,
232  "Video: aspect ratio: 2.21:1");
233  s->aspect_ratio = 221;
234  break;
235 
236  case 5 ... 15:
237  LOG(VB_GENERAL, LOG_INFO,
238  "Video: aspect ratio: reserved");
239  s->aspect_ratio = 0;
240  break;
241 
242  default:
243  s->aspect_ratio = 0;
244  return -3;
245  }
246  }
247 
248  if (DEBUG)
249  LOG(VB_GENERAL, LOG_DEBUG,
250  QString(" size = %1x%2").arg(s->h_size).arg(s->v_size));
251 
252  sw = (int)(headr[3]&0x0F);
253 
254  switch ( sw ) {
255  case 1:
256  s->frame_rate = 23976;
257  form = -1;
258  break;
259  case 2:
260  s->frame_rate = 24000;
261  form = -1;
262  break;
263  case 3:
264  s->frame_rate = 25000;
265  form = VIDEO_PAL;
266  break;
267  case 4:
268  s->frame_rate = 29970;
269  form = VIDEO_NTSC;
270  break;
271  case 5:
272  s->frame_rate = 30000;
273  form = VIDEO_NTSC;
274  break;
275  case 6:
276  s->frame_rate = 50000;
277  form = VIDEO_PAL;
278  break;
279  case 7:
280  s->frame_rate = 60000;
281  form = VIDEO_NTSC;
282  break;
283  }
284  if (DEBUG)
285  LOG(VB_GENERAL, LOG_DEBUG, QString(" frame rate: %1 fps")
286  .arg(s->frame_rate/1000.0, 2,'f',3,QChar('0')));
287 
288  s->bit_rate = (((headr[4] << 10) & 0x0003FC00UL)
289  | ((headr[5] << 2) & 0x000003FCUL) |
290  (((headr[6] & 0xC0) >> 6) & 0x00000003UL));
291 
292  if (DEBUG)
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')));
295 
296  s->video_format = form;
297 
298 
299 
300  s->vbv_buffer_size = (( headr[7] & 0xF8) >> 3 ) | (( headr[6] & 0x1F )<< 5);
301  s->flags = ( headr[7] & 0x06);
302  if (DEBUG)
303  LOG(VB_GENERAL, LOG_DEBUG, QString(" vbvbuffer %1")
304  .arg(16*1024*(s->vbv_buffer_size)));
305 
306  c += 8;
307  if ( !(s->flags & INTRAQ_FLAG) )
308  s->flags = ( headr[7] & 0x07);
309  else {
310  s->flags |= headr[c+63] & 0x01;
311  memset(s->intra_quant, 0, 64);
312  for (int i=0;i<64;i++)
313  s->intra_quant[i] |= (headr[c+i] >> 1) |
314  (( headr[c-1+i] & 0x01) << 7);
315 
316  c += 64;
317  }
318  if (s->flags & NONINTRAQ_FLAG){
319  memcpy(s->non_intra_quant, headr+c, 64);
320  c += 64;
321  }
322  s->set=1;
323 
324  return c;
325 }
326 
327 int find_audio_sync(ringbuffer *rbuf, audio_sync_buf &buf, int off, int type, int le)
328 {
329  int found = 0;
330  int l=0;
331 
332  buf.fill(0);
333  uint8_t b1 = 0x00;
334  uint8_t b2 = 0x00;
335  uint8_t m2 = 0xFF;
336  switch(type){
337  case AC3:
338  b1 = 0x0B;
339  b2 = 0x77;
340  l = 6;
341  break;
342 
343  case MPEG_AUDIO:
344  b1 = 0xFF;
345  b2 = 0xF8;
346  m2 = 0xF8;
347  l = 4;
348  break;
349 
350  default:
351  return -1;
352  }
353 
354  int c = off;
355  while ( c-off < le){
356  uint8_t b = 0;
357  if (mring_peek(rbuf, &b, 1, c) <0) return -1;
358  switch(found){
359 
360  case 0:
361  if ( b == b1) found = 1;
362  break;
363 
364  case 1:
365  if ( (b&m2) == b2){
366  if (mring_peek(rbuf, buf.data(), l, c-1) < -1)
367  return -2;
368  return c-1-off;
369  } else if ( b != b1) found = 0;
370  }
371  c++;
372  }
373  if (found) return -2;
374  return -1;
375 }
376 
377 int find_audio_s(const uint8_t *rbuf, int off, int type, int le)
378 {
379  int found = 0;
380 
381  uint8_t b1 = 0x00;
382  uint8_t b2 = 0x00;
383  uint8_t m2 = 0xFF;
384  switch(type){
385  case AC3:
386  b1 = 0x0B;
387  b2 = 0x77;
388  break;
389 
390  case MPEG_AUDIO:
391  b1 = 0xFF;
392  b2 = 0xF8;
393  m2 = 0xF8;
394  break;
395 
396  default:
397  return -1;
398  }
399 
400  int c = off;
401  while ( c < le){
402  uint8_t b=rbuf[c];
403  switch(found){
404  case 0:
405  if ( b == b1) found = 1;
406  break;
407 
408  case 1:
409  if ( (b&m2) == b2){
410  return c-1;
411  } else if ( b != b1) found = 0;
412  }
413  c++;
414  }
415  if (found) return -2;
416  return -1;
417 }
418 
419 int check_audio_header(ringbuffer *rbuf, audio_frame_t * af, int off, int le,
420  int type)
421 {
422  audio_sync_buf headr {};
423  uint8_t frame = 0;
424  int fr = 0;
425  int half = 0;
426  int c=0;
427 
428  if ( (c = find_audio_sync(rbuf, headr, off, type, le))
429  != 0 ) {
430  if (c==-2){
431  LOG(VB_GENERAL, LOG_ERR, "Incomplete audio header");
432  return -2;
433  }
434  LOG(VB_GENERAL, LOG_ERR, "Error in audio header");
435  return -1;
436  }
437  switch (type){
438 
439  case MPEG_AUDIO:
440  if ( af->layer != ((headr[1] & 0x06) >> 1) ){
441  if ( headr[1] == 0xff){
442  return -3;
443  }
444 #ifdef IN_DEBUG
445  LOG(VB_GENERAL, LOG_ERR, "Wrong audio layer");
446 #endif
447  return -1;
448  }
449  if ( af->bit_rate !=
450  (bitrates[(3-af->layer)][(headr[2] >> 4 )]*1000)){
451 #ifdef IN_DEBUG
452  LOG(VB_GENERAL, LOG_ERR, "Wrong audio bit rate");
453 #endif
454  return -1;
455  }
456  break;
457 
458  case AC3:
459  frame = (headr[4]&0x3F);
460  if (af->bit_rate != ac3_bitrates[frame>>1]*1000){
461 #ifdef IN_DEBUG
462  LOG(VB_GENERAL, LOG_ERR, "Wrong audio bit rate");
463 #endif
464  return -1;
465  }
466  half = ac3half[headr[5] >> 3];
467  fr = (headr[4] & 0xc0) >> 6;
468  if (af->frequency != ((ac3_freq[fr] *100) >> half)){
469 #ifdef IN_DEBUG
470  LOG(VB_GENERAL, LOG_ERR, "Wrong audio frequency");
471 #endif
472  return -1;
473  }
474 
475  break;
476 
477  }
478 
479  return 0;
480 }
481 
482 
483 int get_audio_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
484 {
485  int c = 0;
486  int fr =0;
487  audio_sync_buf headr {};
488 
489  af->set=0;
490 
491  if ( (c = find_audio_sync(rbuf, headr, off, MPEG_AUDIO,le)) < 0 )
492  return c;
493 
494  af->layer = (headr[1] & 0x06) >> 1;
495 
496  if (DEBUG)
497  LOG(VB_GENERAL, LOG_DEBUG, QString("Audiostream: layer: %1")
498  .arg(4-af->layer));
499 
500 
501  af->bit_rate = bitrates[(3-af->layer)][(headr[2] >> 4 )]*1000;
502 
503  if (DEBUG){
504  if (af->bit_rate == 0)
505  LOG(VB_GENERAL, LOG_DEBUG, " Bit rate: free");
506  else if (af->bit_rate == 0xf)
507  LOG(VB_GENERAL, LOG_DEBUG, " BRate: reserved");
508  else
509  LOG(VB_GENERAL, LOG_DEBUG, QString(" BRate: %1 kb/s")
510  .arg(af->bit_rate/1000));
511  }
512 
513  fr = (headr[2] & 0x0c ) >> 2;
514  af->frequency = freq[fr]*100;
515 
516  if (DEBUG){
517  if (af->frequency == 3)
518  LOG(VB_GENERAL, LOG_DEBUG, " Freq: reserved");
519  else
520  LOG(VB_GENERAL, LOG_DEBUG, QString(" Freq: %1 kHz")
521  .arg(af->frequency/1000.0, 2,'f',1,QChar('0')));
522  }
523  af->off = c;
524  af->set = 1;
525 
526  af->frametime = ((samples [3-af->layer] * 27000000ULL) / af->frequency);
527  af->framesize = af->bit_rate *_slots [3-af->layer]/ af->frequency;
528  LOG(VB_GENERAL, LOG_INFO, QString(" frame size: %1").arg(af->framesize));
529  printpts(af->frametime);
530 
531  return c;
532 }
533 
534 int get_ac3_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
535 {
536  audio_sync_buf headr {};
537 
538  af->set=0;
539 
540  int c = find_audio_sync(rbuf, headr, off, AC3, le);
541  if (c < 0)
542  return c;
543 
544  af->off = c;
545 
546  af->layer = 0; // 0 for AC3
547 
548  if (DEBUG)
549  LOG(VB_GENERAL, LOG_DEBUG, "AC3 stream:");
550  uint8_t frame = (headr[4]&0x3F);
551  af->bit_rate = ac3_bitrates[frame>>1]*1000;
552  int half = ac3half[headr[5] >> 3];
553  if (DEBUG)
554  LOG(VB_GENERAL, LOG_DEBUG, QString(" bit rate: %1 kb/s")
555  .arg(af->bit_rate/1000));
556  int fr = (headr[4] & 0xc0) >> 6;
557  af->frequency = (ac3_freq[fr] *100) >> half;
558 
559  if (DEBUG)
560  LOG(VB_GENERAL, LOG_DEBUG,
561  QString(" freq: %1 Hz").arg(af->frequency));
562 
563  switch (headr[4] & 0xc0) {
564  case 0:
565  af->framesize = 4 * af->bit_rate/1000;
566  break;
567 
568  case 0x40:
569  af->framesize = 2 * (320 * af->bit_rate / 147000 + (frame & 1));
570  break;
571 
572  case 0x80:
573  af->framesize = 6 * af->bit_rate/1000;
574  break;
575  }
576 
577  if (DEBUG)
578  LOG(VB_GENERAL, LOG_DEBUG,
579  QString(" frame size %1").arg(af->framesize));
580 
581  af->off = c;
582  af->set = 1;
583 
584  //FIXME calculate frametime
585  af->frametime = 0;
586 
587  return c;
588 }
589 
590 
591 int get_video_ext_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
592 {
593  std::vector<uint8_t> buf;
594  buf.resize(12);
595 
596  int re =ring_find_mpg_header(rbuf, EXTENSION_START_CODE, off, le);
597  if (re < 0) {
598  LOG(VB_GENERAL, LOG_ERR, "Error in find_mpg_header");
599  return re;
600  }
601 
602  if (ring_peek(rbuf, buf, 5, off) < 0) return -2;
603  uint8_t *headr=buf.data()+4;
604 
605  uint8_t ext_id = (headr[0]&0xF0) >> 4;
606 
607  switch (ext_id){
608  case SEQUENCE_EXTENSION:{
609  if (s->ext_set || !s->set) break;
610  if (ring_peek(rbuf, buf, 10, off) < 0) return -2;
611  headr=buf.data()+4;
612 
613  if (DEBUG)
614  LOG(VB_GENERAL, LOG_DEBUG, "Sequence Extension:");
615  s->profile = ((headr[0]&0x0F) << 4) | ((headr[1]&0xF0) >> 4);
616  if (headr[1]&0x08) s->progressive = 1;
617  else s->progressive = 0;
618  s->chroma = (headr[1]&0x06)>>1;
619  if (DEBUG){
620  switch(s->chroma){
621  case 0:
622  LOG(VB_GENERAL, LOG_DEBUG, " chroma reserved ");
623  break;
624  case 1:
625  LOG(VB_GENERAL, LOG_DEBUG, " chroma 4:2:0 ");
626  break;
627  case 2:
628  LOG(VB_GENERAL, LOG_DEBUG, " chroma 4:2:2 ");
629  break;
630  case 3:
631  LOG(VB_GENERAL, LOG_DEBUG, " chroma 4:4:4 ");
632  break;
633  }
634  }
635 
636  uint16_t hsize = ((headr[1]&0x01)<<12) | ((headr[2]&0x80)<<6);
637  uint16_t vsize = ((headr[2]&0x60)<<7);
638  s->h_size |= hsize;
639  s->v_size |= vsize;
640  if (DEBUG)
641  LOG(VB_GENERAL, LOG_DEBUG, QString(" size = %1x%2")
642  .arg(s->h_size).arg(s->v_size));
643 
644  uint32_t bitrate = ((headr[2]& 0x1F) << 25) | (( headr[3] & 0xFE ) << 17);
645  s->bit_rate |= bitrate;
646 
647  if (DEBUG)
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')));
650 
651 
652  uint32_t vbvb = (headr[4]<<10);
653  s->vbv_buffer_size |= vbvb;
654  if (DEBUG)
655  LOG(VB_GENERAL, LOG_DEBUG, QString(" vbvbuffer %1")
656  .arg(16*1024*(s->vbv_buffer_size)));
657  uint8_t fr_n = (headr[5] & 0x60) >> 6;
658  uint8_t fr_d = (headr[5] & 0x1F);
659 
660  s->frame_rate = s->frame_rate * (fr_n+1) / (fr_d+1);
661  if (DEBUG)
662  LOG(VB_GENERAL, LOG_DEBUG, QString(" frame rate: %1")
663  .arg(s->frame_rate/1000.0, 2,'f',3,QChar('0')));
664  s->ext_set=1;
665  break;
666  }
667 
669  break;
670 
672  int pulldown = 0;
673 
674  if (!s->set || s->pulldown_set) break;
675  if (ring_peek(rbuf, buf, 10, off) < 0) return -2;
676  headr=buf.data()+4;
677 
678  if ( (headr[2]&0x03) != 0x03 ) break; // not frame picture
679  if ( (headr[3]&0x02) ) pulldown = 1; // repeat flag set => pulldown
680 
681  if (pulldown){
682  if (s->current_tmpref)
683  s->pulldown = PULLDOWN23;
684  else
685  s->pulldown = PULLDOWN32;
686  s->pulldown_set = 1;
687  }
688  if (DEBUG){
689  switch (s->pulldown) {
690  case PULLDOWN32:
691  LOG(VB_GENERAL, LOG_DEBUG,
692  "Picture Coding Extension: "
693  "3:2 pulldown detected");
694  break;
695  case PULLDOWN23:
696  LOG(VB_GENERAL, LOG_DEBUG,
697  "Picture Coding Extension: "
698  "2:3 pulldown detected");
699  break;
700 #if 0
701  default:
702  LOG(VB_GENERAL, INFO_DEBUG,
703  " no pulldown detected");
704 #endif
705  }
706  }
707  break;
708  }
711  break;
712  }
713 
714 
715  return ext_id;
716 }
717 
pts2time
void pts2time(uint64_t pts, uint8_t *buf, int len)
Definition: element.cpp:154
ac3half
static const std::array< const uint8_t, 12 > ac3half
Definition: element.cpp:51
sequence_t::frame_rate
uint32_t frame_rate
Definition: element.h:93
sequence_t::pulldown_set
uint8_t pulldown_set
Definition: element.h:103
pes.h
find_audio_sync
int find_audio_sync(ringbuffer *rbuf, audio_sync_buf &buf, int off, int type, int le)
Definition: element.cpp:327
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:377
_slots
std::array< unsigned int, 4 > _slots
Definition: element.cpp:38
ringbuffer
Definition: ringbuffer.h:39
sequence_t
Definition: element.h:87
SEC_PER
#define SEC_PER
Definition: element.h:80
get_video_info
int get_video_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
Definition: element.cpp:195
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
freq
static const std::array< const uint32_t, 4 > freq
Definition: element.cpp:45
get_audio_info
int get_audio_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
Definition: element.cpp:483
audio_frame_t::bit_rate
uint32_t bit_rate
Definition: element.h:112
arg
arg(title).arg(filename).arg(doDelete))
PULLDOWN32
#define PULLDOWN32
Definition: element.h:75
get_ac3_info
int get_ac3_info(ringbuffer *rbuf, audio_frame_t *af, int off, int le)
Definition: element.cpp:534
SEQUENCE_EXTENSION
#define SEQUENCE_EXTENSION
Definition: element.h:48
printpts
void printpts(int64_t pts)
Definition: pes.cpp:43
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:94
sequence_t::aspect_ratio
uint8_t aspect_ratio
Definition: element.h:92
NONINTRAQ_FLAG
#define NONINTRAQ_FLAG
Definition: element.h:69
MPEG_AUDIO
@ MPEG_AUDIO
Definition: element.h:84
sequence_t::pulldown
uint8_t pulldown
Definition: element.h:104
sequence_t::non_intra_quant
uint8_t non_intra_quant[64]
Definition: element.h:98
sequence_t::set
int set
Definition: element.h:88
check_audio_header
int check_audio_header(ringbuffer *rbuf, audio_frame_t *af, int off, int le, int type)
Definition: element.cpp:419
ptsdiff
int64_t ptsdiff(uint64_t pts1, uint64_t pts2)
Definition: pes.cpp:78
VIDEO_NTSC
@ VIDEO_NTSC
Definition: element.h:65
mythlogging.h
mring_peek
int mring_peek(ringbuffer *rbuf, uint8_t *buf, unsigned int l, uint32_t off)
Definition: mpg_common.cpp:159
MAX_PTS2
#define MAX_PTS2
Definition: pes.h:53
QUANT_MATRIX_EXTENSION
#define QUANT_MATRIX_EXTENSION
Definition: element.h:51
audio_sync_buf
std::array< uint8_t, 7 > audio_sync_buf
Definition: element.h:123
sequence_t::h_size
uint16_t h_size
Definition: element.h:90
sequence_t::current_tmpref
uint8_t current_tmpref
Definition: element.h:106
INTRAQ_FLAG
#define INTRAQ_FLAG
Definition: element.h:68
mpg_common.h
audio_frame_t::frequency
uint32_t frequency
Definition: element.h:113
sequence_t::profile
uint8_t profile
Definition: element.h:100
audio_frame_t::set
int set
Definition: element.h:110
audio_frame_t::frametime
uint32_t frametime
Definition: element.h:118
element.h
ring_find_mpg_header
int ring_find_mpg_header(ringbuffer *rbuf, uint8_t head, int off, int le)
Definition: mpg_common.cpp:177
sequence_t::flags
uint8_t flags
Definition: element.h:96
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:91
bitrates
std::array< std::array< unsigned int, 16 >, 3 > bitrates
Definition: element.cpp:39
sequence_t::ext_set
int ext_set
Definition: element.h:89
MAX_PTS
#define MAX_PTS
Definition: pes.h:52
PICTURE_DISPLAY_EXTENSION
#define PICTURE_DISPLAY_EXTENSION
Definition: element.h:52
SEQUENCE_HDR_CODE
#define SEQUENCE_HDR_CODE
Definition: element.h:42
AC3
@ AC3
Definition: element.h:84
PULLDOWN23
#define PULLDOWN23
Definition: element.h:76
sequence_t::vbv_buffer_size
uint32_t vbv_buffer_size
Definition: element.h:95
sequence_t::video_format
int video_format
Definition: element.h:99
ac3_freq
static const std::array< const uint32_t, 4 > ac3_freq
Definition: element.cpp:52
sequence_t::intra_quant
uint8_t intra_quant[64]
Definition: element.h:97
NOPULLDOWN
#define NOPULLDOWN
Definition: element.h:74
PICTURE_CODING_EXTENSION
#define PICTURE_CODING_EXTENSION
Definition: element.h:50
get_video_ext_info
int get_video_ext_info(ringbuffer *rbuf, sequence_t *s, int off, int le)
Definition: element.cpp:591
audio_frame_t::framesize
uint32_t framesize
Definition: element.h:117
uint16_t
unsigned short uint16_t
Definition: iso6937tables.h:3
audio_frame_t
Definition: element.h:109
DEBUG
#define DEBUG
Definition: element.cpp:54
ac3_bitrates
static const std::array< const uint16_t, 32 > ac3_bitrates
Definition: element.cpp:49
SEQUENCE_DISPLAY_EXTENSION
#define SEQUENCE_DISPLAY_EXTENSION
Definition: element.h:49
audio_frame_t::off
uint32_t off
Definition: element.h:119
audio_frame_t::layer
int layer
Definition: element.h:111
GROUP_START_CODE
#define GROUP_START_CODE
Definition: element.h:46
sequence_t::chroma
uint8_t chroma
Definition: element.h:102
VIDEO_PAL
@ VIDEO_PAL
Definition: element.h:65
sequence_t::progressive
uint8_t progressive
Definition: element.h:101
samples
static const std::array< const uint64_t, 4 > samples
Definition: element.cpp:46
EXTENSION_START_CODE
#define EXTENSION_START_CODE
Definition: element.h:44