summaryrefslogtreecommitdiff
path: root/community/ogle/xvideofix.patch
blob: aafde447ab08e781419a687f377019b01c204593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
--- ogle-0.9.2/mpeg2_video/video_output_x11.c	2003-11-04 04:02:10.000000000 -0800
+++ ogle-0.9.2-patch/mpeg2_video/video_output_x11.c	2005-04-22 18:37:56.000000000 -0700
@@ -286,6 +286,7 @@
   }
 }
 
+
 /* This section of the code looks for the Xv extension for hardware
  * yuv->rgb and scaling. If it is not found, or any suitable adapter
  * is not found, use_xv will be set to 0. Otherwise it allocates a
@@ -299,121 +300,136 @@
 {
   int xv_found = 0;
 #ifdef HAVE_XV
-  int i, j;
+  int i, j, k;
   int result;
 
   xv_port = 0; /* We have no port yet. */
-  
+
   /* Check for the Xvideo extension */
-  result = XvQueryExtension(mydisplay, &xv_version, &xv_release, 
-			    &xv_request_base, &xv_event_base, 
+  result = XvQueryExtension(mydisplay, &xv_version, &xv_release,
+			    &xv_request_base, &xv_event_base,
 			    &xv_error_base);
   if(result != Success) {
     WARNING("%s", "Xvideo extension not found\n");
     use_xv = 0;
     return;
   }
-  
+
   NOTE("Found Xv extension %d.%d, checking for suitable adaptors\n",
        xv_version, xv_release);
-  
+
   /* Check for available adaptors */
-  result = XvQueryAdaptors(mydisplay, DefaultRootWindow (mydisplay), 
+  result = XvQueryAdaptors(mydisplay, DefaultRootWindow (mydisplay),
 			   &xv_num_adaptors, &xv_adaptor_info);
   if(result != Success) {
     WARNING("%s", "No Xv adaptors found\n");
     use_xv = 0;
     return;
   }
-      
+
   /* Check adaptors */
   for(i = 0; i < xv_num_adaptors; i++) {
-    
+
     /* Is it usable for displaying XvImages */
     if(!(xv_adaptor_info[i].type & XvInputMask) ||
        !(xv_adaptor_info[i].type & XvImageMask))
       continue;
-    
-    xv_port = xv_adaptor_info[i].base_id;
-      
-    /* Check image formats of adaptor */
-    xv_formats = XvListImageFormats(mydisplay, xv_port, &xv_num_formats);
-    for(j = 0; j < xv_num_formats; j++) {
-      if(xv_formats[j].id == 0x32315659) { /* YV12 */
-	//if(xv_formats[j].id == 0x30323449) { /* I420 */
-	xv_id = xv_formats[j].id;
-	break;
-      } 
-    }
-    /* No matching format found */
-    if(j == xv_num_formats)
-      continue;
-      
-    NOTE("Xv adaptor \"%s\" port %li image format %i\n",
-	 xv_adaptor_info[i].name, xv_port, xv_id);
-      
-    /* Allocate XvImages */
+
+		/* Check Available Ports */
+		for (j = 0; j <  xv_adaptor_info[i].num_ports && !xv_port ; j++) {
+			
+			/* Check Image formats of adaptor */
+			xv_formats = XvListImageFormats(mydisplay,xv_adaptor_info[i].base_id + j, &xv_num_formats); 
+			for (k = 0; k < xv_num_formats; k ++) {
+				
+				/* Check for proper format (YV12) and see if we can grab the port */			
+				if ( (xv_formats[k].id == 0x32315659) && (XvGrabPort(mydisplay,xv_adaptor_info[i].base_id + j,0) == Success) ) { 
+					xv_id = xv_formats[k].id;
+					xv_port = xv_adaptor_info[i].base_id +  j;
+					break;
+					}
+				
+				}
+
+			/* delete stuff nicely */
+			XFree(xv_formats);	
+			}
+		
+		/* Check next Adapter */
+		if (xv_port==0) continue;		
+				
+		/* Report what we found */							
+    NOTE("Xv adaptor \"%s\" port %li image format %i\n", xv_adaptor_info[i].name, xv_port, xv_id);
+			
+		/* Allocate XvImage */
     xv_image = XvShmCreateImage(mydisplay, xv_port, xv_id, NULL,
 				padded_width,
-				padded_height, 
+				padded_height,
 				&shm_info);
-    
-    /* Got an Image? */
+
+    /* Got an milk? */
     if(xv_image == NULL)
       continue;
-    
+		
     /* Test and see if we really got padded_width x padded_height */
     if(xv_image->width != padded_width ||
        xv_image->height != padded_height) {
       FATAL("XvShmCreateImage got size: %d x %d\n",
 	    xv_image->width, xv_image->height);
       exit(1);
-    }
-    
+    	}
+		
+		/* Now Finish Up */
     shm_info.shmid = picture_buffer_shmid;
     shm_info.shmaddr = picture_buffer_addr;
-    
-    /* Set the data pointer to the decoders picture segment. */  
+
+    /* Set the data pointer to the decoders picture segment. */
     //    xv_image->data = picture_data->y;
     shm_info.readOnly = True;
-    
+
     /* make sure we don't have any unhandled errors */
     XSync(mydisplay, False);
-    
+
     /* set error handler so we can check if xshmattach failed */
     prev_xerrhandler = XSetErrorHandler(xshm_errorhandler);
-    
+
     /* get the serial of the xshmattach request */
     req_serial = NextRequest(mydisplay);
-    
+
     /* try to attach */
     XShmAttach(mydisplay, &shm_info);
-    
+
     /* make sure xshmattach has been processed and any errors
        have been returned to us */
     XSync(mydisplay, False);
-    
+
     /* revert to the previous xerrorhandler */
     XSetErrorHandler(prev_xerrhandler);
-    
+
     if(use_xshm) {
 #if 0
       shmctl(shm_info.shmid, IPC_RMID, 0); // only works on Linux..
 #endif
-      
+
       CompletionType = XShmGetEventBase(mydisplay) + ShmCompletion;
     }
     xv_found = 1;
 
     /* All set up! */
     break;
-  }
+		}
+	
+	/* Clean up */
+	XvFreeAdaptorInfo(xv_adaptor_info);
+
 #endif /* HAVE_XV */
+	/* In case we didn't find a working Xv */ 
   if(!xv_found) {
     use_xv = 0;
-  }
-}
-     
+	  }
+	
+	}
+
 
 /* This section of the code tries to use the MIT XShm extension for 
  * accellerated transfers to to X. XShm extension is need and only
@@ -1726,6 +1742,8 @@
 
   if(mydisplay) {
     XSync(mydisplay,True);
+    if (use_xv) 
+      XvUngrabPort(mydisplay,xv_port,CurrentTime);
     if(use_xshm)
       XShmDetach(mydisplay, &shm_info);
     if(window.ximage != 0)