1 /*****************************************************************************
2 * vpar_motion.c : motion vectors parsing
4 *****************************************************************************/
6 /*****************************************************************************
8 *****************************************************************************/
16 #include <X11/extensions/XShm.h>
21 #include "vlc_thread.h"
24 #include "debug.h" /* ?? temporaire, requis par netlist.h */
27 #include "input_netlist.h"
28 #include "decoder_fifo.h"
30 #include "video_output.h"
32 #include "vdec_idct.h"
33 #include "video_decoder.h"
34 #include "vdec_motion.h"
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"
48 /*****************************************************************************
49 * vpar_SynchroUpdateTab : Update a mean table in the synchro structure
50 *****************************************************************************/
51 double vpar_SynchroUpdateTab( video_synchro_tab_t * tab, int count )
53 if( tab->count < MAX_COUNT)
56 tab->mean = ( (tab->count-1) * tab->mean + count )
59 tab->deviation = ( (tab->count-1) * tab->deviation
60 + abs (tab->mean - count) ) / tab->count;
62 return tab->deviation;
65 /*****************************************************************************
66 * vpar_SynchroUpdateStructures : Update the synchro structures
67 *****************************************************************************/
68 void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar,
71 double candidate_deviation;
72 double optimal_deviation;
78 p_vpar->synchro.current_p_count++;
81 p_vpar->synchro.current_b_count++;
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;
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)
96 optimal_deviation = candidate_deviation;
97 predict = p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo & 0x1)].mean;
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)
105 optimal_deviation = candidate_deviation;
106 predict = p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo % 3)].mean;
109 p_vpar->synchro.p_count_predict = predict;
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;
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)
123 optimal_deviation = candidate_deviation;
124 predict = p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo & 0x1)].mean;
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)
132 optimal_deviation = candidate_deviation;
133 predict = p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo % 3)].mean;
136 p_vpar->synchro.b_count_predict = predict;
142 p_vpar->synchro.modulo++;
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,
152 // return( i_coding_type == I_CODING_TYPE || i_coding_type == P_CODING_TYPE );
153 return( i_coding_type == I_CODING_TYPE );
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,
162 vpar_SynchroUpdateStructures (p_vpar, i_coding_type);
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,
172 vpar_SynchroUpdateStructures (p_vpar, i_coding_type);
174 return mdate() + 700000;
177 /*****************************************************************************
178 * vpar_SynchroEnd : Called when the image is totally decoded
179 *****************************************************************************/
180 void vpar_SynchroEnd( vpar_thread_t * p_vpar )