static int player_mate_thread_run_per100ms(play_para_t *player, struct player_mate *mate) { mate_print("[MATE]player's mate start do a day work now\n "); player_mate_thread_cmd_proxy(player, mate); /**/ mate_print("[MATE]player's mate finixhed cmd proxy\n "); update_playing_info(player); mate_print("[MATE]player's mate finished update playing info\n "); update_player_states(player, 0); mate_print("[MATE]player's mate finished one day work now\n "); return 0; }
static int player_mate_thread_run_l(play_para_t *player, struct player_mate *mate) { int worktimenum = 0; int runll = 101 / (mate->work_intervals / 1000); /*work_intervals is less than 100ms?*/ int runlldelay = 0; runll = (runll > 0 && runll < 100) ? runll : 0; runlldelay = runll; mate_print("[MATE]player's mate start work now!\n "); while (!mate->mate_should_sleep && !mate->mate_should_exit) { worktimenum++; if (--runlldelay <= 0) { /*run once delay about 100ms...*/ player_mate_thread_run_per100ms(player, mate); runlldelay = runll; } player_mate_thread_run_ll_everytime(player, mate); mate_print("[MATE]player's mate sleep now %d\n ", worktimenum); player_mate_thread_wait(mate, mate->work_intervals); mate_print("[MATE]player's mate wake and try get next day work\n "); } mate_print("[MATE]player's mate exit work now!\n "); return 0; }
int player_mate_release(play_para_t *player) { struct player_mate *mate = (struct player_mate *)(player->player_mate); int ret; if (!mate) { return -1; } mate_print("try release mate thread now\n"); pthread_mutex_lock(&mate->pthread_mutex); mate->mate_should_sleep = 1; mate->mate_should_exit = 1; mate->wake_delay = 0; ret = sem_post(&mate->mate_sem);/*wake mate thread*/ ret = sem_post(&mate->mate_sem);/*wake mate thread*/ ret = sem_post(&mate->mate_sem);/*wake mate thread*/ ret = pthread_cond_signal(&mate->pthread_cond); pthread_mutex_unlock(&mate->pthread_mutex); mate_print("wait mate thread exit\n"); ret = pthread_join(mate->pthread_id, NULL); mate_print("mate thread exited\n"); FREE(player->player_mate); player->player_mate = NULL; return ret; }
static int player_mate_thread_cmd_proxy(play_para_t *player, struct player_mate *mate) { player_cmd_t *cmd = NULL; int ret; /* check the cmd & do for main thread; */ lock_message_pool(player); cmd = peek_message_locked(player); if (cmd) { mate_print("[MATE]Get cmd-------------------------[%x],[%x]\n", cmd->ctrl_cmd, (CMD_START | CMD_PAUSE | CMD_RESUME | CMD_SWITCH_AID)); if (((cmd->ctrl_cmd) & (CMD_START | CMD_PAUSE | CMD_RESUME | CMD_SWITCH_AID)) || ((cmd->set_mode) & (CMD_LOOP | CMD_NOLOOP | CMD_EN_AUTOBUF | CMD_SET_AUTOBUF_LEV))) { cmd = get_message_locked(player); } else { cmd = NULL; } } unlock_message_pool(player); if (!cmd) { return 0; /*no I can handle cmd*/ } if (cmd->ctrl_cmd & CMD_PAUSE) { mate_print("[MATE]Get puase cmd\n"); if (get_player_state(player) != PLAYER_PAUSE) { ret = codec_pause(player->codec); if (ret != 0) { log_error("[%s:%d]pause failed!ret=%d\n", __FUNCTION__, __LINE__, ret); } player->playctrl_info.pause_flag = 1; set_player_state(player, PLAYER_PAUSE); update_playing_info(player); update_player_states(player, 1); } } else if ((cmd->ctrl_cmd & CMD_RESUME) || (cmd->ctrl_cmd & CMD_START)) { mate_print("[MATE]Get resume cmd\n"); if ((get_player_state(player) == PLAYER_PAUSE) || (get_player_state(player) == PLAYER_SEARCHOK)) { ret = codec_resume(player->codec); if (ret != 0) { log_error("[%s:%d]resume failed!ret=%d\n", __FUNCTION__, __LINE__, ret); } player->playctrl_info.pause_flag = 0; set_player_state(player, PLAYER_RUNNING); update_playing_info(player); update_player_states(player, 1); } } else if (cmd->ctrl_cmd & CMD_SWITCH_AID) { player->playctrl_info.seek_base_audio = 1; player->playctrl_info.switch_audio_id = cmd->param; set_black_policy(0); } else if (cmd->set_mode & CMD_LOOP) { player->playctrl_info.loop_flag = 1; } else if (cmd->set_mode & CMD_NOLOOP) { player->playctrl_info.loop_flag = 0; } else if (cmd->set_mode & CMD_EN_AUTOBUF) { player->buffering_enable = cmd->param; } else if (cmd->set_mode & CMD_SET_AUTOBUF_LEV) { player->buffering_threshhold_min = cmd->f_param; player->buffering_threshhold_middle = cmd->f_param1; player->buffering_threshhold_max = cmd->f_param2; } message_free(cmd); return 0; }