register.h 7.92 KB
Newer Older
1 2
/*
 * This file is part of libbluray
3
 * Copyright (C) 2010-2017  Petri Hintukainen <phintuka@users.sourceforge.net>
4
 *
gates's avatar
gates committed
5 6 7 8
 * This library 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 (at your option) any later version.
9
 *
gates's avatar
gates committed
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
gates's avatar
gates committed
12 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
14
 *
gates's avatar
gates committed
15 16 17
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see
 * <http://www.gnu.org/licenses/>.
18 19 20 21 22
 */

#if !defined(_BD_REGISTER_H_)
#define _BD_REGISTER_H_

23
#include "util/attributes.h"
24

25 26
#include <stdint.h>

27 28 29 30

#define BD_PSR_COUNT 128
#define BD_GPR_COUNT 4096

31 32 33 34 35 36 37
/*
 * Player Status Registers
 */

typedef enum {
    PSR_IG_STREAM_ID     = 0,
    PSR_PRIMARY_AUDIO_ID = 1,
38
    PSR_PG_STREAM        = 2, /* PG TextST and PIP PG TextST stream number */
39 40 41 42 43
    PSR_ANGLE_NUMBER     = 3, /* 1..N */
    PSR_TITLE_NUMBER     = 4, /* 1..N  (0 = top menu, 0xffff = first play) */
    PSR_CHAPTER          = 5, /* 1..N  (0xffff = invalid) */
    PSR_PLAYLIST         = 6, /* playlist file name number */
    PSR_PLAYITEM         = 7, /* 0..N-1 (playitem_id) */
44 45 46 47 48 49 50 51 52 53 54 55 56
    PSR_TIME             = 8, /* presetation time */
    PSR_NAV_TIMER        = 9,
    PSR_SELECTED_BUTTON_ID = 10,
    PSR_MENU_PAGE_ID     = 11,
    PSR_STYLE            = 12,
    PSR_PARENTAL         = 13,
    PSR_SECONDARY_AUDIO_VIDEO = 14,
    PSR_AUDIO_CAP        = 15,
    PSR_AUDIO_LANG       = 16,
    PSR_PG_AND_SUB_LANG  = 17,
    PSR_MENU_LANG        = 18,
    PSR_COUNTRY          = 19,
    PSR_REGION           = 20,
Petri Hintukainen's avatar
Petri Hintukainen committed
57 58 59 60
    PSR_OUTPUT_PREFER    = 21,
    PSR_3D_STATUS        = 22,
    PSR_DISPLAY_CAP      = 23,
    PSR_3D_CAP           = 24,
61 62 63 64
    PSR_UHD_CAP          = 25,
    PSR_UHD_DISPLAY_CAP  = 26,
    PSR_UHD_HDR_PREFER   = 27,
    PSR_UHD_SDR_CONV_PREFER = 28,
65 66 67 68 69 70 71 72 73 74 75 76 77 78
    PSR_VIDEO_CAP        = 29,
    PSR_TEXT_CAP         = 30, /* text subtitles */
    PSR_PROFILE_VERSION  = 31, /* player profile and version */
    PSR_BACKUP_PSR4      = 36,
    PSR_BACKUP_PSR5      = 37,
    PSR_BACKUP_PSR6      = 38,
    PSR_BACKUP_PSR7      = 39,
    PSR_BACKUP_PSR8      = 40,
    PSR_BACKUP_PSR10     = 42,
    PSR_BACKUP_PSR11     = 43,
    PSR_BACKUP_PSR12     = 44,
    /* 48-61: caps for characteristic text subtitle */
} bd_psr_idx;

79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

typedef struct bd_registers_s BD_REGISTERS;

/**
 *
 *  Initialize registers
 *
 * @return allocated BD_REGISTERS object with default values
 */
BD_PRIVATE BD_REGISTERS *bd_registers_init(void);

/**
 *
 *  Free BD_REGISTERS object
 *
 * @param registers  BD_REGISTERS object
 */
BD_PRIVATE void bd_registers_free(BD_REGISTERS *);


99
/*
100 101 102 103 104 105
 * GPR (general-purprose register) access
 */

/**
 *
 *  Read value of general-purprose register
106
 *
107 108 109
 * @param registers  BD_REGISTERS object
 * @param reg  register number
 * @return value stored in register, -1 on error (invalid register number)
110
 */
111
uint32_t bd_gpr_read(BD_REGISTERS *, unsigned int reg);
112

113 114 115 116 117 118 119 120 121
/**
 *
 *  Write to general-purprose register
 *
 * @param registers  BD_REGISTERS object
 * @param reg  register number
 * @param val  new value for register
 * @return 0 on success, -1 on error (invalid register number)
 */
122
int bd_gpr_write(BD_REGISTERS *, unsigned int reg, uint32_t val);
123 124


125 126 127 128 129 130 131 132 133 134 135 136
/*
 * PSR (player status / setting register) access
 */

/**
 *
 *  Read value of player status/setting register
 *
 * @param registers  BD_REGISTERS object
 * @param reg  register number
 * @return value stored in register, -1 on error (invalid register number)
 */
137
uint32_t bd_psr_read(BD_REGISTERS *, unsigned int reg);
138

139 140 141 142 143 144 145 146 147 148 149
/**
 *
 *  Write to player status register.
 *
 *  Writing to player setting registers will fail.
 *
 * @param registers  BD_REGISTERS object
 * @param reg  register number
 * @param val  new value for register
 * @return 0 on success, -1 on error (invalid register number)
 */
