Skip to content

Commit f9ad8b2

Browse files
committed
Merge pull request #72 from cchampet/dev_logLevel
Add setLogLevel
2 parents ced56b1 + 65df88d commit f9ad8b2

17 files changed

+147
-71
lines changed

src/AvTranscoder/ProfileLoader.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <fstream>
77
#include <cstdlib>
88
#include <stdexcept>
9+
#include <dirent.h>
910

1011
namespace avtranscoder
1112
{
@@ -200,5 +201,35 @@ bool ProfileLoader::checkAudioProfile( const Profile& profileToCheck )
200201
return isValid;
201202
}
202203

204+
void split( std::vector< std::string >& splitString, const std::string& inputString, const std::string& splitChars )
205+
{
206+
char* part = strtok( const_cast<char*>( inputString.c_str() ), splitChars.c_str() );
207+
while( part != NULL )
208+
{
209+
splitString.push_back( std::string( part ) );
210+
part = strtok( NULL, splitChars.c_str() );
211+
}
212+
}
213+
214+
int getFilesInDir( const std::string& dir, std::vector< std::string >& files )
215+
{
216+
DIR *dp;
217+
struct dirent *dirp;
218+
if( ( dp = opendir( dir.c_str() ) ) == NULL )
219+
{
220+
std::cerr << "Error(" << errno << ") opening " << dir << std::endl;
221+
return errno;
222+
}
223+
224+
while( ( dirp = readdir( dp ) ) != NULL )
225+
{
226+
std::string filename( dirp->d_name );
227+
if( filename == "." || filename == ".." )
228+
continue;
229+
files.push_back( filename );
230+
}
231+
closedir( dp );
232+
return 0;
233+
}
203234

204235
}

src/AvTranscoder/ProfileLoader.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,10 @@ class AvExport ProfileLoader
7373
Profiles _profiles;
7474
};
7575

76+
#ifndef SWIG
77+
void split( std::vector< std::string >& splitString, const std::string& inputString, const std::string& splitChars = ";" );
78+
int getFilesInDir( const std::string& dir, std::vector< std::string >& files );
79+
#endif
80+
7681
}
7782
#endif

src/AvTranscoder/avTranscoder.i

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
%include "AvTranscoder/swig/avException.i"
1111
%include "AvTranscoder/swig/avExport.i"
1212
%include "AvTranscoder/swig/avDocumentation.i"
13+
%include "AvTranscoder/swig/avMediaType.i"
1314
%include "AvTranscoder/swig/avRational.i"
15+
%include "AvTranscoder/swig/avLogLevel.i"
1416

1517
%{
1618
#include <AvTranscoder/ProfileLoader.hpp>

src/AvTranscoder/codec/ICodec.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include <AvTranscoder/common.hpp>
55
#include <AvTranscoder/Option.hpp>
66

7+
extern "C" {
8+
#include <libavcodec/avcodec.h>
9+
}
10+
711
#include <string>
812

913
namespace avtranscoder

src/AvTranscoder/common.cpp

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
#include "common.hpp"
22

33
extern "C" {
4-
#include <libavcodec/avcodec.h>
54
#include <libavformat/avformat.h>
6-
#include <libavutil/error.h>
75
}
86

9-
#include <dirent.h>
10-
#include <iostream>
11-
127
namespace avtranscoder
138
{
149

@@ -17,56 +12,9 @@ void preloadCodecsAndFormats()
1712
av_register_all();
1813
}
1914

20-
void split( std::vector< std::string >& splitedString, const std::string& inputString, const std::string& splitChars )
21-
{
22-
char* part = strtok( const_cast<char*>( inputString.c_str() ), splitChars.c_str() );
23-
while( part != NULL )
24-
{
25-
splitedString.push_back( std::string( part ) );
26-
part = strtok( NULL, splitChars.c_str() );
27-
}
28-
}
29-
30-
int getFilesInDir( const std::string& dir, std::vector< std::string >& files )
31-
{
32-
DIR *dp;
33-
struct dirent *dirp;
34-
if( ( dp = opendir( dir.c_str() ) ) == NULL )
35-
{
36-
std::cerr << "Error(" << errno << ") opening " << dir << std::endl;
37-
return errno;
38-
}
39-
40-
while( ( dirp = readdir( dp ) ) != NULL )
41-
{
42-
std::string filename( dirp->d_name );
43-
if( filename == "." || filename == ".." )
44-
continue;
45-
files.push_back( filename );
46-
}
47-
closedir( dp );
48-
return 0;
49-
}
50-
51-
std::string getFormat( const std::string& filename )
52-
{
53-
std::string format( "" );
54-
55-
AVOutputFormat* avOutputFormat = av_guess_format( NULL, filename.c_str(), NULL);
56-
if( avOutputFormat )
57-
{
58-
if( avOutputFormat->name )
59-
format = std::string( avOutputFormat->name );
60-
}
61-
62-
return format;
63-
}
64-
65-
bool matchFormat( const std::string& format, const std::string& filename )
15+
void setLogLevel( const int level )
6616
{
67-
AVOutputFormat* avOutputFormat = av_guess_format( format.c_str(), filename.c_str(), NULL);
68-
return avOutputFormat != NULL;
17+
av_log_set_level( level );
6918
}
7019

71-
7220
}

