Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-gpu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-gpu
Commits
bf7164b7
Commit
bf7164b7
authored
Mar 12, 2009
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avcodec, switcher: use the global avcodec lock
parent
6f037fa4
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
30 deletions
+42
-30
modules/codec/avcodec/audio.c
modules/codec/avcodec/audio.c
+6
-5
modules/codec/avcodec/avcodec.c
modules/codec/avcodec/avcodec.c
+5
-6
modules/codec/avcodec/avcodec.h
modules/codec/avcodec/avcodec.h
+0
-3
modules/codec/avcodec/encoder.c
modules/codec/avcodec/encoder.c
+12
-10
modules/codec/avcodec/video.c
modules/codec/avcodec/video.c
+6
-6
modules/stream_out/switcher.c
modules/stream_out/switcher.c
+13
-0
No files found.
modules/codec/avcodec/audio.c
View file @
bf7164b7
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#include <vlc_common.h>
#include <vlc_common.h>
#include <vlc_aout.h>
#include <vlc_aout.h>
#include <vlc_codec.h>
#include <vlc_codec.h>
#include <vlc_avcodec.h>
/* ffmpeg header */
/* ffmpeg header */
#ifdef HAVE_LIBAVCODEC_AVCODEC_H
#ifdef HAVE_LIBAVCODEC_AVCODEC_H
...
@@ -188,17 +189,17 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
...
@@ -188,17 +189,17 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
}
}
/* ***** Open the codec ***** */
/* ***** Open the codec ***** */
vlc_mutex_lock
(
&
avcodec_lock
);
int
ret
;
vlc_avcodec_lock
();
if
(
avcodec_open
(
p_sys
->
p_context
,
p_sys
->
p_codec
)
<
0
)
ret
=
avcodec_open
(
p_sys
->
p_context
,
p_sys
->
p_codec
);
vlc_avcodec_unlock
();
if
(
ret
<
0
)
{
{
vlc_mutex_unlock
(
&
avcodec_lock
);
msg_Err
(
p_dec
,
"cannot open codec (%s)"
,
p_sys
->
psz_namecodec
);
msg_Err
(
p_dec
,
"cannot open codec (%s)"
,
p_sys
->
psz_namecodec
);
free
(
p_sys
->
p_context
->
extradata
);
free
(
p_sys
->
p_context
->
extradata
);
free
(
p_sys
);
free
(
p_sys
);
return
VLC_EGENERIC
;
return
VLC_EGENERIC
;
}
}
vlc_mutex_unlock
(
&
avcodec_lock
);
msg_Dbg
(
p_dec
,
"ffmpeg codec (%s) started"
,
p_sys
->
psz_namecodec
);
msg_Dbg
(
p_dec
,
"ffmpeg codec (%s) started"
,
p_sys
->
psz_namecodec
);
...
...
modules/codec/avcodec/avcodec.c
View file @
bf7164b7
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#include <vlc_common.h>
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_plugin.h>
#include <vlc_codec.h>
#include <vlc_codec.h>
#include <vlc_avcodec.h>
/* ffmpeg header */
/* ffmpeg header */
#define HAVE_MMX 1
#define HAVE_MMX 1
...
@@ -201,8 +202,6 @@ vlc_module_begin ()
...
@@ -201,8 +202,6 @@ vlc_module_begin ()
vlc_module_end
()
vlc_module_end
()
vlc_mutex_t
avcodec_lock
=
VLC_STATIC_MUTEX
;
/*****************************************************************************
/*****************************************************************************
* OpenDecoder: probe the decoder and return score
* OpenDecoder: probe the decoder and return score
*****************************************************************************/
*****************************************************************************/
...
@@ -311,9 +310,9 @@ static void CloseDecoder( vlc_object_t *p_this )
...
@@ -311,9 +310,9 @@ static void CloseDecoder( vlc_object_t *p_this )
if
(
!
p_sys
->
b_delayed_open
)
if
(
!
p_sys
->
b_delayed_open
)
{
{
vlc_
mutex_lock
(
&
avcodec_lock
);
vlc_
avcodec_lock
(
);
avcodec_close
(
p_sys
->
p_context
);
avcodec_close
(
p_sys
->
p_context
);
vlc_
mutex_unlock
(
&
avcodec_lock
);
vlc_
avcodec_unlock
(
);
}
}
msg_Dbg
(
p_dec
,
"ffmpeg codec (%s) stopped"
,
p_sys
->
psz_namecodec
);
msg_Dbg
(
p_dec
,
"ffmpeg codec (%s) stopped"
,
p_sys
->
psz_namecodec
);
av_free
(
p_sys
->
p_context
);
av_free
(
p_sys
->
p_context
);
...
@@ -326,7 +325,7 @@ void InitLibavcodec( vlc_object_t *p_object )
...
@@ -326,7 +325,7 @@ void InitLibavcodec( vlc_object_t *p_object )
{
{
static
bool
b_ffmpeginit
=
false
;
static
bool
b_ffmpeginit
=
false
;
vlc_
mutex_lock
(
&
avcodec_lock
);
vlc_
avcodec_lock
(
);
/* *** init ffmpeg library (libavcodec) *** */
/* *** init ffmpeg library (libavcodec) *** */
if
(
!
b_ffmpeginit
)
if
(
!
b_ffmpeginit
)
...
@@ -344,5 +343,5 @@ void InitLibavcodec( vlc_object_t *p_object )
...
@@ -344,5 +343,5 @@ void InitLibavcodec( vlc_object_t *p_object )
msg_Dbg
(
p_object
,
"libavcodec already initialized"
);
msg_Dbg
(
p_object
,
"libavcodec already initialized"
);
}
}
vlc_
mutex_unlock
(
&
avcodec_lock
);
vlc_
avcodec_unlock
(
);
}
}
modules/codec/avcodec/avcodec.h
View file @
bf7164b7
...
@@ -58,9 +58,6 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
...
@@ -58,9 +58,6 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
AVCodec
*
p_codec
,
int
i_codec_id
,
const
char
*
psz_namecodec
);
AVCodec
*
p_codec
,
int
i_codec_id
,
const
char
*
psz_namecodec
);
void
EndAudioDec
(
decoder_t
*
p_dec
);
void
EndAudioDec
(
decoder_t
*
p_dec
);
/* Avcodec global lock */
extern
vlc_mutex_t
avcodec_lock
;
/*****************************************************************************
/*****************************************************************************
* Module descriptor help strings
* Module descriptor help strings
*****************************************************************************/
*****************************************************************************/
...
...
modules/codec/avcodec/encoder.c
View file @
bf7164b7
...
@@ -38,6 +38,7 @@
...
@@ -38,6 +38,7 @@
#include <vlc_sout.h>
#include <vlc_sout.h>
#include <vlc_codec.h>
#include <vlc_codec.h>
#include <vlc_dialog.h>
#include <vlc_dialog.h>
#include <vlc_avcodec.h>
/* ffmpeg header */
/* ffmpeg header */
#define HAVE_MMX 1
#define HAVE_MMX 1
...
@@ -614,11 +615,12 @@ int OpenEncoder( vlc_object_t *p_this )
...
@@ -614,11 +615,12 @@ int OpenEncoder( vlc_object_t *p_this )
p_context
->
extradata
=
NULL
;
p_context
->
extradata
=
NULL
;
p_context
->
flags
|=
CODEC_FLAG_GLOBAL_HEADER
;
p_context
->
flags
|=
CODEC_FLAG_GLOBAL_HEADER
;
vlc_mutex_lock
(
&
avcodec_lock
);
int
ret
;
vlc_avcodec_lock
();
if
(
avcodec_open
(
p_context
,
p_codec
)
)
ret
=
avcodec_open
(
p_context
,
p_codec
);
vlc_avcodec_unlock
();
if
(
ret
)
{
{
vlc_mutex_unlock
(
&
avcodec_lock
);
if
(
p_enc
->
fmt_in
.
i_cat
==
AUDIO_ES
&&
if
(
p_enc
->
fmt_in
.
i_cat
==
AUDIO_ES
&&
(
p_context
->
channels
>
2
||
i_codec_id
==
CODEC_ID_MP2
(
p_context
->
channels
>
2
||
i_codec_id
==
CODEC_ID_MP2
||
i_codec_id
==
CODEC_ID_MP3
)
)
||
i_codec_id
==
CODEC_ID_MP3
)
)
...
@@ -668,10 +670,11 @@ int OpenEncoder( vlc_object_t *p_this )
...
@@ -668,10 +670,11 @@ int OpenEncoder( vlc_object_t *p_this )
}
}
p_context
->
codec
=
NULL
;
p_context
->
codec
=
NULL
;
vlc_mutex_lock
(
&
avcodec_lock
);
vlc_avcodec_lock
();
if
(
avcodec_open
(
p_context
,
p_codec
)
)
ret
=
avcodec_open
(
p_context
,
p_codec
);
vlc_avcodec_unlock
();
if
(
ret
)
{
{
vlc_mutex_unlock
(
&
avcodec_lock
);
msg_Err
(
p_enc
,
"cannot open encoder"
);
msg_Err
(
p_enc
,
"cannot open encoder"
);
dialog_Fatal
(
p_enc
,
dialog_Fatal
(
p_enc
,
_
(
"Streaming / Transcoding failed"
),
_
(
"Streaming / Transcoding failed"
),
...
@@ -689,7 +692,6 @@ int OpenEncoder( vlc_object_t *p_this )
...
@@ -689,7 +692,6 @@ int OpenEncoder( vlc_object_t *p_this )
return
VLC_EGENERIC
;
return
VLC_EGENERIC
;
}
}
}
}
vlc_mutex_unlock
(
&
avcodec_lock
);
p_enc
->
fmt_out
.
i_extra
=
p_context
->
extradata_size
;
p_enc
->
fmt_out
.
i_extra
=
p_context
->
extradata_size
;
if
(
p_enc
->
fmt_out
.
i_extra
)
if
(
p_enc
->
fmt_out
.
i_extra
)
...
@@ -1122,9 +1124,9 @@ void CloseEncoder( vlc_object_t *p_this )
...
@@ -1122,9 +1124,9 @@ void CloseEncoder( vlc_object_t *p_this )
free
(
pp_contexts
);
free
(
pp_contexts
);
}
}
vlc_
mutex_lock
(
&
avcodec_lock
);
vlc_
avcodec_lock
(
);
avcodec_close
(
p_sys
->
p_context
);
avcodec_close
(
p_sys
->
p_context
);
vlc_
mutex_unlock
(
&
avcodec_lock
);
vlc_
avcodec_unlock
(
);
av_free
(
p_sys
->
p_context
);
av_free
(
p_sys
->
p_context
);
free
(
p_sys
->
p_buffer
);
free
(
p_sys
->
p_buffer
);
...
...
modules/codec/avcodec/video.c
View file @
bf7164b7
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
#include <vlc_codec.h>
#include <vlc_codec.h>
#include <vlc_vout.h>
#include <vlc_vout.h>
#include <vlc_codecs.h>
/* BITMAPINFOHEADER */
#include <vlc_codecs.h>
/* BITMAPINFOHEADER */
#include <vlc_avcodec.h>
/* ffmpeg header */
/* ffmpeg header */
#ifdef HAVE_LIBAVCODEC_AVCODEC_H
#ifdef HAVE_LIBAVCODEC_AVCODEC_H
...
@@ -809,13 +810,12 @@ static int ffmpeg_OpenCodec( decoder_t *p_dec )
...
@@ -809,13 +810,12 @@ static int ffmpeg_OpenCodec( decoder_t *p_dec )
p_sys
->
p_context
->
bits_per_coded_sample
=
p_dec
->
fmt_in
.
video
.
i_bits_per_pixel
;
p_sys
->
p_context
->
bits_per_coded_sample
=
p_dec
->
fmt_in
.
video
.
i_bits_per_pixel
;
#endif
#endif
vlc_mutex_lock
(
&
avcodec_lock
);
int
ret
;
if
(
avcodec_open
(
p_sys
->
p_context
,
p_sys
->
p_codec
)
<
0
)
vlc_avcodec_lock
();
{
ret
=
avcodec_open
(
p_sys
->
p_context
,
p_sys
->
p_codec
);
vlc_mutex_unlock
(
&
avcodec_lock
);
vlc_avcodec_unlock
();
if
(
ret
<
0
)
return
VLC_EGENERIC
;
return
VLC_EGENERIC
;
}
vlc_mutex_unlock
(
&
avcodec_lock
);
msg_Dbg
(
p_dec
,
"ffmpeg codec (%s) started"
,
p_sys
->
psz_namecodec
);
msg_Dbg
(
p_dec
,
"ffmpeg codec (%s) started"
,
p_sys
->
psz_namecodec
);
p_sys
->
b_delayed_open
=
false
;
p_sys
->
b_delayed_open
=
false
;
...
...
modules/stream_out/switcher.c
View file @
bf7164b7
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include <vlc_plugin.h>
#include <vlc_plugin.h>
#include <vlc_sout.h>
#include <vlc_sout.h>
#include <vlc_vout.h>
#include <vlc_vout.h>
#include <vlc_avcodec.h>
#include <vlc_block.h>
#include <vlc_block.h>
...
@@ -384,13 +385,16 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
...
@@ -384,13 +385,16 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
id
->
ff_enc_c
->
channels
=
p_fmt
->
audio
.
i_channels
;
id
->
ff_enc_c
->
channels
=
p_fmt
->
audio
.
i_channels
;
id
->
ff_enc_c
->
bit_rate
=
p_fmt
->
i_bitrate
;
id
->
ff_enc_c
->
bit_rate
=
p_fmt
->
i_bitrate
;
vlc_avcodec_lock
();
if
(
avcodec_open
(
id
->
ff_enc_c
,
id
->
ff_enc
)
)
if
(
avcodec_open
(
id
->
ff_enc_c
,
id
->
ff_enc
)
)
{
{
avcodec_unlock
();
msg_Err
(
p_stream
,
"cannot open encoder"
);
msg_Err
(
p_stream
,
"cannot open encoder"
);
av_free
(
id
->
ff_enc_c
);
av_free
(
id
->
ff_enc_c
);
free
(
id
);
free
(
id
);
return
NULL
;
return
NULL
;
}
}
avcodec_unlock
();
id
->
p_buffer_out
=
malloc
(
AVCODEC_MAX_AUDIO_FRAME_SIZE
*
2
);
id
->
p_buffer_out
=
malloc
(
AVCODEC_MAX_AUDIO_FRAME_SIZE
*
2
);
id
->
p_samples
=
calloc
(
id
->
ff_enc_c
->
frame_size
*
p_fmt
->
audio
.
i_channels
,
id
->
p_samples
=
calloc
(
id
->
ff_enc_c
->
frame_size
*
p_fmt
->
audio
.
i_channels
,
...
@@ -428,7 +432,9 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
...
@@ -428,7 +432,9 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
return
id
;
return
id
;
error:
error:
vlc_avcodec_lock
();
avcodec_close
(
id
->
ff_enc_c
);
avcodec_close
(
id
->
ff_enc_c
);
vlc_avcodec_unlock
();
free
(
id
->
p_samples
);
free
(
id
->
p_samples
);
free
(
id
->
p_buffer_out
);
free
(
id
->
p_buffer_out
);
av_free
(
id
->
ff_enc_c
);
av_free
(
id
->
ff_enc_c
);
...
@@ -458,7 +464,9 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
...
@@ -458,7 +464,9 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
if
(
id
->
ff_enc
)
if
(
id
->
ff_enc
)
{
{
vlc_avcodec_lock
();
avcodec_close
(
id
->
ff_enc_c
);
avcodec_close
(
id
->
ff_enc_c
);
vlc_avcodec_unlock
();
av_free
(
id
->
ff_enc_c
);
av_free
(
id
->
ff_enc_c
);
av_free
(
id
->
p_frame
);
av_free
(
id
->
p_frame
);
free
(
id
->
p_buffer_out
);
free
(
id
->
p_buffer_out
);
...
@@ -708,7 +716,9 @@ static mtime_t VideoCommand( sout_stream_t *p_stream, sout_stream_id_t *id )
...
@@ -708,7 +716,9 @@ static mtime_t VideoCommand( sout_stream_t *p_stream, sout_stream_id_t *id )
if
(
id
->
ff_enc
)
if
(
id
->
ff_enc
)
{
{
vlc_avcodec_lock
();
avcodec_close
(
id
->
ff_enc_c
);
avcodec_close
(
id
->
ff_enc_c
);
vlc_avcodec_unlock
();
av_free
(
id
->
ff_enc_c
);
av_free
(
id
->
ff_enc_c
);
av_free
(
id
->
p_frame
);
av_free
(
id
->
p_frame
);
free
(
id
->
p_buffer_out
);
free
(
id
->
p_buffer_out
);
...
@@ -785,11 +795,14 @@ static mtime_t VideoCommand( sout_stream_t *p_stream, sout_stream_id_t *id )
...
@@ -785,11 +795,14 @@ static mtime_t VideoCommand( sout_stream_t *p_stream, sout_stream_id_t *id )
id
->
ff_enc_c
->
mb_decision
=
FF_MB_DECISION_SIMPLE
;
id
->
ff_enc_c
->
mb_decision
=
FF_MB_DECISION_SIMPLE
;
id
->
ff_enc_c
->
pix_fmt
=
PIX_FMT_YUV420P
;
id
->
ff_enc_c
->
pix_fmt
=
PIX_FMT_YUV420P
;
avcodec_lock
();
if
(
avcodec_open
(
id
->
ff_enc_c
,
id
->
ff_enc
)
)
if
(
avcodec_open
(
id
->
ff_enc_c
,
id
->
ff_enc
)
)
{
{
avcodec_unlock
();
msg_Err
(
p_stream
,
"cannot open encoder"
);
msg_Err
(
p_stream
,
"cannot open encoder"
);
return
0
;
return
0
;
}
}
avcodec_unlock
();
id
->
p_buffer_out
=
malloc
(
id
->
ff_enc_c
->
width
*
id
->
ff_enc_c
->
height
*
3
);
id
->
p_buffer_out
=
malloc
(
id
->
ff_enc_c
->
width
*
id
->
ff_enc_c
->
height
*
3
);
id
->
p_frame
=
avcodec_alloc_frame
();
id
->
p_frame
=
avcodec_alloc_frame
();
...
...
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