150
int bd_psr_write(BD_REGISTERS *, unsigned int reg, uint32_t val);
151

152 153 154 155 156 157 158 159 160 161 162 163 164 165
/**
 *
 *  Atomically change bits in player status register.
 *
 *  Replace selected bits of player status register.
 *  New value for PSR is (CURRENT_PSR_VALUE & ~mask) | (val & mask)
 *  Writing to player setting registers will fail.
 *
 * @param registers  BD_REGISTERS object
 * @param reg  register number
 * @param val  new value for register
 * @param mask  bit mask. bits to be written are set to 1.
 * @return 0 on success, -1 on error (invalid register number)
 */
166
BD_PRIVATE int bd_psr_write_bits(BD_REGISTERS *, unsigned int reg, uint32_t val, uint32_t mask);
167

168 169 170 171 172 173 174 175 176 177 178
/**
 *
 *  Write to any PSR, including player setting registers.
 *
 *  This should be called only by the application.
 *
 * @param registers  BD_REGISTERS object
 * @param reg  register number
 * @param val  new value for register
 * @return 0 on success, -1 on error (invalid register number)
 */
179
BD_PRIVATE int bd_psr_setting_write(BD_REGISTERS *, unsigned int reg, uint32_t val);
180 181 182 183 184 185 186

/**
 *
 *  Lock PSRs for atomic read-modify-write operation
 *
 * @param registers  BD_REGISTERS object
 */
187
BD_PRIVATE void bd_psr_lock(BD_REGISTERS *);
188 189 190 191 192 193 194

/**
 *
 *  Unlock PSRs
 *
 * @param registers  BD_REGISTERS object
 */
195
BD_PRIVATE void bd_psr_unlock(BD_REGISTERS *);
196 197 198 199 200 201 202 203 204

/**
 *
 *  Save player state
 *
 *  Copy values of registers 4-8 and 10-12 to backup registers 36-40 and 42-44.
 *
 * @param registers  BD_REGISTERS object
 */
205
BD_PRIVATE void bd_psr_save_state(BD_REGISTERS *);
206 207 208 209 210 211 212 213 214 215

/**
 *
 *  Restore player state
 *
 *  Restore registers 4-8 and 10-12 from backup registers 36-40 and 42-44.
 *  Initialize backup registers to default values.
 *
 * @param registers  BD_REGISTERS object
 */
216
BD_PRIVATE void bd_psr_restore_state(BD_REGISTERS *);
217

218 219 220 221 222 223 224 225
/**
 *
 *  Reset backup registers
 *
 *  Initialize backup registers 36-40 and 42-44 to default values.
 *
 * @param registers  BD_REGISTERS object
 */
226
BD_PRIVATE void bd_psr_reset_backup_registers(BD_REGISTERS *);
227

228 229 230 231 232

/*
 * Events when PSR value is changed
 */

233
/* event types */
234 235 236 237
#define BD_PSR_SAVE    1 /* backup player state. Single event, psr_idx and values undefined */
#define BD_PSR_WRITE   2 /* write, value unchanged */
#define BD_PSR_CHANGE  3 /* write, value changed */
#define BD_PSR_RESTORE 4 /* restore backup values */
238

239
/* event data */
240
typedef struct {
241
    unsigned ev_type; /* event type */
242

243
    unsigned psr_idx; /* register index */
244 245
    uint32_t old_val; /* old value of register */
    uint32_t new_val; /* new value of register */
246 247
} BD_PSR_EVENT;

248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
/**
 *
 *  Register callback function
 *
 *  Function is called every time PSR value changes.
 *
 * @param registers  BD_REGISTERS object
 * @param callback  callback function pointer
 * @param handle  application-specific handle that is provided to callback function as first parameter
 */
void bd_psr_register_cb(BD_REGISTERS *, void (*callback)(void*,BD_PSR_EVENT*), void *cb_handle);

/**
 *
 *  Unregister callback function
 *
 * @param registers  BD_REGISTERS object
 * @param callback  callback function to unregister
 * @param handle  application-specific handle that was used when callback was registered
 */
268 269
void bd_psr_unregister_cb(BD_REGISTERS *, void (*callback)(void*,BD_PSR_EVENT*), void *cb_handle);

270
BD_PRIVATE int psr_init_3D(BD_REGISTERS *, int initial_mode, int force);
271

272 273 274 275 276 277 278 279 280 281 282 283
/**
 *
 * Initialize registers for profile 6 (UHD) playback.
 *
 * Profiles 5 (3D) and 6 (UHD) can't be enabld at the same time.
 *
 * @param registers  BD_REGISTERS object
 * @return 0 on success, -1 on error (invalid state)
 *
 */
BD_PRIVATE int psr_init_UHD(BD_REGISTERS *, int force);

284

285 286 287 288 289 290 291 292 293
/*
 * save / restore registers between playback sessions
 *
 * When state is restored, restore events will be generated and playback state is restored.
 */

BD_PRIVATE void registers_save(BD_REGISTERS *p, uint32_t *psr, uint32_t *gpr);
BD_PRIVATE void registers_restore(BD_REGISTERS *p, const uint32_t *psr, const uint32_t *gpr);

294
#endif /* _BD_REGISTER_H_ */