Commit ea48b014 authored by Benjamin Pracht's avatar Benjamin Pracht

* Implement Crop in the ogl vout

* The implementation is quite dirty, but I just cannot see any other easy solution...
parent 2d202f4d
...@@ -241,6 +241,7 @@ ...@@ -241,6 +241,7 @@
"o_mi_close_window" = id; "o_mi_close_window" = id;
"o_mi_controller" = id; "o_mi_controller" = id;
"o_mi_copy" = id; "o_mi_copy" = id;
"o_mi_crop" = id;
"o_mi_cut" = id; "o_mi_cut" = id;
"o_mi_deinterlace" = id; "o_mi_deinterlace" = id;
"o_mi_device" = id; "o_mi_device" = id;
...@@ -307,6 +308,7 @@ ...@@ -307,6 +308,7 @@
"o_mu_channels" = id; "o_mu_channels" = id;
"o_mu_chapter" = id; "o_mu_chapter" = id;
"o_mu_controls" = id; "o_mu_controls" = id;
"o_mu_crop" = id;
"o_mu_deinterlace" = id; "o_mu_deinterlace" = id;
"o_mu_device" = id; "o_mu_device" = id;
"o_mu_edit" = id; "o_mu_edit" = id;
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
<key>IBOpenObjects</key> <key>IBOpenObjects</key>
<array> <array>
<integer>21</integer> <integer>21</integer>
<integer>1789</integer>
</array> </array>
<key>IBSystem Version</key> <key>IBSystem Version</key>
<string>8H14</string> <string>8H14</string>
......
...@@ -230,6 +230,8 @@ struct intf_sys_t ...@@ -230,6 +230,8 @@ struct intf_sys_t
IBOutlet id o_mu_screen; IBOutlet id o_mu_screen;
IBOutlet id o_mi_aspect_ratio; IBOutlet id o_mi_aspect_ratio;
IBOutlet id o_mu_aspect_ratio; IBOutlet id o_mu_aspect_ratio;
IBOutlet id o_mi_crop;
IBOutlet id o_mu_crop;
IBOutlet id o_mi_subtitle; IBOutlet id o_mi_subtitle;
IBOutlet id o_mu_subtitle; IBOutlet id o_mu_subtitle;
IBOutlet id o_mi_deinterlace; IBOutlet id o_mi_deinterlace;
......
...@@ -557,6 +557,8 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -557,6 +557,8 @@ static VLCMain *_o_sharedMainInstance = nil;
[o_mu_videotrack setTitle: _NS("Video Track")]; [o_mu_videotrack setTitle: _NS("Video Track")];
[o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")]; [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
[o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")]; [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
[o_mi_crop setTitle: _NS("Crop")];
[o_mu_crop setTitle: _NS("Crop")];
[o_mi_screen setTitle: _NS("Video Device")]; [o_mi_screen setTitle: _NS("Video Device")];
[o_mu_screen setTitle: _NS("Video Device")]; [o_mu_screen setTitle: _NS("Video Device")];
[o_mi_subtitle setTitle: _NS("Subtitles Track")]; [o_mi_subtitle setTitle: _NS("Subtitles Track")];
...@@ -1155,6 +1157,9 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -1155,6 +1157,9 @@ static VLCMain *_o_sharedMainInstance = nil;
[o_controls setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)[VLCVoutView getRealVout: p_vout] [o_controls setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)[VLCVoutView getRealVout: p_vout]
var: "aspect-ratio" selector: @selector(toggleVar:)]; var: "aspect-ratio" selector: @selector(toggleVar:)];
[o_controls setupVarMenuItem: o_mi_crop target: (vlc_object_t *)[VLCVoutView getRealVout: p_vout]
var: "crop" selector: @selector(toggleVar:)];
[o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout [o_controls setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
var: "video-device" selector: @selector(toggleVar:)]; var: "video-device" selector: @selector(toggleVar:)];
...@@ -1331,6 +1336,7 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -1331,6 +1336,7 @@ static VLCMain *_o_sharedMainInstance = nil;
[o_mi_device setEnabled: b_enabled]; [o_mi_device setEnabled: b_enabled];
[o_mi_screen setEnabled: b_enabled]; [o_mi_screen setEnabled: b_enabled];
[o_mi_aspect_ratio setEnabled: b_enabled]; [o_mi_aspect_ratio setEnabled: b_enabled];
[o_mi_crop setEnabled: b_enabled];
} }
- (void)manageVolumeSlider - (void)manageVolumeSlider
......
...@@ -61,7 +61,8 @@ struct vout_sys_t ...@@ -61,7 +61,8 @@ struct vout_sys_t
NSRect s_frame; NSRect s_frame;
vlc_bool_t b_got_frame; vlc_bool_t b_got_frame;
vlc_mutex_t lock; vlc_mutex_t lock;
vlc_bool_t b_vout_size_update; int i_vout_size_update_counter;
int i_x, i_y;
}; };
/***************************************************************************** /*****************************************************************************
...@@ -76,7 +77,7 @@ static void Swap ( vout_thread_t * p_vout ); ...@@ -76,7 +77,7 @@ static void Swap ( vout_thread_t * p_vout );
static int Lock ( vout_thread_t * p_vout ); static int Lock ( vout_thread_t * p_vout );
static void Unlock ( vout_thread_t * p_vout ); static void Unlock ( vout_thread_t * p_vout );
static int AspectCallback( vlc_object_t *, char const *, static int AspectCropCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, vlc_value_t, void * );
int E_(OpenVideoGL) ( vlc_object_t * p_this ) int E_(OpenVideoGL) ( vlc_object_t * p_this )
...@@ -150,14 +151,21 @@ static int Init( vout_thread_t * p_vout ) ...@@ -150,14 +151,21 @@ static int Init( vout_thread_t * p_vout )
var_Create( p_vout->p_parent, "aspect-ratio", var_Create( p_vout->p_parent, "aspect-ratio",
VLC_VAR_STRING | VLC_VAR_DOINHERIT ); VLC_VAR_STRING | VLC_VAR_DOINHERIT );
} }
var_AddCallback( p_vout->p_parent, "aspect-ratio", AspectCallback, p_vout ); var_AddCallback( p_vout->p_parent, "aspect-ratio", AspectCropCallback, p_vout );
if( !var_Type( p_vout->p_parent, "crop" ) )
{
var_Create( p_vout->p_parent, "crop",
VLC_VAR_STRING | VLC_VAR_DOINHERIT );
}
var_AddCallback( p_vout->p_parent, "crop", AspectCropCallback, p_vout );
[[p_vout->p_sys->o_glview openGLContext] makeCurrentContext]; [[p_vout->p_sys->o_glview openGLContext] makeCurrentContext];
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static void End( vout_thread_t * p_vout ) static void End( vout_thread_t * p_vout )
{ {
var_DelCallback( p_vout->p_parent, "aspect-ratio", AspectCallback, p_vout ); var_DelCallback( p_vout->p_parent, "aspect-ratio", AspectCropCallback, p_vout );
var_DelCallback( p_vout->p_parent, "crop", AspectCropCallback, p_vout );
[[p_vout->p_sys->o_glview openGLContext] makeCurrentContext]; [[p_vout->p_sys->o_glview openGLContext] makeCurrentContext];
} }
...@@ -205,16 +213,17 @@ static int Manage( vout_thread_t * p_vout ) ...@@ -205,16 +213,17 @@ static int Manage( vout_thread_t * p_vout )
p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE; p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
} }
if( p_vout->p_sys->b_vout_size_update ) if( p_vout->p_sys->i_vout_size_update_counter )
{ {
NSRect old_bounds = [p_vout->p_sys->o_glview bounds]; int i_old_x = p_vout->p_sys->i_x, i_old_y = p_vout->p_sys->i_y;
[p_vout->p_sys->o_glview reshape]; [p_vout->p_sys->o_glview reshape];
if( [p_vout->p_sys->o_glview bounds].size.height != if( p_vout->p_sys->i_x != i_old_x || p_vout->p_sys->i_y != i_old_y )
old_bounds.size.height || {
[p_vout->p_sys->o_glview bounds].size.width != p_vout->p_sys->i_vout_size_update_counter = 0;
old_bounds.size.width); }
else if( p_vout->p_sys->i_vout_size_update_counter > 0 )
{ {
p_vout->p_sys->b_vout_size_update = VLC_FALSE; p_vout->p_sys->i_vout_size_update_counter--;
} }
} }
...@@ -261,14 +270,20 @@ static void Unlock( vout_thread_t * p_vout ) ...@@ -261,14 +270,20 @@ static void Unlock( vout_thread_t * p_vout )
vlc_mutex_unlock( &p_vout->p_sys->lock ); vlc_mutex_unlock( &p_vout->p_sys->lock );
} }
static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd, static int AspectCropCallback( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
/* Only update the vout size if the aspect ratio has actually been changed*/ /* Only update the vout size if the aspect ratio has actually been changed*/
/* We cannot change the size directly in this callback, since fmt_in
hasn't been updated yet, so do it in Manage */
if( strcmp( oldval.psz_string, newval.psz_string ) ) if( strcmp( oldval.psz_string, newval.psz_string ) )
{ {
((vout_thread_t *)p_data)->p_sys->b_vout_size_update = VLC_TRUE; /* khludge ! Here, we are not sure that the vout size will actually
change (for instance if we go from Predefined to 4:3 on a 4:3
stream). So, to to trigger reshape endlessly, we decrease that
counter each time we call reshape. We put it to 0 directly if
we actually change the vout size. */
((vout_thread_t *)p_data)->p_sys->i_vout_size_update_counter = 2;
} }
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -333,23 +348,28 @@ static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd, ...@@ -333,23 +348,28 @@ static int AspectCallback( vlc_object_t *p_this, char const *psz_cmd,
x = bounds.size.width; x = bounds.size.width;
y = bounds.size.height; y = bounds.size.height;
} }
else if( bounds.size.height * p_vout->render.i_aspect * else if( bounds.size.height * p_vout->fmt_in.i_visible_width *
p_vout->fmt_in.i_sar_num < p_vout->fmt_in.i_sar_num <
bounds.size.width * VOUT_ASPECT_FACTOR * p_vout->fmt_in.i_sar_den ) bounds.size.width * p_vout->fmt_in.i_visible_height *
p_vout->fmt_in.i_sar_den )
{ {
x = bounds.size.height * p_vout->render.i_aspect * x = ( bounds.size.height * p_vout->fmt_in.i_visible_width *
p_vout->fmt_in.i_sar_num / ( VOUT_ASPECT_FACTOR * p_vout->fmt_in.i_sar_num ) /
p_vout->fmt_in.i_sar_den ); ( p_vout->fmt_in.i_visible_height * p_vout->fmt_in.i_sar_den);
y = bounds.size.height; y = bounds.size.height;
} }
else else
{ {
x = bounds.size.width; x = bounds.size.width;
y = bounds.size.width * p_vout->fmt_in.i_sar_den * y = ( bounds.size.width * p_vout->fmt_in.i_visible_height *
VOUT_ASPECT_FACTOR / ( p_vout->fmt_in.i_sar_num * p_vout->fmt_in.i_sar_den) /
p_vout->render.i_aspect ); ( p_vout->fmt_in.i_visible_width * p_vout->fmt_in.i_sar_num );
} }
p_vout->p_sys->i_x = x;
p_vout->p_sys->i_y = y;
glViewport( ( bounds.size.width - x ) / 2, glViewport( ( bounds.size.width - x ) / 2,
( bounds.size.height - y ) / 2, x, y ); ( bounds.size.height - y ) / 2, x, y );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment