Mercurial > mplayer.hg
annotate libvo/vo_corevideo.m @ 29573:2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
author | reimar |
---|---|
date | Tue, 01 Sep 2009 20:09:01 +0000 |
parents | 349de9bdfcce |
children | 0aa36133f638 |
rev | line source |
---|---|
28446
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
1 /* |
29210 | 2 * CoreVideo video output driver |
28836 | 3 * Copyright (c) 2005 Nicolas Plourde <nicolasplourde@gmail.com> |
4 * | |
28446
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
5 * This file is part of MPlayer. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
6 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
7 * MPlayer is free software; you can redistribute it and/or modify |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
10 * (at your option) any later version. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
11 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
12 * MPlayer is distributed in the hope that it will be useful, |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
15 * GNU General Public License for more details. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
16 * |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
17 * You should have received a copy of the GNU General Public License along |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
18 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
20 */ |
7681eab10aea
Add standard license headers, unify header formatting.
diego
parents:
28306
diff
changeset
|
21 |
29210 | 22 #import "vo_corevideo.h" |
16385 | 23 #include <sys/types.h> |
24 #include <sys/ipc.h> | |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
25 #include <sys/mman.h> |
28077 | 26 #include <unistd.h> |
27988 | 27 #include <CoreServices/CoreServices.h> |
28 //special workaround for Apple bug #6267445 | |
29 //(OSServices Power API disabled in OSServices.h for 64bit systems) | |
30 #ifndef __POWER__ | |
31 #include <CoreServices/../Frameworks/OSServices.framework/Headers/Power.h> | |
32 #endif | |
15289 | 33 |
34 //MPLAYER | |
35 #include "config.h" | |
36 #include "fastmemcpy.h" | |
37 #include "video_out.h" | |
38 #include "video_out_internal.h" | |
39 #include "aspect.h" | |
40 #include "mp_msg.h" | |
41 #include "m_option.h" | |
28075
ca9badc94740
#include appropriate headers instead of locally declaring function prototypes.
diego
parents:
28051
diff
changeset
|
42 #include "mp_fifo.h" |
ca9badc94740
#include appropriate headers instead of locally declaring function prototypes.
diego
parents:
28051
diff
changeset
|
43 #include "libvo/sub.h" |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
44 #include "subopt-helper.h" |
15289 | 45 |
46 #include "input/input.h" | |
47 #include "input/mouse.h" | |
48 | |
49 #include "osdep/keycodes.h" | |
29533
9c8f8e375823
Reuse the osx_common convert_key function to convert OSX keycodes to MPlayer
reimar
parents:
29272
diff
changeset
|
50 #include "osx_common.h" |
15289 | 51 |
52 //Cocoa | |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
53 NSDistantObject *mplayerosxProxy; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
54 id <MPlayerOSXVOProto> mplayerosxProto; |
15611 | 55 MPlayerOpenGLView *mpGLView; |
15289 | 56 NSAutoreleasePool *autoreleasepool; |
57 OSType pixelFormat; | |
58 | |
16385 | 59 //shared memory |
60 BOOL shared_buffer = false; | |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
61 #define DEFAULT_BUFFER_NAME "mplayerosx" |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
62 static char *buffer_name; |
16385 | 63 |
15728 | 64 //Screen |
28306 | 65 int screen_id = -1; |
15728 | 66 NSRect screen_frame; |
67 NSScreen *screen_handle; | |
68 NSArray *screen_array; | |
15289 | 69 |
70 //image | |
71 unsigned char *image_data; | |
25180 | 72 // For double buffering |
73 static uint8_t image_page = 0; | |
74 static unsigned char *image_datas[2]; | |
75 | |
15289 | 76 static uint32_t image_width; |
77 static uint32_t image_height; | |
78 static uint32_t image_depth; | |
79 static uint32_t image_bytes; | |
80 static uint32_t image_format; | |
81 | |
82 //vo | |
83 static int isFullscreen; | |
15320 | 84 static int isOntop; |
15327 | 85 static int isRootwin; |
25446 | 86 extern int enable_mouse_movements; |
15289 | 87 |
15731 | 88 static float winAlpha = 1; |
15289 | 89 static int int_pause = 0; |
90 | |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
91 static BOOL isLeopardOrLater; |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
92 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
93 static vo_info_t info = |
15289 | 94 { |
28837 | 95 "Mac OS X Core Video", |
29210 | 96 "corevideo", |
15289 | 97 "Nicolas Plourde <nicolas.plourde@gmail.com>", |
98 "" | |
99 }; | |
100 | |
29210 | 101 LIBVO_EXTERN(corevideo) |
15289 | 102 |
103 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) | |
104 { | |
105 switch (image_format) | |
106 { | |
107 case IMGFMT_RGB32: | |
108 vo_draw_alpha_rgb32(w,h,src,srca,stride,image_data+4*(y0*image_width+x0),4*image_width); | |
109 break; | |
110 case IMGFMT_YUY2: | |
111 vo_draw_alpha_yuy2(w,h,src,srca,stride,image_data + (x0 + y0 * image_width) * 2,image_width*2); | |
112 break; | |
113 } | |
114 } | |
115 | |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
116 static void update_screen_info(void) |
15289 | 117 { |
15728 | 118 screen_array = [NSScreen screens]; |
29177
1dfd99eb3280
Fix a signedness issue that caused a warning to be wrongfully printed at runtime.
gpoirier
parents:
29170
diff
changeset
|
119 if(screen_id < (int)[screen_array count]) |
15289 | 120 { |
28306 | 121 screen_handle = [screen_array objectAtIndex:(screen_id < 0 ? 0 : screen_id)]; |
15289 | 122 } |
15728 | 123 else |
124 { | |
29210 | 125 mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] Device ID %d does not exist, falling back to main device\n", screen_id); |
15728 | 126 screen_handle = [screen_array objectAtIndex:0]; |
28306 | 127 screen_id = -1; |
15728 | 128 } |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
129 |
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
130 screen_frame = ![mpGLView window] || screen_id >= 0 ? [screen_handle frame] : [[[mpGLView window] screen] frame]; |
25414
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
131 vo_screenwidth = screen_frame.size.width; |
5c03a9bdf220
Record screen size and display size in vo_ variables.
ulion
parents:
25413
diff
changeset
|
132 vo_screenheight = screen_frame.size.height; |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
133 xinerama_x = xinerama_y = 0; |
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
134 aspect_save_screenres(vo_screenwidth, vo_screenheight); |
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
135 } |
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
136 |
29573
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
137 static void free_file_specific(void) |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
138 { |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
139 if(shared_buffer) |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
140 { |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
141 [mplayerosxProto stop]; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
142 mplayerosxProto = nil; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
143 [mplayerosxProxy release]; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
144 mplayerosxProxy = nil; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
145 |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
146 if (munmap(image_data, image_width*image_height*image_bytes) == -1) |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
147 mp_msg(MSGT_VO, MSGL_FATAL, "[vo_corevideo] uninit: munmap failed. Error: %s\n", strerror(errno)); |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
148 |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
149 if (shm_unlink(buffer_name) == -1) |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
150 mp_msg(MSGT_VO, MSGL_FATAL, "[vo_corevideo] uninit: shm_unlink failed. Error: %s\n", strerror(errno)); |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
151 } else { |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
152 free(image_datas[0]); |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
153 if (vo_doublebuffering) |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
154 free(image_datas[1]); |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
155 image_datas[0] = NULL; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
156 image_datas[1] = NULL; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
157 image_data = NULL; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
158 } |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
159 } |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
160 |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
161 static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
162 { |
29573
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
163 free_file_specific(); |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
164 config_movie_aspect((float)d_width/d_height); |
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
165 |
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
166 vo_dwidth = d_width *= mpGLView->winSizeMult; |
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
167 vo_dheight = d_height *= mpGLView->winSizeMult; |
16385 | 168 |
15289 | 169 //misc mplayer setup |
170 image_width = width; | |
171 image_height = height; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
172 switch (image_format) |
15289 | 173 { |
174 case IMGFMT_BGR32: | |
175 case IMGFMT_RGB32: | |
176 image_depth = 32; | |
177 break; | |
16385 | 178 case IMGFMT_YUY2: |
15289 | 179 image_depth = 16; |
180 break; | |
181 } | |
182 image_bytes = (image_depth + 7) / 8; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
183 |
16385 | 184 if(!shared_buffer) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
185 { |
25120
9b4ca4dc1294
Fix a memory leak when working in shared_buffer mode.
ulion
parents:
25114
diff
changeset
|
186 image_data = malloc(image_width*image_height*image_bytes); |
25180 | 187 image_datas[0] = image_data; |
188 if (vo_doublebuffering) | |
189 image_datas[1] = malloc(image_width*image_height*image_bytes); | |
190 image_page = 0; | |
25120
9b4ca4dc1294
Fix a memory leak when working in shared_buffer mode.
ulion
parents:
25114
diff
changeset
|
191 |
16385 | 192 vo_fs = flags & VOFLAG_FULLSCREEN; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
193 |
16385 | 194 //config OpenGL View |
195 [mpGLView config]; | |
196 [mpGLView reshape]; | |
197 } | |
198 else | |
199 { | |
29567
349de9bdfcce
Make shm_fd a local variable and close it when we need it no longer, thus
reimar
parents:
29566
diff
changeset
|
200 int shm_fd; |
29210 | 201 mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] writing output to a shared buffer " |
29170
9d40283d9a5d
Unify error message output and update error messages.
diego
parents:
29137
diff
changeset
|
202 "named \"%s\"\n",buffer_name); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
203 |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
204 // create shared memory |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
205 shm_fd = shm_open(buffer_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
206 if (shm_fd == -1) |
16385 | 207 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
208 mp_msg(MSGT_VO, MSGL_FATAL, |
29210 | 209 "[vo_corevideo] failed to open shared memory. Error: %s\n", strerror(errno)); |
16385 | 210 return 1; |
211 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
212 |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
213 |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
214 if (ftruncate(shm_fd, image_width*image_height*image_bytes) == -1) |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
215 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
216 mp_msg(MSGT_VO, MSGL_FATAL, |
29210 | 217 "[vo_corevideo] failed to size shared memory, possibly already in use. Error: %s\n", strerror(errno)); |
29567
349de9bdfcce
Make shm_fd a local variable and close it when we need it no longer, thus
reimar
parents:
29566
diff
changeset
|
218 close(shm_fd); |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
219 shm_unlink(buffer_name); |
16385 | 220 return 1; |
221 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
222 |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
223 image_data = mmap(NULL, image_width*image_height*image_bytes, |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
224 PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0); |
29567
349de9bdfcce
Make shm_fd a local variable and close it when we need it no longer, thus
reimar
parents:
29566
diff
changeset
|
225 close(shm_fd); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
226 |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
227 if (image_data == MAP_FAILED) |
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
228 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
229 mp_msg(MSGT_VO, MSGL_FATAL, |
29210 | 230 "[vo_corevideo] failed to map shared memory. Error: %s\n", strerror(errno)); |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
231 shm_unlink(buffer_name); |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
232 return 1; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
233 } |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
234 |
28837 | 235 //connect to mplayerosx |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
236 mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:[NSString stringWithCString:buffer_name] host:nil]; |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
237 if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) { |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
238 [mplayerosxProxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
239 mplayerosxProto = (id <MPlayerOSXVOProto>)mplayerosxProxy; |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
240 [mplayerosxProto startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:d_width*100/d_height]; |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
241 } |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
242 else { |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
243 [mplayerosxProxy release]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
244 mplayerosxProxy = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
245 mplayerosxProto = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
246 } |
16385 | 247 } |
15289 | 248 return 0; |
249 } | |
250 | |
251 static void check_events(void) | |
252 { | |
29272
c95bad660986
When used with shared_buffer, there's no need for a NSApp object, which causes MPlayer to be marked as unresponsive.
adrian
parents:
29271
diff
changeset
|
253 if (mpGLView) |
c95bad660986
When used with shared_buffer, there's no need for a NSApp object, which causes MPlayer to be marked as unresponsive.
adrian
parents:
29271
diff
changeset
|
254 [mpGLView check_events]; |
15289 | 255 } |
256 | |
257 static void draw_osd(void) | |
258 { | |
259 vo_draw_text(image_width, image_height, draw_alpha); | |
260 } | |
261 | |
262 static void flip_page(void) | |
263 { | |
29271
82b6fbc72099
When used with shared_buffer, autorelease in each flip_page so objects don't accumulate until exit.
adrian
parents:
29263
diff
changeset
|
264 if(shared_buffer) { |
82b6fbc72099
When used with shared_buffer, autorelease in each flip_page so objects don't accumulate until exit.
adrian
parents:
29263
diff
changeset
|
265 NSAutoreleasePool *pool = [NSAutoreleasePool new]; |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
266 [mplayerosxProto render]; |
29271
82b6fbc72099
When used with shared_buffer, autorelease in each flip_page so objects don't accumulate until exit.
adrian
parents:
29263
diff
changeset
|
267 [pool release]; |
82b6fbc72099
When used with shared_buffer, autorelease in each flip_page so objects don't accumulate until exit.
adrian
parents:
29263
diff
changeset
|
268 } else { |
25114
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
269 [mpGLView setCurrentTexture]; |
16385 | 270 [mpGLView render]; |
25180 | 271 if (vo_doublebuffering) { |
272 image_page = 1 - image_page; | |
273 image_data = image_datas[image_page]; | |
274 } | |
25114
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
275 } |
15289 | 276 } |
277 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
278 static int draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) |
15289 | 279 { |
280 return 0; | |
281 } | |
282 | |
283 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
284 static int draw_frame(uint8_t *src[]) |
15289 | 285 { |
286 switch (image_format) | |
287 { | |
288 case IMGFMT_BGR32: | |
289 case IMGFMT_RGB32: | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
23381
diff
changeset
|
290 fast_memcpy(image_data, src[0], image_width*image_height*image_bytes); |
15289 | 291 break; |
292 | |
293 case IMGFMT_YUY2: | |
294 memcpy_pic(image_data, src[0], image_width * 2, image_height, image_width * 2, image_width * 2); | |
295 break; | |
296 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
297 |
15289 | 298 return 0; |
299 } | |
300 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
301 static int query_format(uint32_t format) |
15289 | 302 { |
303 image_format = format; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
304 |
15289 | 305 switch(format) |
306 { | |
307 case IMGFMT_YUY2: | |
308 pixelFormat = kYUVSPixelFormat; | |
309 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
310 |
15289 | 311 case IMGFMT_RGB32: |
312 case IMGFMT_BGR32: | |
313 pixelFormat = k32ARGBPixelFormat; | |
314 return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN; | |
315 } | |
316 return 0; | |
317 } | |
318 | |
319 static void uninit(void) | |
320 { | |
21551 | 321 SetSystemUIMode( kUIModeNormal, 0); |
322 CGDisplayShowCursor(kCGDirectMainDisplay); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
323 |
29573
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
324 free_file_specific(); |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
325 |
21551 | 326 if(mpGLView) |
327 { | |
25136 | 328 NSAutoreleasePool *finalPool; |
24742
0bef706332b5
Fix deallocate bug which sometimes causes a crash when reinitializing.
nplourde
parents:
24698
diff
changeset
|
329 mpGLView = nil; |
21551 | 330 [autoreleasepool release]; |
25136 | 331 finalPool = [[NSAutoreleasePool alloc] init]; |
25078
3efbdaab822f
Let NSApp handle events when uninit to fix the delay dealloc bug of mpGLView.
ulion
parents:
24965
diff
changeset
|
332 [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES]; |
3efbdaab822f
Let NSApp handle events when uninit to fix the delay dealloc bug of mpGLView.
ulion
parents:
24965
diff
changeset
|
333 [finalPool release]; |
21551 | 334 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
335 |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
336 if (buffer_name) free(buffer_name); |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
337 buffer_name = NULL; |
15289 | 338 } |
339 | |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
340 static opt_t subopts[] = { |
28306 | 341 {"device_id", OPT_ARG_INT, &screen_id, NULL}, |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
342 {"shared_buffer", OPT_ARG_BOOL, &shared_buffer, NULL}, |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
343 {"buffer_name", OPT_ARG_MSTRZ,&buffer_name, NULL}, |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
344 {NULL} |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
345 }; |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
346 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
347 static int preinit(const char *arg) |
15289 | 348 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
349 |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
350 // set defaults |
28306 | 351 screen_id = -1; |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
352 shared_buffer = false; |
28204 | 353 buffer_name = NULL; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
354 |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
355 if (subopt_parse(arg, subopts) != 0) { |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
356 mp_msg(MSGT_VO, MSGL_FATAL, |
29210 | 357 "\n-vo corevideo command line help:\n" |
358 "Example: mplayer -vo corevideo:device_id=1:shared_buffer:buffer_name=mybuff\n" | |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
359 "\nOptions:\n" |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
360 " device_id=<0-...>\n" |
28837 | 361 " Set screen device ID for fullscreen.\n" |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
362 " shared_buffer\n" |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
363 " Write output to a shared memory buffer instead of displaying it.\n" |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
364 " buffer_name=<name>\n" |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
365 " Name of the shared buffer created with shm_open() as well as\n" |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
366 " the name of the NSConnection MPlayer will try to open.\n" |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
367 " Setting buffer_name implicitly enables shared_buffer.\n" |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
368 "\n" ); |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
369 return -1; |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
370 } |
15728 | 371 |
15289 | 372 autoreleasepool = [[NSAutoreleasePool alloc] init]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
373 |
28204 | 374 if (!buffer_name) |
375 buffer_name = strdup(DEFAULT_BUFFER_NAME); | |
376 else | |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
377 shared_buffer = true; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
378 |
16385 | 379 if(!shared_buffer) |
16144 | 380 { |
29272
c95bad660986
When used with shared_buffer, there's no need for a NSApp object, which causes MPlayer to be marked as unresponsive.
adrian
parents:
29271
diff
changeset
|
381 NSApplicationLoad(); |
c95bad660986
When used with shared_buffer, there's no need for a NSApp object, which causes MPlayer to be marked as unresponsive.
adrian
parents:
29271
diff
changeset
|
382 NSApp = [NSApplication sharedApplication]; |
c95bad660986
When used with shared_buffer, there's no need for a NSApp object, which causes MPlayer to be marked as unresponsive.
adrian
parents:
29271
diff
changeset
|
383 isLeopardOrLater = floor(NSAppKitVersionNumber) > 824; |
c95bad660986
When used with shared_buffer, there's no need for a NSApp object, which causes MPlayer to be marked as unresponsive.
adrian
parents:
29271
diff
changeset
|
384 |
27397
d47744b95b78
Give a CONFIG_ prefix to preprocessor directives that lacked one and
diego
parents:
27394
diff
changeset
|
385 #if !defined (CONFIG_MACOSX_FINDER) || !defined (CONFIG_SDL) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
386 //this chunk of code is heavily based off SDL_macosx.m from SDL |
17358
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
387 ProcessSerialNumber myProc, frProc; |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
388 Boolean sameProc; |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
389 |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
390 if (GetFrontProcess(&frProc) == noErr) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
391 { |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
392 if (GetCurrentProcess(&myProc) == noErr) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
393 { |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
394 if (SameProcess(&frProc, &myProc, &sameProc) == noErr && !sameProc) |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
395 { |
27988 | 396 TransformProcessType(&myProc, kProcessTransformToForegroundApplication); |
17358
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
397 } |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
398 SetFrontProcess(&myProc); |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
399 } |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
400 } |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
401 #endif |
22ec2e9cb530
do not give focus to vo_macosx in shared buffer mode. Patch by Hector Chu<hectorchu@gmail.com>
nplourde
parents:
16385
diff
changeset
|
402 |
16385 | 403 if(!mpGLView) |
404 { | |
405 mpGLView = [[MPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPlayerOpenGLView defaultPixelFormat]]; | |
406 [mpGLView autorelease]; | |
407 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
408 |
16385 | 409 [mpGLView display]; |
410 [mpGLView preinit]; | |
16144 | 411 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
412 |
15289 | 413 return 0; |
414 } | |
415 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
416 static int control(uint32_t request, void *data, ...) |
15289 | 417 { |
418 switch (request) | |
419 { | |
26755
46f0b4d34fa1
cosmetics: Remove useless parentheses from from return statements.
diego
parents:
25468
diff
changeset
|
420 case VOCTRL_PAUSE: return int_pause = 1; |
46f0b4d34fa1
cosmetics: Remove useless parentheses from from return statements.
diego
parents:
25468
diff
changeset
|
421 case VOCTRL_RESUME: return int_pause = 0; |
15289 | 422 case VOCTRL_QUERY_FORMAT: return query_format(*((uint32_t*)data)); |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
423 case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); if(!shared_buffer){ [mpGLView ontop]; } else { [mplayerosxProto ontop]; } return VO_TRUE; |
15611 | 424 case VOCTRL_ROOTWIN: vo_rootwin = (!(vo_rootwin)); [mpGLView rootwin]; return VO_TRUE; |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
425 case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); if(!shared_buffer){ [mpGLView fullscreen: NO]; } else { [mplayerosxProto toggleFullscreen]; } return VO_TRUE; |
15289 | 426 case VOCTRL_GET_PANSCAN: return VO_TRUE; |
15611 | 427 case VOCTRL_SET_PANSCAN: [mpGLView panscan]; return VO_TRUE; |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
428 case VOCTRL_UPDATE_SCREENINFO: update_screen_info(); return VO_TRUE; |
15289 | 429 } |
430 return VO_NOTIMPL; | |
431 } | |
432 | |
433 ////////////////////////////////////////////////////////////////////////// | |
434 // NSOpenGLView Subclass | |
435 ////////////////////////////////////////////////////////////////////////// | |
15611 | 436 @implementation MPlayerOpenGLView |
24076 | 437 - (void) preinit |
15289 | 438 { |
29566
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
439 GLint swapInterval = 1; |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
440 CVReturn error; |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
441 |
15726 | 442 //init menu |
443 [self initMenu]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
444 |
15726 | 445 //create window |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
446 window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) |
15726 | 447 styleMask:NSTitledWindowMask|NSTexturedBackgroundWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask |
448 backing:NSBackingStoreBuffered defer:NO]; | |
449 | |
16144 | 450 [window autorelease]; |
15726 | 451 [window setDelegate:mpGLView]; |
452 [window setContentView:mpGLView]; | |
453 [window setInitialFirstResponder:mpGLView]; | |
454 [window setAcceptsMouseMovedEvents:YES]; | |
455 [window setTitle:@"MPlayer - The Movie Player"]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
456 |
15726 | 457 isFullscreen = 0; |
15855 | 458 winSizeMult = 1; |
29566
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
459 |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
460 //create OpenGL Context |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
461 glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil]; |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
462 |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
463 [self setOpenGLContext:glContext]; |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
464 [glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval]; |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
465 [glContext setView:self]; |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
466 [glContext makeCurrentContext]; |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
467 |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
468 error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache); |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
469 if(error != kCVReturnSuccess) |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
470 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture Cache(%d)\n", error); |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
471 } |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
472 |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
473 - (void) releaseVideoSpecific |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
474 { |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
475 CVPixelBufferRelease(frameBuffers[0]); |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
476 frameBuffers[0] = NULL; |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
477 CVPixelBufferRelease(frameBuffers[1]); |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
478 frameBuffers[1] = NULL; |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
479 CVOpenGLTextureRelease(texture); |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
480 texture = NULL; |
15726 | 481 } |
482 | |
24076 | 483 - (void) config |
15726 | 484 { |
485 uint32_t d_width; | |
486 uint32_t d_height; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
487 |
15726 | 488 NSRect frame; |
15289 | 489 CVReturn error = kCVReturnSuccess; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
490 |
15728 | 491 //config window |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
492 d_width = vo_dwidth; d_height = vo_dheight; |
15726 | 493 frame = NSMakeRect(0, 0, d_width, d_height); |
494 [window setContentSize: frame.size]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
495 |
29566
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
496 [self releaseVideoSpecific]; |
25180 | 497 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[0]); |
15289 | 498 if(error != kCVReturnSuccess) |
29210 | 499 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Buffer(%d)\n", error); |
25180 | 500 if (vo_doublebuffering) { |
501 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[1], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[1]); | |
502 if(error != kCVReturnSuccess) | |
29210 | 503 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Double Buffer(%d)\n", error); |
25180 | 504 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
505 |
25180 | 506 error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); |
15289 | 507 if(error != kCVReturnSuccess) |
29210 | 508 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture(%d)\n", error); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
509 |
15728 | 510 //show window |
511 [window center]; | |
512 [window makeKeyAndOrderFront:mpGLView]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
513 |
15726 | 514 if(vo_rootwin) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
515 [mpGLView rootwin]; |
15726 | 516 |
517 if(vo_fs) | |
518 [mpGLView fullscreen: NO]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
519 |
15726 | 520 if(vo_ontop) |
521 [mpGLView ontop]; | |
15289 | 522 } |
523 | |
524 /* | |
15570 | 525 Init Menu |
526 */ | |
527 - (void)initMenu | |
528 { | |
21395 | 529 NSMenu *menu, *aspectMenu; |
15570 | 530 NSMenuItem *menuItem; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
531 |
15570 | 532 [NSApp setMainMenu:[[NSMenu alloc] init]]; |
533 | |
534 //Create Movie Menu | |
535 menu = [[NSMenu alloc] initWithTitle:@"Movie"]; | |
536 menuItem = [[NSMenuItem alloc] initWithTitle:@"Half Size" action:@selector(menuAction:) keyEquivalent:@"0"]; [menu addItem:menuItem]; | |
537 kHalfScreenCmd = menuItem; | |
538 menuItem = [[NSMenuItem alloc] initWithTitle:@"Normal Size" action:@selector(menuAction:) keyEquivalent:@"1"]; [menu addItem:menuItem]; | |
539 kNormalScreenCmd = menuItem; | |
540 menuItem = [[NSMenuItem alloc] initWithTitle:@"Double Size" action:@selector(menuAction:) keyEquivalent:@"2"]; [menu addItem:menuItem]; | |
541 kDoubleScreenCmd = menuItem; | |
542 menuItem = [[NSMenuItem alloc] initWithTitle:@"Full Size" action:@selector(menuAction:) keyEquivalent:@"f"]; [menu addItem:menuItem]; | |
543 kFullScreenCmd = menuItem; | |
15909 | 544 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [menu addItem:menuItem]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
545 |
15570 | 546 aspectMenu = [[NSMenu alloc] initWithTitle:@"Aspect Ratio"]; |
547 menuItem = [[NSMenuItem alloc] initWithTitle:@"Keep" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
548 if(vo_keepaspect) [menuItem setState:NSOnState]; | |
549 kKeepAspectCmd = menuItem; | |
550 menuItem = [[NSMenuItem alloc] initWithTitle:@"Pan-Scan" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
551 if(vo_panscan) [menuItem setState:NSOnState]; | |
552 kPanScanCmd = menuItem; | |
15909 | 553 menuItem = (NSMenuItem *)[NSMenuItem separatorItem]; [aspectMenu addItem:menuItem]; |
15570 | 554 menuItem = [[NSMenuItem alloc] initWithTitle:@"Original" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; |
555 kAspectOrgCmd = menuItem; | |
556 menuItem = [[NSMenuItem alloc] initWithTitle:@"4:3" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
557 kAspectFullCmd = menuItem; | |
558 menuItem = [[NSMenuItem alloc] initWithTitle:@"16:9" action:@selector(menuAction:) keyEquivalent:@""]; [aspectMenu addItem:menuItem]; | |
559 kAspectWideCmd = menuItem; | |
560 menuItem = [[NSMenuItem alloc] initWithTitle:@"Aspect Ratio" action:nil keyEquivalent:@""]; | |
561 [menuItem setSubmenu:aspectMenu]; | |
562 [menu addItem:menuItem]; | |
563 [aspectMenu release]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
564 |
15570 | 565 //Add to menubar |
566 menuItem = [[NSMenuItem alloc] initWithTitle:@"Movie" action:nil keyEquivalent:@""]; | |
567 [menuItem setSubmenu:menu]; | |
568 [[NSApp mainMenu] addItem:menuItem]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
569 |
15570 | 570 //Create Window Menu |
571 menu = [[NSMenu alloc] initWithTitle:@"Window"]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
572 |
15570 | 573 menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"]; [menu addItem:menuItem]; |
574 menuItem = [[NSMenuItem alloc] initWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""]; [menu addItem:menuItem]; | |
575 | |
576 //Add to menubar | |
577 menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; | |
578 [menuItem setSubmenu:menu]; | |
579 [[NSApp mainMenu] addItem:menuItem]; | |
580 [NSApp setWindowsMenu:menu]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
581 |
15570 | 582 [menu release]; |
583 [menuItem release]; | |
584 } | |
585 | |
586 /* | |
587 Menu Action | |
588 */ | |
589 - (void)menuAction:(id)sender | |
590 { | |
591 uint32_t d_width; | |
592 uint32_t d_height; | |
593 NSRect frame; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
594 |
15570 | 595 aspect((int *)&d_width, (int *)&d_height,A_NOZOOM); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
596 |
15731 | 597 if(sender == kQuitCmd) |
598 { | |
599 mplayer_put_key(KEY_ESC); | |
600 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
601 |
15570 | 602 if(sender == kHalfScreenCmd) |
603 { | |
604 if(isFullscreen) { | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
605 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
15570 | 606 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
607 |
15855 | 608 winSizeMult = 0.5; |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
609 frame.size.width = d_width*winSizeMult; |
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
610 frame.size.height = d_height*winSizeMult; |
15570 | 611 [window setContentSize: frame.size]; |
612 [self reshape]; | |
613 } | |
614 if(sender == kNormalScreenCmd) | |
615 { | |
616 if(isFullscreen) { | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
617 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
15570 | 618 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
619 |
15855 | 620 winSizeMult = 1; |
15570 | 621 frame.size.width = d_width; |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
622 frame.size.height = d_height; |
15570 | 623 [window setContentSize: frame.size]; |
624 [self reshape]; | |
625 } | |
626 if(sender == kDoubleScreenCmd) | |
627 { | |
628 if(isFullscreen) { | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
629 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
15570 | 630 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
631 |
15855 | 632 winSizeMult = 2; |
633 frame.size.width = d_width*winSizeMult; | |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
634 frame.size.height = d_height*winSizeMult; |
15570 | 635 [window setContentSize: frame.size]; |
636 [self reshape]; | |
637 } | |
638 if(sender == kFullScreenCmd) | |
639 { | |
640 vo_fs = (!(vo_fs)); | |
21546
253a1e98bfe3
vo_macosx.m disable window animation when going to fullscreen
nplourde
parents:
21395
diff
changeset
|
641 [self fullscreen:NO]; |
15570 | 642 } |
643 | |
644 if(sender == kKeepAspectCmd) | |
645 { | |
646 vo_keepaspect = (!(vo_keepaspect)); | |
647 if(vo_keepaspect) | |
648 [kKeepAspectCmd setState:NSOnState]; | |
649 else | |
650 [kKeepAspectCmd setState:NSOffState]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
651 |
15909 | 652 [self reshape]; |
15570 | 653 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
654 |
15570 | 655 if(sender == kPanScanCmd) |
656 { | |
657 vo_panscan = (!(vo_panscan)); | |
658 if(vo_panscan) | |
659 [kPanScanCmd setState:NSOnState]; | |
660 else | |
661 [kPanScanCmd setState:NSOffState]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
662 |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
663 [self panscan]; |
15570 | 664 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
665 |
15570 | 666 if(sender == kAspectOrgCmd) |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
667 change_movie_aspect(-1); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
668 |
15570 | 669 if(sender == kAspectFullCmd) |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
670 change_movie_aspect(4.0f/3.0f); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
671 |
15570 | 672 if(sender == kAspectWideCmd) |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
673 change_movie_aspect(16.0f/9.0f); |
15570 | 674 } |
675 | |
676 /* | |
15289 | 677 Setup OpenGL |
678 */ | |
679 - (void)prepareOpenGL | |
680 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
681 glEnable(GL_BLEND); |
15289 | 682 glDisable(GL_DEPTH_TEST); |
683 glDepthMask(GL_FALSE); | |
684 glDisable(GL_CULL_FACE); | |
685 [self reshape]; | |
686 } | |
687 | |
688 /* | |
689 reshape OpenGL viewport | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
690 */ |
15289 | 691 - (void)reshape |
692 { | |
693 uint32_t d_width; | |
694 uint32_t d_height; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
695 |
15289 | 696 NSRect frame = [self frame]; |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
697 vo_dwidth = frame.size.width; |
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
698 vo_dheight = frame.size.height; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
699 |
15289 | 700 glViewport(0, 0, frame.size.width, frame.size.height); |
701 glMatrixMode(GL_PROJECTION); | |
702 glLoadIdentity(); | |
703 glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0); | |
704 glMatrixMode(GL_MODELVIEW); | |
705 glLoadIdentity(); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
706 |
15729 | 707 //set texture frame |
15289 | 708 if(vo_keepaspect) |
709 { | |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
710 aspect( (int *)&d_width, (int *)&d_height, A_WINZOOM); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
711 |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
712 textureFrame = NSMakeRect((vo_dwidth - d_width) / 2, (vo_dheight - d_height) / 2, d_width, d_height); |
15289 | 713 } |
714 else | |
715 { | |
15729 | 716 textureFrame = frame; |
15289 | 717 } |
718 } | |
719 | |
720 /* | |
721 Render frame | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
722 */ |
15289 | 723 - (void) render |
724 { | |
21395 | 725 int curTime; |
726 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
727 glClear(GL_COLOR_BUFFER_BIT); |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
728 |
15289 | 729 glEnable(CVOpenGLTextureGetTarget(texture)); |
730 glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
731 |
15289 | 732 glColor3f(1,1,1); |
733 glBegin(GL_QUADS); | |
15729 | 734 glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); |
25424 | 735 glTexCoord2f(lowerLeft[0], lowerLeft[1]); glVertex2i(textureFrame.origin.x-(vo_panscan_x >> 1), NSMaxY(textureFrame)+(vo_panscan_y >> 1)); |
736 glTexCoord2f(lowerRight[0], lowerRight[1]); glVertex2i(NSMaxX(textureFrame)+(vo_panscan_x >> 1), NSMaxY(textureFrame)+(vo_panscan_y >> 1)); | |
737 glTexCoord2f(upperRight[0], upperRight[1]); glVertex2i(NSMaxX(textureFrame)+(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); | |
15289 | 738 glEnd(); |
15339 | 739 glDisable(CVOpenGLTextureGetTarget(texture)); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
740 |
15339 | 741 //render resize box |
742 if(!isFullscreen) | |
743 { | |
744 NSRect frame = [self frame]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
745 |
15339 | 746 glBegin(GL_LINES); |
747 glColor4f(0.2, 0.2, 0.2, 0.5); | |
748 glVertex2i(frame.size.width-1, frame.size.height-1); glVertex2i(frame.size.width-1, frame.size.height-1); | |
749 glVertex2i(frame.size.width-1, frame.size.height-5); glVertex2i(frame.size.width-5, frame.size.height-1); | |
750 glVertex2i(frame.size.width-1, frame.size.height-9); glVertex2i(frame.size.width-9, frame.size.height-1); | |
751 | |
752 glColor4f(0.4, 0.4, 0.4, 0.5); | |
753 glVertex2i(frame.size.width-1, frame.size.height-2); glVertex2i(frame.size.width-2, frame.size.height-1); | |
754 glVertex2i(frame.size.width-1, frame.size.height-6); glVertex2i(frame.size.width-6, frame.size.height-1); | |
755 glVertex2i(frame.size.width-1, frame.size.height-10); glVertex2i(frame.size.width-10, frame.size.height-1); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
756 |
15339 | 757 glColor4f(0.6, 0.6, 0.6, 0.5); |
758 glVertex2i(frame.size.width-1, frame.size.height-3); glVertex2i(frame.size.width-3, frame.size.height-1); | |
759 glVertex2i(frame.size.width-1, frame.size.height-7); glVertex2i(frame.size.width-7, frame.size.height-1); | |
760 glVertex2i(frame.size.width-1, frame.size.height-11); glVertex2i(frame.size.width-11, frame.size.height-1); | |
761 glEnd(); | |
762 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
763 |
15289 | 764 glFlush(); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
765 |
28010
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
766 curTime = TickCount()/60; |
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
767 |
28837 | 768 //automatically hide mouse cursor (and future on-screen control?) |
15327 | 769 if(isFullscreen && !mouseHide && !isRootwin) |
15289 | 770 { |
28010
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
771 if( ((curTime - lastMouseHide) >= 5) || (lastMouseHide == 0) ) |
15289 | 772 { |
18057 | 773 CGDisplayHideCursor(kCGDirectMainDisplay); |
28010
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
774 mouseHide = TRUE; |
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
775 lastMouseHide = curTime; |
15289 | 776 } |
777 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
778 |
17725 | 779 //update activity every 30 seconds to prevent |
17546 | 780 //screensaver from starting up. |
28010
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
781 if( ((curTime - lastScreensaverUpdate) >= 30) || (lastScreensaverUpdate == 0) ) |
17546 | 782 { |
783 UpdateSystemActivity(UsrActivity); | |
28010
0a0f63090e60
factorize mouse hiding and screensaver disabling code
gpoirier
parents:
28001
diff
changeset
|
784 lastScreensaverUpdate = curTime; |
17546 | 785 } |
15289 | 786 } |
787 | |
788 /* | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
789 Create OpenGL texture from current frame & set texco |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
790 */ |
15289 | 791 - (void) setCurrentTexture |
792 { | |
793 CVReturn error = kCVReturnSuccess; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
794 |
29137
0f6fc0df2c23
fix a memory leak leading to ~80 bytes being leaked at each call to flip_page.
gpoirier
parents:
28837
diff
changeset
|
795 CVOpenGLTextureRelease(texture); |
25180 | 796 error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); |
15289 | 797 if(error != kCVReturnSuccess) |
29210 | 798 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture(%d)\n", error); |
15289 | 799 |
800 CVOpenGLTextureGetCleanTexCoords(texture, lowerLeft, lowerRight, upperRight, upperLeft); | |
801 } | |
802 | |
803 /* | |
804 redraw win rect | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
805 */ |
15289 | 806 - (void) drawRect: (NSRect *) bounds |
807 { | |
808 [self render]; | |
809 } | |
810 | |
811 /* | |
812 Toggle Fullscreen | |
813 */ | |
814 - (void) fullscreen: (BOOL) animate | |
815 { | |
816 static NSRect old_frame; | |
817 static NSRect old_view_frame; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
818 |
15573 | 819 panscan_calc(); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
820 |
15289 | 821 //go fullscreen |
822 if(vo_fs) | |
823 { | |
15327 | 824 if(!isRootwin) |
825 { | |
15882 | 826 SetSystemUIMode( kUIModeAllHidden, kUIOptionAutoShowMenuBar); |
18057 | 827 CGDisplayHideCursor(kCGDirectMainDisplay); |
15327 | 828 mouseHide = YES; |
829 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
830 |
15289 | 831 old_frame = [window frame]; //save main window size & position |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
832 update_screen_info(); |
25413 | 833 |
15728 | 834 [window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx |
15289 | 835 old_view_frame = [self bounds]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
836 |
15289 | 837 //fix origin for multi screen setup |
15728 | 838 screen_frame.origin.x = 0; |
839 screen_frame.origin.y = 0; | |
840 [self setFrame:screen_frame]; | |
15289 | 841 [self setNeedsDisplay:YES]; |
842 [window setHasShadow:NO]; | |
843 isFullscreen = 1; | |
844 } | |
845 else | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
846 { |
15902
16534910f0fb
fix various window resizing bug with menu option
nplourde
parents:
15882
diff
changeset
|
847 SetSystemUIMode( kUIModeNormal, 0); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
848 |
15289 | 849 isFullscreen = 0; |
18057 | 850 CGDisplayShowCursor(kCGDirectMainDisplay); |
15289 | 851 mouseHide = NO; |
852 | |
853 //revert window to previous setting | |
854 [self setFrame:old_view_frame]; | |
855 [self setNeedsDisplay:YES]; | |
16081
72c352edce8f
restore window shadow when quitting fullscreen mode
nplourde
parents:
15909
diff
changeset
|
856 [window setHasShadow:YES]; |
15289 | 857 [window setFrame:old_frame display:YES animate:animate];//zoom-out window with nice useless sfx |
858 } | |
859 } | |
860 | |
861 /* | |
862 Toggle ontop | |
863 */ | |
864 - (void) ontop | |
865 { | |
15320 | 866 if(vo_ontop) |
867 { | |
868 [window setLevel:NSScreenSaverWindowLevel]; | |
869 isOntop = YES; | |
870 } | |
871 else | |
872 { | |
873 [window setLevel:NSNormalWindowLevel]; | |
874 isOntop = NO; | |
875 } | |
15289 | 876 } |
877 | |
878 /* | |
879 Toggle panscan | |
880 */ | |
881 - (void) panscan | |
882 { | |
15331 | 883 panscan_calc(); |
15289 | 884 } |
885 | |
886 /* | |
15327 | 887 Toggle rootwin |
888 */ | |
889 - (void) rootwin | |
890 { | |
891 if(vo_rootwin) | |
892 { | |
893 [window setLevel:CGWindowLevelForKey(kCGDesktopWindowLevelKey)]; | |
894 [window orderBack:self]; | |
895 isRootwin = YES; | |
896 } | |
897 else | |
898 { | |
899 [window setLevel:NSNormalWindowLevel]; | |
900 isRootwin = NO; | |
901 } | |
902 } | |
903 | |
904 /* | |
15289 | 905 Check event for new event |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
906 */ |
15289 | 907 - (void) check_events |
908 { | |
909 event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:0.0001] inMode:NSEventTrackingRunLoopMode dequeue:YES]; | |
25178 | 910 if (event == nil) |
911 return; | |
15289 | 912 [NSApp sendEvent:event]; |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
913 // Without SDL's bootstrap code (include SDL.h in mplayer.c), |
28837 | 914 // on Leopard, we have trouble to get the play window automatically focused |
915 // when the app is actived. The Following code fix this problem. | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
26755
diff
changeset
|
916 #ifndef CONFIG_SDL |
25179
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
917 if (isLeopardOrLater && [event type] == NSAppKitDefined |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
918 && [event subtype] == NSApplicationActivatedEventType) { |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
919 [window makeMainWindow]; |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
920 [window makeKeyAndOrderFront:mpGLView]; |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
921 } |
6e8b40d412f0
Fix play window not get actived problem on Leopard.
ulion
parents:
25178
diff
changeset
|
922 #endif |
15289 | 923 } |
924 | |
925 /* | |
15731 | 926 From NSView, respond to key equivalents. |
927 */ | |
928 - (BOOL)performKeyEquivalent:(NSEvent *)theEvent | |
929 { | |
930 switch([theEvent keyCode]) | |
931 { | |
932 case 0x21: [window setAlphaValue: winAlpha-=0.05]; return YES; | |
933 case 0x1e: [window setAlphaValue: winAlpha+=0.05]; return YES; | |
934 } | |
935 return NO; | |
936 } | |
937 | |
938 /* | |
15289 | 939 Process key event |
940 */ | |
941 - (void) keyDown: (NSEvent *) theEvent | |
942 { | |
29533
9c8f8e375823
Reuse the osx_common convert_key function to convert OSX keycodes to MPlayer
reimar
parents:
29272
diff
changeset
|
943 int key = convert_key([theEvent keyCode], *[[theEvent characters] UTF8String]); |
9c8f8e375823
Reuse the osx_common convert_key function to convert OSX keycodes to MPlayer
reimar
parents:
29272
diff
changeset
|
944 if (key != -1) |
15289 | 945 mplayer_put_key(key); |
946 } | |
947 | |
948 /* | |
949 Process mouse button event | |
950 */ | |
951 - (void) mouseMoved: (NSEvent *) theEvent | |
952 { | |
15327 | 953 if(isFullscreen && !isRootwin) |
15289 | 954 { |
18057 | 955 CGDisplayShowCursor(kCGDirectMainDisplay); |
15289 | 956 mouseHide = NO; |
957 } | |
25468
a77c438fedf7
Do not send mouse movements events in root win mode.
ulion
parents:
25446
diff
changeset
|
958 if (enable_mouse_movements && !isRootwin) { |
25446 | 959 NSPoint p =[self convertPoint:[theEvent locationInWindow] fromView:nil]; |
960 if ([self mouse:p inRect:textureFrame]) { | |
961 char cmdstr[40]; | |
962 snprintf(cmdstr, sizeof(cmdstr), "set_mouse_pos %i %i", | |
963 (int)(vo_fs ? p.x : (p.x - textureFrame.origin.x)), | |
964 (int)(vo_fs ? [self frame].size.height - p.y: (NSMaxY(textureFrame) - p.y))); | |
965 mp_input_queue_cmd(mp_input_parse_cmd(cmdstr)); | |
966 } | |
967 } | |
15289 | 968 } |
969 | |
970 - (void) mouseDown: (NSEvent *) theEvent | |
971 { | |
972 [self mouseEvent: theEvent]; | |
973 } | |
974 | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
975 - (void) mouseUp: (NSEvent *) theEvent |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
976 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
977 [self mouseEvent: theEvent]; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
978 } |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
979 |
15289 | 980 - (void) rightMouseDown: (NSEvent *) theEvent |
981 { | |
982 [self mouseEvent: theEvent]; | |
983 } | |
984 | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
985 - (void) rightMouseUp: (NSEvent *) theEvent |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
986 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
987 [self mouseEvent: theEvent]; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
988 } |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
989 |
15289 | 990 - (void) otherMouseDown: (NSEvent *) theEvent |
991 { | |
992 [self mouseEvent: theEvent]; | |
993 } | |
994 | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
995 - (void) otherMouseUp: (NSEvent *) theEvent |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
996 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
997 [self mouseEvent: theEvent]; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
998 } |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
999 |
15289 | 1000 - (void) scrollWheel: (NSEvent *) theEvent |
1001 { | |
1002 if([theEvent deltaY] > 0) | |
1003 mplayer_put_key(MOUSE_BTN3); | |
1004 else | |
1005 mplayer_put_key(MOUSE_BTN4); | |
1006 } | |
1007 | |
1008 - (void) mouseEvent: (NSEvent *) theEvent | |
1009 { | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1010 if ( [theEvent buttonNumber] >= 0 && [theEvent buttonNumber] <= 9 ) |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1011 { |
25422 | 1012 int buttonNumber = [theEvent buttonNumber]; |
1013 // Fix to mplayer defined button order: left, middle, right | |
1014 if (buttonNumber == 1) | |
1015 buttonNumber = 2; | |
25423 | 1016 else if (buttonNumber == 2) |
1017 buttonNumber = 1; | |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1018 switch([theEvent type]) |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1019 { |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1020 case NSLeftMouseDown: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1021 case NSRightMouseDown: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1022 case NSOtherMouseDown: |
25422 | 1023 mplayer_put_key((MOUSE_BTN0 + buttonNumber) | MP_KEY_DOWN); |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1024 break; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1025 case NSLeftMouseUp: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1026 case NSRightMouseUp: |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1027 case NSOtherMouseUp: |
25422 | 1028 mplayer_put_key(MOUSE_BTN0 + buttonNumber); |
24077
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1029 break; |
9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
nplourde
parents:
24076
diff
changeset
|
1030 } |
15289 | 1031 } |
1032 } | |
1033 | |
1034 /* | |
1035 NSResponder | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
1036 */ |
15289 | 1037 - (BOOL) acceptsFirstResponder |
1038 { | |
1039 return YES; | |
1040 } | |
1041 | |
1042 - (BOOL) becomeFirstResponder | |
1043 { | |
1044 return YES; | |
1045 } | |
1046 | |
1047 - (BOOL) resignFirstResponder | |
1048 { | |
1049 return YES; | |
1050 } | |
15325 | 1051 |
1052 - (void)windowWillClose:(NSNotification *)aNotification | |
1053 { | |
21551 | 1054 mpGLView = NULL; |
15325 | 1055 mplayer_put_key(KEY_ESC); |
1056 } | |
1057 @end |