Commit 24fb1f94 authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

working http_server / Makefile?

parent 8b88ad7d
# This makefile is for cross-compiling on student computers, i.e. login.student.lth.se
#COMMON_DIR=/usr/local/cs/rtp
COMMON_DIR=/home/sven/slask/rtp-kamera/fr_login
COMMON_DIR?=/usr/local/cs/rtp
COMPILER_DIR=${COMMON_DIR}/tools/comptools-mips-r12_1.2-0/comptools-mips-r12_1.2-0_amd64/mipsisa32r2el/r12
# Absolute path to the Axis Software Development Kit containing camera specific libs and headers, used for capture.h and its corresponding object file (i.e. libcapture)
......@@ -28,4 +27,4 @@ CFLAGS+=-O3 -g -Wall
LDLIBS+=-lpthread
http_server: http_server.o camera.o Makefile
${CC} ${CPPFLAGS} ${CFLAGS} $< ${LDFLAGS} -lpthread -o $@
${CC} ${CPPFLAGS} ${CFLAGS} http_server.o camera.o ${LDFLAGS} -lpthread -o $@
......@@ -13,24 +13,20 @@
#undef DEBUG
#ifdef USE_CAMERA
#ifndef FAKE
#include "capture.h"
#else
#include "fakecapture.h"
#endif
#include "camera.h"
#endif
#define BUFSIZE 50000
struct client{
int connfd;
char sendBuff[BUFSIZE];
byte sendBuff[BUFSIZE];
#ifdef USE_CAMERA
media_stream *stream;
char* frame_data;
camera* cam;
byte* frame_data;
#endif
};
int client_write_string(struct client* client);
int client_writen(struct client* client, size_t n);
int client_write_n(struct client* client, size_t n);
/////////////// camera stuff
......@@ -44,20 +40,16 @@ pthread_cond_t global_cond = PTHREAD_COND_INITIALIZER;
#ifdef USE_CAMERA
int try_open_stream(struct client* client)
int try_open_camera(struct client* client)
{
client->stream = capture_open_stream(IMAGE_JPEG, "fps=25&resolution=640x480");
if (!client->stream){ // Check if null
client->cam = camera_open();
if (!client->cam){ // Check if null
printf("axism3006v: Stream is null, can't connect to camera");
return ERR_OPEN_STREAM;
}
return 0;
}
void close_stream(struct client* client)
{
capture_close_stream(client->stream);
}
/* Sets up the packet structure in client->sendBuff.
* This is a minimal HTTP header for an image/jpeg
......@@ -85,7 +77,7 @@ ssize_t setup_packet(struct client* client, uint32_t frame_sz)
/* send packet with frame
* returns 0 on success
*/
int client_send_frame(struct client* client, media_frame* frame)
int client_send_frame(struct client* client, frame* fr)
{
// this should be a compile-time check
#ifndef DISABLE_SANITY_CHECKS
......@@ -96,8 +88,8 @@ int client_send_frame(struct client* client, media_frame* frame)
}
#endif
size_t frame_sz = capture_frame_size(frame);
char* data = capture_frame_data(frame);
size_t frame_sz = get_frame_size(fr);
byte* data = get_frame_bytes(fr);
int result;
ssize_t packet_sz = setup_packet(client, frame_sz);
......@@ -115,7 +107,7 @@ int client_send_frame(struct client* client, media_frame* frame)
#endif
memcpy(client->frame_data, data, frame_sz);
written=client_writen(client, packet_sz);
written=client_write_n(client, packet_sz);
if(written != packet_sz) {
printf("WARNING! packet_sz=%d, written=%d\n", packet_sz, written);
result = 3;
......@@ -129,13 +121,13 @@ int client_send_frame(struct client* client, media_frame* frame)
int try_get_frame(struct client* client)
{
int result=-1;
media_frame *frame = frame = capture_get_frame(client->stream);
frame *fr = fr = camera_get_frame(client->cam);
if(frame) {
if((result = client_send_frame(client, frame))) {
if(fr) {
if((result = client_send_frame(client, fr))) {
printf("Warning: client_send_frame returned %d\n", result);
}
capture_frame_free(frame);
frame_free(fr);
} else {
return ERR_GET_FRAME;
}
......@@ -152,7 +144,7 @@ int client_write_string(struct client* client)
while (written < n) {
ssize_t tmp = write(client->connfd, client->sendBuff, n-written);
if (tmp < 0) {
perror("writen ERROR");
perror("write_n ERROR");
return tmp;
}
written += tmp;
......@@ -166,13 +158,13 @@ int client_write_string(struct client* client)
* Note: an error occurs if the web browser closes the connection
* (might happen when reloading too frequently)
*/
int client_writen(struct client* client, size_t n)
int client_write_n(struct client* client, size_t n)
{
size_t written = 0;
while (written < n) {
ssize_t tmp = write(client->connfd, client->sendBuff, n-written);
if (tmp < 0) {
perror("writen ERROR");
perror("write_n ERROR");
return tmp;
}
written += tmp;
......@@ -210,8 +202,8 @@ void* serve_client(void *ctxt)
int hres = parse_http_request(buf, 1024);
if(hres == 0) {
#ifdef USE_CAMERA
if( try_open_stream(client)) {
printf("ERROR opening capture stream\n");
if( try_open_camera(client)) {
printf("ERROR opening camera\n");
} else {
try_get_frame(client);
}
......
Supports Markdown
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