]> git.sesse.net Git - vlc/blob - src/video_parser/vpar_synchro.c
. ultimisation des calculs de pr�diction dans la synchro
[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         
54     tab->mean = ( tab->mean + 3 * count ) / 4;
55     tab->deviation = ( tab->deviation + 3 * abs (tab->mean - count) ) / 4;
56
57     return tab->deviation;
58 }
59
60 /*****************************************************************************
61  * vpar_SynchroUpdateStructures : Update the synchro structures
62  *****************************************************************************/
63 void vpar_SynchroUpdateStructures( vpar_thread_t * p_vpar,
64                                    int i_coding_type )
65 {
66     double candidate_deviation;
67     double optimal_deviation;
68     double predict;
69
70     switch(i_coding_type)
71     {
72         case P_CODING_TYPE:
73             p_vpar->synchro.current_p_count++;
74             break;
75         case B_CODING_TYPE:
76             p_vpar->synchro.current_b_count++;
77             break;
78         case I_CODING_TYPE:
79
80             /* update all the structures for P images */
81             optimal_deviation = vpar_SynchroUpdateTab(
82                             &p_vpar->synchro.tab_p[0],
83                             p_vpar->synchro.current_p_count);
84             predict = p_vpar->synchro.tab_p[0].mean;
85
86             candidate_deviation = vpar_SynchroUpdateTab(
87                             &p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo & 0x1)],
88                             p_vpar->synchro.current_p_count);
89             if (candidate_deviation < optimal_deviation)
90             {
91                 optimal_deviation = candidate_deviation;
92                 predict = p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo & 0x1)].mean;
93             }
94
95             candidate_deviation = vpar_SynchroUpdateTab(
96                             &p_vpar->synchro.tab_p[3 + (p_vpar->synchro.modulo % 3)],
97                             p_vpar->synchro.current_p_count);
98             if (candidate_deviation < optimal_deviation)
99             {
100                 optimal_deviation = candidate_deviation;
101                 predict = p_vpar->synchro.tab_p[1 + (p_vpar->synchro.modulo % 3)].mean;
102             }
103
104             p_vpar->synchro.p_count_predict = predict;
105             p_vpar->synchro.current_p_count = 0;
106
107
108             /* update all the structures for B images */
109             optimal_deviation = vpar_SynchroUpdateTab(
110                             &p_vpar->synchro.tab_b[0],
111                             p_vpar->synchro.current_b_count);
112             predict = p_vpar->synchro.tab_b[0].mean;
113
114             candidate_deviation = vpar_SynchroUpdateTab(
115                             &p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo & 0x1)],
116                             p_vpar->synchro.current_b_count);
117             if (candidate_deviation < optimal_deviation)
118             {
119                 optimal_deviation = candidate_deviation;
120                 predict = p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo & 0x1)].mean;
121             }
122
123             candidate_deviation = vpar_SynchroUpdateTab(
124                             &p_vpar->synchro.tab_b[3 + (p_vpar->synchro.modulo % 3)],
125                             p_vpar->synchro.current_b_count);
126             if (candidate_deviation < optimal_deviation)
127             {
128                 optimal_deviation = candidate_deviation;
129                 predict = p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo % 3)].mean;
130             }
131
132             p_vpar->synchro.b_count_predict = predict;
133             p_vpar->synchro.current_b_count = 0;
134
135
136             break;
137     }
138
139     p_vpar->synchro.modulo++;
140 }
141
142 /*****************************************************************************
143  * vpar_SynchroChoose : Decide whether we will decode a picture or not
144  *****************************************************************************/
145 boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type,
146                               int i_structure )
147 {
148 //    return( 1 );
149 //    return( i_coding_type == I_CODING_TYPE || i_coding_type == P_CODING_TYPE );
150     intf_DbgMsg("vpar debug: synchro image %i - modulo is %i\n", i_coding_type, p_vpar->synchro.modulo);
151     intf_DbgMsg("vpar debug: synchro predict P %e - predict B %e\n", p_vpar->synchro.p_count_predict, p_vpar->synchro.b_count_predict);
152
153     return(0);
154     return( i_coding_type == I_CODING_TYPE );
155 }
156
157 /*****************************************************************************
158  * vpar_SynchroTrash : Update timers when we trash a picture
159  *****************************************************************************/
160 void vpar_SynchroTrash( vpar_thread_t * p_vpar, int i_coding_type,
161                         int i_structure )
162 {
163     vpar_SynchroUpdateStructures (p_vpar, i_coding_type);
164
165 }
166
167 /*****************************************************************************
168  * vpar_SynchroDecode : Update timers when we decide to decode a picture
169  *****************************************************************************/
170 mtime_t vpar_SynchroDecode( vpar_thread_t * p_vpar, int i_coding_type,
171                             int i_structure )
172 {
173     vpar_SynchroUpdateStructures (p_vpar, i_coding_type);
174
175     return mdate() + 700000;
176 }
177
178 /*****************************************************************************
179  * vpar_SynchroEnd : Called when the image is totally decoded
180  *****************************************************************************/
181 void vpar_SynchroEnd( vpar_thread_t * p_vpar )
182 {
183
184 }
185