Commit 16f15dbb authored by Francisco Cabrera Fernandez's avatar Francisco Cabrera Fernandez
Browse files

F

parent 63bebd14
......@@ -104,33 +104,59 @@ int main(void)
}//fin servidor
void controlVideo(int socket_to_clientTCP,int id_cliente, int &comunicacion[], Mat frame, VideoCapture cap, vector<uchar> encoded, sockaddr_in client_addr, socklen_t client_addr_size){
pthread_mutex_t pausa;
pthread_mutex_t finalizar;
pthread_mutex_init(&finalizar, NULL);
pthread_mutex_init(&pausa, NULL);
pthread_t hilo_stream;
if (int pthread_create(&hilo_stream, NULL, streamVideo(id_cliente, frame, cap, encoded, comunicacion, pausa, client_addr, client_addr_size), NULL) != 0) perror("No se pudo enviar el video");//separo thread (idcliente, udp)
bool inicializado = false;
if (int pthread_create(&hilo_stream, NULL, streamVideo(id_cliente, frame, cap, encoded, comunicacion, pausa, finalizar, client_addr, client_addr_size, inicializado), NULL) != 0) perror("No se pudo enviar el video");//separo thread (idcliente, udp)
char data;
while (aux != 5){
//primitiva RECEIVE
int recv(socket_to_clientTCP, data, 1, MSG_WAITALL);
switch (data){
case 1:
pthread_mutex_unlock(&finalizar);
break;
case 2:
pthread_mutex_unlock(&pausa);
break;
case 3:
pthread_mutex_lock(&pausa);
break;
case 4:
pthread_mutex_lock(&finalizar);
break;
}
pthread_mutex_lock(&mutex);
int aux = comunicacion[id_cliente];
pthread_mutex_unlock(&mutex);
}
pthread_join(hilo_stream, NULL);
}
void streamVideo(int id_cliente, Mat frame, VideoCapture cap, vector<uchar> encoded, int &comunicacion[], pthread_mutex_t &pausa, sockaddr_in client_addr, socklen_t client_addr_size){
//primitiva SOCKET
int socket_to_clientUDP = socket(PF_INET, SOCK_DGRAM, 0);
//primitiva BIND
bind(socket_to_clientUDP,(struct sockaddr*)&client_addr, client_addr_size);
void streamVideo(int id_cliente, Mat frame, VideoCapture cap, vector<uchar> encoded, int &comunicacion[], pthread_mutex_t &pausa, pthread_mutex_t &finalizar, sockaddr_in client_addr, socklen_t client_addr_size, bool inicializado){
if (!inicializado){
//primitiva SOCKET
int socket_to_clientUDP = socket(PF_INET, SOCK_DGRAM, 0);
//primitiva BIND
bind(socket_to_clientUDP,(struct sockaddr*)&client_addr, client_addr_size);
inicializado = true;
}
pthread_mutex_lock(&mutex);
while (comunicacion[id_cliente] != SALIR) { //MIRAR ESTO PARA CORREGIR
pthread_mutex_unlock(&mutex);
int aux = comunicacion[id_cliente];
pthread_mutex_unlock(&mutex);
while ( aux != SALIR) { //MIRAR ESTO PARA CORREGIR
int pthread_mutex_lock(&pausa);
int pthread_mutex_unlock(&pausa);
//pasar las frames
cap >> frame; //obtener nuevo frame
imshow("servidor", frame); //muestra la imagen en la ventana servidor
......@@ -142,7 +168,6 @@ void streamVideo(int id_cliente, Mat frame, VideoCapture cap, vector<uchar> enco
compression_params.push_back(80);
imencode(".jpg", frame, encoded, compression_params);
//SEND
int sent_data_size = sendto(
socket_to_clientUDP,
......@@ -150,9 +175,23 @@ void streamVideo(int id_cliente, Mat frame, VideoCapture cap, vector<uchar> enco
(struct sockaddr*)& client_addr, client_addr_size
);
pthread_mutex_lock(&mutex);
int aux = comunicacion[id_cliente];
pthread_mutex_unlock(&mutex);
if(aux == FINALIZAR){
pthread_mutex_lock(&finalizar); //tcp le da unlock cuando comunicacion[id] = INICIO
streamVideo(id_cliente, frame, cap, encoded, &comunicacion[], &pausa, &finalizar, client_addr, client_addr_size, inicializado);
}
pthread_mutex_lock(&mutex);
aux = comunicacion[id_cliente];
pthread_mutex_unlock(&mutex);
}
pthread_mutex_unlock(&mutex); //ESTO PODRIA ESTAR MAL, NO NOS PUTEES CAMACHO, FELIZ CUMPLE :)
}
//primitiva CLOSE
close(socket_to_clientUDP);
}//fin streamVideo
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment