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 picture->aspect_ratio_information = buffer[3] >> 4;
|
|
43 picture->frame_rate_code = buffer[3] & 15;
|
|
44 picture->fps=frameratecode2framerate[picture->frame_rate_code];
|
|
45 picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6);
|
|
46 picture->mpeg1 = 1;
|
|
47 picture->picture_structure = 3; //FRAME_PICTURE;
|
|
48 picture->display_time=100;
|
|
49 return 0;
|
|
50 }
|
|
51
|
|
52 static int header_process_sequence_extension (mp_mpeg_header_t * picture,
|
|
53 unsigned char * buffer)
|
|
54 {
|
|
55 /* check chroma format, size extensions, marker bit */
|
12562
|
56
|
|
57 if ( ((buffer[1] & 0x06) == 0x00) ||
|
|
58 ((buffer[1] & 0x01) != 0x00) || (buffer[2] & 0xe0) ||
|
|
59 ((buffer[3] & 0x01) != 0x01) )
|
2565
|
60 return 1;
|
|
61
|
|
62 picture->progressive_sequence = (buffer[1] >> 3) & 1;
|
|
63 picture->mpeg1 = 0;
|
|
64 return 0;
|
|
65 }
|
|
66
|
|
67 static int header_process_picture_coding_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
|
|
68 {
|
|
69 picture->picture_structure = buffer[2] & 3;
|
|
70 picture->top_field_first = buffer[3] >> 7;
|
|
71 picture->repeat_first_field = (buffer[3] >> 1) & 1;
|
|
72 picture->progressive_frame = buffer[4] >> 7;
|
|
73
|
|
74 // repeat_first implementation by A'rpi/ESP-team, based on libmpeg3:
|
|
75 picture->display_time=100;
|
|
76 if(picture->repeat_first_field){
|
|
77 if(picture->progressive_sequence){
|
|
78 if(picture->top_field_first)
|
|
79 picture->display_time+=200;
|
|
80 else
|
|
81 picture->display_time+=100;
|
|
82 } else
|
|
83 if(picture->progressive_frame){
|
|
84 picture->display_time+=50;
|
|
85 }
|
|
86 }
|
|
87 //temopral hack. We calc time on every field, so if we have 2 fields
|
|
88 // interlaced we'll end with double time for 1 frame
|
|
89 if( picture->picture_structure!=3 ) picture->display_time/=2;
|
|
90 return 0;
|
|
91 }
|
|
92
|
|
93 int mp_header_process_extension (mp_mpeg_header_t * picture, unsigned char * buffer)
|
|
94 {
|
|
95 switch (buffer[0] & 0xf0) {
|
|
96 case 0x10: /* sequence extension */
|
|
97 return header_process_sequence_extension (picture, buffer);
|
|
98 case 0x80: /* picture coding extension */
|
|
99 return header_process_picture_coding_extension (picture, buffer);
|
|
100 }
|
|
101 return 0;
|
|
102 }
|
|
103
|