Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Steve Lhomme
VLC
Commits
fbd4154e
Commit
fbd4154e
authored
Sep 13, 2014
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avcodec: use avcodec_free_context() where applicable
Fix leak on error, fix mismatched free function on success.
parent
f32044fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
36 deletions
+46
-36
modules/codec/avcodec/avcodec.c
modules/codec/avcodec/avcodec.c
+39
-36
modules/codec/avcodec/avcommon_compat.h
modules/codec/avcodec/avcommon_compat.h
+7
-0
No files found.
modules/codec/avcodec/avcodec.c
View file @
fbd4154e
...
...
@@ -248,10 +248,9 @@ static int OpenDecoder( vlc_object_t *p_this )
{
decoder_t
*
p_dec
=
(
decoder_t
*
)
p_this
;
unsigned
i_codec_id
;
int
i_cat
,
i_result
;
int
i_cat
;
const
char
*
psz_namecodec
;
AVCodecContext
*
p_context
=
NULL
;
const
AVCodec
*
p_codec
=
NULL
;
/* *** determine codec type *** */
...
...
@@ -288,37 +287,44 @@ static int OpenDecoder( vlc_object_t *p_this )
}
/* *** get a p_context *** */
p_context
=
avcodec_alloc_context3
(
p_codec
);
if
(
!
p_context
)
AVCodecContext
*
avctx
=
avcodec_alloc_context3
(
p_codec
);
if
(
unlikely
(
avctx
==
NULL
)
)
return
VLC_ENOMEM
;
p_context
->
debug
=
var_InheritInteger
(
p_dec
,
"avcodec-debug"
);
p_context
->
opaque
=
(
void
*
)
p_this
;
p_dec
->
b_need_packetized
=
true
;
avctx
->
debug
=
var_InheritInteger
(
p_dec
,
"avcodec-debug"
);
avctx
->
opaque
=
p_dec
;
int
ret
;
switch
(
i_cat
)
{
case
VIDEO_ES
:
i_resul
t
=
InitVideoDec
(
p_dec
,
p_context
,
p_codec
);
break
;
case
AUDIO_ES
:
i_resul
t
=
InitAudioDec
(
p_dec
,
p_context
,
p_codec
);
break
;
case
SPU_ES
:
i_resul
t
=
InitSubtitleDec
(
p_dec
,
p_context
,
p_codec
);
break
;
default:
return
VLC_EGENERIC
;
case
VIDEO_ES
:
re
t
=
InitVideoDec
(
p_dec
,
avctx
,
p_codec
);
break
;
case
AUDIO_ES
:
re
t
=
InitAudioDec
(
p_dec
,
avctx
,
p_codec
);
break
;
case
SPU_ES
:
re
t
=
InitSubtitleDec
(
p_dec
,
avctx
,
p_codec
);
break
;
default:
ret
=
VLC_EGENERIC
;
}
if
(
i_resul
t
=
=
VLC_SUCCESS
)
if
(
re
t
!
=
VLC_SUCCESS
)
{
if
(
p_context
->
profile
!=
FF_PROFILE_UNKNOWN
)
p_dec
->
fmt_in
.
i_profile
=
p_context
->
profile
;
if
(
p_context
->
level
!=
FF_LEVEL_UNKNOWN
)
p_dec
->
fmt_in
.
i_level
=
p_context
->
level
;
avcodec_free_context
(
&
avctx
);
return
ret
;
}
return
i_result
;
if
(
avctx
->
profile
!=
FF_PROFILE_UNKNOWN
)
p_dec
->
fmt_in
.
i_profile
=
avctx
->
profile
;
if
(
avctx
->
level
!=
FF_LEVEL_UNKNOWN
)
p_dec
->
fmt_in
.
i_level
=
avctx
->
level
;
p_dec
->
b_need_packetized
=
true
;
return
VLC_SUCCESS
;
}
/*****************************************************************************
...
...
@@ -336,21 +342,18 @@ static void CloseDecoder( vlc_object_t *p_this )
break
;
}
if
(
p_sys
->
p_context
)
{
av_free
(
p_sys
->
p_context
->
extradata
);
p_sys
->
p_context
->
extradata
=
NULL
;
av_free
(
p_sys
->
p_context
->
extradata
);
p_sys
->
p_context
->
extradata
=
NULL
;
if
(
!
p_sys
->
b_delayed_open
)
{
vlc_avcodec_lock
();
avcodec_close
(
p_sys
->
p_context
);
vlc_avcodec_unlock
();
}
msg_Dbg
(
p_dec
,
"ffmpeg codec (%s) stopped"
,
p_sys
->
p_codec
->
name
);
av_free
(
p_sys
->
p_context
);
if
(
!
p_sys
->
b_delayed_open
)
{
vlc_avcodec_lock
();
avcodec_close
(
p_sys
->
p_context
);
vlc_avcodec_unlock
();
}
msg_Dbg
(
p_dec
,
"ffmpeg codec (%s) stopped"
,
p_sys
->
p_codec
->
name
);
avcodec_free_context
(
&
p_sys
->
p_context
);
free
(
p_sys
);
}
...
...
modules/codec/avcodec/avcommon_compat.h
View file @
fbd4154e
...
...
@@ -36,6 +36,13 @@
( (LIBAVCODEC_VERSION_MICRO < 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, b, c ) ) || \
(LIBAVCODEC_VERSION_MICRO >= 100 && LIBAVCODEC_VERSION_INT >= AV_VERSION_INT( a, d, e ) ) )
# if (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 52, 0))
static
inline
void
avcodec_free_context
(
AVCodecContext
**
ctx
)
{
av_freep
(
ctx
);
}
#endif
#endif
/* HAVE_LIBAVCODEC_AVCODEC_H */
#ifdef HAVE_LIBAVUTIL_AVUTIL_H
...
...
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