vlc_vout_display.h 13.8 KB
Newer Older
1 2 3 4 5 6 7 8
/*****************************************************************************
 * vlc_vout_display.h: vout_display_t definitions
 *****************************************************************************
 * Copyright (C) 2009 Laurent Aimar
 * $Id$
 *
 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
9 10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12 13 14 15
 * (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
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
19 20 21
 * You should have received a copy of the GNU Lesser 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.
22 23 24 25 26 27 28
 *****************************************************************************/

#ifndef VLC_VOUT_DISPLAY_H
#define VLC_VOUT_DISPLAY_H 1

#include <vlc_es.h>
#include <vlc_picture.h>
29
#include <vlc_picture_pool.h>
30
#include <vlc_subpicture.h>
31
#include <vlc_actions.h>
32
#include <vlc_mouse.h>
33
#include <vlc_vout.h>
34
#include <vlc_vout_window.h>
35
#include <vlc_viewpoint.h>
36

37 38 39 40 41 42 43 44 45 46
/**
 * \defgroup video_display Video output display
 * Video output display: output buffers and rendering
 *
 * \ingroup video_output
 * @{
 * \file
 * Video output display modules interface
 */

47 48 49 50 51
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;

/**
52
 * Possible alignments for vout_display.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
 */
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;

/**
 * Initial/Current configuration for a vout_display_t
 */
typedef struct {
69
    struct vout_window_t *window; /**< Window */
70 71 72
#if defined(_WIN32) || defined(__OS2__)
    bool is_fullscreen VLC_DEPRECATED;  /* Is the display fullscreen */
#endif
73 74 75 76

    /* Display properties */
    struct {
        /* Display size */
77 78
        unsigned  width;
        unsigned  height;
79 80

        /* Display SAR */
81
        vlc_rational_t sar;
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    } 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 {
97 98
        unsigned num;
        unsigned den;
99 100
    } zoom;

101
    vlc_viewpoint_t viewpoint;
102 103 104
} vout_display_cfg_t;

/**
105
 * Information from a vout_display_t to configure
106 107
 * the core behaviour.
 *
108
 * By default they are all false or NULL.
109 110 111
 *
 */
typedef struct {
112 113 114 115
    bool is_slow;                           /* The picture memory has slow read/write */
    bool has_double_click;                  /* Is double-click generated */
    bool has_pictures_invalid;              /* Will VOUT_DISPLAY_EVENT_PICTURES_INVALID be used */
    const vlc_fourcc_t *subpicture_chromas; /* List of supported chromas for subpicture rendering. */
116 117 118 119 120 121 122 123 124 125 126
} vout_display_info_t;

/**
 * Control query for vout_display_t
 */
enum {
    /* Ask to reset the internal buffers after a VOUT_DISPLAY_EVENT_PICTURES_INVALID
     * request.
     */
    VOUT_DISPLAY_RESET_PICTURES,

127
#if defined(_WIN32) || defined(__OS2__)
128
    /* Ask the module to acknowledge/refuse the fullscreen state change after
129
     * being requested (externally or by VOUT_DISPLAY_EVENT_FULLSCREEN */
130
    VOUT_DISPLAY_CHANGE_FULLSCREEN VLC_DEPRECATED_ENUM,     /* bool fs */
131 132
    /* Ask the module to acknowledge/refuse the window management state change
     * after being requested externally or by VOUT_DISPLAY_WINDOW_STATE */
133
    VOUT_DISPLAY_CHANGE_WINDOW_STATE VLC_DEPRECATED_ENUM,   /* unsigned state */
134
#endif
135
    /* Ask the module to acknowledge the display size change */
136
    VOUT_DISPLAY_CHANGE_DISPLAY_SIZE,   /* const vout_display_cfg_t *p_cfg */
137 138

    /* Ask the module to acknowledge/refuse fill display state change after
139
     * being requested externally */
140 141 142
    VOUT_DISPLAY_CHANGE_DISPLAY_FILLED, /* const vout_display_cfg_t *p_cfg */

    /* Ask the module to acknowledge/refuse zoom change after being requested
143
     * externally */
144 145 146
    VOUT_DISPLAY_CHANGE_ZOOM, /* const vout_display_cfg_t *p_cfg */

    /* Ask the module to acknowledge/refuse source aspect ratio after being
147
     * requested externally */
148
    VOUT_DISPLAY_CHANGE_SOURCE_ASPECT,
149 150

