Mercurial > mplayer.hg
comparison libvo/vo_corevideo.m @ 29564:4ae3d2d7946e
Use MPlayer's standard aspect handling functions in corevideo
instead of reimplementing them incompletely.
author | reimar |
---|---|
date | Tue, 01 Sep 2009 09:36:04 +0000 |
parents | 9c8f8e375823 |
children | b128ce47771d |
comparison
equal
deleted
inserted
replaced
29563:0ba024eac67c | 29564:4ae3d2d7946e |
---|---|
82 | 82 |
83 //vo | 83 //vo |
84 static int isFullscreen; | 84 static int isFullscreen; |
85 static int isOntop; | 85 static int isOntop; |
86 static int isRootwin; | 86 static int isRootwin; |
87 extern float monitor_aspect; | |
88 extern float movie_aspect; | |
89 static float old_movie_aspect; | |
90 extern int enable_mouse_movements; | 87 extern int enable_mouse_movements; |
91 | 88 |
92 static float winAlpha = 1; | 89 static float winAlpha = 1; |
93 static int int_pause = 0; | 90 static int int_pause = 0; |
94 | 91 |
115 vo_draw_alpha_yuy2(w,h,src,srca,stride,image_data + (x0 + y0 * image_width) * 2,image_width*2); | 112 vo_draw_alpha_yuy2(w,h,src,srca,stride,image_data + (x0 + y0 * image_width) * 2,image_width*2); |
116 break; | 113 break; |
117 } | 114 } |
118 } | 115 } |
119 | 116 |
120 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) | 117 static void update_screen_info(void) |
121 { | 118 { |
122 | |
123 //init screen | |
124 screen_array = [NSScreen screens]; | 119 screen_array = [NSScreen screens]; |
125 if(screen_id < (int)[screen_array count]) | 120 if(screen_id < (int)[screen_array count]) |
126 { | 121 { |
127 screen_handle = [screen_array objectAtIndex:(screen_id < 0 ? 0 : screen_id)]; | 122 screen_handle = [screen_array objectAtIndex:(screen_id < 0 ? 0 : screen_id)]; |
128 } | 123 } |
130 { | 125 { |
131 mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] Device ID %d does not exist, falling back to main device\n", screen_id); | 126 mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] Device ID %d does not exist, falling back to main device\n", screen_id); |
132 screen_handle = [screen_array objectAtIndex:0]; | 127 screen_handle = [screen_array objectAtIndex:0]; |
133 screen_id = -1; | 128 screen_id = -1; |
134 } | 129 } |
135 screen_frame = [screen_handle frame]; | 130 |
131 screen_frame = ![mpGLView window] || screen_id >= 0 ? [screen_handle frame] : [[[mpGLView window] screen] frame]; | |
136 vo_screenwidth = screen_frame.size.width; | 132 vo_screenwidth = screen_frame.size.width; |
137 vo_screenheight = screen_frame.size.height; | 133 vo_screenheight = screen_frame.size.height; |
134 xinerama_x = xinerama_y = 0; | |
135 aspect_save_screenres(vo_screenwidth, vo_screenheight); | |
136 } | |
137 | |
138 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) | |
139 { | |
140 config_movie_aspect((float)d_width/d_height); | |
141 | |
142 vo_dwidth = d_width *= mpGLView->winSizeMult; | |
143 vo_dheight = d_height *= mpGLView->winSizeMult; | |
138 | 144 |
139 //misc mplayer setup | 145 //misc mplayer setup |
140 image_width = width; | 146 image_width = width; |
141 image_height = height; | 147 image_height = height; |
142 switch (image_format) | 148 switch (image_format) |
157 image_datas[0] = image_data; | 163 image_datas[0] = image_data; |
158 if (vo_doublebuffering) | 164 if (vo_doublebuffering) |
159 image_datas[1] = malloc(image_width*image_height*image_bytes); | 165 image_datas[1] = malloc(image_width*image_height*image_bytes); |
160 image_page = 0; | 166 image_page = 0; |
161 | 167 |
162 monitor_aspect = (float)screen_frame.size.width/(float)screen_frame.size.height; | |
163 | |
164 //set aspect | |
165 panscan_init(); | |
166 aspect_save_orig(width,height); | |
167 aspect_save_prescale(d_width,d_height); | |
168 aspect_save_screenres(screen_frame.size.width, screen_frame.size.height); | |
169 aspect((int *)&d_width,(int *)&d_height,A_NOZOOM); | |
170 | |
171 movie_aspect = (float)d_width/(float)d_height; | |
172 old_movie_aspect = movie_aspect; | |
173 | |
174 vo_fs = flags & VOFLAG_FULLSCREEN; | 168 vo_fs = flags & VOFLAG_FULLSCREEN; |
175 | 169 |
176 //config OpenGL View | 170 //config OpenGL View |
177 [mpGLView config]; | 171 [mpGLView config]; |
178 [mpGLView reshape]; | 172 [mpGLView reshape]; |
179 } | 173 } |
180 else | 174 else |
181 { | 175 { |
182 mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] writing output to a shared buffer " | 176 mp_msg(MSGT_VO, MSGL_INFO, "[vo_corevideo] writing output to a shared buffer " |
183 "named \"%s\"\n",buffer_name); | 177 "named \"%s\"\n",buffer_name); |
184 | |
185 movie_aspect = (float)d_width/(float)d_height; | |
186 | 178 |
187 // create shared memory | 179 // create shared memory |
188 shm_fd = shm_open(buffer_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); | 180 shm_fd = shm_open(buffer_name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); |
189 if (shm_fd == -1) | 181 if (shm_fd == -1) |
190 { | 182 { |
216 //connect to mplayerosx | 208 //connect to mplayerosx |
217 mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:[NSString stringWithCString:buffer_name] host:nil]; | 209 mplayerosxProxy=[NSConnection rootProxyForConnectionWithRegisteredName:[NSString stringWithCString:buffer_name] host:nil]; |
218 if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) { | 210 if ([mplayerosxProxy conformsToProtocol:@protocol(MPlayerOSXVOProto)]) { |
219 [mplayerosxProxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)]; | 211 [mplayerosxProxy setProtocolForProxy:@protocol(MPlayerOSXVOProto)]; |
220 mplayerosxProto = (id <MPlayerOSXVOProto>)mplayerosxProxy; | 212 mplayerosxProto = (id <MPlayerOSXVOProto>)mplayerosxProxy; |
221 [mplayerosxProto startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:(int)(movie_aspect*100)]; | 213 [mplayerosxProto startWithWidth: image_width withHeight: image_height withBytes: image_bytes withAspect:d_width*100/d_height]; |
222 } | 214 } |
223 else { | 215 else { |
224 [mplayerosxProxy release]; | 216 [mplayerosxProxy release]; |
225 mplayerosxProxy = nil; | 217 mplayerosxProxy = nil; |
226 mplayerosxProto = nil; | 218 mplayerosxProto = nil; |
426 case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); if(!shared_buffer){ [mpGLView ontop]; } else { [mplayerosxProto ontop]; } return VO_TRUE; | 418 case VOCTRL_ONTOP: vo_ontop = (!(vo_ontop)); if(!shared_buffer){ [mpGLView ontop]; } else { [mplayerosxProto ontop]; } return VO_TRUE; |
427 case VOCTRL_ROOTWIN: vo_rootwin = (!(vo_rootwin)); [mpGLView rootwin]; return VO_TRUE; | 419 case VOCTRL_ROOTWIN: vo_rootwin = (!(vo_rootwin)); [mpGLView rootwin]; return VO_TRUE; |
428 case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); if(!shared_buffer){ [mpGLView fullscreen: NO]; } else { [mplayerosxProto toggleFullscreen]; } return VO_TRUE; | 420 case VOCTRL_FULLSCREEN: vo_fs = (!(vo_fs)); if(!shared_buffer){ [mpGLView fullscreen: NO]; } else { [mplayerosxProto toggleFullscreen]; } return VO_TRUE; |
429 case VOCTRL_GET_PANSCAN: return VO_TRUE; | 421 case VOCTRL_GET_PANSCAN: return VO_TRUE; |
430 case VOCTRL_SET_PANSCAN: [mpGLView panscan]; return VO_TRUE; | 422 case VOCTRL_SET_PANSCAN: [mpGLView panscan]; return VO_TRUE; |
423 case VOCTRL_UPDATE_SCREENINFO: update_screen_info(); return VO_TRUE; | |
431 } | 424 } |
432 return VO_NOTIMPL; | 425 return VO_NOTIMPL; |
433 } | 426 } |
434 | 427 |
435 ////////////////////////////////////////////////////////////////////////// | 428 ////////////////////////////////////////////////////////////////////////// |
466 | 459 |
467 NSRect frame; | 460 NSRect frame; |
468 CVReturn error = kCVReturnSuccess; | 461 CVReturn error = kCVReturnSuccess; |
469 | 462 |
470 //config window | 463 //config window |
471 aspect((int *)&d_width, (int *)&d_height,A_NOZOOM); | 464 d_width = vo_dwidth; d_height = vo_dheight; |
472 frame = NSMakeRect(0, 0, d_width, d_height); | 465 frame = NSMakeRect(0, 0, d_width, d_height); |
473 [window setContentSize: frame.size]; | 466 [window setContentSize: frame.size]; |
474 | 467 |
475 //create OpenGL Context | 468 //create OpenGL Context |
476 glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil]; | 469 glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil]; |
594 if(isFullscreen) { | 587 if(isFullscreen) { |
595 vo_fs = (!(vo_fs)); [self fullscreen:NO]; | 588 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
596 } | 589 } |
597 | 590 |
598 winSizeMult = 0.5; | 591 winSizeMult = 0.5; |
599 frame.size.width = (d_width*winSizeMult); | 592 frame.size.width = d_width*winSizeMult; |
600 frame.size.height = ((d_width/movie_aspect)*winSizeMult); | 593 frame.size.height = d_height*winSizeMult; |
601 [window setContentSize: frame.size]; | 594 [window setContentSize: frame.size]; |
602 [self reshape]; | 595 [self reshape]; |
603 } | 596 } |
604 if(sender == kNormalScreenCmd) | 597 if(sender == kNormalScreenCmd) |
605 { | 598 { |
607 vo_fs = (!(vo_fs)); [self fullscreen:NO]; | 600 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
608 } | 601 } |
609 | 602 |
610 winSizeMult = 1; | 603 winSizeMult = 1; |
611 frame.size.width = d_width; | 604 frame.size.width = d_width; |
612 frame.size.height = d_width/movie_aspect; | 605 frame.size.height = d_height; |
613 [window setContentSize: frame.size]; | 606 [window setContentSize: frame.size]; |
614 [self reshape]; | 607 [self reshape]; |
615 } | 608 } |
616 if(sender == kDoubleScreenCmd) | 609 if(sender == kDoubleScreenCmd) |
617 { | 610 { |
619 vo_fs = (!(vo_fs)); [self fullscreen:NO]; | 612 vo_fs = (!(vo_fs)); [self fullscreen:NO]; |
620 } | 613 } |
621 | 614 |
622 winSizeMult = 2; | 615 winSizeMult = 2; |
623 frame.size.width = d_width*winSizeMult; | 616 frame.size.width = d_width*winSizeMult; |
624 frame.size.height = (d_width/movie_aspect)*winSizeMult; | 617 frame.size.height = d_height*winSizeMult; |
625 [window setContentSize: frame.size]; | 618 [window setContentSize: frame.size]; |
626 [self reshape]; | 619 [self reshape]; |
627 } | 620 } |
628 if(sender == kFullScreenCmd) | 621 if(sender == kFullScreenCmd) |
629 { | 622 { |
652 | 645 |
653 [self panscan]; | 646 [self panscan]; |
654 } | 647 } |
655 | 648 |
656 if(sender == kAspectOrgCmd) | 649 if(sender == kAspectOrgCmd) |
657 { | 650 change_movie_aspect(-1); |
658 movie_aspect = old_movie_aspect; | |
659 | |
660 if(isFullscreen) | |
661 { | |
662 [self reshape]; | |
663 } | |
664 else | |
665 { | |
666 frame.size.width = d_width*winSizeMult; | |
667 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
668 [window setContentSize: frame.size]; | |
669 [self reshape]; | |
670 } | |
671 } | |
672 | 651 |
673 if(sender == kAspectFullCmd) | 652 if(sender == kAspectFullCmd) |
674 { | 653 change_movie_aspect(4.0f/3.0f); |
675 movie_aspect = 4.0f/3.0f; | |
676 | |
677 if(isFullscreen) | |
678 { | |
679 [self reshape]; | |
680 } | |
681 else | |
682 { | |
683 frame.size.width = d_width*winSizeMult; | |
684 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
685 [window setContentSize: frame.size]; | |
686 [self reshape]; | |
687 } | |
688 } | |
689 | 654 |
690 if(sender == kAspectWideCmd) | 655 if(sender == kAspectWideCmd) |
691 { | 656 change_movie_aspect(16.0f/9.0f); |
692 movie_aspect = 16.0f/9.0f; | |
693 | |
694 if(isFullscreen) | |
695 { | |
696 [self reshape]; | |
697 } | |
698 else | |
699 { | |
700 frame.size.width = d_width*winSizeMult; | |
701 frame.size.height = (d_width/movie_aspect)*winSizeMult; | |
702 [window setContentSize: frame.size]; | |
703 [self reshape]; | |
704 } | |
705 } | |
706 } | 657 } |
707 | 658 |
708 /* | 659 /* |
709 Setup OpenGL | 660 Setup OpenGL |
710 */ | 661 */ |
722 */ | 673 */ |
723 - (void)reshape | 674 - (void)reshape |
724 { | 675 { |
725 uint32_t d_width; | 676 uint32_t d_width; |
726 uint32_t d_height; | 677 uint32_t d_height; |
727 float aspectX; | |
728 float aspectY; | |
729 int padding = 0; | |
730 | 678 |
731 NSRect frame = [self frame]; | 679 NSRect frame = [self frame]; |
680 vo_dwidth = frame.size.width; | |
681 vo_dheight = frame.size.height; | |
732 | 682 |
733 glViewport(0, 0, frame.size.width, frame.size.height); | 683 glViewport(0, 0, frame.size.width, frame.size.height); |
734 glMatrixMode(GL_PROJECTION); | 684 glMatrixMode(GL_PROJECTION); |
735 glLoadIdentity(); | 685 glLoadIdentity(); |
736 glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0); | 686 glOrtho(0, frame.size.width, frame.size.height, 0, -1.0, 1.0); |
738 glLoadIdentity(); | 688 glLoadIdentity(); |
739 | 689 |
740 //set texture frame | 690 //set texture frame |
741 if(vo_keepaspect) | 691 if(vo_keepaspect) |
742 { | 692 { |
743 aspect( (int *)&d_width, (int *)&d_height, A_NOZOOM); | 693 aspect( (int *)&d_width, (int *)&d_height, A_WINZOOM); |
744 d_height = ((float)d_width/movie_aspect); | 694 |
745 | 695 textureFrame = NSMakeRect((vo_dwidth - d_width) / 2, (vo_dheight - d_height) / 2, d_width, d_height); |
746 aspectX = (float)((float)frame.size.width/(float)d_width); | |
747 aspectY = (float)((float)(frame.size.height)/(float)d_height); | |
748 | |
749 if((d_height*aspectX)>(frame.size.height)) | |
750 { | |
751 padding = (frame.size.width - d_width*aspectY)/2; | |
752 textureFrame = NSMakeRect(padding, 0, d_width*aspectY, d_height*aspectY); | |
753 } | |
754 else | |
755 { | |
756 padding = ((frame.size.height) - d_height*aspectX)/2; | |
757 textureFrame = NSMakeRect(0, padding, d_width*aspectX, d_height*aspectX); | |
758 } | |
759 } | 696 } |
760 else | 697 else |
761 { | 698 { |
762 textureFrame = frame; | 699 textureFrame = frame; |
763 } | 700 } |
764 vo_dwidth = textureFrame.size.width; | |
765 vo_dheight = textureFrame.size.height; | |
766 } | 701 } |
767 | 702 |
768 /* | 703 /* |
769 Render frame | 704 Render frame |
770 */ | 705 */ |
875 CGDisplayHideCursor(kCGDirectMainDisplay); | 810 CGDisplayHideCursor(kCGDirectMainDisplay); |
876 mouseHide = YES; | 811 mouseHide = YES; |
877 } | 812 } |
878 | 813 |
879 old_frame = [window frame]; //save main window size & position | 814 old_frame = [window frame]; //save main window size & position |
880 if(screen_id >= 0) | 815 update_screen_info(); |
881 screen_frame = [screen_handle frame]; | |
882 else { | |
883 screen_frame = [[window screen] frame]; | |
884 vo_screenwidth = screen_frame.size.width; | |
885 vo_screenheight = screen_frame.size.height; | |
886 } | |
887 | 816 |
888 [window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx | 817 [window setFrame:screen_frame display:YES animate:animate]; //zoom-in window with nice useless sfx |
889 old_view_frame = [self bounds]; | 818 old_view_frame = [self bounds]; |
890 | 819 |
891 //fix origin for multi screen setup | 820 //fix origin for multi screen setup |