Mercurial > mplayer.hg
annotate libvo/vo_corevideo.m @ 36623:e0572501d2cd
Add a (missing) icon to menu entry "audio track".
author | ib |
---|---|
date | Fri, 24 Jan 2014 01:06:57 +0000 |
parents | db6d34cfbd34 |
children | 072f64f1eec3 |
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" | |
36598 | 38 #define NO_DRAW_SLICE |
39 #define NO_DRAW_FRAME | |
15289 | 40 #include "video_out_internal.h" |
41 #include "aspect.h" | |
42 #include "mp_msg.h" | |
43 #include "m_option.h" | |
28075
ca9badc94740
#include appropriate headers instead of locally declaring function prototypes.
diego
parents:
28051
diff
changeset
|
44 #include "mp_fifo.h" |
32471 | 45 #include "sub/sub.h" |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
46 #include "subopt-helper.h" |
15289 | 47 |
48 #include "input/input.h" | |
49 #include "input/mouse.h" | |
50 | |
51 #include "osdep/keycodes.h" | |
29533
9c8f8e375823
Reuse the osx_common convert_key function to convert OSX keycodes to MPlayer
reimar
parents:
29272
diff
changeset
|
52 #include "osx_common.h" |
15289 | 53 |
54 //Cocoa | |
35065 | 55 static NSDistantObject *mplayerosxProxy; |
56 static id <MPlayerOSXVOProto> mplayerosxProto; | |
57 static MPlayerOpenGLView *mpGLView; | |
58 static NSAutoreleasePool *autoreleasepool; | |
59 static OSType pixelFormat; | |
15289 | 60 |
16385 | 61 //shared memory |
35065 | 62 static BOOL shared_buffer = false; |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
63 #define DEFAULT_BUFFER_NAME "mplayerosx" |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
64 static char *buffer_name; |
16385 | 65 |
15728 | 66 //Screen |
35065 | 67 static int screen_id = -1; |
15289 | 68 |
69 //image | |
35065 | 70 static unsigned char *image_data; |
25180 | 71 // For double buffering |
72 static uint8_t image_page = 0; | |
73 static unsigned char *image_datas[2]; | |
74 | |
15289 | 75 static uint32_t image_width; |
76 static uint32_t image_height; | |
77 static uint32_t image_bytes; | |
34878
3e6cfa2053bf
Add a separate stride variable to make it easier to optimize later (e.g. align stride).
reimar
parents:
34876
diff
changeset
|
78 static uint32_t image_stride; |
15289 | 79 static uint32_t image_format; |
80 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
81 static vo_info_t info = |
15289 | 82 { |
28837 | 83 "Mac OS X Core Video", |
29210 | 84 "corevideo", |
15289 | 85 "Nicolas Plourde <nicolas.plourde@gmail.com>", |
86 "" | |
87 }; | |
88 | |
29210 | 89 LIBVO_EXTERN(corevideo) |
15289 | 90 |
91 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, unsigned char *srca, int stride) | |
92 { | |
34876
c5f89bf5b952
corevideo: Reduce code duplication in OSD rendering code.
reimar
parents:
34875
diff
changeset
|
93 unsigned char *dst = image_data + image_bytes * (y0 * image_width + x0); |
35128 | 94 vo_draw_alpha_func draw = vo_get_draw_alpha(image_format); |
95 if (!draw) return; | |
96 draw(w,h,src,srca,stride,dst,image_stride); | |
15289 | 97 } |
98 | |
29573
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
99 static void free_file_specific(void) |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
100 { |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
101 if(shared_buffer) |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
102 { |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
103 [mplayerosxProto stop]; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
104 mplayerosxProto = nil; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
105 [mplayerosxProxy release]; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
106 mplayerosxProxy = nil; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
107 |
34878
3e6cfa2053bf
Add a separate stride variable to make it easier to optimize later (e.g. align stride).
reimar
parents:
34876
diff
changeset
|
108 if (munmap(image_data, image_height*image_stride) == -1) |
29573
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
109 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
|
110 |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
111 if (shm_unlink(buffer_name) == -1) |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
112 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
|
113 } else { |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
114 free(image_datas[0]); |
34875
444a6a469743
Remove unnecessary if, free can be called unconditionally.
reimar
parents:
34825
diff
changeset
|
115 free(image_datas[1]); |
29573
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
116 image_datas[0] = NULL; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
117 image_datas[1] = NULL; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
118 image_data = NULL; |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
119 } |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
120 } |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
121 |
35150
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
122 static void update_screen_info_shared_buffer(void) |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
123 { |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
124 NSRect rc = [[NSScreen mainScreen] frame]; |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
125 vo_screenwidth = rc.size.width; |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
126 vo_screenheight = rc.size.height; |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
127 xinerama_x = rc.origin.x; |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
128 xinerama_y = rc.origin.y; |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
129 aspect_save_screenres(vo_screenwidth, vo_screenheight); |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
130 } |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
131 |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
132 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
|
133 { |
29573
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
134 free_file_specific(); |
16385 | 135 |
15289 | 136 //misc mplayer setup |
137 image_width = width; | |
138 image_height = height; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
139 switch (image_format) |
15289 | 140 { |
30974
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
141 case IMGFMT_RGB24: |
34825 | 142 image_bytes = 3; |
30974
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
143 break; |
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
144 case IMGFMT_ARGB: |
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
145 case IMGFMT_BGRA: |
34825 | 146 image_bytes = 4; |
15289 | 147 break; |
16385 | 148 case IMGFMT_YUY2: |
35019 | 149 case IMGFMT_UYVY: |
34825 | 150 image_bytes = 2; |
15289 | 151 break; |
152 } | |
34878
3e6cfa2053bf
Add a separate stride variable to make it easier to optimize later (e.g. align stride).
reimar
parents:
34876
diff
changeset
|
153 // should be aligned, but that would break the shared buffer |
3e6cfa2053bf
Add a separate stride variable to make it easier to optimize later (e.g. align stride).
reimar
parents:
34876
diff
changeset
|
154 image_stride = image_width * image_bytes; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
155 |
16385 | 156 if(!shared_buffer) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
157 { |
34878
3e6cfa2053bf
Add a separate stride variable to make it easier to optimize later (e.g. align stride).
reimar
parents:
34876
diff
changeset
|
158 image_data = malloc(image_height*image_stride); |
25180 | 159 image_datas[0] = image_data; |
160 if (vo_doublebuffering) | |
34878
3e6cfa2053bf
Add a separate stride variable to make it easier to optimize later (e.g. align stride).
reimar
parents:
34876
diff
changeset
|
161 image_datas[1] = malloc(image_height*image_stride); |
25180 | 162 image_page = 0; |
25120
9b4ca4dc1294
Fix a memory leak when working in shared_buffer mode.
ulion
parents:
25114
diff
changeset
|
163 |
16385 | 164 //config OpenGL View |
36267 | 165 [mpGLView configWidth:d_width height:d_height flags:flags]; |
16385 | 166 [mpGLView reshape]; |
35146 | 167 [[mpGLView window] setTitle:[NSString stringWithUTF8String:vo_wintitle ? vo_wintitle : title]]; |
16385 | 168 } |
169 else | |
170 { | |
29567
349de9bdfcce
Make shm_fd a local variable and close it when we need it no longer, thus
reimar
parents:
29566
diff
changeset
|
171 int shm_fd; |
29210 | 172 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
|
173 "named \"%s\"\n",buffer_name); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
174 |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
175 // create shared memory |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
176 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
|
177 if (shm_fd == -1) |
16385 | 178 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
179 mp_msg(MSGT_VO, MSGL_FATAL, |
29210 | 180 "[vo_corevideo] failed to open shared memory. Error: %s\n", strerror(errno)); |
16385 | 181 return 1; |
182 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
183 |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
184 |
34878
3e6cfa2053bf
Add a separate stride variable to make it easier to optimize later (e.g. align stride).
reimar
parents:
34876
diff
changeset
|
185 if (ftruncate(shm_fd, image_height*image_stride) == -1) |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
186 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
187 mp_msg(MSGT_VO, MSGL_FATAL, |
29210 | 188 "[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
|
189 close(shm_fd); |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
190 shm_unlink(buffer_name); |
16385 | 191 return 1; |
192 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
193 |
34878
3e6cfa2053bf
Add a separate stride variable to make it easier to optimize later (e.g. align stride).
reimar
parents:
34876
diff
changeset
|
194 image_data = mmap(NULL, image_height*image_stride, |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
195 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
|
196 close(shm_fd); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
197 |
28016
3b8e66828e10
use mmap instead of shmat for MPlayerOSX, patch by Adrian Stutz<adrian@sttz.ch>
nplourde
parents:
28010
diff
changeset
|
198 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
|
199 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
200 mp_msg(MSGT_VO, MSGL_FATAL, |
29210 | 201 "[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
|
202 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
|
203 return 1; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
204 } |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
205 |
28837 | 206 //connect to mplayerosx |
35146 | 207 mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:[NSString stringWithUTF8String:buffer_name] host:nil]; |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
208 if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) { |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
209 [mplayerosxProxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
210 mplayerosxProto = (id <MPlayerOSXVOProto>)mplayerosxProxy; |
29564
4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
reimar
parents:
29533
diff
changeset
|
211 [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
|
212 } |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
213 else { |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
214 [mplayerosxProxy release]; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
215 mplayerosxProxy = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
216 mplayerosxProto = nil; |
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
217 } |
16385 | 218 } |
15289 | 219 return 0; |
220 } | |
221 | |
222 static void check_events(void) | |
223 { | |
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
|
224 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
|
225 [mpGLView check_events]; |
15289 | 226 } |
227 | |
228 static void draw_osd(void) | |
229 { | |
230 vo_draw_text(image_width, image_height, draw_alpha); | |
231 } | |
232 | |
233 static void flip_page(void) | |
234 { | |
29271
82b6fbc72099
When used with shared_buffer, autorelease in each flip_page so objects don't accumulate until exit.
adrian
parents:
29263
diff
changeset
|
235 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
|
236 NSAutoreleasePool *pool = [NSAutoreleasePool new]; |
25157
cf3b6015735d
Set protocol for the vo proxy used in shared-buffer mode.
ulion
parents:
25137
diff
changeset
|
237 [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
|
238 [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
|
239 } else { |
25114
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
240 [mpGLView setCurrentTexture]; |
16385 | 241 [mpGLView render]; |
25180 | 242 if (vo_doublebuffering) { |
243 image_page = 1 - image_page; | |
244 image_data = image_datas[image_page]; | |
245 } | |
25114
bed4188998ca
Move the setCurrentTexture call into flip_page(), fix osd flicker problem.
ulion
parents:
25078
diff
changeset
|
246 } |
15289 | 247 } |
248 | |
30972
886527159cae
Implement VOCTRL_DRAW_IMAGE instead of the deprecated draw_frame, avoiding
reimar
parents:
30922
diff
changeset
|
249 static uint32_t draw_image(mp_image_t *mpi) |
886527159cae
Implement VOCTRL_DRAW_IMAGE instead of the deprecated draw_frame, avoiding
reimar
parents:
30922
diff
changeset
|
250 { |
35057 | 251 if (!(mpi->flags & MP_IMGFLAG_DIRECT)) |
34878
3e6cfa2053bf
Add a separate stride variable to make it easier to optimize later (e.g. align stride).
reimar
parents:
34876
diff
changeset
|
252 memcpy_pic(image_data, mpi->planes[0], image_width*image_bytes, image_height, image_stride, mpi->stride[0]); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
253 |
36593 | 254 return VO_TRUE; |
15289 | 255 } |
256 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
257 static int query_format(uint32_t format) |
15289 | 258 { |
36594
8c5bec08a72d
vo_corevideo: Fix VFCAP flags, adding ACCEPT_STRIDE and NOSLICES.
reimar
parents:
36593
diff
changeset
|
259 const int supportflags = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_OSD | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE | VOCAP_NOSLICES; |
15289 | 260 image_format = format; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
261 |
15289 | 262 switch(format) |
263 { | |
264 case IMGFMT_YUY2: | |
265 pixelFormat = kYUVSPixelFormat; | |
30974
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
266 return supportflags; |
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
267 |
35019 | 268 case IMGFMT_UYVY: |
269 pixelFormat = k2vuyPixelFormat; | |
270 return supportflags; | |
271 | |
30974
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
272 case IMGFMT_RGB24: |
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
273 pixelFormat = k24RGBPixelFormat; |
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
274 return supportflags; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
275 |
30974
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
276 case IMGFMT_ARGB: |
15289 | 277 pixelFormat = k32ARGBPixelFormat; |
30974
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
278 return supportflags; |
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
279 |
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
280 case IMGFMT_BGRA: |
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
281 pixelFormat = k32BGRAPixelFormat; |
bd964ca1f6fa
Fix RGB support for corevideo: corevideo can only support
reimar
parents:
30973
diff
changeset
|
282 return supportflags; |
15289 | 283 } |
284 return 0; | |
285 } | |
286 | |
35057 | 287 static int get_image(mp_image_t *mpi) |
288 { | |
289 if (!(mpi->flags & (MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_ACCEPT_WIDTH)) || | |
290 (mpi->type != MP_IMGTYPE_TEMP && mpi->type != MP_IMGTYPE_STATIC)) | |
291 return VO_FALSE; | |
292 | |
293 // mpi should not be planar format here | |
294 mpi->planes[0] = image_data; | |
295 mpi->stride[0] = image_stride; | |
296 mpi->flags |= MP_IMGFLAG_DIRECT; | |
297 mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK; | |
298 return VO_TRUE; | |
299 } | |
300 | |
15289 | 301 static void uninit(void) |
302 { | |
21551 | 303 SetSystemUIMode( kUIModeNormal, 0); |
304 CGDisplayShowCursor(kCGDirectMainDisplay); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
305 |
29573
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
306 free_file_specific(); |
2b14be337eaf
Fix some of the major memleaks of vo_corevideo with -fixed-vo
reimar
parents:
29567
diff
changeset
|
307 |
21551 | 308 if(mpGLView) |
309 { | |
25136 | 310 NSAutoreleasePool *finalPool; |
24742
0bef706332b5
Fix deallocate bug which sometimes causes a crash when reinitializing.
nplourde
parents:
24698
diff
changeset
|
311 mpGLView = nil; |
21551 | 312 [autoreleasepool release]; |
25136 | 313 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
|
314 [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
|
315 [finalPool release]; |
21551 | 316 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
317 |
32537
8fa2f43cb760
Remove most of the NULL pointer check before free all over the code
cboesch
parents:
32471
diff
changeset
|
318 free(buffer_name); |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
319 buffer_name = NULL; |
15289 | 320 } |
321 | |
29603 | 322 static const opt_t subopts[] = { |
28306 | 323 {"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
|
324 {"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
|
325 {"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
|
326 {NULL} |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
327 }; |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
328 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
16145
diff
changeset
|
329 static int preinit(const char *arg) |
15289 | 330 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
331 |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
332 // set defaults |
28306 | 333 screen_id = -1; |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
334 shared_buffer = false; |
28204 | 335 buffer_name = NULL; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
336 |
28130
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
337 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
|
338 mp_msg(MSGT_VO, MSGL_FATAL, |
29210 | 339 "\n-vo corevideo command line help:\n" |
340 "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
|
341 "\nOptions:\n" |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
342 " device_id=<0-...>\n" |
35074
3fb18ad99003
Deprecate corevideo device_id in favour of -xineramascreen.
reimar
parents:
35073
diff
changeset
|
343 " DEPRECATED, use -xineramascreen instead.\n" |
28837 | 344 " 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
|
345 " shared_buffer\n" |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
346 " 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
|
347 " buffer_name=<name>\n" |
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
348 " 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
|
349 " 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
|
350 " 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
|
351 "\n" ); |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
352 return -1; |
b5898cb411da
Replace vo_macosx's custom options parsing with a subopt_parse()-based one
gpoirier
parents:
28077
diff
changeset
|
353 } |
15728 | 354 |
15289 | 355 autoreleasepool = [[NSAutoreleasePool alloc] init]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
356 |
35074
3fb18ad99003
Deprecate corevideo device_id in favour of -xineramascreen.
reimar
parents:
35073
diff
changeset
|
357 if (screen_id != -1) |
3fb18ad99003
Deprecate corevideo device_id in favour of -xineramascreen.
reimar
parents:
35073
diff
changeset
|
358 xinerama_screen = screen_id; |
3fb18ad99003
Deprecate corevideo device_id in favour of -xineramascreen.
reimar
parents:
35073
diff
changeset
|
359 |
28204 | 360 if (!buffer_name) |
361 buffer_name = strdup(DEFAULT_BUFFER_NAME); | |
362 else | |
28180
781ef511a767
Add an option to vo_macosx to set a custom buffer_name.
gpoirier
parents:
28130
diff
changeset
|
363 shared_buffer = true; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
364 |
16385 | 365 if(!shared_buffer) |
16144 | 366 { |
16385 | 367 if(!mpGLView) |
368 { | |
369 mpGLView = [[MPlayerOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) pixelFormat:[MPlayerOpenGLView defaultPixelFormat]]; | |
370 [mpGLView autorelease]; | |
371 } | |
372 [mpGLView display]; | |
373 [mpGLView preinit]; | |
16144 | 374 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
375 |
15289 | 376 return 0; |
377 } | |
378 | |
33330
ad12e6080ed1
Fix compilation for OSX due to r33392 - control() vaarg removal.
iive
parents:
32537
diff
changeset
|
379 static int control(uint32_t request, void *data) |
15289 | 380 { |
381 switch (request) | |
382 { | |
30972
886527159cae
Implement VOCTRL_DRAW_IMAGE instead of the deprecated draw_frame, avoiding
reimar
parents:
30922
diff
changeset
|
383 case VOCTRL_DRAW_IMAGE: return draw_image(data); |
31737 | 384 case VOCTRL_QUERY_FORMAT: return query_format(*(uint32_t*)data); |
35057 | 385 case VOCTRL_GET_IMAGE: return get_image(data); |
31737 | 386 case VOCTRL_ONTOP: vo_ontop = !vo_ontop; if(!shared_buffer){ [mpGLView ontop]; } else { [mplayerosxProto ontop]; } return VO_TRUE; |
387 case VOCTRL_ROOTWIN: vo_rootwin = !vo_rootwin; [mpGLView rootwin]; return VO_TRUE; | |
388 case VOCTRL_FULLSCREEN: vo_fs = !vo_fs; if(!shared_buffer){ [mpGLView fullscreen: NO]; } else { [mplayerosxProto toggleFullscreen]; } return VO_TRUE; | |
15289 | 389 case VOCTRL_GET_PANSCAN: return VO_TRUE; |
35069 | 390 case VOCTRL_SET_PANSCAN: panscan_calc(); return VO_TRUE; |
35150
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
391 case VOCTRL_UPDATE_SCREENINFO: |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
392 if (shared_buffer) |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
393 update_screen_info_shared_buffer(); |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
394 else |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
395 [mpGLView update_screen_info]; |
4683218a0324
vo corevideo: VOCTRL_UPDATE_SCREENINFO: Fix shared_buffer case
al
parents:
35146
diff
changeset
|
396 return VO_TRUE; |
15289 | 397 } |
398 return VO_NOTIMPL; | |
399 } | |
400 | |
401 ////////////////////////////////////////////////////////////////////////// | |
402 // NSOpenGLView Subclass | |
403 ////////////////////////////////////////////////////////////////////////// | |
15611 | 404 @implementation MPlayerOpenGLView |
24076 | 405 - (void) preinit |
15289 | 406 { |
29566
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
407 CVReturn error; |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
408 |
35086
8848682f4035
Split out an objective-C common OS X layer, to be reused by -vo gl.
reimar
parents:
35085
diff
changeset
|
409 [super preinit]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
410 |
35086
8848682f4035
Split out an objective-C common OS X layer, to be reused by -vo gl.
reimar
parents:
35085
diff
changeset
|
411 error = CVOpenGLTextureCacheCreate(NULL, 0, [[self openGLContext] CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache); |
29566
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
412 if(error != kCVReturnSuccess) |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
413 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
|
414 } |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
415 |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
416 - (void) releaseVideoSpecific |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
417 { |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
418 CVPixelBufferRelease(frameBuffers[0]); |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
419 frameBuffers[0] = NULL; |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
420 CVPixelBufferRelease(frameBuffers[1]); |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
421 frameBuffers[1] = NULL; |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
422 CVOpenGLTextureRelease(texture); |
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
423 texture = NULL; |
15726 | 424 } |
425 | |
29574
0aa36133f638
Add a dealloc function to corevideo to reduce the memleaks from
reimar
parents:
29573
diff
changeset
|
426 - (void) dealloc |
0aa36133f638
Add a dealloc function to corevideo to reduce the memleaks from
reimar
parents:
29573
diff
changeset
|
427 { |
0aa36133f638
Add a dealloc function to corevideo to reduce the memleaks from
reimar
parents:
29573
diff
changeset
|
428 [self releaseVideoSpecific]; |
0aa36133f638
Add a dealloc function to corevideo to reduce the memleaks from
reimar
parents:
29573
diff
changeset
|
429 CVOpenGLTextureCacheRelease(textureCache); |
0aa36133f638
Add a dealloc function to corevideo to reduce the memleaks from
reimar
parents:
29573
diff
changeset
|
430 textureCache = NULL; |
0aa36133f638
Add a dealloc function to corevideo to reduce the memleaks from
reimar
parents:
29573
diff
changeset
|
431 [super dealloc]; |
0aa36133f638
Add a dealloc function to corevideo to reduce the memleaks from
reimar
parents:
29573
diff
changeset
|
432 } |
0aa36133f638
Add a dealloc function to corevideo to reduce the memleaks from
reimar
parents:
29573
diff
changeset
|
433 |
36267 | 434 - (void) configWidth:(uint32_t)width height:(uint32_t)height flags:(uint32_t)flags |
15726 | 435 { |
15289 | 436 CVReturn error = kCVReturnSuccess; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
437 |
36267 | 438 [super configWidth:width height:height flags:flags]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
439 |
29566
b128ce47771d
Reduce vo_corevideo memleaks by initializing static context etc. only once
reimar
parents:
29564
diff
changeset
|
440 [self releaseVideoSpecific]; |
34878
3e6cfa2053bf
Add a separate stride variable to make it easier to optimize later (e.g. align stride).
reimar
parents:
34876
diff
changeset
|
441 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_stride, NULL, NULL, NULL, &frameBuffers[0]); |
15289 | 442 if(error != kCVReturnSuccess) |
29210 | 443 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Buffer(%d)\n", error); |
25180 | 444 if (vo_doublebuffering) { |
34878
3e6cfa2053bf
Add a separate stride variable to make it easier to optimize later (e.g. align stride).
reimar
parents:
34876
diff
changeset
|
445 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[1], image_stride, NULL, NULL, NULL, &frameBuffers[1]); |
25180 | 446 if(error != kCVReturnSuccess) |
29210 | 447 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Double Buffer(%d)\n", error); |
25180 | 448 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
449 |
25180 | 450 error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); |
15289 | 451 if(error != kCVReturnSuccess) |
29210 | 452 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture(%d)\n", error); |
15570 | 453 } |
454 | |
455 /* | |
15289 | 456 Setup OpenGL |
457 */ | |
458 - (void)prepareOpenGL | |
459 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
460 glEnable(GL_BLEND); |
15289 | 461 glDisable(GL_DEPTH_TEST); |
462 glDepthMask(GL_FALSE); | |
463 glDisable(GL_CULL_FACE); | |
464 [self reshape]; | |
465 } | |
466 | |
467 /* | |
468 reshape OpenGL viewport | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
469 */ |
15289 | 470 - (void)reshape |
471 { | |
31739
923b5da53f65
Declare variables with proper types to avoid dangerous pointer casts.
reimar
parents:
31738
diff
changeset
|
472 int d_width, d_height; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
473 |
35091 | 474 [super reshape]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
475 |
35090 | 476 glViewport(0, 0, vo_dwidth, vo_dheight); |
15289 | 477 glMatrixMode(GL_PROJECTION); |
478 glLoadIdentity(); | |
35090 | 479 glOrtho(0, vo_dwidth, vo_dheight, 0, -1.0, 1.0); |
15289 | 480 glMatrixMode(GL_MODELVIEW); |
481 glLoadIdentity(); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
482 |
35090 | 483 d_width = vo_dwidth; |
484 d_height = vo_dheight; | |
15729 | 485 //set texture frame |
35127
dd8ebdd08791
Use aspect_scaling() function also for vo_corevideo.
reimar
parents:
35091
diff
changeset
|
486 if(aspect_scaling()) |
15289 | 487 { |
31739
923b5da53f65
Declare variables with proper types to avoid dangerous pointer casts.
reimar
parents:
31738
diff
changeset
|
488 aspect(&d_width, &d_height, A_WINZOOM); |
15289 | 489 } |
35090 | 490 textureFrame = NSMakeRect((vo_dwidth - d_width) / 2, (vo_dheight - d_height) / 2, d_width, d_height); |
15289 | 491 } |
492 | |
493 /* | |
494 Render frame | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
495 */ |
15289 | 496 - (void) render |
497 { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
498 glClear(GL_COLOR_BUFFER_BIT); |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
499 |
15289 | 500 glEnable(CVOpenGLTextureGetTarget(texture)); |
501 glBindTexture(CVOpenGLTextureGetTarget(texture), CVOpenGLTextureGetName(texture)); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
502 |
15289 | 503 glColor3f(1,1,1); |
504 glBegin(GL_QUADS); | |
15729 | 505 glTexCoord2f(upperLeft[0], upperLeft[1]); glVertex2i( textureFrame.origin.x-(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); |
25424 | 506 glTexCoord2f(lowerLeft[0], lowerLeft[1]); glVertex2i(textureFrame.origin.x-(vo_panscan_x >> 1), NSMaxY(textureFrame)+(vo_panscan_y >> 1)); |
507 glTexCoord2f(lowerRight[0], lowerRight[1]); glVertex2i(NSMaxX(textureFrame)+(vo_panscan_x >> 1), NSMaxY(textureFrame)+(vo_panscan_y >> 1)); | |
508 glTexCoord2f(upperRight[0], upperRight[1]); glVertex2i(NSMaxX(textureFrame)+(vo_panscan_x >> 1), textureFrame.origin.y-(vo_panscan_y >> 1)); | |
15289 | 509 glEnd(); |
15339 | 510 glDisable(CVOpenGLTextureGetTarget(texture)); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
511 |
15339 | 512 //render resize box |
35082
6d8be70115a8
Remove local variables that (except for very brief moments before
reimar
parents:
35081
diff
changeset
|
513 if(!vo_fs) |
15339 | 514 { |
515 NSRect frame = [self frame]; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
516 |
15339 | 517 glBegin(GL_LINES); |
518 glColor4f(0.2, 0.2, 0.2, 0.5); | |
519 glVertex2i(frame.size.width-1, frame.size.height-1); glVertex2i(frame.size.width-1, frame.size.height-1); | |
520 glVertex2i(frame.size.width-1, frame.size.height-5); glVertex2i(frame.size.width-5, frame.size.height-1); | |
521 glVertex2i(frame.size.width-1, frame.size.height-9); glVertex2i(frame.size.width-9, frame.size.height-1); | |
522 | |
523 glColor4f(0.4, 0.4, 0.4, 0.5); | |
524 glVertex2i(frame.size.width-1, frame.size.height-2); glVertex2i(frame.size.width-2, frame.size.height-1); | |
525 glVertex2i(frame.size.width-1, frame.size.height-6); glVertex2i(frame.size.width-6, frame.size.height-1); | |
526 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
|
527 |
15339 | 528 glColor4f(0.6, 0.6, 0.6, 0.5); |
529 glVertex2i(frame.size.width-1, frame.size.height-3); glVertex2i(frame.size.width-3, frame.size.height-1); | |
530 glVertex2i(frame.size.width-1, frame.size.height-7); glVertex2i(frame.size.width-7, frame.size.height-1); | |
531 glVertex2i(frame.size.width-1, frame.size.height-11); glVertex2i(frame.size.width-11, frame.size.height-1); | |
532 glEnd(); | |
533 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
534 |
15289 | 535 glFlush(); |
536 } | |
537 | |
538 /* | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
539 Create OpenGL texture from current frame & set texco |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
540 */ |
15289 | 541 - (void) setCurrentTexture |
542 { | |
543 CVReturn error = kCVReturnSuccess; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
544 |
29137
0f6fc0df2c23
fix a memory leak leading to ~80 bytes being leaked at each call to flip_page.
gpoirier
parents:
28837
diff
changeset
|
545 CVOpenGLTextureRelease(texture); |
25180 | 546 error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); |
15289 | 547 if(error != kCVReturnSuccess) |
29210 | 548 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture(%d)\n", error); |
15289 | 549 |
550 CVOpenGLTextureGetCleanTexCoords(texture, lowerLeft, lowerRight, upperRight, upperLeft); | |
551 } | |
552 | |
553 /* | |
554 redraw win rect | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29210
diff
changeset
|
555 */ |
15289 | 556 - (void) drawRect: (NSRect *) bounds |
557 { | |
558 [self render]; | |
559 } | |
15325 | 560 @end |