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