Skip to content

Commit d96eb98

Browse files
committed
Merge pull request #104 from cchampet/dev_loadProfilesOnWindows
Load profiles on Windows
2 parents f443503 + 9534590 commit d96eb98

17 files changed

+171
-58
lines changed

src/AvTranscoder/avTranscoder.i

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@
1515
%include "AvTranscoder/swig/avLogLevel.i"
1616

1717
%{
18-
#include <AvTranscoder/ProfileLoader.hpp>
1918
#include <AvTranscoder/Option.hpp>
2019
%}
2120

2221
namespace std {
2322
%template(IntPair) pair< size_t, size_t >;
24-
%template(ProfileMap) map< string, string >;
25-
%template(ProfilesVector) vector< map< string, string > >;
2623
}
2724

2825
%include "AvTranscoder/progress/progress.i"
2926
%include "AvTranscoder/mediaProperty/mediaProperty.i"
3027
%include "AvTranscoder/frame/frame.i"
28+
%include "AvTranscoder/profile/profile.i"
3129

32-
%include <AvTranscoder/ProfileLoader.hpp>
3330
%include <AvTranscoder/Option.hpp>
3431

3532
%include "AvTranscoder/codec/codec.i"

src/AvTranscoder/common.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef _AV_TRANSCODER_COMMON_HPP_
22
#define _AV_TRANSCODER_COMMON_HPP_
33