src/AvTranscoder/common.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ extern "C" {
99
#define INT64_C(c) (c ## LL)
1010
#define UINT64_C(c) (c ## ULL)
1111
#endif
12-
#include <libavformat/version.h>
1312
#include <libavcodec/version.h>
14-
#include <libavcodec/avcodec.h>
13+
#include <libavutil/error.h>
1514
#include <libavutil/rational.h>
15+
#include <libavutil/log.h>
1616
}
1717

1818
#include <string>
1919
#include <cstring>
20-
#include <vector>
2120

2221
#ifdef SWIG
2322
#define AvExport
@@ -59,13 +58,12 @@ typedef AVRational Rational;
5958
/// Register all the codecs and formats which are enabled at configuration time.
6059
void AvExport preloadCodecsAndFormats();
6160

62-
#ifndef SWIG
63-
void split( std::vector< std::string >& splitedString, const std::string& inputString, const std::string& splitChars = ";" );
64-
int getFilesInDir( const std::string& dir, std::vector< std::string >& files );
65-
#endif
66-
67-
std::string AvExport getFormat( const std::string& filename );
68-
bool AvExport matchFormat( const std::string& format, const std::string& filename );
61+
/**
62+
* @brief Set the log level of ffmpeg/libav.
63+
* @param level: refer to define AV_LOG_xxx (from AV_LOG_QUIET to AV_LOG_DEBUG)
64+
* @see SWIG interface avLogLevel.i
65+
*/
66+
void AvExport setLogLevel( const int level );
6967

7068
}
7169

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "OutputFile.hpp"
22

3+
#include <AvTranscoder/util.hpp>
4+
35
#include <iostream>
46
#include <stdexcept>
57

src/AvTranscoder/frame/VideoFrame.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <AvTranscoder/ProfileLoader.hpp>
66

77
extern "C" {
8+
#include <libavcodec/avcodec.h>
89
#include <libavutil/pixfmt.h>
910
#include <libavutil/pixdesc.h>
1011
}

