]> git.sesse.net Git - vlc/blob - src/video_parser/vpar_synchro.c
Avancement du debuggage du motion.
[vlc] / src / video_parser / vpar_synchro.c
1 /*****************************************************************************
2  * vpar_motion.c : motion vectors parsing
3  * (c)1999 VideoLAN
4  *****************************************************************************/
5
6 /*****************************************************************************
7  * Preamble
8  *****************************************************************************/
9 #include <errno.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <string.h>
14 #include <sys/uio.h>
15 #include <X11/Xlib.h>
16 #include <X11/extensions/XShm.h>
17
18 #include "config.h"
19 #include "common.h"
20 #include "mtime.h"
21 #include "vlc_thread.h"
22
23 #include "intf_msg.h"
24 #include "debug.h"                    /* ?? temporaire, requis par netlist.h */
25
26 #include "input.h"
27 #include "input_netlist.h"
28 #include "decoder_fifo.h"
29 #include "video.h"
30 #include "video_output.h"
31
32 #include "vdec_idct.h"
33 #include "video_decoder.h"
34 #include "vdec_motion.h"
35
36 #include "vpar_blocks.h"
37 #include "vpar_headers.h"
38 #include "video_fifo.h"
39 #include "vpar_synchro.h"
40 #include "video_parser.h"
41
42 #define MAX_COUNT 3
43
44 /*
45  * Local prototypes
46  */
47
48 /*****************************************************************************
49  * vpar_SynchroUpdateTab : Update a mean table in the synchro structure
50  *****************************************************************************/
51 double vpar_SynchroUpdateTab( video_synchro_tab_t * tab, int count )
52 {
53     if( tab->count < MAX_COUNT)
54         tab->count++;
55
56     tab->mean = ( (tab->count-1) * tab->mean + count )
57                     / tab->count;
58
59     tab->deviation = ( (tab->count-1) * tab->deviation
60                     + abs (tab->mean - count) ) / tab->count;
61
62     return tab->deviation;
63 }
64
65 /*****************************************************************************
66  * vpar_SynchroUpdateStructures : Update the synchro structures
67  *****************************************************************************/
68 void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar,
69                                    int i_coding_type )
70 {
71     double candidate_deviation;
72     double optimal_deviation;
73     double predict;
74
75     switch(i_coding_type)
76     {
77         case P_CODING_TYPE:
78             p_vpar->synchro.current_p_count++;
79             break;
80         case B_CODING_TYPE:
81             p_vpar->synchro.current_b_count++;
82             break;
83         case I_CODING_TYPE:
84
85             /* update all the structures for P images */
86             optimal_deviation = vpar_SynchroUpdateTab(
87                             &p_vpar->synchro.tab_p[0],
88                             p_vpar->synchro.current_p_count);
89             predict = p_vpar->synchro.tab_p[0].mean;
90
91             candidate_deviation = vpar_SynchroUpdateTab(
92                             &p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo & 0x1)],
93                             p_vpar->synchro.current_p_count);
94             if (candidate_deviation < optimal_deviation)
95             {
96                 optimal_deviation = candidate_deviation;
97                 predict = p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo & 0x1)].mean;
98             }
99
100             candidate_deviation = vpar_SynchroUpdateTab(
101                             &p_vpar->synchro.tab_p[3 + (p_vpar->synchro.modulo % 3)],
102                             p_vpar->synchro.current_p_count);
103             if (candidate_deviation < optimal_deviation)
104             {
105                 optimal_deviation = candidate_deviation;
106                 predict = p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo % 3)].mean;
107             }
108
109             p_vpar->synchro.p_count_predict = predict;
110
111
112             /* update all the structures for B images */
113             optimal_deviation = vpar_SynchroUpdateTab(
114                             &p_vpar->synchro.tab_b[0],
115                             p_vpar->synchro.current_b_count);
116             predict = p_vpar->synchro.tab_b[0].mean;
117
118             candidate_deviation = vpar_SynchroUpdateTab(
119                             &p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo & 0x1)],
120                             p_vpar->synchro.current_b_count);
121             if (candidate_deviation < optimal_deviation)
122             {
123                 optimal_deviation = candidate_deviation;
124                 predict = p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo & 0x1)].mean;
125             }
126
127             candidate_deviation = vpar_SynchroUpdateTab(
128                             &p_vpar->synchro.tab_b[3 + (p_vpar->synchro.modulo % 3)],
129                             p_vpar->synchro.current_b_count);
130             if (candidate_deviation < optimal_deviation)
131             {
132                 optimal_deviation = candidate_deviation;
133                 predict = p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo % 3)].mean;
134             }
135
136             p_vpar->synchro.b_count_predict = predict;
137
138
139             break;
140     }
141
142     p_vpar->synchro.modulo++;
143 }
144
145 /*****************************************************************************
146  * vpar_SynchroChoose : Decide whether we will decode a picture or not
147  *****************************************************************************/
148 boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type,
149                               int i_structure )
150 {
151 //    return( 1 );
152     return( i_coding_type == I_CODING_TYPE || i_coding_type == P_CODING_TYPE );
153     //return( i_coding_type == I_CODING_TYPE );
154 }
155
156 /*****************************************************************************
157  * vpar_SynchroTrash : Update timers when we trash a picture
158  *****************************************************************************/
159 void vpar_SynchroTrash( vpar_thread_t * p_vpar, int i_coding_type,
160                         int i_structure )
161 {
162     vpar_SynchroUpdateStructures (p_vpar, i_coding_type);
163
164 }
165
166 /*****************************************************************************
167  * vpar_SynchroDecode : Update timers when we decide to decode a picture
168  *****************************************************************************/
169 mtime_t vpar_SynchroDecode( vpar_thread_t * p_vpar, int i_coding_type,
170                             int i_structure )
171 {
172     vpar_SynchroUpdateStructures (p_vpar, i_coding_type);
173
174     return mdate() + 700000;
175 }
176
177 /*****************************************************************************
178  * vpar_SynchroEnd : Called when the image is totally decoded
179  *****************************************************************************/
180 void vpar_SynchroEnd( vpar_thread_t * p_vpar )
181 {
182
183 }
184