Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mediastreamer2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
External Wiki
External Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
BC
public
mediastreamer2
Commits
6921d874
Commit
6921d874
authored
Apr 13, 2016
by
Sylvain Berfini
🎩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added jpeg_writer filter in video preview graph
parent
64c7fbaa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
39 deletions
+79
-39
msjpegwriter.h
include/mediastreamer2/msjpegwriter.h
+2
-1
jpegwriter.c
src/videofilters/jpegwriter.c
+5
-0
videostream.c
src/voip/videostream.c
+72
-38
No files found.
include/mediastreamer2/msjpegwriter.h
View file @
6921d874
...
...
@@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <mediastreamer2/msfilter.h>
#define MS_JPEG_WRITER_TAKE_SNAPSHOT MS_FILTER_METHOD(MS_JPEG_WRITER_ID,0,const char)
#define MS_JPEG_WRITER_TAKE_SNAPSHOT MS_FILTER_METHOD(MS_JPEG_WRITER_ID, 0, const char)
#define MS_JPEG_WRITER_SNAPSHOT_TAKEN MS_FILTER_EVENT(MS_JPEG_WRITER_ID, 0, const char)
#endif
src/videofilters/jpegwriter.c
View file @
6921d874
...
...
@@ -32,6 +32,7 @@ typedef struct {
char
*
tmpFilename
;
AVCodec
*
codec
;
AVFrame
*
pict
;
MSFilter
*
f
;
}
JpegWriter
;
static
void
close_file
(
JpegWriter
*
obj
,
bool_t
doRenaming
);
...
...
@@ -55,6 +56,8 @@ static void close_file(JpegWriter *obj, bool_t doRenaming) {
if
(
doRenaming
)
{
if
(
rename
(
obj
->
tmpFilename
,
obj
->
filename
)
!=
0
)
{
ms_error
(
"Could not rename %s into %s"
,
obj
->
tmpFilename
,
obj
->
filename
);
}
else
{
ms_filter_notify
(
obj
->
f
,
MS_JPEG_WRITER_SNAPSHOT_TAKEN
,
(
void
*
)
obj
->
filename
);
}
}
ms_free
(
obj
->
filename
);
...
...
@@ -66,6 +69,7 @@ static void close_file(JpegWriter *obj, bool_t doRenaming) {
static
void
jpg_init
(
MSFilter
*
f
){
JpegWriter
*
s
=
ms_new0
(
JpegWriter
,
1
);
s
->
f
=
f
;
s
->
codec
=
avcodec_find_encoder
(
CODEC_ID_MJPEG
);
if
(
s
->
codec
==
NULL
){
ms_error
(
"Could not find CODEC_ID_MJPEG !"
);
...
...
@@ -76,6 +80,7 @@ static void jpg_init(MSFilter *f){
static
void
jpg_uninit
(
MSFilter
*
f
){
JpegWriter
*
s
=
(
JpegWriter
*
)
f
->
data
;
s
->
f
=
NULL
;
if
(
s
->
file
!=
NULL
){
close_file
(
s
,
FALSE
);
}
...
...
src/voip/videostream.c
View file @
6921d874
...
...
@@ -1544,17 +1544,18 @@ MSVideoSize video_preview_get_current_size(VideoPreview *stream){
return
ret
;
}
void
video_preview_start
(
VideoPreview
*
stream
,
MSWebCam
*
device
){
void
video_preview_start
(
VideoPreview
*
stream
,
MSWebCam
*
device
)
{
MSPixFmt
format
;
float
fps
;
int
mirroring
=
1
;
int
corner
=-
1
;
MSVideoSize
disp_size
=
stream
->
sent_vsize
;
MSVideoSize
vsize
=
disp_size
;
const
char
*
displaytype
=
stream
->
display_name
;
int
mirroring
=
1
;
int
corner
=
-
1
;
MSVideoSize
disp_size
=
stream
->
sent_vsize
;
MSVideoSize
vsize
=
disp_size
;
const
char
*
displaytype
=
stream
->
display_name
;
MSConnectionHelper
ch
;
if
(
stream
->
fps
!=
0
)
fps
=
stream
->
fps
;
else
fps
=
(
float
)
29
.
97
;
if
(
stream
->
fps
!=
0
)
fps
=
stream
->
fps
;
else
fps
=
(
float
)
29
.
97
;
stream
->
source
=
ms_web_cam_create_reader
(
device
);
...
...
@@ -1567,52 +1568,85 @@ void video_preview_start(VideoPreview *stream, MSWebCam *device){
}
/* configure the filters */
ms_filter_call_method
(
stream
->
source
,
MS_FILTER_SET_VIDEO_SIZE
,
&
vsize
);
if
(
ms_filter_get_id
(
stream
->
source
)
!=
MS_STATIC_IMAGE_ID
)
ms_filter_call_method
(
stream
->
source
,
MS_FILTER_SET_FPS
,
&
fps
);
ms_filter_call_method
(
stream
->
source
,
MS_FILTER_GET_PIX_FMT
,
&
format
);
ms_filter_call_method
(
stream
->
source
,
MS_FILTER_GET_VIDEO_SIZE
,
&
vsize
);
if
(
format
==
MS_MJPEG
){
stream
->
pixconv
=
ms_factory_create_filter
(
stream
->
ms
.
factory
,
MS_MJPEG_DEC_ID
);
ms_filter_call_method
(
stream
->
source
,
MS_FILTER_SET_VIDEO_SIZE
,
&
vsize
);
if
(
ms_filter_get_id
(
stream
->
source
)
!=
MS_STATIC_IMAGE_ID
)
{
ms_filter_call_method
(
stream
->
source
,
MS_FILTER_SET_FPS
,
&
fps
);
}
ms_filter_call_method
(
stream
->
source
,
MS_FILTER_GET_PIX_FMT
,
&
format
);
ms_filter_call_method
(
stream
->
source
,
MS_FILTER_GET_VIDEO_SIZE
,
&
vsize
);
if
(
format
==
MS_MJPEG
)
{
stream
->
pixconv
=
ms_factory_create_filter
(
stream
->
ms
.
factory
,
MS_MJPEG_DEC_ID
);
if
(
stream
->
pixconv
==
NULL
){
ms_error
(
"Could not create mjpeg decoder, check your build options."
);
}
}
else
{
stream
->
pixconv
=
ms_factory_create_filter
(
stream
->
ms
.
factory
,
MS_PIX_CONV_ID
);
ms_filter_call_method
(
stream
->
pixconv
,
MS_FILTER_SET_PIX_FMT
,
&
format
);
ms_filter_call_method
(
stream
->
pixconv
,
MS_FILTER_SET_VIDEO_SIZE
,
&
vsize
);
}
else
{
stream
->
pixconv
=
ms_factory_create_filter
(
stream
->
ms
.
factory
,
MS_PIX_CONV_ID
);
ms_filter_call_method
(
stream
->
pixconv
,
MS_FILTER_SET_PIX_FMT
,
&
format
);
ms_filter_call_method
(
stream
->
pixconv
,
MS_FILTER_SET_VIDEO_SIZE
,
&
vsize
);
}
format
=
MS_YUV420P
;
stream
->
output2
=
ms_factory_create_filter_from_name
(
stream
->
ms
.
factory
,
displaytype
);
ms_filter_call_method
(
stream
->
output2
,
MS_FILTER_SET_PIX_FMT
,
&
format
);
ms_filter_call_method
(
stream
->
output2
,
MS_FILTER_SET_VIDEO_SIZE
,
&
disp_size
);
ms_filter_call_method
(
stream
->
output2
,
MS_VIDEO_DISPLAY_ENABLE_MIRRORING
,
&
mirroring
);
ms_filter_call_method
(
stream
->
output2
,
MS_VIDEO_DISPLAY_SET_LOCAL_VIEW_MODE
,
&
corner
);
/* and then connect all */
format
=
MS_YUV420P
;
ms_filter_link
(
stream
->
source
,
0
,
stream
->
pixconv
,
0
);
ms_filter_link
(
stream
->
pixconv
,
0
,
stream
->
output2
,
0
);
if
(
stream
->
preview_window_id
!=
0
){
video_stream_set_native_preview_window_id
(
stream
,
stream
->
preview_window_id
);
if
(
displaytype
)
{
stream
->
output2
=
ms_factory_create_filter_from_name
(
stream
->
ms
.
factory
,
displaytype
);
ms_filter_call_method
(
stream
->
output2
,
MS_FILTER_SET_PIX_FMT
,
&
format
);
ms_filter_call_method
(
stream
->
output2
,
MS_FILTER_SET_VIDEO_SIZE
,
&
disp_size
);
ms_filter_call_method
(
stream
->
output2
,
MS_VIDEO_DISPLAY_ENABLE_MIRRORING
,
&
mirroring
);
ms_filter_call_method
(
stream
->
output2
,
MS_VIDEO_DISPLAY_SET_LOCAL_VIEW_MODE
,
&
corner
);
/* and then connect all */
}
stream
->
local_jpegwriter
=
ms_factory_create_filter
(
stream
->
ms
.
factory
,
MS_JPEG_WRITER_ID
);
if
(
stream
->
local_jpegwriter
)
{
stream
->
tee
=
ms_factory_create_filter
(
stream
->
ms
.
factory
,
MS_TEE_ID
);
}
ms_connection_helper_start
(
&
ch
);
ms_connection_helper_link
(
&
ch
,
stream
->
source
,
-
1
,
0
);
if
(
stream
->
pixconv
)
{
ms_connection_helper_link
(
&
ch
,
stream
->
pixconv
,
0
,
0
);
}
if
(
stream
->
tee
)
{
ms_connection_helper_link
(
&
ch
,
stream
->
tee
,
0
,
0
);
}
if
(
stream
->
output2
)
{
if
(
stream
->
preview_window_id
!=
0
)
{
video_stream_set_native_preview_window_id
(
stream
,
stream
->
preview_window_id
);
}
ms_filter_link
(
stream
->
tee
,
1
,
stream
->
output2
,
0
);
}
if
(
stream
->
local_jpegwriter
)
{
ms_filter_link
(
stream
->
tee
,
2
,
stream
->
local_jpegwriter
,
0
);
}
/* create the ticker */
stream
->
ms
.
sessions
.
ticker
=
ms_ticker_new
();
ms_ticker_set_name
(
stream
->
ms
.
sessions
.
ticker
,
"Video MSTicker"
);
ms_ticker_set_name
(
stream
->
ms
.
sessions
.
ticker
,
"Video MSTicker"
);
ms_ticker_attach
(
stream
->
ms
.
sessions
.
ticker
,
stream
->
source
);
stream
->
ms
.
state
=
MSStreamStarted
;
stream
->
ms
.
state
=
MSStreamStarted
;
}
static
MSFilter
*
_video_preview_stop
(
VideoPreview
*
stream
,
bool_t
keep_source
)
{
static
MSFilter
*
_video_preview_stop
(
VideoPreview
*
stream
,
bool_t
keep_source
)
{
MSFilter
*
source
=
NULL
;
MSConnectionHelper
ch
;
ms_ticker_detach
(
stream
->
ms
.
sessions
.
ticker
,
stream
->
source
);
ms_filter_unlink
(
stream
->
source
,
0
,
stream
->
pixconv
,
0
);
ms_filter_unlink
(
stream
->
pixconv
,
0
,
stream
->
output2
,
0
);
ms_connection_helper_start
(
&
ch
);
ms_connection_helper_unlink
(
&
ch
,
stream
->
source
,
-
1
,
0
);
if
(
stream
->
pixconv
)
{
ms_connection_helper_unlink
(
&
ch
,
stream
->
pixconv
,
0
,
0
);
}
if
(
stream
->
tee
)
{
ms_connection_helper_unlink
(
&
ch
,
stream
->
tee
,
0
,
0
);
}
if
(
stream
->
output2
)
{
ms_filter_unlink
(
stream
->
tee
,
1
,
stream
->
output2
,
0
);
}
if
(
stream
->
local_jpegwriter
)
{
ms_filter_unlink
(
stream
->
tee
,
2
,
stream
->
local_jpegwriter
,
0
);
}
if
(
keep_source
)
{
if
(
keep_source
)
{
source
=
stream
->
source
;
ms_message
(
"video_preview_stop: keeping source %p"
,
source
);
stream
->
source
=
NULL
;
// prevent destroy of the source
...
...
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