vlc_vout_display.h 14.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*****************************************************************************
 * vlc_vout_display.h: vout_display_t definitions
 *****************************************************************************
 * Copyright (C) 2009 Laurent Aimar
 * $Id$
 *
 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifndef VLC_VOUT_DISPLAY_H
#define VLC_VOUT_DISPLAY_H 1

/**
 * \file
 * This file defines vout display structures and functions in vlc
 */

#include <vlc_es.h>
#include <vlc_picture.h>
34
#include <vlc_picture_pool.h>
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#include <vlc_subpicture.h>
#include <vlc_keys.h>
#include <vlc_mouse.h>
#include <vlc_vout_window.h>

/* XXX
 * Do NOT use video_format_t::i_aspect but i_sar_num/den everywhere. i_aspect
 * will be removed as soon as possible.
 *
 */
typedef struct vout_display_t vout_display_t;
typedef struct vout_display_sys_t vout_display_sys_t;
typedef struct vout_display_owner_t vout_display_owner_t;
typedef struct vout_display_owner_sys_t vout_display_owner_sys_t;

/**
51
 * Possible alignments for vout_display.
52 53 54 55 56 57 58 59 60 61 62 63
 */
typedef enum
{
    VOUT_DISPLAY_ALIGN_CENTER,
    /* */
    VOUT_DISPLAY_ALIGN_LEFT,
    VOUT_DISPLAY_ALIGN_RIGHT,
    /* */
    VOUT_DISPLAY_ALIGN_TOP,
    VOUT_DISPLAY_ALIGN_BOTTOM,
} vout_display_align_t;

64 65 66 67 68 69 70 71 72 73
/**
 * Window management state.
 */
enum {
    VOUT_WINDOW_STATE_NORMAL=0,
    VOUT_WINDOW_STATE_ABOVE=1,
    VOUT_WINDOW_STATE_BELOW=2,
    VOUT_WINDOW_STACK_MASK=3,
};

74 75 76 77 78 79 80 81 82 83 84 85
/**
 * Initial/Current configuration for a vout_display_t
 */
typedef struct {
    bool is_fullscreen;  /* Is the display fullscreen */

    /* Display properties */
    struct {
        /* Window title (may be NULL) */
        const char *title;

        /* Display size */
86 87
        unsigned  width;
        unsigned  height;
88 89 90

        /* Display SAR */
        struct {
91 92
            unsigned num;
            unsigned den;
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
        } sar;
    } display;

    /* Alignment of the picture inside the display */
    struct {
        int horizontal;
        int vertical;
    } align;

    /* Do we fill up the display with the video */
    bool is_display_filled;

    /* Zoom to use
     * It will be applied to the whole display if b_display_filled is set, otherwise
     * only on the video source */
    struct {
        int num;
        int den;
    } zoom;

} vout_display_cfg_t;

/**
116
 * Information from a vout_display_t to configure
117 118
 * the core behaviour.
 *
119
 * By default they are all false or NULL.
120 121 122
 *
 */
typedef struct {
123 124 125 126 127 128
    bool is_slow;                           /* The picture memory has slow read/write */
    bool has_double_click;                  /* Is double-click generated */
    bool has_hide_mouse;                    /* Is mouse automatically hidden */
    bool has_pictures_invalid;              /* Will VOUT_DISPLAY_EVENT_PICTURES_INVALID be used */
    bool has_event_thread;                  /* Will events (key at least) be emitted using an independent thread */
    const vlc_fourcc_t *subpicture_chromas; /* List of supported chromas for subpicture rendering. */
129 130 131 132 133 134
} vout_display_info_t;

/**
 * Control query for vout_display_t
 */
enum {
135
    /* Hide the mouse. It will be sent when
136 137 138 139 140 141 142 143 144
     * vout_display_t::info.b_hide_mouse is false */
    VOUT_DISPLAY_HIDE_MOUSE,

    /* Ask to reset the internal buffers after a VOUT_DISPLAY_EVENT_PICTURES_INVALID
     * request.
     */
    VOUT_DISPLAY_RESET_PICTURES,

    /* Ask the module to acknowledge/refuse the fullscreen state change after
145
     * being requested (externally or by VOUT_DISPLAY_EVENT_FULLSCREEN */
146 147
    VOUT_DISPLAY_CHANGE_FULLSCREEN,     /* const vout_display_cfg_t *p_cfg */

148 149 150
    /* Ask the module to acknowledge/refuse the window management state change
     * after being requested externally or by VOUT_DISPLAY_WINDOW_STATE */
    VOUT_DISPLAY_CHANGE_WINDOW_STATE,         /* unsigned state */
151 152

    /* Ask the module to acknowledge/refuse the display size change requested
153
     * (externally or by VOUT_DISPLAY_EVENT_DISPLAY_SIZE) */
154
    VOUT_DISPLAY_CHANGE_DISPLAY_SIZE,   /* const vout_display_cfg_t *p_cfg, int is_forced */
155 156

