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