1 /*****************************************************************************
2 * vpar_motion.c : motion vectors parsing
4 *****************************************************************************/
6 /*****************************************************************************
8 *****************************************************************************/
19 #include "vlc_thread.h"
22 #include "debug.h" /* ?? temporaire, requis par netlist.h */
25 #include "input_netlist.h"
26 #include "decoder_fifo.h"
28 #include "video_output.h"
30 #include "vdec_idct.h"
31 #include "video_decoder.h"
32 #include "vdec_motion.h"
34 #include "vpar_blocks.h"
35 #include "vpar_headers.h"
36 #include "video_fifo.h"
37 #include "vpar_synchro.h"
38 #include "video_parser.h"
46 /*****************************************************************************
47 * vpar_SynchroUpdateTab : Update a mean table in the synchro structure
48 *****************************************************************************/
49 float vpar_SynchroUpdateTab( video_synchro_tab_t * tab, int count )
52 tab->mean = ( tab->mean + MAX_COUNT * count ) / ( MAX_COUNT + 1 );
53 tab->deviation = ( tab->deviation + MAX_COUNT * abs (tab->mean - count) )
56 return tab->deviation;
59 /*****************************************************************************
60 * vpar_SynchroUpdateStructures : Update the synchro structures
61 *****************************************************************************/
62 void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar,
65 float candidate_deviation;
66 float optimal_deviation;
72 p_vpar->synchro.current_p_count++;
75 p_vpar->synchro.current_b_count++;
79 /* update all the structures for P images */
82 optimal_deviation = vpar_SynchroUpdateTab(
83 &p_vpar->synchro.tab_p[0],
84 p_vpar->synchro.current_p_count);
85 predict = p_vpar->synchro.tab_p[0].mean;
88 candidate_deviation = vpar_SynchroUpdateTab(
89 &p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo & 0x1)],
90 p_vpar->synchro.current_p_count);
91 if (candidate_deviation < optimal_deviation)
93 optimal_deviation = candidate_deviation;
94 predict = p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo & 0x1)].mean;
98 candidate_deviation = vpar_SynchroUpdateTab(
99 &p_vpar->synchro.tab_p[3 + (p_vpar->synchro.modulo % 3)],
100 p_vpar->synchro.current_p_count);
101 if (candidate_deviation < optimal_deviation)
103 optimal_deviation = candidate_deviation;
104 predict = p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo % 3)].mean;
107 p_vpar->synchro.p_count_predict = predict;
108 p_vpar->synchro.current_p_count = 0;
111 /* update all the structures for B images */
114 optimal_deviation = vpar_SynchroUpdateTab(
115 &p_vpar->synchro.tab_b[0],
116 p_vpar->synchro.current_b_count);
117 predict = p_vpar->synchro.tab_b[0].mean;
120 candidate_deviation = vpar_SynchroUpdateTab(
121 &p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo & 0x1)],
122 p_vpar->synchro.current_b_count);
123 if (candidate_deviation < optimal_deviation)
125 optimal_deviation = candidate_deviation;
126 predict = p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo & 0x1)].mean;
130 candidate_deviation = vpar_SynchroUpdateTab(
131 &p_vpar->synchro.tab_b[3 + (p_vpar->synchro.modulo % 3)],
132 p_vpar->synchro.current_b_count);
133 if (candidate_deviation < optimal_deviation)
135 optimal_deviation = candidate_deviation;
136 predict = p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo % 3)].mean;
139 p_vpar->synchro.b_count_predict = predict;
140 p_vpar->synchro.current_b_count = 0;
146 p_vpar->synchro.modulo++;
149 /*****************************************************************************
150 * vpar_SynchroChoose : Decide whether we will decode a picture or not
151 *****************************************************************************/
152 boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type,
158 if( i_coding_type == 1 )
160 if( i_coding_type == 2 )
167 return( i_coding_type == I_CODING_TYPE || (i_coding_type == P_CODING_TYPE) && (meuh == 2));
168 intf_DbgMsg("vpar debug: synchro image %i - modulo is %i\n", i_coding_type, p_vpar->synchro.modulo);
169 intf_DbgMsg("vpar debug: synchro predict P %e - predict B %e\n", p_vpar->synchro.p_count_predict, p_vpar->synchro.b_count_predict);
172 return( i_coding_type == I_CODING_TYPE );
175 /*****************************************************************************
176 * vpar_SynchroTrash : Update timers when we trash a picture
177 *****************************************************************************/
178 void vpar_SynchroTrash( vpar_thread_t * p_vpar, int i_coding_type,
181 //fprintf ( stderr, "trashing type %i\n", p_vpar->picture.i_coding_type );
183 vpar_SynchroUpdateStructures (p_vpar, i_coding_type);
187 /*****************************************************************************
188 * vpar_SynchroDecode : Update timers when we decide to decode a picture
189 *****************************************************************************/
190 void vpar_SynchroDecode( vpar_thread_t * p_vpar, int i_coding_type,
193 //fprintf ( stderr, "decoding type %i\n", p_vpar->picture.i_coding_type );
195 vpar_SynchroUpdateStructures (p_vpar, i_coding_type);
197 p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_stop].decode_date = mdate();
198 p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_stop].i_image_type
200 p_vpar->synchro.i_fifo_stop = (p_vpar->synchro.i_fifo_stop + 1) & 0xf;
202 fprintf ( stderr, "%i images in synchro fifo\n", ( p_vpar->synchro.i_fifo_stop - p_vpar->synchro.i_fifo_start ) & 0xf );
205 /*****************************************************************************
206 * vpar_SynchroEnd : Called when the image is totally decoded
207 *****************************************************************************/
208 void vpar_SynchroEnd( vpar_thread_t * p_vpar )
210 mtime_t * p_decode_time;
212 fprintf ( stderr, "type %i decoding time was %lli\n",
213 p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].i_image_type,
215 - p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].decode_date )
216 / (( p_vpar->synchro.i_fifo_stop - p_vpar->synchro.i_fifo_start ) & 0xf ));
218 p_vpar->synchro.decode_time =
219 ( (p_vpar->synchro.decode_time * 3) + (mdate()
220 - p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].decode_date)
221 / (( p_vpar->synchro.i_fifo_stop - p_vpar->synchro.i_fifo_start)
224 p_vpar->synchro.i_fifo_start = (p_vpar->synchro.i_fifo_start + 1) & 0xf;
227 /*****************************************************************************
228 * vpar_SynchroDate : When an image has been decoded, ask for its date
229 *****************************************************************************/
230 mtime_t vpar_SynchroDate( vpar_thread_t * p_vpar )
232 decoder_fifo_t * fifo;
235 fifo = p_vpar->bit_stream.p_decoder_fifo;
236 displaydate = fifo->buffer[fifo->i_start]->i_pts;
238 if (displaydate) fprintf(stderr, "displaying type %i at %lli, (time %lli, delta %lli)\n", p_vpar->synchro.fifo[p_vpar->synchro.i_fifo_start].i_image_type, displaydate, mdate() + 1000000, displaydate - mdate() - 1000000);