    /* Ask the module to acknowledge/refuse fill display state change after
157
     * being requested externally */
158 159 160
    VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, /* const vout_display_cfg_t *p_cfg */

    /* Ask the module to acknowledge/refuse zoom change after being requested
161
     * externally */
162 163 164
    VOUT_DISPLAY_CHANGE_ZOOM, /* const vout_display_cfg_t *p_cfg */

    /* Ask the module to acknowledge/refuse source aspect ratio after being
165
     * requested externally */
166 167 168
    VOUT_DISPLAY_CHANGE_SOURCE_ASPECT, /* const video_format_t *p_source */

    /* Ask the module to acknowledge/refuse source crop change after being
169
     * requested externally.
170 171 172
     * The cropping requested is stored by video_format_t::i_x/y_offset and
     * video_format_t::i_visible_width/height */
    VOUT_DISPLAY_CHANGE_SOURCE_CROP,   /* const video_format_t *p_source */
173 174

    /* Ask an opengl interface if available. */
175
    VOUT_DISPLAY_GET_OPENGL,           /* vlc_gl_t ** */
176 177 178 179 180
};

/**
 * Event from vout_display_t
 *
181 182
 * Events modifiying the state may be sent multiple times.
 * Only the transition will be retained and acted upon.
183 184 185 186 187 188 189 190 191
 */
enum {
    /* TODO:
     * ZOOM ? DISPLAY_FILLED ? ON_TOP ?
     */
    /* */
    VOUT_DISPLAY_EVENT_PICTURES_INVALID,    /* The buffer are now invalid and need to be changed */

    VOUT_DISPLAY_EVENT_FULLSCREEN,
192
    VOUT_DISPLAY_EVENT_WINDOW_STATE,
193

194
    VOUT_DISPLAY_EVENT_DISPLAY_SIZE,        /* The display size need to change : int i_width, int i_height, bool is_fullscreen */
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220

    /* */
    VOUT_DISPLAY_EVENT_CLOSE,
    VOUT_DISPLAY_EVENT_KEY,

    /* Full mouse state.
     * You can use it OR use the other mouse events. The core will do
     * the conversion.
     */
    VOUT_DISPLAY_EVENT_MOUSE_STATE,

    /* Mouse event */
    VOUT_DISPLAY_EVENT_MOUSE_MOVED,
    VOUT_DISPLAY_EVENT_MOUSE_PRESSED,
    VOUT_DISPLAY_EVENT_MOUSE_RELEASED,
    VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK,
};

/**
 * Vout owner structures
 */
struct vout_display_owner_t {
    /* Private place holder for the vout_display_t creator
     */
    vout_display_owner_sys_t *sys;

221
    /* Event coming from the module
222 223 224 225 226
     *
     * This function is set prior to the module instantiation and must not
     * be overwritten nor used directly (use the vout_display_SendEvent*
     * wrapper.
     *
227 228
     * You can send it at any time i.e. from any vout_display_t functions or
     * from another thread.
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
229
     * Be careful, it does not ensure correct serialization if it is used
230
     * from multiple threads.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
     */
    void            (*event)(vout_display_t *, int, va_list);

    /* Window management
     *
     * These functions are set prior to the module instantiation and must not
     * be overwritten nor used directly (use the vout_display_*Window
     * wrapper */
    vout_window_t *(*window_new)(vout_display_t *, const vout_window_cfg_t *);
    void           (*window_del)(vout_display_t *, vout_window_t *);
};

struct vout_display_t {
    VLC_COMMON_MEMBERS

    /* Module */
    module_t *module;

    /* Initial and current configuration.
250
     * You cannot modify it directly, you must use the appropriate events.
251
     *
252
     * It reflects the current values, i.e. after the event has been accepted
253 254 255 256 257 258
     * and applied/configured if needed.
     */
    const vout_display_cfg_t *cfg;

    /* video source format.
     *
259
     * Cropping is not requested while in the open function.
260 261 262 263 264 265 266
     * You cannot change it.
     */
    video_format_t source;

    /* picture_t format.
     *
     * You can only change it inside the module open function to
267 268
     * match what you want, and when a VOUT_DISPLAY_RESET_PICTURES control
     * request is made and succeeds.
269 270 271 272 273 274
     *
     * By default, it is equal to ::source except for the aspect ratio
     * which is undefined(0) and is ignored.
     */
    video_format_t fmt;

275
    /* Information
276
     *
277
     * You can only set them in the open function.
278 279 280
     */
    vout_display_info_t info;

281
    /* Return a pointer over the current picture_pool_t* (mandatory).
282
     *
283 284
     * For performance reasons, it is best to provide at least count
     * pictures but it is not mandatory.
285
     * You can return NULL when you cannot/do not want to allocate
286 287 288
     * pictures.
     * The vout display module keeps the ownership of the pool and can
     * destroy it only when closing or on invalid pictures control.
289
     */
290
    picture_pool_t *(*pool)(vout_display_t *, unsigned count);
291

292
    /* Prepare a picture and an optional subpicture for display (optional).
293 294
     *
     * It is called before the next pf_display call to provide as much
295 296
     * time as possible to prepare the given picture and the subpicture
     * for display.
297
     * You are guaranted that pf_display will always be called and using
298 299 300
     * the exact same picture_t and subpicture_t.
     * You cannot change the pixel content of the picture_t or of the
     * subpicture_t.
301
     */
302
    void       (*prepare)(vout_display_t *, picture_t *, subpicture_t *);
303

304
    /* Display a picture and an optional subpicture (mandatory).
305
     *
306 307 308 309
     * The picture and the optional subpicture must be displayed as soon as
     * possible.
     * You cannot change the pixel content of the picture_t or of the
     * subpicture_t.
310
     *
311 312
     * This function gives away the ownership of the picture and of the
     * subpicture, so you must release them as soon as possible.
313
     */
314
    void       (*display)(vout_display_t *, picture_t *, subpicture_t *);
315 316 317 318

