Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
mongoose
Commits
dbc07c8b
Commit
dbc07c8b
authored
Sep 15, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved mjpg_streamer to a separate dir
parent
ce953575
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
15 deletions
+38
-15
Makefile
examples/mjpg_streamer/Makefile
+12
-0
mjpg_streamer.c
examples/mjpg_streamer/mjpg_streamer.c
+26
-15
No files found.
examples/mjpg_streamer/Makefile
0 → 100644
View file @
dbc07c8b
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG
=
mjpg_streamer
CFLAGS
=
-W
-Wall
-I
../..
-g
-O0
$(CFLAGS_EXTRA)
SOURCES
=
$(PROG)
.c ../../mongoose.c
$(PROG)
:
$(SOURCES)
$(CC)
-o
$(PROG)
$(SOURCES)
$(CFLAGS)
clean
:
rm
-rf
$(PROG)
*
.exe
*
.dSYM
*
.obj
*
.exp .
*
o
*
.lib
examples/mjpg.c
→
examples/mjpg
_streamer/mjpg_streamer
.c
View file @
dbc07c8b
...
@@ -12,8 +12,8 @@ static void send_file(struct mg_connection *conn, const char *path) {
...
@@ -12,8 +12,8 @@ static void send_file(struct mg_connection *conn, const char *path) {
FILE
*
fp
;
FILE
*
fp
;
if
(
stat
(
path
,
&
st
)
==
0
&&
(
fp
=
fopen
(
path
,
"rb"
))
!=
NULL
)
{
if
(
stat
(
path
,
&
st
)
==
0
&&
(
fp
=
fopen
(
path
,
"rb"
))
!=
NULL
)
{
mg_printf
(
conn
,
"--
myboundary
\r\n
Content-Type: image/jpeg
\r\n
"
mg_printf
(
conn
,
"--
w00t
\r\n
Content-Type: image/jpeg
\r\n
"
"Content-Length: %l
lu
\r\n\r\n
"
,
(
unsigned
long
long
)
st
.
st_size
);
"Content-Length: %l
u
\r\n\r\n
"
,
(
unsigned
long
)
st
.
st_size
);
while
((
n
=
fread
(
buf
,
1
,
sizeof
(
buf
),
fp
))
>
0
)
{
while
((
n
=
fread
(
buf
,
1
,
sizeof
(
buf
),
fp
))
>
0
)
{
mg_write
(
conn
,
buf
,
n
);
mg_write
(
conn
,
buf
,
n
);
}
}
...
@@ -30,14 +30,26 @@ struct conn_state {
...
@@ -30,14 +30,26 @@ struct conn_state {
static
int
ev_handler
(
struct
mg_connection
*
conn
,
enum
mg_event
ev
)
{
static
int
ev_handler
(
struct
mg_connection
*
conn
,
enum
mg_event
ev
)
{
const
char
**
file_names
=
(
const
char
**
)
conn
->
server_param
;
const
char
**
file_names
=
(
const
char
**
)
conn
->
server_param
;
struct
conn_state
*
state
;
struct
conn_state
*
state
;
int
result
=
MG_FALSE
;
time_t
now
=
time
(
NULL
);
switch
(
ev
)
{
case
MG_AUTH
:
return
MG_TRUE
;
case
MG_REQUEST
:
if
(
strcmp
(
conn
->
uri
,
"/stream"
)
!=
0
)
{
mg_send_header
(
conn
,
"Content-Type"
,
"text/html"
);
mg_printf_data
(
conn
,
"%s"
,
"Go to <a href=/stream>/stream</a> for MJPG stream"
);
return
MG_TRUE
;
}
if
(
ev
==
MG_REQUEST
)
{
mg_printf
(
conn
,
"%s"
,
mg_printf
(
conn
,
"%s"
,
"HTTP/1.0 200 OK
\r\n
"
"Cache-Control: no-cache
\r\n
"
"HTTP/1.0 200 OK
\r\n
"
"Cache-Control: no-cache
\r\n
"
"Pragma: no-cache
\r\n
Expires: Thu, 01 Dec 1994 16:00:00 GMT
\r\n
"
"Pragma: no-cache
\r\n
Expires: Thu, 01 Dec 1994 16:00:00 GMT
\r\n
"
"Connection: close
\r\n
Content-Type: multipart/x-mixed-replace; "
"Connection: close
\r\n
Content-Type: multipart/x-mixed-replace; "
"boundary=--myboundary
\r\n\r\n
"
);
"boundary=--w00t
\r\n\r\n
"
);
send_file
(
conn
,
file_names
[
0
]);
send_file
(
conn
,
file_names
[
0
]);
...
@@ -45,11 +57,9 @@ static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
...
@@ -45,11 +57,9 @@ static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
conn
->
connection_param
=
state
;
conn
->
connection_param
=
state
;
state
->
file_index
=
1
;
// First file is already sent
state
->
file_index
=
1
;
// First file is already sent
state
->
last_poll
=
time
(
NULL
);
state
->
last_poll
=
time
(
NULL
);
result
=
MG_MORE
;
return
MG_MORE
;
}
else
if
(
ev
==
MG_POLL
)
{
case
MG_POLL
:
time_t
now
=
time
(
NULL
);
state
=
(
struct
conn_state
*
)
conn
->
connection_param
;
state
=
(
struct
conn_state
*
)
conn
->
connection_param
;
if
(
state
!=
NULL
&&
now
>
state
->
last_poll
)
{
if
(
state
!=
NULL
&&
now
>
state
->
last_poll
)
{
...
@@ -57,20 +67,21 @@ static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
...
@@ -57,20 +67,21 @@ static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
send_file
(
conn
,
file_names
[
state
->
file_index
]);
send_file
(
conn
,
file_names
[
state
->
file_index
]);
state
->
file_index
++
;
state
->
file_index
++
;
if
(
file_names
[
state
->
file_index
]
==
NULL
)
{
if
(
file_names
[
state
->
file_index
]
==
NULL
)
{
result
=
MG_TRUE
;
// No more images, close connection
return
MG_TRUE
;
// No more images, close connection
}
}
}
}
state
->
last_poll
=
now
;
state
->
last_poll
=
now
;
}
}
return
MG_FALSE
;
}
else
if
(
ev
==
MG_CLOSE
)
{
case
MG_CLOSE
:
free
(
conn
->
connection_param
);
free
(
conn
->
connection_param
);
conn
->
connection_param
=
NULL
;
conn
->
connection_param
=
NULL
;
}
else
if
(
ev
==
MG_AUTH
)
{
return
MG_FALSE
;
result
=
MG_TRUE
;
}
return
result
;
default:
return
MG_FALSE
;
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
Write
Preview
Markdown
is supported
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