Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
EDAF55
C-camera
Commits
24fb1f94
Commit
24fb1f94
authored
Nov 08, 2016
by
Sven Gestegård Robertz
Browse files
working http_server / Makefile?
parent
8b88ad7d
Changes
2
Hide whitespace changes
Inline
Side-by-side
examples/Makefile
View file @
24fb1f94
# 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
$@
examples/http_server.c
View file @
24fb1f94
...
...
@@ -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
*
stre
am
;
char
*
frame_data
;
camera
*
c
am
;
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
->
stre
am
=
ca
pture_open_stream
(
IMAGE_JPEG
,
"fps=25&resolution=640x480"
);
if
(
!
client
->
stre
am
){
// Check if null
client
->
c
am
=
ca
mera_open
(
);
if
(
!
client
->
c
am
){
// 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
*
fr
ame
)
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
(
fr
ame
);
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
*
fr
ame
=
fr
ame
=
ca
pture
_get_frame
(
client
->
stre
am
);
frame
*
fr
=
fr
=
ca
mera
_get_frame
(
client
->
c
am
);
if
(
fr
ame
)
{
if
((
result
=
client_send_frame
(
client
,
fr
ame
)))
{
if
(
fr
)
{
if
((
result
=
client_send_frame
(
client
,
fr
)))
{
printf
(
"Warning: client_send_frame returned %d
\n
"
,
result
);
}
capture_
frame_free
(
fr
ame
);
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 ca
pture stream
\n
"
);
if
(
try_open_
camera
(
client
))
{
printf
(
"ERROR opening ca
mera
\n
"
);
}
else
{
try_get_frame
(
client
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment