//according to the request this fuction composes //checks if the request is valid and construct //a response string to reply the client void getResponse(rtspd_t* rtspd, char response[]){ int status = BAD_REQUEST; printf("getting ----------- response\n"); if(strcmp(rtspd->request, "SETUP") == 0){ printf("send setup response\n"); rtspd->sessionid = getSessionId(); status = getVideo(); printf("video file ok: %d\n", status); //initMovie(rtspd->videoName, rtspd->client_fd); rtspd->data = send_frame_data_new(rtspd->videoName, rtspd->client_fd); composeResponse(rtspd, status, response); //setup complete change state to ready strcpy(rtspd->current_state, "READY"); }else if(strcmp(rtspd->request, "PLAY") == 0&& strcmp(rtspd->current_state,"READY")==0){ status = OK; composeResponse(rtspd, status, response); streamVideo(rtspd->data); strcpy(rtspd->current_state, "PLAYING"); }else if(strcmp(rtspd->request, "PLAY")==0 && strcmp(rtspd->current_state, "PLAYING")==0){ status = OK; printf("start playing, %s, %d\n\n", rtspd->videoName,rtspd->client_fd); composeResponse(rtspd, status, response); streamVideo(rtspd->data); strcpy(rtspd->current_state, "PLAYING"); }else if(strcmp(rtspd->request, "PAUSE")==0 && strcmp(rtspd->current_state, "PLAYING")==0){ status = OK; printf("pause video \n"); pauseVideo(rtspd->data); composeResponse(rtspd, status, response); strcpy(rtspd->current_state, "READY"); }else if(strcmp(rtspd->request, "TEARDOWN")==0 &&(strcmp(rtspd->current_state, "PLAYING")==0 || strcmp(rtspd->current_state, "READY")==0)){ status = OK; printf("TEARDOWN video \n"); deleteTimer(rtspd->data); composeResponse(rtspd, status, response); strcpy(rtspd->current_state, "INIT"); }else{ status = NOT_VALID; composeResponse(rtspd, status, response); } }
void Server::handleRequest(QHttpRequest* req, QHttpResponse* resp) { if (req->path().contains(QRegExp("^\\/api\\/"))) { if (!handleApiRequest(req, resp)) { simpleWrite(resp, 405, "Api request not supported. Maybe a typo"); } } else if (req->path().startsWith("/video/")) { streamVideo(req, resp); } else { sendFile(req, resp); } }