Skip to content

Commit 3ef900e

Browse files
author
Clement Champetier
committed
common: add preloadCodecsAndFormats function
* Remove call of 'av_register_all' everywhere in the library. * This ffmpeg function initializes static elements, so it's dangerous to call it several times in several classes, if the user creates a multi- threads applications. * The user needs to call it at the beginning, only once.
1 parent 955da92 commit 3ef900e

13 files changed

+21
-15
lines changed

src/AvTranscoder/Library.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ Libraries getLibraries()
9191

9292
std::vector<std::string> getInputExtensions()
9393
{
94-
av_register_all();
9594
std::vector<std::string> extensions;
9695
AVInputFormat* iFormat = NULL;
9796

@@ -130,7 +129,6 @@ std::vector<std::string> getInputExtensions()
130129

131130
std::vector<std::string> getOutputExtensions()
132131
{
133-
av_register_all();
134132
std::vector<std::string> extensions;
135133
AVOutputFormat* oFormat = NULL;
136134

src/AvTranscoder/codec/ICodec.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ ICodec::ICodec( const ECodecType type, const std::string& codecName )
1515
, _avCodec( NULL )
1616
, _type( type )
1717
{
18-
avcodec_register_all(); // TODO: call only once
19-
2018
setCodec( type, codecName );
2119
allocateContext();
2220
loadCodecOptions();
@@ -27,8 +25,6 @@ ICodec::ICodec( const ECodecType type, const AVCodecID codecId )
2725
, _avCodec( NULL )
2826
, _type( type )
2927
{
30-
avcodec_register_all(); // TODO: call only once
31-
3228
setCodec( type, codecId );
3329
allocateContext();
3430
loadCodecOptions();

src/AvTranscoder/common.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ extern "C" {
1212
namespace avtranscoder
1313
{
1414

15+
void preloadCodecsAndFormats()
16+
{
17+
av_register_all();
18+
}
19+
1520
void split( std::vector< std::string >& splitedString, const std::string& inputString, const std::string& splitChars )
1621
{
1722
char* part = strtok( const_cast<char*>( inputString.c_str() ), splitChars.c_str() );
@@ -47,7 +52,6 @@ std::string getFormat( const std::string& filename )
4752
{
4853
std::string format( "" );
4954

50-
av_register_all();
5155
AVOutputFormat* avOutputFormat = av_guess_format( NULL, filename.c_str(), NULL);
5256
if( avOutputFormat )
5357
{

src/AvTranscoder/common.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ namespace avtranscoder
5656

5757
typedef AVRational Rational;
5858

59+
/// Register all the codecs and formats which are enabled at configuration time.
60+
void preloadCodecsAndFormats();
61+
5962
#ifndef SWIG
6063
void split( std::vector< std::string >& splitedString, const std::string& inputString, const std::string& splitChars = ";" );
6164
int getFilesInDir( const std::string& dir, std::vector< std::string >& files );

src/AvTranscoder/encoder/AudioEncoder.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ AudioEncoder::AudioEncoder( const std::string& audioCodecName )
1919

2020
void AudioEncoder::setup()
2121
{
22-
av_register_all();
23-
2422
AVCodecContext& avCodecContext = _codec.getAVCodecContext();
2523
const AVCodec& avCodec = _codec.getAVCodec();
2624

src/AvTranscoder/encoder/VideoEncoder.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ VideoEncoder::VideoEncoder( const std::string& videoCodecName )
2020

2121
void VideoEncoder::setup()
2222
{
23-
av_register_all();
24-
2523
AVCodecContext& avCodecContext( _codec.getAVCodecContext() );
2624

2725
if( &avCodecContext == NULL )

src/AvTranscoder/file/FormatContext.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ FormatContext::FormatContext( const std::string& filename, int req_flags )
1212
, _options()
1313
, _isOpen( true )
1414
{
15-
av_register_all(); // TODO: call it once
16-
1715
int err = avformat_open_input( &_avFormatContext, filename.c_str(), NULL, NULL );
1816
if( err < 0 )
1917
{
@@ -29,8 +27,6 @@ FormatContext::FormatContext( int req_flags )
2927
, _options()
3028
, _isOpen( false )
3129
{
32-
av_register_all(); // TODO: call it once
33-
3430
_avFormatContext = avformat_alloc_context();
3531
loadOptions( _options, _avFormatContext, req_flags );
3632
}

test/pyTest/testProperties.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from pyAvTranscoder import avtranscoder as av
66

7+
av.preloadCodecsAndFormats()
8+
79

810
def testAddMetadataDate():
911
"""

test/pyTest/testSetFrame.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from pyAvTranscoder import avtranscoder as av
66

7+
av.preloadCodecsAndFormats()
8+
79

810
def testSetVideoFrame():
911
"""

test/pyTest/testTranscoderAdd.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from pyAvTranscoder import avtranscoder as av
66

7+
av.preloadCodecsAndFormats()
8+
79

810
def testAddStreamTranscoder():
911
"""

0 commit comments

Comments
 (0)