annotate libmpdemux/mpeg_hdr.c @ 3473:8a46f6a9efd0

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