Mercurial > mplayer.hg
comparison libmpdemux/mpeg_hdr.c @ 2565:4bc54a0f775f
mpeg video header parser
author | arpi |
---|---|
date | Tue, 30 Oct 2001 18:45:54 +0000 |
parents | |
children | 5c3d36c1d92b |
comparison
equal
deleted
inserted
replaced
2564:3d04a0991dce | 2565:4bc54a0f775f |
---|---|
1 | |
2 // based on libmpeg2/header.c by Aaron Holtzman <aholtzma@ess.engr.uvic.ca> | |
3 | |
4 // #include <inttypes.h> | |
5 #include <stdio.h> | |
6 | |
7 #include "config.h" | |
8 #include "mpeg_hdr.h" | |
9 | |
10 static int frameratecode2framerate[16] = { | |
11 0, | |
12 // Official mpeg1/2 framerates: | |
13 24000*10000/1001, 24*10000,25*10000, 30000*10000/1001, 30*10000,50*10000,60000*10000/1001, 60*10000, | |
14 // libmpeg3's "Unofficial economy rates": | |
15 1*10000,5*10000,10*10000,12*10000,15*10000,0,0 | |
16 }; | |
17 | |
18 | |
19 int mp_header_process_sequence_header (mp_mpeg_header_t * picture, unsigned char * buffer) | |
20 { | |
21 int width, height; | |
22 | |
23 if ((buffer[6] & 0x20) != 0x20){ | |
24 printf("missing marker bit!\n"); | |
25 return 1; /* missing marker_bit */ | |
26 } | |
27 | |
28 height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2]; | |
29 | |
30 picture->display_picture_width = (height >> 12); | |
31 picture->display_picture_height = (height & 0xfff); | |
32 | |
33 width = ((height >> 12) + 15) & ~15; | |
34 height = ((height & 0xfff) + 15) & ~15; | |
35 | |
36 if ((width > 768) || (height > 576)){ | |
37 printf("size restrictions for MP@ML or MPEG1 exceeded! (%dx%d)\n",width,height); | |
38 // return 1; /* size restrictions for MP@ML or MPEG1 */ | |
39 } | |
40 | |
41 picture->aspect_ratio_information = buffer[3] >> 4; | |
42 picture->frame_rate_code = buffer[3] & 15; | |
43 picture->fps=frameratecode2framerate[picture->frame_rate_code]; | |
44 picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6); | |
45 picture->mpeg1 = 1; | |
46 picture->picture_structure = 3; //FRAME_PICTURE; | |
47 picture->display_time=100; | |
48 return 0; | |
49 } | |
50 | |
51 static int header_process_sequence_extension (mp_mpeg_header_t * picture, | |
52 unsigned char * buffer) | |
53 { | |
54 /* check chroma format, size extensions, marker bit */ | |
55 if (((buffer[1] & 0x07) != 0x02) || (buffer[2] & 0xe0) || | |
56 ((buffer[3] & 0x01) != 0x01)) | |
57 return 1; | |
58 | |
59 picture->progressive_sequence = (buffer[1] >> 3) & 1; | |
60 picture->mpeg1 = 0; | |
61 return 0; | |
62 } | |
63 | |
64 static int header_process_picture_coding_extension (mp_mpeg_header_t * picture, unsigned char * buffer) | |
65 { | |
66 picture->picture_structure = buffer[2] & 3; | |
67 picture->top_field_first = buffer[3] >> 7; | |
68 picture->repeat_first_field = (buffer[3] >> 1) & 1; | |
69 picture->progressive_frame = buffer[4] >> 7; | |
70 | |
71 // repeat_first implementation by A'rpi/ESP-team, based on libmpeg3: | |
72 picture->display_time=100; | |
73 if(picture->repeat_first_field){ | |
74 if(picture->progressive_sequence){ | |
75 if(picture->top_field_first) | |
76 picture->display_time+=200; | |
77 else | |
78 picture->display_time+=100; | |
79 } else | |
80 if(picture->progressive_frame){ | |
81 picture->display_time+=50; | |
82 } | |
83 } | |
84 //temopral hack. We calc time on every field, so if we have 2 fields | |
85 // interlaced we'll end with double time for 1 frame | |
86 if( picture->picture_structure!=3 ) picture->display_time/=2; | |
87 return 0; | |
88 } | |
89 | |
90 int mp_header_process_extension (mp_mpeg_header_t * picture, unsigned char * buffer) | |
91 { | |
92 switch (buffer[0] & 0xf0) { | |
93 case 0x10: /* sequence extension */ | |
94 return header_process_sequence_extension (picture, buffer); | |
95 case 0x80: /* picture coding extension */ | |
96 return header_process_picture_coding_extension (picture, buffer); | |
97 } | |
98 return 0; | |
99 } | |
100 |