    /* Ask the module to acknowledge/refuse source crop change after being
151
     * requested externally.
152 153
     * The cropping requested is stored by video_format_t::i_x/y_offset and
     * video_format_t::i_visible_width/height */
154
    VOUT_DISPLAY_CHANGE_SOURCE_CROP,
155 156 157 158

    /* Ask the module to acknowledge/refuse VR/360° viewing direction after
     * being requested externally */
    VOUT_DISPLAY_CHANGE_VIEWPOINT,   /* const vout_display_cfg_t *p_cfg */
159 160 161 162 163
};

/**
 * Event from vout_display_t
 *
164 165
 * Events modifiying the state may be sent multiple times.
 * Only the transition will be retained and acted upon.
166 167 168 169 170 171 172 173
 */
enum {
    /* TODO:
     * ZOOM ? DISPLAY_FILLED ? ON_TOP ?
     */
    /* */
    VOUT_DISPLAY_EVENT_PICTURES_INVALID,    /* The buffer are now invalid and need to be changed */

174
#if defined(_WIN32) || defined(__OS2__)
175
    VOUT_DISPLAY_EVENT_FULLSCREEN,
176
    VOUT_DISPLAY_EVENT_WINDOW_STATE,
177
#endif
178 179 180 181 182 183

    /* Mouse event */
    VOUT_DISPLAY_EVENT_MOUSE_MOVED,
    VOUT_DISPLAY_EVENT_MOUSE_PRESSED,
    VOUT_DISPLAY_EVENT_MOUSE_RELEASED,
    VOUT_DISPLAY_EVENT_MOUSE_DOUBLE_CLICK,
184 185 186

    /* VR navigation */
    VOUT_DISPLAY_EVENT_VIEWPOINT_MOVED,
187 188 189 190 191 192 193 194
};

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

197
    /* Event coming from the module
198 199 200 201 202
     *
     * This function is set prior to the module instantiation and must not
     * be overwritten nor used directly (use the vout_display_SendEvent*
     * wrapper.
     *
203 204
     * 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
205
     * Be careful, it does not ensure correct serialization if it is used
206
     * from multiple threads.
207 208 209 210 211
     */
    void            (*event)(vout_display_t *, int, va_list);
};

struct vout_display_t {
212
    struct vlc_common_members obj;
213 214 215 216 217

    /* Module */
    module_t *module;

    /* Initial and current configuration.
218
     * You cannot modify it directly, you must use the appropriate events.
219
     *
220
     * It reflects the current values, i.e. after the event has been accepted
221 222 223 224 225 226
     * and applied/configured if needed.
     */
    const vout_display_cfg_t *cfg;

    /* video source format.
     *
227
     * Cropping is not requested while in the open function.
228 229 230 231 232 233 234
     * You cannot change it.
     */
    video_format_t source;

    /* picture_t format.
     *
     * You can only change it inside the module open function to
235 236
     * match what you want, and when a VOUT_DISPLAY_RESET_PICTURES control
     * request is made and succeeds.
237 238 239 240 241 242
     *
     * By default, it is equal to ::source except for the aspect ratio
     * which is undefined(0) and is ignored.
     */
    video_format_t fmt;

243
    /* Information
244
     *
245
     * You can only set them in the open function.
246 247 248
     */
    vout_display_info_t info;

249
    /* Return a pointer over the current picture_pool_t* (mandatory).
250
     *
251 252
     * For performance reasons, it is best to provide at least count
     * pictures but it is not mandatory.
253
     * You can return NULL when you cannot/do not want to allocate
254 255 256
     * pictures.
     * The vout display module keeps the ownership of the pool and can
     * destroy it only when closing or on invalid pictures control.
257
     */
258
    picture_pool_t *(*pool)(vout_display_t *, unsigned count);
259

260
    /* Prepare a picture and an optional subpicture for display (optional).
261 262
     *
     * It is called before the next pf_display call to provide as much
263 264
     * time as possible to prepare the given picture and the subpicture
     * for display.
265
     * You are guaranted that pf_display will always be called and using
266 267 268
     * the exact same picture_t and subpicture_t.
     * You cannot change the pixel content of the picture_t or of the
     * subpicture_t.
269
     */
270 271
    void       (*prepare)(vout_display_t *, picture_t *, subpicture_t *,
                          mtime_t date);
272

273
    /* Display a picture and an optional subpicture (mandatory).
274
     *
275 276 277 278
     * 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.
279
     *
280 281
     * This function gives away the ownership of the picture and of the
     * subpicture, so you must release them as soon as possible.
282
     */
283
    void       (*display)(vout_display_t *, picture_t *, subpicture_t *);
284 285 286 287 288 289

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

