Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
dbc07c8b
Commit
dbc07c8b
authored
10 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
Moved mjpg_streamer to a separate dir
parent
ce953575
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/mjpg_streamer/Makefile
+12
-0
12 additions, 0 deletions
examples/mjpg_streamer/Makefile
examples/mjpg_streamer/mjpg_streamer.c
+105
-0
105 additions, 0 deletions
examples/mjpg_streamer/mjpg_streamer.c
with
117 additions
and
0 deletions
examples/mjpg_streamer/Makefile
0 → 100644
+
12
−
0
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
This diff is collapsed.
Click to expand it.
examples/mjpg.c
→
examples/mjpg
_streamer/mjpg_streamer
.c
+
105
−
0
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: %lu
\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,47 +30,58 @@ struct conn_state {
...
@@ -30,47 +30,58 @@ 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
);
if
(
ev
==
MG_REQUEST
)
{
switch
(
ev
)
{
mg_printf
(
conn
,
"%s"
,
"HTTP/1.0 200 OK
\r\n
"
"Cache-Control: no-cache
\r\n
"
case
MG_AUTH
:
"Pragma: no-cache
\r\n
Expires: Thu, 01 Dec 1994 16:00:00 GMT
\r\n
"
return
MG_TRUE
;
"Connection: close
\r\n
Content-Type: multipart/x-mixed-replace; "
"boundary=--myboundary
\r\n\r\n
"
);
case
MG_REQUEST
:
if
(
strcmp
(
conn
->
uri
,
"/stream"
)
!=
0
)
{
send_file
(
conn
,
file_names
[
0
]);
mg_send_header
(
conn
,
"Content-Type"
,
"text/html"
);
mg_printf_data
(
conn
,
"%s"
,
state
=
(
struct
conn_state
*
)
malloc
(
sizeof
(
*
state
));
"Go to <a href=/stream>/stream</a> for MJPG stream"
);
conn
->
connection_param
=
state
;
return
MG_TRUE
;
state
->
file_index
=
1
;
// First file is already sent
}
state
->
last_poll
=
time
(
NULL
);
result
=
MG_MORE
;
mg_printf
(
conn
,
"%s"
,
"HTTP/1.0 200 OK
\r\n
"
"Cache-Control: no-cache
\r\n
"
}
else
if
(
ev
==
MG_POLL
)
{
"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; "
time_t
now
=
time
(
NULL
);
"boundary=--w00t
\r\n\r\n
"
);
state
=
(
struct
conn_state
*
)
conn
->
connection_param
;
send_file
(
conn
,
file_names
[
0
]);
if
(
state
!=
NULL
&&
now
>
state
->
last_poll
)
{
if
(
file_names
[
state
->
file_index
]
!=
NULL
)
{
state
=
(
struct
conn_state
*
)
malloc
(
sizeof
(
*
state
));
send_file
(
conn
,
file_names
[
state
->
file_index
]);
conn
->
connection_param
=
state
;
state
->
file_index
++
;
state
->
file_index
=
1
;
// First file is already sent
if
(
file_names
[
state
->
file_index
]
==
NULL
)
{
state
->
last_poll
=
time
(
NULL
);
result
=
MG_TRUE
;
// No more images, close connection
return
MG_MORE
;
case
MG_POLL
:
state
=
(
struct
conn_state
*
)
conn
->
connection_param
;
if
(
state
!=
NULL
&&
now
>
state
->
last_poll
)
{
if
(
file_names
[
state
->
file_index
]
!=
NULL
)
{
send_file
(
conn
,
file_names
[
state
->
file_index
]);
state
->
file_index
++
;
if
(
file_names
[
state
->
file_index
]
==
NULL
)
{
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
[])
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment