]> git.sesse.net Git - vlc/blob - src/video_parser/vpar_synchro.c
c2038d1f8246ceea4217cad55feb9fb3a00a6665
[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             p_vpar->synchro.current_p_count = 0;
111
112
113             /* 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;
118
119             candidate_deviation = vpar_SynchroUpdateTab(
120                             &p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo & 0x1)],
121                             p_vpar->synchro.current_b_count);
122             if (candidate_deviation < optimal_deviation)
123             {
124                 optimal_deviation = candidate_deviation;
125                 predict = p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo & 0x1)].mean;
126             }
127
128             candidate_deviation = vpar_SynchroUpdateTab(
129                             &p_vpar->synchro.tab_b[3 + (p_vpar->synchro.modulo % 3)],
130                             p_vpar->synchro.current_b_count);
131             if (candidate_deviation < optimal_deviation)
132             {
133                 optimal_deviation = candidate_deviation;
134                 predict = p_vpar->synchro.tab_b[1 + (p_vpar->synchro.modulo % 3)].mean;
135             }
136
137             p_vpar->synchro.b_count_predict = predict;
138             p_vpar->synchro.current_b_count = 0;
139
140
141             break;
142     }
143
144     p_vpar->synchro.modulo++;
145 }
146
147 /*****************************************************************************
148  * vpar_SynchroChoose : Decide whether we will decode a picture or not
149  *****************************************************************************/
150 boolean_t vpar_SynchroChoose( vpar_thread_t * p_vpar, int i_coding_type,
151                               int i_structure )
152 {
153 //    return( 1 );
154 //    return( i_coding_type == I_CODING_TYPE || i_coding_type == P_CODING_TYPE );
155     intf_DbgMsg("vpar debug: synchro image %i - modulo is %i\n", i_coding_type, p_vpar->synchro.modulo);
156     intf_DbgMsg("vpar debug: synchro predict P %e - predict B %e\n", p_vpar->synchro.p_count_predict, p_vpar->synchro.b_count_predict);
157
158     return( i_coding_type == I_CODING_TYPE );
159 }
160
161 /*****************************************************************************
162  * vpar_SynchroTrash : Update timers when we trash a picture
163  *****************************************************************************/
164 void vpar_SynchroTrash( vpar_thread_t * p_vpar, int i_coding_type,
165                         int i_structure )
166 {
167     vpar_SynchroUpdateStructures (p_vpar, i_coding_type);
168
169 }
170
171 /*****************************************************************************
172  * vpar_SynchroDecode : Update timers when we decide to decode a picture
173  *****************************************************************************/
174 mtime_t vpar_SynchroDecode( vpar_thread_t * p_vpar, int i_coding_type,
175                             int i_structure )
176 {
177     vpar_SynchroUpdateStructures (p_vpar, i_coding_type);
178
179     return mdate() + 700000;
180 }
181
182 /*****************************************************************************
183  * vpar_SynchroEnd : Called when the image is totally decoded
184  *****************************************************************************/
185 void vpar_SynchroEnd( vpar_thread_t * p_vpar )
186 {
187
188 }
189