    /* Private place holder for the vout_display_t module (optional)
     *
290
     * A module is free to use it as it wishes.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
     */
    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);
}

309 310 311
VLC_DEPRECATED /* Use vout_window_ReportSize() in window provider instead. */
static inline void vout_display_SendEventDisplaySize(vout_display_t *vd,
                                                     int width, int height)
312
{
313
    vout_window_ReportSize(vd->cfg->window, width, height);
314
}
315

316 317 318 319
static inline void vout_display_SendEventPicturesInvalid(vout_display_t *vd)
{
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_PICTURES_INVALID);
}
320 321

VLC_DEPRECATED /* Use vout_window_ReportClose() in window provider instead. */
322 323
static inline void vout_display_SendEventClose(vout_display_t *vd)
{
324
    vout_window_ReportClose(vd->cfg->window);
325
}
326 327 328 329

#if defined(_WIN32) || defined(__OS2__)
VLC_DEPRECATED
/* Use vout_window_ReportKeyPress() in window provider instead. */
330 331
static inline void vout_display_SendEventKey(vout_display_t *vd, int key)
{
332
    vout_window_ReportKeyPress(vd->cfg->window, key);
333
}
334

335
static inline void vout_display_SendEventFullscreen(vout_display_t *vd, bool is_fullscreen)
336
{
337
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_FULLSCREEN, is_fullscreen);
338
}
339 340

VLC_DEPRECATED /* Core needs not know about this. Don't call. */
341
static inline void vout_display_SendWindowState(vout_display_t *vd, unsigned state)
342
{
343
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_WINDOW_STATE, state);
344
}
345
#endif
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
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);
}
362 363 364 365 366
static inline void vout_display_SendEventViewpointMoved(vout_display_t *vd,
                                                        const vlc_viewpoint_t *vp)
{
    vout_display_SendEvent(vd, VOUT_DISPLAY_EVENT_VIEWPOINT_MOVED, vp);
}
367 368

/**
369
 * Asks for a new window of a given type.
370
 */
371
static inline vout_window_t *vout_display_NewWindow(vout_display_t *vd, unsigned type)
372
{
373 374
    vout_window_t *wnd = vd->cfg->window;

375
    return (type == wnd->type) ? wnd : NULL;
376
}
377

378 379
static inline bool vout_display_IsWindowed(vout_display_t *vd)
{
380
    return vd->cfg->window->type != VOUT_WINDOW_TYPE_DUMMY;
381 382
}

383
/**
384
 * Computes the default display size given the source and
385 386
 * the display configuration.
 *
387
 * This asssumes that the picture is already cropped.
388
 */
389
VLC_API void vout_display_GetDefaultDisplaySize(unsigned *width, unsigned *height, const video_format_t *source, const vout_display_cfg_t *);
390 391 392 393 394 395 396 397


/**
 * Structure used to store the result of a vout_display_PlacePicture.
 */
typedef struct {
    int x;
    int y;
398 399
    unsigned width;
    unsigned height;
400 401 402
} vout_display_place_t;

/**
403
 * Computes how to place a picture inside the display to respect
404
 * the given parameters.
405
 * This assumes that cropping is done by an external mean.
406 407 408 409 410 411
 *
 * \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).
 */
412
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);
413

414 415 416 417 418 419 420 421 422 423 424 425 426

/**
 * Helper function that applies the necessary transforms to the mouse position
 * and then calls vout_display_SendEventMouseMoved.
 *
 * \param vd vout_display_t.
 * \param orient_display The orientation of the picture as seen on screen (probably ORIENT_NORMAL).
 * \param m_x Mouse x position (relative to place, origin is top left).
 * \param m_y Mouse y position (relative to place, origin is top left).
 * \param place Place of the picture.
 */
VLC_API void vout_display_SendMouseMovedDisplayCoordinates(vout_display_t *vd, video_orientation_t orient_display, int m_x, int m_y,
                                                           vout_display_place_t *place);
427

428 429
/** @} */
#endif /* VLC_VOUT_DISPLAY_H */