static void keyboard_cb (const gchar * key_input, gpointer user_data) { GstPlay *play = (GstPlay *) user_data; switch (g_ascii_tolower (key_input[0])) { case 'i': { GstPlayerMediaInfo *media_info = gst_player_get_media_info (play->player); if (media_info) { print_media_info (media_info); g_object_unref (media_info); print_current_tracks (play); } break; } case ' ': toggle_paused (play); break; case 'q': case 'Q': g_main_loop_quit (play->loop); break; case '>': if (!play_next (play)) { g_print ("\nReached end of play list.\n"); g_main_loop_quit (play->loop); } break; case '<': play_prev (play); break; case 27: /* ESC */ if (key_input[1] == '\0') { g_main_loop_quit (play->loop); break; } /* fall through */ default: if (strcmp (key_input, GST_PLAY_KB_ARROW_RIGHT) == 0) { relative_seek (play, +0.08); } else if (strcmp (key_input, GST_PLAY_KB_ARROW_LEFT) == 0) { relative_seek (play, -0.01); } else if (strcmp (key_input, GST_PLAY_KB_ARROW_UP) == 0) { play_set_relative_volume (play, +1.0 / VOLUME_STEPS); } else if (strcmp (key_input, GST_PLAY_KB_ARROW_DOWN) == 0) { play_set_relative_volume (play, -1.0 / VOLUME_STEPS); } else { GST_INFO ("keyboard input:"); for (; *key_input != '\0'; ++key_input) GST_INFO (" code %3d", *key_input); } break; } }
static void keyboard_cb (const gchar * key_input, gpointer user_data) { GstPlay *play = (GstPlay *) user_data; gchar key = '\0'; /* only want to switch/case on single char, not first char of string */ if (key_input[0] != '\0' && key_input[1] == '\0') key = g_ascii_tolower (key_input[0]); switch (key) { case 'k': print_keyboard_help (); break; case ' ': toggle_paused (play); break; case 'q': case 'Q': g_main_loop_quit (play->loop); break; case 'n': case '>': if (!play_next (play)) { g_print ("\n%s\n", _("Reached end of play list.")); g_main_loop_quit (play->loop); } break; case 'b': case '<': play_prev (play); break; case '+': if (play->rate > -0.2 && play->rate < 0.0) play_set_relative_playback_rate (play, 0.0, TRUE); else if (ABS (play->rate) < 2.0) play_set_relative_playback_rate (play, 0.1, FALSE); else if (ABS (play->rate) < 4.0) play_set_relative_playback_rate (play, 0.5, FALSE); else play_set_relative_playback_rate (play, 1.0, FALSE); break; case '-': if (play->rate > 0.0 && play->rate < 0.20) play_set_relative_playback_rate (play, 0.0, TRUE); else if (ABS (play->rate) <= 2.0) play_set_relative_playback_rate (play, -0.1, FALSE); else if (ABS (play->rate) <= 4.0) play_set_relative_playback_rate (play, -0.5, FALSE); else play_set_relative_playback_rate (play, -1.0, FALSE); break; case 'd': play_set_relative_playback_rate (play, 0.0, TRUE); break; case 't': play_switch_trick_mode (play); break; case 27: /* ESC */ if (key_input[1] == '\0') { g_main_loop_quit (play->loop); break; } case 'a': play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_AUDIO); break; case 'v': play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_VIDEO); break; case 's': play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_SUBTITLE); break; case '0': play_do_seek (play, 0, play->rate, play->trick_mode); break; default: if (strcmp (key_input, GST_PLAY_KB_ARROW_RIGHT) == 0) { relative_seek (play, +0.08); } else if (strcmp (key_input, GST_PLAY_KB_ARROW_LEFT) == 0) { relative_seek (play, -0.01); } else if (strcmp (key_input, GST_PLAY_KB_ARROW_UP) == 0) { play_set_relative_volume (play, +1.0 / VOLUME_STEPS); } else if (strcmp (key_input, GST_PLAY_KB_ARROW_DOWN) == 0) { play_set_relative_volume (play, -1.0 / VOLUME_STEPS); } else { GST_INFO ("keyboard input:"); for (; *key_input != '\0'; ++key_input) GST_INFO (" code %3d", *key_input); } break; } }
void run() { WSADATA wsa; if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0) { printf("Init failed"); exit(-1); } SOCKET server_fd; server_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (server_fd == INVALID_SOCKET) { printf("Invalid socket"); exit(-1); } struct sockaddr_in server_addr; int port = 56789; memset(&server_addr, 0, sizeof(struct sockaddr_in)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = INADDR_ANY; server_addr.sin_port = htons(port); if (bind(server_fd, (struct sockaddr*)&server_addr, sizeof(server_addr)) == SOCKET_ERROR) { printf("Socket bind error"); exit(-1); } if (listen(server_fd, SOMAXCONN) == SOCKET_ERROR) { printf("Socket execute error"); exit(-1); } char hostname[255]; char *ip; char *local = "*"; struct hostent *hostinfo; if (gethostname(hostname, sizeof(hostname)) == 0) { if ((hostinfo = gethostbyname(hostname)) != NULL) { ip = inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list); } else { ip = local; } } else { ip = local; } printf("Server is listening on %s:%d\n", ip, port); char doccmd[BUF_SIZE]; sprintf_s(doccmd, BUF_SIZE, "start http://%s:%d/", ip, port); //system(doccmd); while (true) { SOCKET client; struct sockaddr_in client_addr; memset(&client_addr, 0, sizeof(struct sockaddr_in)); client = accept(server_fd, (struct sockaddr*)&client_addr, 0); if (client == INVALID_SOCKET) { printf("Invalid socket"); } char request[BUF_SIZE]; char htmlfile[255]; int receive_rs = recv(client, request, sizeof(request), 0); struct req_head head = parse_request_head(request); printf("Request: %s\n", head.path); if (strcmp(head.path, "/next") == 0) { play_next(); strcpy_s(htmlfile, "html/index.html"); } else if (strcmp(head.path, "/prev") == 0) { play_prev(); strcpy_s(htmlfile, "html/index.html"); } else if (strcmp(head.path, "/play") == 0) { play(); strcpy_s(htmlfile, "html/index.html"); } else if (strcmp(head.path, "/up") == 0) { volume_up(); strcpy_s(htmlfile, "html/index.html"); } else if (strcmp(head.path, "/down") == 0) { volume_down(); strcpy_s(htmlfile, "html/index.html"); } else if (strcmp(head.path, "/mute") == 0) { mute(); strcpy_s(htmlfile, "html/index.html"); } else if (strcmp(head.path, "/shutdown") == 0) { poweroff(); strcpy_s(htmlfile, "html/index.html"); } else if (strcmp(head.path, "/") == 0) { strcpy_s(htmlfile, "html/index.html"); } else { strcpyn(htmlfile, head.path, 1, sizeof(head) - 1); } // 加载要显示的页面 struct fbuf *html = load_file(htmlfile); //printf("Loading file: %s\n", htmlfile); char *content; if (html == NULL) { content = (char *)calloc(BUF_SIZE, sizeof(char)); sprintf_s(content, BUF_SIZE, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n%s", 22, "<h1>404 NOT FOUND</h1>"); send(client, content, strlen(content), 0); } else { size_t total_size = html->buf_size + 67; content = (char *)calloc(total_size, sizeof(char)); sprintf_s(content, total_size, "HTTP/1.1 200 OK\r\nContent-Type: %s\r\nContent-Length: %d\r\n\r\n", html->mime, html->buf_size * sizeof(char)); // send head send(client, content, strlen(content), 0); // send body send(client, html->buf, html->buf_size, 0); } free(content); free(html); closesocket(client); } closesocket(server_fd); }