| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
#ifdef HAVE_CONFIG_H |
|---|
| 25 |
# include "config.h" |
|---|
| 26 |
#endif |
|---|
| 27 |
#include "mediacontrol_internal.h" |
|---|
| 28 |
#include "libvlc_internal.h" |
|---|
| 29 |
|
|---|
| 30 |
#include <vlc/mediacontrol.h> |
|---|
| 31 |
#include <vlc/libvlc.h> |
|---|
| 32 |
|
|---|
| 33 |
#include <vlc_vout.h> |
|---|
| 34 |
#include <vlc_osd.h> |
|---|
| 35 |
|
|---|
| 36 |
#include <stdlib.h> |
|---|
| 37 |
#include <string.h> |
|---|
| 38 |
|
|---|
| 39 |
#include <errno.h> |
|---|
| 40 |
#include <stdio.h> |
|---|
| 41 |
#include <ctype.h> |
|---|
| 42 |
|
|---|
| 43 |
#ifdef HAVE_UNISTD_H |
|---|
| 44 |
# include <unistd.h> |
|---|
| 45 |
#endif |
|---|
| 46 |
#ifdef HAVE_SYS_TIME_H |
|---|
| 47 |
# include <sys/time.h> |
|---|
| 48 |
#endif |
|---|
| 49 |
#ifdef HAVE_SYS_TYPES_H |
|---|
| 50 |
# include <sys/types.h> |
|---|
| 51 |
#endif |
|---|
| 52 |
|
|---|
| 53 |
mediacontrol_RGBPicture * |
|---|
| 54 |
mediacontrol_snapshot( mediacontrol_Instance *self, |
|---|
| 55 |
const mediacontrol_Position * a_position, |
|---|
| 56 |
mediacontrol_Exception *exception ) |
|---|
| 57 |
{ |
|---|
| 58 |
(void)a_position; |
|---|
| 59 |
vlc_object_t* p_cache; |
|---|
| 60 |
vout_thread_t* p_vout; |
|---|
| 61 |
input_thread_t *p_input; |
|---|
| 62 |
mediacontrol_RGBPicture *p_pic = NULL; |
|---|
| 63 |
char path[256]; |
|---|
| 64 |
snapshot_t *p_snapshot; |
|---|
| 65 |
libvlc_exception_t ex; |
|---|
| 66 |
|
|---|
| 67 |
libvlc_exception_init( &ex ); |
|---|
| 68 |
mediacontrol_exception_init( exception ); |
|---|
| 69 |
|
|---|
| 70 |
p_input = libvlc_get_input_thread( self->p_media_player, &ex ); |
|---|
| 71 |
if( ! p_input ) |
|---|
| 72 |
{ |
|---|
| 73 |
RAISE_NULL( mediacontrol_InternalException, "No input" ); |
|---|
| 74 |
} |
|---|
| 75 |
p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD ); |
|---|
| 76 |
if( ! p_vout ) |
|---|
| 77 |
{ |
|---|
| 78 |
RAISE_NULL( mediacontrol_InternalException, "No video output" ); |
|---|
| 79 |
} |
|---|
| 80 |
p_cache = vlc_object_create( p_input, sizeof( vlc_object_t ) ); |
|---|
| 81 |
if( p_cache == NULL ) |
|---|
| 82 |
{ |
|---|
| 83 |
vlc_object_release( p_vout ); |
|---|
| 84 |
vlc_object_release( p_input ); |
|---|
| 85 |
RAISE_NULL( mediacontrol_InternalException, "Out of memory" ); |
|---|
| 86 |
} |
|---|
| 87 |
snprintf( path, 255, "object:%ju", (uintmax_t)(uintptr_t)p_cache ); |
|---|
| 88 |
var_SetString( p_vout, "snapshot-path", path ); |
|---|
| 89 |
var_SetString( p_vout, "snapshot-format", "png" ); |
|---|
| 90 |
|
|---|
| 91 |
vlc_object_lock( p_cache ); |
|---|
| 92 |
vout_Control( p_vout, VOUT_SNAPSHOT ); |
|---|
| 93 |
vlc_object_wait( p_cache ); |
|---|
| 94 |
vlc_object_release( p_vout ); |
|---|
| 95 |
|
|---|
| 96 |
p_snapshot = ( snapshot_t* ) p_cache->p_private; |
|---|
| 97 |
vlc_object_unlock( p_cache ); |
|---|
| 98 |
vlc_object_release( p_cache ); |
|---|
| 99 |
vlc_object_release( p_input ); |
|---|
| 100 |
|
|---|
| 101 |
if( p_snapshot ) |
|---|
| 102 |
{ |
|---|
| 103 |
p_pic = private_mediacontrol_createRGBPicture( p_snapshot->i_width, |
|---|
| 104 |
p_snapshot->i_height, |
|---|
| 105 |
VLC_FOURCC( 'p','n','g',' ' ), |
|---|
| 106 |
p_snapshot->date, |
|---|
| 107 |
p_snapshot->p_data, |
|---|
| 108 |
p_snapshot->i_datasize ); |
|---|
| 109 |
if( !p_pic ) |
|---|
| 110 |
{ |
|---|
| 111 |
free( p_snapshot->p_data ); |
|---|
| 112 |
free( p_snapshot ); |
|---|
| 113 |
RAISE_NULL( mediacontrol_InternalException, "Out of memory" ); |
|---|
| 114 |
} |
|---|
| 115 |
} |
|---|
| 116 |
else |
|---|
| 117 |
{ |
|---|
| 118 |
RAISE_NULL( mediacontrol_InternalException, "Snapshot exception" ); |
|---|
| 119 |
} |
|---|
| 120 |
return p_pic; |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
static |
|---|
| 124 |
int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel, |
|---|
| 125 |
char *psz_string, text_style_t *p_style, |
|---|
| 126 |
int i_flags, int i_hmargin, int i_vmargin, |
|---|
| 127 |
mtime_t i_start, mtime_t i_stop ) |
|---|
| 128 |
{ |
|---|
| 129 |
subpicture_t *p_spu; |
|---|
| 130 |
video_format_t fmt; |
|---|
| 131 |
|
|---|
| 132 |
if( !psz_string ) return VLC_EGENERIC; |
|---|
| 133 |
|
|---|
| 134 |
p_spu = spu_CreateSubpicture( p_vout->p_spu ); |
|---|
| 135 |
if( !p_spu ) return VLC_EGENERIC; |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
memset( &fmt, 0, sizeof(video_format_t) ); |
|---|
| 139 |
fmt.i_chroma = VLC_FOURCC('T','E','X','T'); |
|---|
| 140 |
fmt.i_aspect = 0; |
|---|
| 141 |
fmt.i_width = fmt.i_height = 0; |
|---|
| 142 |
fmt.i_x_offset = fmt.i_y_offset = 0; |
|---|
| 143 |
p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_vout), &fmt ); |
|---|
| 144 |
if( !p_spu->p_region ) |
|---|
| 145 |
{ |
|---|
| 146 |
msg_Err( p_vout, "cannot allocate SPU region" ); |
|---|
| 147 |
spu_DestroySubpicture( p_vout->p_spu, p_spu ); |
|---|
| 148 |
return VLC_EGENERIC; |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
p_spu->p_region->psz_text = strdup( psz_string ); |
|---|
| 152 |
p_spu->p_region->i_align = i_flags & SUBPICTURE_ALIGN_MASK; |
|---|
| 153 |
p_spu->p_region->p_style = p_style; |
|---|
| 154 |
p_spu->i_start = i_start; |
|---|
| 155 |
p_spu->i_stop = i_stop; |
|---|
| 156 |
p_spu->b_ephemer = false; |
|---|
| 157 |
p_spu->b_absolute = false; |
|---|
| 158 |
|
|---|
| 159 |
p_spu->i_x = i_hmargin; |
|---|
| 160 |
p_spu->i_y = i_vmargin; |
|---|
| 161 |
p_spu->i_flags = i_flags & ~SUBPICTURE_ALIGN_MASK; |
|---|
| 162 |
p_spu->i_channel = i_channel; |
|---|
| 163 |
|
|---|
| 164 |
spu_DisplaySubpicture( p_vout->p_spu, p_spu ); |
|---|
| 165 |
|
|---|
| 166 |
return VLC_SUCCESS; |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
void |
|---|
| 171 |
mediacontrol_display_text( mediacontrol_Instance *self, |
|---|
| 172 |
const char * message, |
|---|
| 173 |
const mediacontrol_Position * begin, |
|---|
| 174 |
const mediacontrol_Position * end, |
|---|
| 175 |
mediacontrol_Exception *exception ) |
|---|
| 176 |
{ |
|---|
| 177 |
vout_thread_t *p_vout = NULL; |
|---|
| 178 |
char* psz_message; |
|---|
| 179 |
input_thread_t *p_input; |
|---|
| 180 |
libvlc_exception_t ex; |
|---|
| 181 |
|
|---|
| 182 |
libvlc_exception_init( &ex ); |
|---|
| 183 |
mediacontrol_exception_init( exception ); |
|---|
| 184 |
|
|---|
| 185 |
p_input = libvlc_get_input_thread( self->p_media_player, &ex ); |
|---|
| 186 |
if( ! p_input ) |
|---|
| 187 |
{ |
|---|
| 188 |
RAISE_VOID( mediacontrol_InternalException, "No input" ); |
|---|
| 189 |
} |
|---|
| 190 |
p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD ); |
|---|
| 191 |
if( ! p_vout ) |
|---|
| 192 |
{ |
|---|
| 193 |
RAISE_VOID( mediacontrol_InternalException, "No video output" ); |
|---|
| 194 |
} |
|---|
| 195 |
|
|---|
| 196 |
psz_message = strdup( message ); |
|---|
| 197 |
if( !psz_message ) |
|---|
| 198 |
{ |
|---|
| 199 |
RAISE_VOID( mediacontrol_InternalException, "no more memory" ); |
|---|
| 200 |
} |
|---|
| 201 |
|
|---|
| 202 |
if( begin->origin == mediacontrol_RelativePosition && |
|---|
| 203 |
begin->value == 0 && |
|---|
| 204 |
end->origin == mediacontrol_RelativePosition ) |
|---|
| 205 |
{ |
|---|
| 206 |
mtime_t i_duration = 0; |
|---|
| 207 |
mtime_t i_now = mdate(); |
|---|
| 208 |
|
|---|
| 209 |
i_duration = 1000 * private_mediacontrol_unit_convert( |
|---|
| 210 |
self->p_media_player, |
|---|
| 211 |
end->key, |
|---|
| 212 |
mediacontrol_MediaTime, |
|---|
| 213 |
end->value ); |
|---|
| 214 |
|
|---|
| 215 |
mediacontrol_showtext( p_vout, DEFAULT_CHAN, psz_message, NULL, |
|---|
| 216 |
OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0, |
|---|
| 217 |
i_now, i_now + i_duration ); |
|---|
| 218 |
} |
|---|
| 219 |
else |
|---|
| 220 |
{ |
|---|
| 221 |
mtime_t i_debut, i_fin, i_now; |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
i_now = mdate(); |
|---|
| 226 |
|
|---|
| 227 |
i_debut = private_mediacontrol_position2microsecond( self->p_media_player, |
|---|
| 228 |
( mediacontrol_Position* ) begin ); |
|---|
| 229 |
i_debut += i_now; |
|---|
| 230 |
|
|---|
| 231 |
i_fin = private_mediacontrol_position2microsecond( self->p_media_player, |
|---|
| 232 |
( mediacontrol_Position * ) end ); |
|---|
| 233 |
i_fin += i_now; |
|---|
| 234 |
|
|---|
| 235 |
vout_ShowTextAbsolute( p_vout, DEFAULT_CHAN, psz_message, NULL, |
|---|
| 236 |
OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0, |
|---|
| 237 |
i_debut, i_fin ); |
|---|
| 238 |
} |
|---|
| 239 |
|
|---|
| 240 |
vlc_object_release( p_vout ); |
|---|
| 241 |
} |
|---|
| 242 |
|
|---|
| 243 |
unsigned short |
|---|
| 244 |
mediacontrol_sound_get_volume( mediacontrol_Instance *self, |
|---|
| 245 |
mediacontrol_Exception *exception ) |
|---|
| 246 |
{ |
|---|
| 247 |
libvlc_exception_t ex; |
|---|
| 248 |
int i_ret = 0; |
|---|
| 249 |
|
|---|
| 250 |
mediacontrol_exception_init( exception ); |
|---|
| 251 |
libvlc_exception_init( &ex ); |
|---|
| 252 |
|
|---|
| 253 |
i_ret = libvlc_audio_get_volume( self->p_instance, &ex ); |
|---|
| 254 |
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex ); |
|---|
| 255 |
|
|---|
| 256 |
return (unsigned short)i_ret; |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
void |
|---|
| 260 |
mediacontrol_sound_set_volume( mediacontrol_Instance *self, |
|---|
| 261 |
const unsigned short volume, |
|---|
| 262 |
mediacontrol_Exception *exception ) |
|---|
| 263 |
{ |
|---|
| 264 |
|
|---|
| 265 |
libvlc_exception_t ex; |
|---|
| 266 |
|
|---|
| 267 |
mediacontrol_exception_init( exception ); |
|---|
| 268 |
libvlc_exception_init( &ex ); |
|---|
| 269 |
|
|---|
| 270 |
libvlc_audio_set_volume( self->p_instance, volume, &ex ); |
|---|
| 271 |
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); |
|---|
| 272 |
} |
|---|
| 273 |
|
|---|
| 274 |
int mediacontrol_set_visual( mediacontrol_Instance *self, |
|---|
| 275 |
WINDOWHANDLE visual_id, |
|---|
| 276 |
mediacontrol_Exception *exception ) |
|---|
| 277 |
{ |
|---|
| 278 |
libvlc_exception_t ex; |
|---|
| 279 |
|
|---|
| 280 |
mediacontrol_exception_init( exception ); |
|---|
| 281 |
libvlc_exception_init( &ex ); |
|---|
| 282 |
|
|---|
| 283 |
libvlc_media_player_set_drawable( self->p_media_player, (libvlc_drawable_t)visual_id, &ex ); |
|---|
| 284 |
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex ); |
|---|
| 285 |
return true; |
|---|
| 286 |
} |
|---|
| 287 |
|
|---|
| 288 |
int |
|---|
| 289 |
mediacontrol_get_rate( mediacontrol_Instance *self, |
|---|
| 290 |
mediacontrol_Exception *exception ) |
|---|
| 291 |
{ |
|---|
| 292 |
libvlc_exception_t ex; |
|---|
| 293 |
int i_ret; |
|---|
| 294 |
|
|---|
| 295 |
mediacontrol_exception_init( exception ); |
|---|
| 296 |
libvlc_exception_init( &ex ); |
|---|
| 297 |
|
|---|
| 298 |
i_ret = libvlc_media_player_get_rate( self->p_media_player, &ex ); |
|---|
| 299 |
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex ); |
|---|
| 300 |
|
|---|
| 301 |
return i_ret / 10; |
|---|
| 302 |
} |
|---|
| 303 |
|
|---|
| 304 |
void |
|---|
| 305 |
mediacontrol_set_rate( mediacontrol_Instance *self, |
|---|
| 306 |
const int rate, |
|---|
| 307 |
mediacontrol_Exception *exception ) |
|---|
| 308 |
{ |
|---|
| 309 |
libvlc_exception_t ex; |
|---|
| 310 |
|
|---|
| 311 |
mediacontrol_exception_init( exception ); |
|---|
| 312 |
libvlc_exception_init( &ex ); |
|---|
| 313 |
|
|---|
| 314 |
libvlc_media_player_set_rate( self->p_media_player, rate * 10, &ex ); |
|---|
| 315 |
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); |
|---|
| 316 |
} |
|---|
| 317 |
|
|---|
| 318 |
int |
|---|
| 319 |
mediacontrol_get_fullscreen( mediacontrol_Instance *self, |
|---|
| 320 |
mediacontrol_Exception *exception ) |
|---|
| 321 |
{ |
|---|
| 322 |
libvlc_exception_t ex; |
|---|
| 323 |
int i_ret; |
|---|
| 324 |
|
|---|
| 325 |
mediacontrol_exception_init( exception ); |
|---|
| 326 |
libvlc_exception_init( &ex ); |
|---|
| 327 |
|
|---|
| 328 |
i_ret = libvlc_get_fullscreen( self->p_media_player, &ex ); |
|---|
| 329 |
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex ); |
|---|
| 330 |
|
|---|
| 331 |
return i_ret; |
|---|
| 332 |
} |
|---|
| 333 |
|
|---|
| 334 |
void |
|---|
| 335 |
mediacontrol_set_fullscreen( mediacontrol_Instance *self, |
|---|
| 336 |
const int b_fullscreen, |
|---|
| 337 |
mediacontrol_Exception *exception ) |
|---|
| 338 |
{ |
|---|
| 339 |
libvlc_exception_t ex; |
|---|
| 340 |
|
|---|
| 341 |
mediacontrol_exception_init( exception ); |
|---|
| 342 |
libvlc_exception_init( &ex ); |
|---|
| 343 |
|
|---|
| 344 |
libvlc_set_fullscreen( self->p_media_player, b_fullscreen, &ex ); |
|---|
| 345 |
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); |
|---|
| 346 |
} |
|---|