src/AvTranscoder/mediaProperty/VideoProperties.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern "C" {
88

99
#include <stdexcept>
1010
#include <iomanip>
11+
#include <sstream>
1112

1213
#ifdef _MSC_VER
1314
#include <float.h>

src/AvTranscoder/mediaProperty/VideoProperties.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#ifndef _AV_TRANSCODER_MEDIA_PROPERTY_VIDEO_PROPERTIES_HPP
22
#define _AV_TRANSCODER_MEDIA_PROPERTY_VIDEO_PROPERTIES_HPP
33

4-
#include <AvTranscoder/common.hpp>
54
#include "PixelProperties.hpp"
5+
6+
#include <AvTranscoder/common.hpp>
67
#include <AvTranscoder/mediaProperty/util.hpp>
78
#include <AvTranscoder/file/util.hpp>
89
#include <AvTranscoder/file/FormatContext.hpp>

src/AvTranscoder/mediaProperty/util.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "util.hpp"
22

3-
extern "C" {
4-
#include <libavutil/dict.h>
5-
}
3+
#include <sstream>
64

75
namespace avtranscoder
86
{

src/AvTranscoder/mediaProperty/util.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
#include <AvTranscoder/common.hpp>
55

6+
extern "C" {
7+
#include <libavutil/dict.h>
8+
}
9+
610
#include <vector>
711
#include <utility>
812
#include <string>

src/AvTranscoder/swig/avLogLevel.i

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Print no output.
3+
*/
4+
#define AV_LOG_QUIET -8
5+
6+
/**
7+
* Something went really wrong and we will crash now.
8+
*/
9+
#define AV_LOG_PANIC 0
10+
11+
/**
12+
* Something went wrong and recovery is not possible.
13+
* For example, no header was found for a format which depends
14+
* on headers or an illegal combination of parameters is used.
15+
*/
16+
#define AV_LOG_FATAL 8
17+
18+
/**
19+
* Something went wrong and cannot losslessly be recovered.
20+
* However, not all future data is affected.
21+
*/
22+
#define AV_LOG_ERROR 16
23+
24+
/**
25+
* Something somehow does not look correct. This may or may not
26+
* lead to problems. An example would be the use of '-vstrict -2'.
27+
*/
28+
#define AV_LOG_WARNING 24
29+
30+
/**
31+
* Standard information.
32+
*/
33+
#define AV_LOG_INFO 32
34+
35+
/**
36+
* Detailed information.
37+
*/
38+
#define AV_LOG_VERBOSE 40
39+
40+
/**
41+
* Stuff which is only useful for libav* developers.
42+
*/
43+
#define AV_LOG_DEBUG 48

src/AvTranscoder/swig/avMediaType.i

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// ffmpeg/libav media type
2+
enum AVMediaType {
3+
AVMEDIA_TYPE_UNKNOWN = -1, ///< Usually treated as AVMEDIA_TYPE_DATA
4+
AVMEDIA_TYPE_VIDEO,
5+
AVMEDIA_TYPE_AUDIO,
6+
AVMEDIA_TYPE_DATA, ///< Opaque data information usually continuous
7+
AVMEDIA_TYPE_SUBTITLE,
8+
AVMEDIA_TYPE_ATTACHMENT, ///< Opaque data information usually sparse
9+
AVMEDIA_TYPE_NB
10+
};

src/AvTranscoder/swig/avRational.i

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/**
2-
* Rational number numerator/denominator.
3-
*/
1+
/// ffmpeg/libav Rational number numerator/denominator
42
typedef struct AVRational{
53
int num; ///< numerator
64
int den; ///< denominator

src/AvTranscoder/util.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@ extern "C" {
99
namespace avtranscoder
1010
{
1111

12+
std::string getFormat( const std::string& filename )
13+
{
14+
std::string format( "" );
15+
16+
AVOutputFormat* avOutputFormat = av_guess_format( NULL, filename.c_str(), NULL);
17+
if( avOutputFormat )
18+
{
19+
if( avOutputFormat->name )
20+
format = std::string( avOutputFormat->name );
21+
}
22+
23+
return format;
24+
}
25+
26+
bool matchFormat( const std::string& format, const std::string& filename )
27+
{
28+
AVOutputFormat* avOutputFormat = av_guess_format( format.c_str(), filename.c_str(), NULL);
29+
return avOutputFormat != NULL;
30+
}
31+
1232
std::vector<std::string> getPixelFormats( const std::string& videoCodecName )
1333
{
1434
std::vector<std::string> pixelFormats;

src/AvTranscoder/util.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ namespace avtranscoder
1818

1919
typedef std::map<std::string, OptionArray> OptionArrayMap;
2020

21+
/**
22+
* @brief Get format name from a given filename
23+
*/
24+
std::string AvExport getFormat( const std::string& filename );
25+
26+
/**
27+
* @brief Check if a format name corresponds to the format of a given filename
28+
*/
29+
bool AvExport matchFormat( const std::string& format, const std::string& filename );
30+
2131
/**
2232
* @brief Get pixel format supported by a video codec.
2333
* @param videoCodecName: the video codec name (empty if not indicated, and so get all pixel formats supported by all video codecs).

0 commit comments

Comments
 (0)