/*设置某个节点的状态*/ static int app_mult_set_node_tc(MULTICAST_Output_Server_NODE *node) { if(node == NULL) { PRINTF("Error\n"); return -1; } int num = 0; int vrate = 0; int vcbr = 0; int arate = 0; int trate = 0; int crate = 0; int ret = 0; app_get_encode_rate(&vrate, &arate, &vcbr); if(node->config.tc_flag == NOTUSED || vcbr == 0) { if(node->tc_num != -1) { tc_del_element(node->tc_num); node->tc_num = -1; } return 0; } if(node->config.tc_flag == ISUSED) { if(node->client == NULL) { if(node->tc_num != -1) { tc_del_element(node->tc_num); node->tc_num = -1; } return 0; } num = node->client->num + 1; if(vcbr == 1) { trate = app_trans_rate(vrate, arate, node->config.type); crate = trate * (node->config.tc_rate + 100) / 100; //set rate ret = tc_add_element(num, node->config.main_ip, node->config.video_port, arate, crate); if(ret < 0) { PRINTF("Warnning\n"); node->tc_num = -1; } else { node->tc_num = num; } } } return 0; }
static int multicast_list_delete_node(MULTICAST_Output_Server_NODE *node) { if(g_mult_head == NULL || node == NULL) { ERR_PRN("\n"); return -1; } MULTICAST_Output_Server_NODE *temp = NULL; //MULTICAST_Output_Server_NODE *temp2 = NULL; mid_mutex_lock(g_mult_head->mutex); temp = g_mult_head->first; PRINTF("temp=%p,node=%p\n", temp, node); if(temp == node) { g_mult_head->first = node->next; g_mult_head->num --; } else { while(temp->next != node && temp->next != NULL) { temp = temp->next; } if(temp->next == NULL) { PRINTF("ERROR,can't find the node\n"); temp->next = NULL; } else { temp->next = node->next; g_mult_head->num --; } } if(g_mult_head->num < 0) { ERR_PRN("\n"); } //close the socket // multicast_client_delete(&(node->client[0])); stream_client_close(node->client); //close tc num tc_del_element(node->tc_num); node->tc_num = -1; multicast_node_delete(&node); mid_mutex_unlock(g_mult_head->mutex); multicast_list_print_all(); return 0; }
/*add 一个class对应一路流用来限制码率*/ int tc_add_element(int classid, char *dst_ip, unsigned short dst_port, int a_rate, int c_rate) { //return ; //return 0; PRINTF("classid=%d,ip %s:%d, a_rate=%d,c_rate=%d\n", classid, dst_ip, dst_port, a_rate, c_rate); if(classid > TC_MAX_NUM || dst_ip == NULL || dst_port < 1000 || a_rate == 0 || c_rate == 0) { PRINTF("Error\n"); return 0; } //if classid is not null ,must del first if(g_tc_info_array[classid].class_id != -1) { if(tc_compare_element(dst_ip, dst_port, a_rate, c_rate, &(g_tc_info_array[classid])) == 0) { PRINTF("the tc info is same\n"); return 0; } tc_del_element(classid); } char command[256] = {0}; PRINTF("\n*************** add TC route ... ****************\n"); memset(command, 0, sizeof(command)); snprintf(command, sizeof(command), "tc class add dev eth0 parent 1:99 classid 1:%d htb rate %dkbps ceil %dkbit prio 1 quantum 6000000", classid, a_rate, c_rate); PRINTF("++++++++++++++++++add system command 1:%s.\n", command); system(command); memset(command, 0, sizeof(command)); //add protocol 17=UDP snprintf(command, sizeof(command), "tc filter add dev eth0 protocol ip parent 1:0 prio %d u32 match ip protocol 17 0xff match ip dst %s match ip dport %d 0xffff flowid 1:%d", classid, dst_ip, dst_port, classid); PRINTF("++++++++++++++++++add system command 2:%s.\n", command); system(command); g_tc_info_array[classid].class_id = classid; snprintf(g_tc_info_array[classid].dst_ip, sizeof(g_tc_info_array[classid].dst_ip), "%s", dst_ip); g_tc_info_array[classid].dst_port = dst_port; g_tc_info_array[classid].average_rate = a_rate; g_tc_info_array[classid].ceiling_rate = c_rate; tc_status_print(); return 0; }
static int stream_rtsp_set_clinet_tc(int num, int tc_flag, int tc_rate, char *dst_ip, unsigned short port) { int vrate = 0; int vcbr = 0; int arate = 0; int trate = 0; int crate = 0; int ret = 0; // int tc_flag =0; int tc_num = num ; tc_del_element(tc_num); app_get_encode_rate(&vrate, &arate, &vcbr); if(vcbr == 0 || tc_flag == NOTUSED) { PRINTF("vcbr = %d,tc_flag =%d\n", vcbr, tc_flag); return -1; } if(vcbr == 1) { trate = app_trans_rate(vrate, arate, TYPE_RTP); crate = trate * (tc_rate + 100) / 100; //set rate ret = tc_add_element(num, dst_ip, port, trate, crate); if(ret < 0) { PRINTF("Warnning\n"); return -1; //node->tc_num = -1; } else { return 0; //node->tc_num = num; } } return -1; }
int stream_rtsp_del_client_tc(int num) { PRINTF("tc num = %d\n", num); tc_del_element(num); return 0; }