[libdvdnav-devel] [Git][videolan/libdvdnav][master] constify structures passed as reading parameters

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sun May 15 08:02:10 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / libdvdnav


Commits:
cf720818 by Steve Lhomme at 2022-05-08T17:20:25+00:00
constify structures passed as reading parameters

Most of them come from libdvdread and should never be modified.

- - - - -


14 changed files:

- examples/menus.c
- src/dvdnav.c
- src/dvdnav_internal.h
- src/highlight.c
- src/navigation.c
- src/searching.c
- src/vm/decoder.c
- src/vm/decoder.h
- src/vm/getset.c
- src/vm/getset.h
- src/vm/play.c
- src/vm/vm.c
- src/vm/vm.h
- src/vm/vmget.c


Changes:

=====================================
examples/menus.c
=====================================
@@ -228,7 +228,7 @@ int main(int argc, char **argv) {
 	  printf("Found %i DVD menu buttons...\n", pci->hli.hl_gi.btn_ns);
 
 	  for (button = 0; button < pci->hli.hl_gi.btn_ns; button++) {
-	    btni_t *btni = &(pci->hli.btnit[button]);
+	    const btni_t *btni = &(pci->hli.btnit[button]);
 	    printf("Button %i top-left @ (%i,%i), bottom-right @ (%i,%i)\n",
 		    button + 1, btni->x_start, btni->y_start,
 		    btni->x_end, btni->y_end);


=====================================
src/dvdnav.c
=====================================
@@ -310,7 +310,7 @@ const char* dvdnav_err_to_string(dvdnav_t *this) {
 }
 
 /* converts a dvd_time_t to PTS ticks */
-int64_t dvdnav_convert_time(dvd_time_t *time) {
+int64_t dvdnav_convert_time(const dvd_time_t *time) {
   int64_t result;
   int64_t frames;
 


=====================================
src/dvdnav_internal.h
=====================================
@@ -158,7 +158,7 @@ typedef struct {
 typedef struct {
   vobu_admap_t        *admap;
   int32_t             admap_len;
-  vts_tmap_t          *tmap;
+  const vts_tmap_t    *tmap;
   int32_t             tmap_len;
   int32_t             tmap_interval;
 } dvdnav_jump_args_t;
@@ -224,7 +224,7 @@ struct dvdnav_s {
 /** HELPER FUNCTIONS **/
 
 /* converts a dvd_time_t to PTS ticks */
-int64_t dvdnav_convert_time(dvd_time_t *time);
+int64_t dvdnav_convert_time(const dvd_time_t *time);
 
 /** USEFUL MACROS **/
 


=====================================
src/highlight.c
=====================================
@@ -220,7 +220,7 @@ dvdnav_status_t dvdnav_get_current_highlight(dvdnav_t *this, int32_t *button) {
   return DVDNAV_STATUS_OK;
 }
 
-static btni_t *get_current_button(dvdnav_t *this, pci_t *pci) {
+static const btni_t *get_current_button(dvdnav_t *this, pci_t *pci) {
   int32_t button = 0;
 
   if(!pci->hli.hl_gi.hli_ss) {
@@ -241,7 +241,7 @@ static btni_t *get_current_button(dvdnav_t *this, pci_t *pci) {
 }
 
 static dvdnav_status_t button_auto_action(dvdnav_t *this, pci_t *pci) {
-  btni_t *button_ptr;
+  const btni_t *button_ptr;
   if ((button_ptr = get_current_button(this, pci)) == NULL)
       return DVDNAV_STATUS_ERR;
 
@@ -252,7 +252,7 @@ static dvdnav_status_t button_auto_action(dvdnav_t *this, pci_t *pci) {
 }
 
 dvdnav_status_t dvdnav_upper_button_select(dvdnav_t *this, pci_t *pci) {
-  btni_t *button_ptr;
+  const btni_t *button_ptr;
 
   if(!(button_ptr = get_current_button(this, pci)))
     return DVDNAV_STATUS_ERR;
@@ -262,7 +262,7 @@ dvdnav_status_t dvdnav_upper_button_select(dvdnav_t *this, pci_t *pci) {
 }
 
 dvdnav_status_t dvdnav_lower_button_select(dvdnav_t *this, pci_t *pci) {
-  btni_t *button_ptr;
+  const btni_t *button_ptr;
 
   if(!(button_ptr = get_current_button(this, pci)))
     return DVDNAV_STATUS_ERR;
@@ -272,7 +272,7 @@ dvdnav_status_t dvdnav_lower_button_select(dvdnav_t *this, pci_t *pci) {
 }
 
 dvdnav_status_t dvdnav_right_button_select(dvdnav_t *this, pci_t *pci) {
-  btni_t *button_ptr;
+  const btni_t *button_ptr;
 
   if(!(button_ptr = get_current_button(this, pci)))
     return DVDNAV_STATUS_ERR;
@@ -282,7 +282,7 @@ dvdnav_status_t dvdnav_right_button_select(dvdnav_t *this, pci_t *pci) {
 }
 
 dvdnav_status_t dvdnav_left_button_select(dvdnav_t *this, pci_t *pci) {
-  btni_t *button_ptr;
+  const btni_t *button_ptr;
 
   if(!(button_ptr = get_current_button(this, pci)))
     return DVDNAV_STATUS_ERR;
@@ -293,7 +293,7 @@ dvdnav_status_t dvdnav_left_button_select(dvdnav_t *this, pci_t *pci) {
 
 dvdnav_status_t dvdnav_get_highlight_area(pci_t *nav_pci , int32_t button, int32_t mode,
                                           dvdnav_highlight_area_t *highlight) {
-  btni_t *button_ptr;
+  const btni_t *button_ptr;
 
 #ifdef BUTTON_TESTING
   fprintf(MSG_OUT, "libdvdnav: Button get_highlight_area %i\n", button);
@@ -331,7 +331,7 @@ dvdnav_status_t dvdnav_get_highlight_area(pci_t *nav_pci , int32_t button, int32
 
 dvdnav_status_t dvdnav_button_activate(dvdnav_t *this, pci_t *pci) {
   int32_t button;
-  btni_t *button_ptr = NULL;
+  const btni_t *button_ptr = NULL;
 
   if(!pci->hli.hl_gi.hli_ss) {
     printerr("Not in a menu.");
@@ -480,7 +480,7 @@ dvdnav_status_t dvdnav_mouse_select(dvdnav_t *this, pci_t *pci, int32_t x, int32
 
   /* Loop through all buttons */
   for(button = 1; button <= pci->hli.hl_gi.btn_ns; button++) {
-    btni_t *button_ptr = &(pci->hli.btnit[button-1]);
+    const btni_t *button_ptr = &(pci->hli.btnit[button-1]);
 
     if((x >= button_ptr->x_start) && (x <= button_ptr->x_end) &&
        (y >= button_ptr->y_start) && (y <= button_ptr->y_end)) {


=====================================
src/navigation.c
=====================================
@@ -65,7 +65,7 @@ dvdnav_status_t dvdnav_get_number_of_titles(dvdnav_t *this, int32_t *titles) {
 }
 
 static dvdnav_status_t get_title_by_number(dvdnav_t *this, int32_t title,
-                                           title_info_t **pp_title)
+                                           const title_info_t **pp_title)
 {
     int32_t titlescount;
     dvdnav_status_t status = dvdnav_get_number_of_titles(this, &titlescount);
@@ -83,7 +83,7 @@ static dvdnav_status_t get_title_by_number(dvdnav_t *this, int32_t title,
 }
 
 dvdnav_status_t dvdnav_get_number_of_parts(dvdnav_t *this, int32_t title, int32_t *parts) {
-  title_info_t *info;
+  const title_info_t *info;
   dvdnav_status_t status = get_title_by_number(this, title, &info);
   if(status == DVDNAV_STATUS_OK)
       (*parts) = info->nr_of_ptts;
@@ -91,7 +91,7 @@ dvdnav_status_t dvdnav_get_number_of_parts(dvdnav_t *this, int32_t title, int32_
 }
 
 dvdnav_status_t dvdnav_get_number_of_angles(dvdnav_t *this, int32_t title, int32_t *angles) {
-    title_info_t *info;
+    const title_info_t *info;
     dvdnav_status_t status = get_title_by_number(this, title, &info);
     if(status == DVDNAV_STATUS_OK)
         (*angles) = info->nr_of_angles;


=====================================
src/searching.c
=====================================
@@ -132,7 +132,7 @@ dvdnav_status_t dvdnav_time_search(dvdnav_t *this,
   uint64_t length = 0;
   uint32_t first_cell_nr, last_cell_nr, cell_nr;
   int32_t found;
-  cell_playback_t *cell;
+  const cell_playback_t *cell;
   dvd_state_t *state;
 
   if(this->position_current.still != 0) {
@@ -218,7 +218,7 @@ dvdnav_status_t dvdnav_sector_search(dvdnav_t *this,
   uint32_t first_cell_nr, last_cell_nr, cell_nr;
   int32_t found;
   int forward = 0;
-  cell_playback_t *cell;
+  const cell_playback_t *cell;
   dvd_state_t *state;
   dvdnav_status_t result;
 
@@ -536,7 +536,7 @@ dvdnav_status_t dvdnav_get_position(dvdnav_t *this, uint32_t *pos,
                                     uint32_t *len) {
   uint32_t cur_sector;
   int32_t cell_nr, first_cell_nr, last_cell_nr;
-  cell_playback_t *cell;
+  const cell_playback_t *cell;
   dvd_state_t *state;
 
   if(!this->started) {
@@ -604,8 +604,8 @@ dvdnav_status_t dvdnav_get_position_in_title(dvdnav_t *this,
   uint32_t cur_sector;
   uint32_t first_cell_nr;
   uint32_t last_cell_nr;
-  cell_playback_t *first_cell;
-  cell_playback_t *last_cell;
+  const cell_playback_t *first_cell;
+  const cell_playback_t *last_cell;
   dvd_state_t *state;
 
   state = &(this->vm->state);
@@ -637,11 +637,11 @@ dvdnav_status_t dvdnav_get_position_in_title(dvdnav_t *this,
 uint32_t dvdnav_describe_title_chapters(dvdnav_t *this, int32_t title, uint64_t **times, uint64_t *duration) {
   int32_t retval=0;
   uint16_t parts, i;
-  title_info_t *ptitle = NULL;
-  ptt_info_t *ptt = NULL;
+  const title_info_t *ptitle = NULL;
+  const ptt_info_t *ptt = NULL;
   ifo_handle_t *ifo = NULL;
-  pgc_t *pgc;
-  cell_playback_t *cell;
+  const pgc_t *pgc;
+  const cell_playback_t *cell;
   uint64_t length, *tmp=NULL;
 
   *times = NULL;
@@ -791,14 +791,14 @@ static vobu_admap_t* dvdnav_admap_get(dvdnav_t *this, dvd_state_t *state,
 }
 
 /* Get a tmap, tmap_len and tmap_interval */
-static vts_tmap_t* dvdnav_tmap_get(dvdnav_t *this, dvd_state_t *state,
+static const vts_tmap_t* dvdnav_tmap_get(dvdnav_t *this, dvd_state_t *state,
             int32_t *tmap_len, int32_t *tmap_interval) {
   int32_t domain;
   ifo_handle_t *ifo = NULL;
   vts_tmapt_t *tmapt = NULL;
   uint16_t tmap_count = 0;
   int32_t pgcN = 0;
-  vts_tmap_t *tmap = NULL;
+  const vts_tmap_t *tmap = NULL;
   int32_t result = 0;
 
   domain = state->domain;
@@ -878,7 +878,7 @@ static vts_tmap_t* dvdnav_tmap_get(dvdnav_t *this, dvd_state_t *state,
 
 /* Get a sector from a tmap */
 static int32_t dvdnav_tmap_get_entry(dvdnav_t *this,
-                                     vts_tmap_t *tmap, uint16_t tmap_len,
+                                     const vts_tmap_t *tmap, uint16_t tmap_len,
                                      int32_t idx, uint32_t *sector) {
   /* tmaps start at idx 0 which represents a sector at time 1 * tmap_interval
    * this creates a "fake" tmap index at idx -1 for sector 0 */
@@ -936,7 +936,7 @@ static int32_t dvdnav_admap_search(vobu_admap_t *admap, uint32_t admap_len,
 
 /* Do a binary search for the earlier tmap entry near find_sector */
 static int32_t dvdnav_tmap_search(dvdnav_t *this,
-                                  vts_tmap_t *tmap, uint32_t tmap_len,
+                                  const vts_tmap_t *tmap, uint32_t tmap_len,
             uint32_t find_sector, int32_t *tmap_idx, uint32_t *sector) {
   int32_t adj = 1;
   int32_t prv_pos = 0;
@@ -992,9 +992,9 @@ static int32_t dvdnav_cell_find(dvdnav_t *this, dvd_state_t *state,
   uint32_t cells_bgn = 0;
   uint32_t cells_end = 0;
   uint32_t cell_idx = 0;
-  pgc_t *pgc = NULL;
+  const pgc_t *pgc = NULL;
   int pgN = 0;
-  cell_playback_t *cell = NULL;
+  const cell_playback_t *cell = NULL;
   int found = 0;
 
   pgc = state->pgc;


=====================================
src/vm/decoder.c
=====================================
@@ -643,7 +643,7 @@ static void eval_set_version_2(command_t* command, int32_t cond) {
 /* Evaluate a command
    returns row number of goto, 0 if no goto, -1 if link.
    Link command in return_values */
-static int32_t eval_command(uint8_t *bytes, registers_t* registers, link_t *return_values) {
+static int32_t eval_command(const uint8_t *bytes, registers_t* registers, link_t *return_values) {
   int32_t cond, res = 0;
   command_t command;
   command.instruction =( (uint64_t) bytes[0] << 56 ) |
@@ -731,7 +731,7 @@ static int32_t eval_command(uint8_t *bytes, registers_t* registers, link_t *retu
 }
 
 /* Evaluate a set of commands in the given register set (which is modified) */
-int32_t vmEval_CMD(vm_cmd_t commands[], int32_t num_commands,
+int32_t vmEval_CMD(const vm_cmd_t commands[], int32_t num_commands,
                registers_t *registers, link_t *return_values) {
   int32_t i = 0;
   int32_t total = 0;


=====================================
src/vm/decoder.h
=====================================
@@ -94,7 +94,7 @@ typedef struct {
 /* the big VM function, executing the given commands and writing
  * the link where to continue, the return value indicates if a jump
  * has been performed */
-int32_t vmEval_CMD(vm_cmd_t commands[], int32_t num_commands,
+int32_t vmEval_CMD(const vm_cmd_t commands[], int32_t num_commands,
                registers_t *registers, link_t *return_values);
 
 /* extracts some bits from the command */


=====================================
src/vm/getset.c
=====================================
@@ -145,7 +145,7 @@ int set_MENU(vm_t *vm, int menu) {
 }
 
 int set_PGCN(vm_t *vm, int pgcN) {
-  pgcit_t *pgcit;
+  const pgcit_t *pgcit;
 
   pgcit = get_PGCIT(vm);
   if (pgcit == NULL)
@@ -249,7 +249,7 @@ int get_TT(vm_t *vm, int vtsN, int vts_ttn) {
  */
 int get_ID(vm_t *vm, int id) {
   int pgcN, i;
-  pgcit_t *pgcit;
+  const pgcit_t *pgcit;
 
   /* Relies on state to get the correct pgcit. */
   pgcit = get_PGCIT(vm);
@@ -288,7 +288,7 @@ int get_ID(vm_t *vm, int id) {
 
 /* FIXME: we have a pgcN member in the vm's state now, so this should be obsolete */
 int get_PGCN(vm_t *vm) {
-  pgcit_t *pgcit;
+  const pgcit_t *pgcit;
   int pgcN = 1;
 
   if ((vm->state).pgc == NULL) {
@@ -311,7 +311,7 @@ int get_PGCN(vm_t *vm) {
   return 0; /*  error */
 }
 
-pgcit_t* get_MENU_PGCIT(vm_t *vm, ifo_handle_t *h, uint16_t lang) {
+const pgcit_t* get_MENU_PGCIT(vm_t *vm, ifo_handle_t *h, uint16_t lang) {
   int i;
 
   if(h == NULL || h->pgci_ut == NULL) {
@@ -347,8 +347,8 @@ pgcit_t* get_MENU_PGCIT(vm_t *vm, ifo_handle_t *h, uint16_t lang) {
 }
 
 /* Uses state to decide what to return */
-pgcit_t* get_PGCIT(vm_t *vm) {
-  pgcit_t *pgcit = NULL;
+const pgcit_t* get_PGCIT(vm_t *vm) {
+  const pgcit_t *pgcit = NULL;
 
   switch ((vm->state).domain) {
   case DVD_DOMAIN_VTSTitle:


=====================================
src/vm/getset.h
=====================================
@@ -45,6 +45,6 @@ int get_TT(vm_t *vm, int vtsN, int vts_ttn);
 int get_ID(vm_t *vm, int id);
 int get_PGCN(vm_t *vm);
 
-pgcit_t* get_MENU_PGCIT(vm_t *vm, ifo_handle_t *h, uint16_t lang);
-pgcit_t* get_PGCIT(vm_t *vm);
+const pgcit_t* get_MENU_PGCIT(vm_t *vm, ifo_handle_t *h, uint16_t lang);
+const pgcit_t* get_PGCIT(vm_t *vm);
 


=====================================
src/vm/play.c
=====================================
@@ -261,7 +261,7 @@ link_t play_Cell(vm_t *vm) {
 }
 
 link_t play_Cell_post(vm_t *vm) {
-  cell_playback_t *cell;
+  const cell_playback_t *cell;
 
 #ifdef TRACE
   Log3(vm, "play_Cell_post: (vm->state).cellN (%i)", (vm->state).cellN);


=====================================
src/vm/vm.c
=====================================
@@ -741,7 +741,7 @@ int vm_jump_resume(vm_t *vm) {
   return !!process_command(vm, link_values);
 }
 
-int vm_exec_cmd(vm_t *vm, vm_cmd_t *cmd) {
+int vm_exec_cmd(vm_t *vm, const vm_cmd_t *cmd) {
   link_t link_values;
 
   if(vmEval_CMD(cmd, 1, &vm->state.registers, &link_values))


=====================================
src/vm/vm.h
=====================================
@@ -31,7 +31,7 @@ typedef struct {
 
   DVDDomain_t  domain;
   int       vtsN;         /* 0 is vmgm? */
-  pgc_t    *pgc;          /* either this or 'int pgcN' is enough? */
+  const pgc_t  *pgc;    /* either this or 'int pgcN' is enough? */
   int       pgcN;         /* but provide pgcN for quick lookup */
   int       pgN;          /* is this needed? can always fid pgN from cellN? */
   int       cellN;
@@ -141,7 +141,7 @@ int vm_jump_prev_pg(vm_t *vm);
 int vm_jump_up(vm_t *vm);
 int vm_jump_menu(vm_t *vm, DVDMenuID_t menuid);
 int vm_jump_resume(vm_t *vm);
-int vm_exec_cmd(vm_t *vm, vm_cmd_t *cmd);
+int vm_exec_cmd(vm_t *vm, const vm_cmd_t *cmd);
 
 /* getting information */
 int vm_get_current_menu(vm_t *vm, int *menuid);


=====================================
src/vm/vmget.c
=====================================
@@ -45,7 +45,7 @@
 /* getting information */
 
 int vm_get_current_menu(vm_t *vm, int *menuid) {
-  pgcit_t* pgcit;
+  const pgcit_t* pgcit;
   int pgcn;
   pgcn = (vm->state).pgcN;
   pgcit = get_PGCIT(vm);
@@ -216,7 +216,7 @@ void vm_get_angle_info(vm_t *vm, int *current, int *num_avail) {
   *current = 1;
 
   if((vm->state).domain == DVD_DOMAIN_VTSTitle) {
-    title_info_t *title;
+    const title_info_t *title;
     /* TTN_REG does not always point to the correct title.. */
     if((vm->state).TTN_REG > vm->vmgi->tt_srpt->nr_of_srpts)
       return;



View it on GitLab: https://code.videolan.org/videolan/libdvdnav/-/commit/cf72081862636bd2a5796e878aa111f03284a0a1

-- 
View it on GitLab: https://code.videolan.org/videolan/libdvdnav/-/commit/cf72081862636bd2a5796e878aa111f03284a0a1
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the libdvdnav-devel mailing list