annotate libmpdemux/mpeg_hdr.c @ 6420:370b50a47a18

Darwin/Mac OS X dvd support. Patch from Joey Parrish <joey@yunamusic.com>
author atmos4
date Thu, 13 Jun 2002 22:39:59 +0000
parents 268ea6bda6ff
children 83d91a7cba19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
1
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
2 // based on libmpeg2/header.c by Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
3
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
4 // #include <inttypes.h>
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
5 #include <stdio.h>
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
6
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
7 #include "config.h"
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
8 #include "mpeg_hdr.h"
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
9
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
10 static int frameratecode2framerate[16] = {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
11 0,
5441
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
12 // Official mpeg1/2 framerates: (1-8)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
13 24000*10000/1001, 24*10000,25*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
14 30000*10000/1001, 30*10000,50*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
15 60000*10000/1001, 60*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
16 // Xing's 15fps: (9)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
17 15*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
18 // libmpeg3's "Unofficial economy rates": (10-13)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
19 5*10000,10*10000,12*10000,15*10000,
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
20 // some invalid ones: (14-15)
268ea6bda6ff after some STFW i've found some info about fps codes
arpi
parents: 5440
diff changeset
21 0,0
2565
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
22 };
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
23
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
24
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
25 int mp_header_process_sequence_header (mp_mpeg_header_t * picture, unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
26 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
27 int width, height;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
28
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
29 if ((buffer[6] & 0x20) != 0x20){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
30 printf("missing marker bit!\n");
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
31 return 1; /* missing marker_bit */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
32 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
33
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
34 height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
35
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
36 picture->display_picture_width = (height >> 12);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
37 picture->display_picture_height = (height & 0xfff);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
38
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
39 width = ((height >> 12) + 15) & ~15;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
40 height = ((height & 0xfff) + 15) & ~15;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
41
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
42 if ((width > 768) || (height > 576)){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
43 printf("size restrictions for MP@ML or MPEG1 exceeded! (%dx%d)\n",width,height);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
44 // return 1; /* size restrictions for MP@ML or MPEG1 */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
45 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
46
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
47 picture->aspect_ratio_information = buffer[3] >> 4;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
48 picture->frame_rate_code = buffer[3] & 15;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
49 picture->fps=frameratecode2framerate[picture->frame_rate_code];
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
50 picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
51 picture->mpeg1 = 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
52 picture->picture_structure = 3; //FRAME_PICTURE;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
53 picture->display_time=100;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
54 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
55 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
56
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
57 static int header_process_sequence_extension (mp_mpeg_header_t * picture,
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
58 unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
59 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
60 /* check chroma format, size extensions, marker bit */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
61 if (((buffer[1] & 0x07) != 0x02) || (buffer[2] & 0xe0) ||
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
62 ((buffer[3] & 0x01) != 0x01))
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
63 return 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
64
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
65 picture->progressive_sequence = (buffer[1] >> 3) & 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
66 picture->mpeg1 = 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
67 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
68 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
69
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
70 static int header_process_picture_coding_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
71 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
72 picture->picture_structure = buffer[2] & 3;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
73 picture->top_field_first = buffer[3] >> 7;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
74 picture->repeat_first_field = (buffer[3] >> 1) & 1;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
75 picture->progressive_frame = buffer[4] >> 7;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
76
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
77 // repeat_first implementation by A'rpi/ESP-team, based on libmpeg3:
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
78 picture->display_time=100;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
79 if(picture->repeat_first_field){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
80 if(picture->progressive_sequence){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
81 if(picture->top_field_first)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
82 picture->display_time+=200;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
83 else
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
84 picture->display_time+=100;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
85 } else
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
86 if(picture->progressive_frame){
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
87 picture->display_time+=50;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
88 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
89 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
90 //temopral hack. We calc time on every field, so if we have 2 fields
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
91 // interlaced we'll end with double time for 1 frame
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
92 if( picture->picture_structure!=3 ) picture->display_time/=2;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
93 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
94 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
95
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
96 int mp_header_process_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
97 {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
98 switch (buffer[0] & 0xf0) {
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
99 case 0x10: /* sequence extension */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
100 return header_process_sequence_extension (picture, buffer);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
101 case 0x80: /* picture coding extension */
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
102 return header_process_picture_coding_extension (picture, buffer);
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
103 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
104 return 0;
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
105 }
4bc54a0f775f mpeg video header parser
arpi
parents:
diff changeset
106