comparison input/input.c @ 13603:80fc8f48f14c

Do not loose commands while paused.
author reimar
date Sun, 10 Oct 2004 17:39:07 +0000
parents fec54060c91f
children 741649fe31cb
comparison
equal deleted inserted replaced
13602:14090f7300a8 13603:80fc8f48f14c
1124 cmd_queue_length++; 1124 cmd_queue_length++;
1125 return 1; 1125 return 1;
1126 } 1126 }
1127 1127
1128 static mp_cmd_t* 1128 static mp_cmd_t*
1129 mp_input_get_queued_cmd(void) { 1129 mp_input_get_queued_cmd(int peek_only) {
1130 mp_cmd_t* ret; 1130 mp_cmd_t* ret;
1131 1131
1132 if(cmd_queue_length == 0) 1132 if(cmd_queue_length == 0)
1133 return NULL; 1133 return NULL;
1134 1134
1135 ret = cmd_queue[cmd_queue_start]; 1135 ret = cmd_queue[cmd_queue_start];
1136 1136
1137 if (!peek_only) {
1137 cmd_queue_length--; 1138 cmd_queue_length--;
1138 cmd_queue_start = (cmd_queue_start + 1) % CMD_QUEUE_SIZE; 1139 cmd_queue_start = (cmd_queue_start + 1) % CMD_QUEUE_SIZE;
1140 }
1139 1141
1140 return ret; 1142 return ret;
1141 } 1143 }
1142 1144
1145 /**
1146 * \param peek_only when set, the returned command stays in the queue.
1147 * Do not free the returned cmd whe you set this!
1148 */
1143 mp_cmd_t* 1149 mp_cmd_t*
1144 mp_input_get_cmd(int time, int paused) { 1150 mp_input_get_cmd(int time, int paused, int peek_only) {
1145 mp_cmd_t* ret = NULL; 1151 mp_cmd_t* ret = NULL;
1146 mp_cmd_filter_t* cf; 1152 mp_cmd_filter_t* cf;
1153 int from_queue;
1147 1154
1148 while(1) { 1155 while(1) {
1149 ret = mp_input_get_queued_cmd(); 1156 from_queue = 1;
1157 ret = mp_input_get_queued_cmd(peek_only);
1150 if(ret) break; 1158 if(ret) break;
1159 from_queue = 0;
1151 ret = mp_input_read_keys(time,paused); 1160 ret = mp_input_read_keys(time,paused);
1152 if(ret) break; 1161 if(ret) break;
1153 ret = mp_input_read_cmds(time); 1162 ret = mp_input_read_cmds(time);
1154 break; 1163 break;
1155 } 1164 }
1157 1166
1158 for(cf = cmd_filters ; cf ; cf = cf->next) { 1167 for(cf = cmd_filters ; cf ; cf = cf->next) {
1159 if(cf->filter(ret,paused,cf->ctx)) 1168 if(cf->filter(ret,paused,cf->ctx))
1160 return NULL; 1169 return NULL;
1161 } 1170 }
1171
1172 if (!from_queue && peek_only)
1173 mp_input_queue_cmd(ret);
1162 1174
1163 return ret; 1175 return ret;
1164 } 1176 }
1165 1177
1166 void 1178 void
1608 } 1620 }
1609 1621
1610 int 1622 int
1611 mp_input_check_interrupt(int time) { 1623 mp_input_check_interrupt(int time) {
1612 mp_cmd_t* cmd; 1624 mp_cmd_t* cmd;
1613 if((cmd = mp_input_get_cmd(time,0)) == NULL) 1625 if((cmd = mp_input_get_cmd(time,0,1)) == NULL)
1614 return 0; 1626 return 0;
1615 switch(cmd->id) { 1627 switch(cmd->id) {
1616 case MP_CMD_QUIT: 1628 case MP_CMD_QUIT:
1617 case MP_CMD_PLAY_TREE_STEP: 1629 case MP_CMD_PLAY_TREE_STEP:
1618 case MP_CMD_PLAY_TREE_UP_STEP: 1630 case MP_CMD_PLAY_TREE_UP_STEP:
1619 case MP_CMD_PLAY_ALT_SRC_STEP: 1631 case MP_CMD_PLAY_ALT_SRC_STEP:
1620 // The cmd will be executed when we are back in the main loop 1632 // The cmd will be executed when we are back in the main loop
1621 if(! mp_input_queue_cmd(cmd)) {
1622 mp_msg(MSGT_INPUT,MSGL_ERR,"mpdemux_check_interrupt: can't queue cmd %s\n",cmd->name);
1623 mp_cmd_free(cmd);
1624 }
1625 return 1; 1633 return 1;
1626 } 1634 }
1635 // remove the cmd from the queue
1636 cmd = mp_input_get_cmd(time,0,0);
1627 mp_cmd_free(cmd); 1637 mp_cmd_free(cmd);
1628 return 0; 1638 return 0;
1629 } 1639 }