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 
37 
38 std::array<unsigned int,4> slotsPerLayer {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 = ((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 
427  int c = find_audio_sync(rbuf, headr, off, type, le);
428  if (c != 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 fr =0;
485  audio_sync_buf headr {};
486 
487  af->set=0;
488 
489  int c = find_audio_sync(rbuf, headr, off, MPEG_AUDIO,le);
490  if (c < 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 * slotsPerLayer[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  audio_sync_buf headr {};
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  std::vector<uint8_t> buf;
593  buf.resize(12);
594 
595  int re =ring_find_mpg_header(rbuf, EXTENSION_START_CODE, off, le);
596  if (re < 0) {
597  LOG(VB_GENERAL, LOG_ERR, "Error in find_mpg_header");
598  return re;
599  }
600 
601  if (ring_peek(rbuf, buf, 5, off) < 0) return -2;
602  uint8_t *headr=buf.data()+4;
603 
604  uint8_t ext_id = (headr[0]&0xF0) >> 4;
605 
606  switch (ext_id){
607  case SEQUENCE_EXTENSION:{
608  if (s->ext_set || !s->set) break;
609  if (ring_peek(rbuf, buf, 10, off) < 0) return -2;
610  headr=buf.data()+4;
611 
612  if (DEBUG)
613  LOG(VB_GENERAL, LOG_DEBUG, "Sequence Extension:");
614  s->profile = ((headr[0]&0x0F) << 4) | ((headr[1]&0xF0) >> 4);
615  if (headr[1]&0x08) s->progressive = 1;
616  else s->progressive = 0;
617  s->chroma = (headr[1]&0x06)>>1;
618  if (DEBUG){
619  switch(s->chroma){
620  case 0:
621  LOG(VB_GENERAL, LOG_DEBUG, " chroma reserved ");
622  break;
623  case 1:
624  LOG(VB_GENERAL, LOG_DEBUG, " chroma 4:2:0 ");
625  break;
626  case 2:
627  LOG(VB_GENERAL, LOG_DEBUG, " chroma 4:2:2 ");
628  break;
629  case 3:
630  LOG(VB_GENERAL, LOG_DEBUG, " chroma 4:4:4 ");
631  break;
632  }
633  }
634 
635  uint16_t hsize = ((headr[1]&0x01)<<12) | ((headr[2]&0x80)<<6);
636  uint16_t vsize = ((headr[2]&0x60)<<7);
637  s->h_size |= hsize;
638  s->v_size |= vsize;
639  if (DEBUG)
640  LOG(VB_GENERAL, LOG_DEBUG, QString(" size = %1x%2")
641  .arg(s->h_size).arg(s->v_size));
642 
643  uint32_t bitrate = ((headr[2]& 0x1F) << 25) | (( headr[3] & 0xFE ) << 17);
644  s->bit_rate |= bitrate;
645 
646  if (DEBUG)
647  LOG(VB_GENERAL, LOG_DEBUG, QString(" bit rate: %1 Mbit/s")
648  .arg(400.0*(s->bit_rate)/1000000.0, 0,'f',2,QChar('0')));
649 
650 
651  uint32_t vbvb = (headr[4]<<10);
652  s->vbv_buffer_size |= vbvb;
653  if (DEBUG)
654  LOG(VB_GENERAL, LOG_DEBUG, QString(" vbvbuffer %1")
655  .arg(16*1024*(s->vbv_buffer_size)));
656  uint8_t fr_n = (headr[5] & 0x60) >> 6;
657  uint8_t fr_d = (headr[5] & 0x1F);
658 
659  s->frame_rate = s->frame_rate * (fr_n+1) / (fr_d+1);
660  if (DEBUG)
661  LOG(VB_GENERAL, LOG_DEBUG, QString(" frame rate: %1")
662  .arg(s->frame_rate/1000.0, 2,'f',3,QChar('0')));
663  s->ext_set=1;
664  break;
665  }
666 
668  break;
669 
671  int pulldown = 0;
672 
673  if (!s->set || s->pulldown_set) break;
674  if (ring_peek(rbuf, buf, 10, off) < 0) return -2;
675  headr=buf.data()+4;
676 
677  if ( (headr[2]&0x03) != 0x03 ) break; // not frame picture
678  if ( (headr[3]&0x02) ) pulldown = 1; // repeat flag set => pulldown
679 
680  if (pulldown){
681  if (s->current_tmpref)
682  s->pulldown = PULLDOWN23;
683  else
684  s->pulldown = PULLDOWN32;
685  s->pulldown_set = 1;
686  }
687  if (DEBUG){
688  switch (s->pulldown) {
689  case PULLDOWN32:
690  LOG(VB_GENERAL, LOG_DEBUG,
691  "Picture Coding Extension: "
692  "3:2 pulldown detected");
693  break;
694  case PULLDOWN23:
695  LOG(VB_GENERAL, LOG_DEBUG,
696  "Picture Coding Extension: "
697  "2:3 pulldown detected");
698  break;
699 #if 0
700  default:
701  LOG(VB_GENERAL, INFO_DEBUG,
702  " no pulldown detected");
703 #endif
704  }
705  }
706  break;
707  }
710  break;
711  }
712 
713 
714  return ext_id;
715 }
716 
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:124
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
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:482
audio_frame_t::bit_rate
uint32_t bit_rate
Definition: element.h:112
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:533
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:39
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
slotsPerLayer
std::array< unsigned int, 4 > slotsPerLayer
Definition: element.cpp:38
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
mpeg::chrono::pts
std::chrono::duration< CHRONO_TYPE, std::ratio< 1, 90000 > > pts
Definition: mythchrono.h:55
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:590
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