4+
#include <AvTranscoder/system.hpp>
5+
46
extern "C" {
57
#ifndef __STDC_CONSTANT_MACROS
68
#define __STDC_CONSTANT_MACROS
@@ -21,7 +23,7 @@ extern "C" {
2123
#ifdef SWIG
2224
#define AvExport
2325
#else
24-
#if ( defined( WIN32 ) || defined( WIN64 ) || defined( _WIN32 ) || defined( _WIN64 ) || defined( __WINDOWS__ ) || defined( __TOS_WIN__ ) || defined( __WIN32__ ) )
26+
#if defined( __WINDOWS__ )
2527
#define AvExport __declspec( dllexport )
2628
#elif defined( __GNUC__ ) // Add compiler definition here...
2729
#if __GNUC__ - 0 > 3 || ( __GNUC__ - 0 == 3 && __GNUC_MINOR__ - 0 > 2 )

src/AvTranscoder/decoder/AudioDecoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define _AV_TRANSCODER_ESSENCE_STREAM_AV_INPUT_AUDIO_HPP_
33

44
#include "IDecoder.hpp"
5-
#include <AvTranscoder/ProfileLoader.hpp>
5+
#include <AvTranscoder/profile/ProfileLoader.hpp>
66

77
struct AVFrame;
88

src/AvTranscoder/decoder/VideoDecoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define _AV_TRANSCODER_DECODER_VIDEO_DECODER_HPP_
33

44
#include "IDecoder.hpp"
5-
#include <AvTranscoder/ProfileLoader.hpp>
5+
#include <AvTranscoder/profile/ProfileLoader.hpp>
66

77
struct AVFrame;
88

src/AvTranscoder/encoder/AudioEncoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "IEncoder.hpp"
55
#include <AvTranscoder/codec/AudioCodec.hpp>
6-
#include <AvTranscoder/ProfileLoader.hpp>
6+
#include <AvTranscoder/profile/ProfileLoader.hpp>
77

88
namespace avtranscoder
99
{

src/AvTranscoder/encoder/VideoEncoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "IEncoder.hpp"
55
#include <AvTranscoder/codec/VideoCodec.hpp>
6-
#include <AvTranscoder/ProfileLoader.hpp>
6+
#include <AvTranscoder/profile/ProfileLoader.hpp>
77

88
namespace avtranscoder
99
{

src/AvTranscoder/file/IOutputFile.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <AvTranscoder/codec/DataCodec.hpp>
99

1010
#include <AvTranscoder/stream/OutputStream.hpp>
11-
#include <AvTranscoder/ProfileLoader.hpp>
1211

1312
#include <string>
1413
#include <stdexcept>

src/AvTranscoder/file/InputFile.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <AvTranscoder/stream/InputStream.hpp>
88
#include <AvTranscoder/mediaProperty/FileProperties.hpp>
99
#include <AvTranscoder/progress/IProgress.hpp>
10-
#include <AvTranscoder/ProfileLoader.hpp>
10+
#include <AvTranscoder/profile/ProfileLoader.hpp>
1111

1212
#include <string>
1313
#include <vector>

src/AvTranscoder/frame/AudioFrame.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define _AV_TRANSCODER_FRAME_AUDIO_FRAME_HPP_
33

44
#include "Frame.hpp"
5-
#include <AvTranscoder/ProfileLoader.hpp>
5+
#include <AvTranscoder/profile/ProfileLoader.hpp>
66

77
extern "C" {
88
#include <libavutil/samplefmt.h>

src/AvTranscoder/frame/VideoFrame.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define _AV_TRANSCODER_FRAME_VIDEO_FRAME_HPP_
33

44
#include "Frame.hpp"
5-
#include <AvTranscoder/ProfileLoader.hpp>
5+
#include <AvTranscoder/profile/ProfileLoader.hpp>
66

77
extern "C" {
88
#include <libavutil/pixfmt.h>

src/AvTranscoder/ProfileLoader.cpp renamed to src/AvTranscoder/profile/ProfileLoader.cpp

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#include "ProfileLoader.hpp"
22

3-
#include "common.hpp"
3+
#include "util.hpp"
44

55
#include <iostream>
66
#include <fstream>
77
#include <cstdlib>
88
#include <stdexcept>
9-
#include <dirent.h>
109

1110
namespace avtranscoder
1211
{
@@ -21,7 +20,7 @@ void ProfileLoader::loadProfile( const std::string& avProfileFileName )
2120
{
2221
std::ifstream infile;
2322
infile.open( avProfileFileName.c_str(), std::ifstream::in );
24-
23+
2524
ProfileLoader::Profile customProfile;
2625

2726
std::string line;
@@ -36,7 +35,7 @@ void ProfileLoader::loadProfile( const std::string& avProfileFileName )
3635
}
3736

3837
void ProfileLoader::loadProfiles( const std::string& avProfilesPath )
39-
{
38+
{
4039
std::string realAvProfilesPath = avProfilesPath;
4140
if( realAvProfilesPath.empty() )
4241
{
@@ -47,7 +46,7 @@ void ProfileLoader::loadProfiles( const std::string& avProfilesPath )
4746
else
4847
realAvProfilesPath = AVTRANSCODER_DEFAULT_AVPROFILES;
4948
}
50-
49+
5150
std::vector< std::string > paths;
5251
split( paths, realAvProfilesPath, ":" );
5352
for( std::vector< std::string >::iterator dirIt = paths.begin(); dirIt != paths.end(); ++dirIt )
@@ -203,35 +202,4 @@ bool ProfileLoader::checkAudioProfile( const Profile& profileToCheck )
203202
return isValid;
204203
}
205204

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

src/AvTranscoder/ProfileLoader.hpp renamed to src/AvTranscoder/profile/ProfileLoader.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#ifndef _AV_TRANSCODER_PROFILE_HPP_
22
#define _AV_TRANSCODER_PROFILE_HPP_
33

4-
#include "common.hpp"
4+
#include <AvTranscoder/common.hpp>
55

66
#include <string>
7-
#include <cstring>
87
#include <vector>
98
#include <map>
109

@@ -74,10 +73,5 @@ class AvExport ProfileLoader
7473
Profiles _profiles;
7574
};
7675

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

src/AvTranscoder/profile/profile.i

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
%{
2+
#include <AvTranscoder/profile/ProfileLoader.hpp>
3+
%}
4+
5+
namespace std {
6+
%template(IntPair) pair< size_t, size_t >;
7+
%template(ProfileMap) map< string, string >;
8+
%template(ProfilesVector) vector< map< string, string > >;
9+
}
10+
11+
%include <AvTranscoder/profile/ProfileLoader.hpp>

src/AvTranscoder/profile/util.hpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#ifndef _AV_TRANSCODER_PROFILE_UTIL_HPP_
2+
#define _AV_TRANSCODER_PROFILE_UTIL_HPP_
3+
4+
#if defined ( __LINUX__ )
5+
6+
#define DIRLIST_SEP_CHARS ":;"
7+
#define DIRSEP "/"
8+
#include <dirent.h>
9+
10+
#elif defined ( __MACOS__ )
11+
12+
#define DIRLIST_SEP_CHARS ";:"
13+
#define DIRSEP "/"
14+
#include <dirent.h>
15+
16+
#elif defined ( __WINDOWS__ )
17+
18+
#define DIRLIST_SEP_CHARS ";"
19+
#define DIRSEP "\\"
20+
21+
// CINTERFACE needs to be declared if compiling with VC++
22+
#include <shlobj.h>
23+
#include <tchar.h>
24+
#ifndef _MSC_VER
25+
#define SHGFP_TYPE_CURRENT 0
26+
#endif
27+
28+
#endif
29+
30+
#include <string>
31+
#include <iostream>
32+
33+
namespace avtranscoder
34+
{
35+
36+
void split( std::vector< std::string >& splitString, const std::string& inputString, const std::string& splitChars )
37+
{
38+
char* part = strtok( const_cast<char*>( inputString.c_str() ), splitChars.c_str() );
39+
while( part != NULL )
40+
{
41+
splitString.push_back( std::string( part ) );
42+
part = strtok( NULL, splitChars.c_str() );
43+
}
44+
}
45+
46+
int getFilesInDir( const std::string& dir, std::vector< std::string >& files )
47+
{
48+
#if defined ( __WINDOWS__ )
49+
WIN32_FIND_DATA findData;
50+
HANDLE findHandle;
51+
52+
findHandle = FindFirstFile( ( dir + "\\*" ).c_str(), &findData );
53+
if( findHandle == INVALID_HANDLE_VALUE )
54+
{
55+
return -1;
56+
}
57+
while(1)
58+
{
59+
const std::string filename( findData.cFileName );
60+
bool isdir = ( findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) != 0;
61+
if( ! isdir )
62+
files.push_back( filename );
63+
64+
int rval = FindNextFile( findHandle, &findData );
65+
if( rval == 0 )
66+
break;
67+
}
68+
69+
#else
70+
DIR *dp;
71+
struct dirent *dirp;
72+
if( ( dp = opendir( dir.c_str() ) ) == NULL )
73+
{
74+
std::cerr << "Error(" << errno << ") opening " << dir << std::endl;
75+
return errno;
76+
}
77+
78+
while( ( dirp = readdir( dp ) ) != NULL )
79+
{
80+
const std::string filename( dirp->d_name );
81+
if( filename == "." || filename == ".." )
82+
continue;
83+
files.push_back( filename );
84+
}
85+
closedir( dp );
86+
#endif
87+
88+
return 0;
89+
}
90+
91+
}
92+
93+
#endif

src/AvTranscoder/system.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef _AV_TRANSCODER_SYSTEM_HPP_
2+
#define _AV_TRANSCODER_SYSTEM_HPP_
3+
4+
#if defined( linux ) \
5+
|| defined( __linux ) \
6+
|| defined( LINUX ) \
7+
|| defined( _LINUX ) \
8+
|| defined( __LINUX__ ) \
9+
10+
#ifndef __LINUX__
11+
#define __LINUX__
12+
#endif
13+
14+
15+
#elif defined( macintosh ) \
16+
|| defined( Macintosh ) \
17+
|| defined( __APPLE__ ) \
18+
|| defined( __MACH__ ) \
19+
|| defined( MACOS ) \
20+
|| defined( MACOSX ) \
21+
|| defined( __MACOS__ ) \
22+
23+
#ifndef __MACOS__
24+
#define __MACOS__
25+
#endif
26+
27+
28+
#elif defined( WIN32 ) \
29+
|| defined( _WIN32 ) \
30+
|| defined( __WIN32__ ) \
31+
|| defined( WIN64 ) \
32+
|| defined( _WIN64 ) \
33+
|| defined( __WIN64__ ) \
34+
|| defined( __TOS_WIN__ ) \
35+
|| defined( WINDOWS ) \
36+
|| defined( _WINDOWS ) \
37+
|| defined( __WINDOWS__ ) \
38+
39+
#ifndef __WINDOWS__
40+
#define __WINDOWS__
41+
#endif
42+
43+
#else
44+
45+
#warning "Your operating system is not recognized."
46+
47+
#endif
48+
49+
#endif

src/AvTranscoder/transcoder/StreamTranscoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <AvTranscoder/file/IOutputFile.hpp>
1313

14-
#include <AvTranscoder/ProfileLoader.hpp>
14+
#include <AvTranscoder/profile/ProfileLoader.hpp>
1515

1616
namespace avtranscoder
1717
{

src/AvTranscoder/transcoder/Transcoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <AvTranscoder/file/InputFile.hpp>
66
#include <AvTranscoder/file/IOutputFile.hpp>
77
#include <AvTranscoder/stream/IInputStream.hpp>
8-
#include <AvTranscoder/ProfileLoader.hpp>
8+
#include <AvTranscoder/profile/ProfileLoader.hpp>
99

1010
#include "StreamTranscoder.hpp"
1111

0 commit comments

Comments
 (0)