    /* Control on the module (mandatory) */
    int        (*control)(vout_display_t *, int, va_list);

319
    /* Manage pending event (optional) */
320 321 322 323
    void       (*manage)(vout_display_t *);

    /* Private place holder for the vout_display_t module (optional)
     *
324
     * A module is free to use it as it wishes.
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
     */
    vout_display_sys_t *sys;

    /* Reserved for the vout_display_t owner.
     *
     * It must not be overwritten nor used directly by a module.
     */
    vout_display_owner_t owner;
};

static inline void vout_display_SendEvent(vout_display_t *vd, int query, ...)
{
    va_list args;
    va_start(args, query);
    vd->owner.event(vd, query, args);
    va_end(args);
}

343
static inline void vout_display_SendEventDisplaySize(vout_display_t *vd, int width, int height, bool is_fullscreen)
344
{
345
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_DISPLAY_SIZE, width, height, is_fullscreen);
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
}
static inline void vout_display_SendEventPicturesInvalid(vout_display_t *vd)
{
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_PICTURES_INVALID);
}
static inline void vout_display_SendEventClose(vout_display_t *vd)
{
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_CLOSE);
}
static inline void vout_display_SendEventKey(vout_display_t *vd, int key)
{
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_KEY, key);
}
static inline void vout_display_SendEventFullscreen(vout_display_t *vd, bool is_fullscreen)
{
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_FULLSCREEN, is_fullscreen);
}
363
static inline void vout_display_SendWindowState(vout_display_t *vd, unsigned state)
364
{
365
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_WINDOW_STATE, state);
366
}
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
/* The mouse position (State and Moved event) must be expressed against vout_display_t::source unit */
static inline void vout_display_SendEventMouseState(vout_display_t *vd, int x, int y, int button_mask)
{
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_STATE, x, y, button_mask);
}
static inline void vout_display_SendEventMouseMoved(vout_display_t *vd, int x, int y)
{
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_MOVED, x, y);
}
static inline void vout_display_SendEventMousePressed(vout_display_t *vd, int button)
{
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_PRESSED, button);
}
static inline void vout_display_SendEventMouseReleased(vout_display_t *vd, int button)
{
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_RELEASED, button);
}
static inline void vout_display_SendEventMouseDoubleClick(vout_display_t *vd)
{
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK);
}

/**
390
 * Asks for a new window with the given configuration as hint.
391 392 393 394 395 396 397
 *
 * b_standalone/i_x/i_y may be overwritten by the core
 */
static inline vout_window_t *vout_display_NewWindow(vout_display_t *vd, const vout_window_cfg_t *cfg)
{
    return vd->owner.window_new(vd, cfg);
}
398 399 400 401
/**
 * Deletes a window created by vout_display_NewWindow if window is non NULL
 * or any unused windows otherwise.
 */
402 403 404 405 406 407 408
static inline void vout_display_DeleteWindow(vout_display_t *vd,
                                             vout_window_t *window)
{
    vd->owner.window_del(vd, window);
}

/**
409
 * Computes the default display size given the source and
410 411
 * the display configuration.
 *
412
 * This asssumes that the picture is already cropped.
413
 */
414
VLC_API void vout_display_GetDefaultDisplaySize(unsigned *width, unsigned *height, const video_format_t *source, const vout_display_cfg_t *);
415 416 417 418 419 420 421 422


/**
 * Structure used to store the result of a vout_display_PlacePicture.
 */
typedef struct {
    int x;
    int y;
423 424
    unsigned width;
    unsigned height;
425 426 427
} vout_display_place_t;

/**
428
 * Computes how to place a picture inside the display to respect
429
 * the given parameters.
430
 * This assumes that cropping is done by an external mean.
431 432 433 434 435 436
 *
 * \param p_place Place inside the window (window pixel unit)
 * \param p_source Video source format
 * \param p_cfg Display configuration
 * \param b_clip If true, prevent the video to go outside the display (break zoom).
 */
437
VLC_API void vout_display_PlacePicture(vout_display_place_t *place, const video_format_t *source, const vout_display_cfg_t *cfg, bool do_clipping);
438 439 440

#endif /* VLC_VOUT_DISPLAY_H */