Skip to content

Commit 13554eb

Browse files
committed
Merge pull request #146 from mikrosimage/develop
Pull develop branch of MIK fork
2 parents e653228 + c391609 commit 13554eb

29 files changed

+206
-103
lines changed

CMakeLists.txt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@ cmake_minimum_required(VERSION 2.8.11)
22

33
project(AvTranscoder)
44

5-
# Set AvTranscoder versions
6-
set(AVTRANSCODER_VERSION_MAJOR "0")
7-
set(AVTRANSCODER_VERSION_MINOR "5")
8-
set(AVTRANSCODER_VERSION_MICRO "10")
9-
set(AVTRANSCODER_VERSION ${AVTRANSCODER_VERSION_MAJOR}.${AVTRANSCODER_VERSION_MINOR}.${AVTRANSCODER_VERSION_MICRO})
10-
11-
# Define AvTranscoder versions
12-
add_definitions(-DAVTRANSCODER_VERSION_MAJOR=${AVTRANSCODER_VERSION_MAJOR})
13-
add_definitions(-DAVTRANSCODER_VERSION_MINOR=${AVTRANSCODER_VERSION_MINOR})
14-
add_definitions(-DAVTRANSCODER_VERSION_MICRO=${AVTRANSCODER_VERSION_MICRO})
15-
165
# Define AvTranscoder default path to profiles
176
add_definitions(-DAVTRANSCODER_DEFAULT_AVPROFILES="${CMAKE_INSTALL_PREFIX}/share/avprofiles")
187

@@ -37,8 +26,10 @@ if(AVTRANSCODER_COVERAGE)
3726
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
3827
endif()
3928

29+
# Build library
4030
add_subdirectory(src)
4131

32+
# Build apps
4233
if(AVTRANSCODER_DISABLE_APPS)
4334
message("Apps disabled, will not build applications.")
4435
else()

cmake/AvTranscoderMacros.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,24 @@
22
set(AVTRANSCODER_APP_PATH "${PROJECT_SOURCE_DIR}/app")
33
set(AVTRANSCODER_SRC_PATH "${PROJECT_SOURCE_DIR}/src")
44
file(GLOB_RECURSE AVTRANSCODER_SRC_FILES "AvTranscoder/*.cpp" "AvTranscoder/*.hpp")
5+
6+
# Get AvTranscoder versions
7+
# AVTRANSCODER_VERSION_MAJOR
8+
# AVTRANSCODER_VERSION_MINOR
9+
# AVTRANSCODER_VERSION_MICRO
10+
# AVTRANSCODER_VERSION
11+
file(STRINGS "${AVTRANSCODER_SRC_PATH}/AvTranscoder/common.hpp" _avtranscoder_VERSION_HPP_CONTENTS REGEX "#define AVTRANSCODER_VERSION_")
12+
foreach(v MAJOR MINOR MICRO)
13+
if("${_avtranscoder_VERSION_HPP_CONTENTS}" MATCHES "#define AVTRANSCODER_VERSION_${v} ([0-9]+)")
14+
set(AVTRANSCODER_VERSION_${v} "${CMAKE_MATCH_1}")
15+
else()
16+
set(AVTRANSCODER_RETRIEVE_VERSION_FAILED 1)
17+
endif()
18+
endforeach()
19+
unset(_avtranscoder_VERSION_HPP_CONTENTS)
20+
21+
set(AVTRANSCODER_VERSION "${AVTRANSCODER_VERSION_MAJOR}.${AVTRANSCODER_VERSION_MINOR}.${AVTRANSCODER_VERSION_MICRO}")
22+
23+
if(AVTRANSCODER_RETRIEVE_VERSION_FAILED)
24+
message(SEND_ERROR "Failed to retrieve AvTranscoder version: ${AVTRANSCODER_VERSION}")
25+
endif()

src/AvTranscoder/common.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifndef _AV_TRANSCODER_COMMON_HPP_
22
#define _AV_TRANSCODER_COMMON_HPP_
33

4+
#define AVTRANSCODER_VERSION_MAJOR 0
5+
#define AVTRANSCODER_VERSION_MINOR 5
6+
#define AVTRANSCODER_VERSION_MICRO 12
7+
48
#include <AvTranscoder/system.hpp>
59

610
extern "C" {

src/AvTranscoder/decoder/AudioDecoder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ void AudioDecoder::setupDecoder( const ProfileLoader::Profile& profile )
6262
throw std::runtime_error( msg );
6363
}
6464

65-
LOG_INFO( "Setup audio decoder with:\n" << profile )
65+
if( ! profile.empty() )
66+
{
67+
LOG_INFO( "Setup audio decoder with:\n" << profile )
68+
}
6669

6770
AudioCodec& codec = _inputStream->getAudioCodec();
6871

src/AvTranscoder/decoder/VideoDecoder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ void VideoDecoder::setupDecoder( const ProfileLoader::Profile& profile )
6060
throw std::runtime_error( msg );
6161
}
6262

63-
LOG_INFO( "Setup video decoder with:\n" << profile )
63+
if( ! profile.empty() )
64+
{
65+
LOG_INFO( "Setup video decoder with:\n" << profile )
66+
}
6467

6568
VideoCodec& codec = _inputStream->getVideoCodec();
6669

src/AvTranscoder/encoder/AudioEncoder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ AudioEncoder::~AudioEncoder()
3737

3838
void AudioEncoder::setupAudioEncoder( const AudioFrameDesc& frameDesc, const ProfileLoader::Profile& profile )
3939
{
40-
LOG_INFO( "Setup audio encoder with:\n" << profile )
40+
if( ! profile.empty() )
41+
{
42+
LOG_INFO( "Setup audio encoder with:\n" << profile )
43+
}
4144

4245
// set sampleRate, number of channels, sample format
4346
_codec.setAudioParameters( frameDesc );

src/AvTranscoder/encoder/VideoEncoder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ VideoEncoder::~VideoEncoder()
3838

3939
void VideoEncoder::setupVideoEncoder( const VideoFrameDesc& frameDesc, const ProfileLoader::Profile& profile )
4040
{
41-
LOG_INFO( "Setup video encoder with:\n" << profile )
41+
if( ! profile.empty() )
42+
{
43+
LOG_INFO( "Setup video encoder with:\n" << profile )
44+
}
4245

4346
// set width, height, pixel format, fps
4447
_codec.setImageParameters( frameDesc );

src/AvTranscoder/file/FormatContext.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,9 @@ AVStream& FormatContext::addAVStream( const AVCodec& avCodec )
142142
return *stream;
143143
}
144144

145-
bool FormatContext::seek( uint64_t position, const int flag )
145+
bool FormatContext::seek( const uint64_t position, const int flag )
146146
{
147-
if( (int)getStartTime() != AV_NOPTS_VALUE )
148-
position += getStartTime();
149-
147+
LOG_INFO( "Seek in '" << _avFormatContext->filename << "' at " << position << " (in AV_TIME_BASE units)" )
150148
int err = av_seek_frame( _avFormatContext, -1, position, flag );
151149
if( err < 0 )
152150
{

src/AvTranscoder/file/FormatContext.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ class AvExport FormatContext
7777
* @brief Seek at a specific position
7878
* @param position: can be in AV_TIME_BASE units, in frames... depending on the flag value
7979
* @param flag: seeking mode (AVSEEK_FLAG_xxx)
80-
* @note before seek, add offset of start time
8180
* @return seek status
81+
* @see flushDecoder
8282
*/
83-
bool seek( uint64_t position, const int flag );
83+
bool seek( const uint64_t position, const int flag );
8484

8585
size_t getNbStreams() const { return _avFormatContext->nb_streams; }
8686
/// Get duration of the program, in seconds

src/AvTranscoder/file/IOutputFile.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class AvExport IOutputFile
2626

2727
/**
2828
* @brief Add a video output stream
29-
* @note call setup() before adding any stream
3029
* @param videoCodec description of output stream
3130
**/
3231
virtual IOutputStream& addVideoStream( const VideoCodec& videoCodec )
@@ -36,7 +35,6 @@ class AvExport IOutputFile
3635

3736
/**
3837
* @brief Add an audio output stream
39-
* @note call setup() before adding any stream
4038
* @param audioCodec description of output stream
4139
**/
4240
virtual IOutputStream& addAudioStream( const AudioCodec& audioCodec )
@@ -46,7 +44,6 @@ class AvExport IOutputFile
4644

4745
/**
4846
* @brief Add a data output stream
49-
* @note call setup() before adding any stream
5047
* @param dataCodec description of output stream
5148
**/
5249
virtual IOutputStream& addDataStream( const DataCodec& dataCodec )
@@ -62,7 +59,9 @@ class AvExport IOutputFile
6259
/**
6360
* @brief Wrap a packet of data in the output ressource
6461
* @param data coded packet information for the current stream
65-
* @param streamId refers to the stream in output ressource
62+
* @param streamIndex refers to the stream in output ressource
63+
* @return the wrapping status after wrapping
64+
* @see EWrappingStatus
6665
**/
6766
virtual IOutputStream::EWrappingStatus wrap( const CodedData& data, const size_t streamIndex ) = 0;
6867

@@ -73,7 +72,7 @@ class AvExport IOutputFile
7372

7473
/**
7574
* @brief Get the output stream
76-
* @param streamId select the output stream
75+
* @param streamIndex select the output stream
7776
* @return the output stream reference
7877
**/
7978
virtual IOutputStream& getStream( const size_t streamIndex ) = 0;

src/AvTranscoder/file/InputFile.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ void InputFile::setupUnwrapping( const ProfileLoader::Profile& profile )
173173
throw std::runtime_error( msg );
174174
}
175175

176-
// set profile
177-
LOG_INFO( "Setup unwrapping with:\n" << profile )
176+
if( ! profile.empty() )
177+
{
178+
LOG_INFO( "Setup unwrapping with:\n" << profile )
179+
}
178180

179181
for( ProfileLoader::Profile::const_iterator it = profile.begin(); it != profile.end(); ++it )
180182
{

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ IOutputStream& OutputFile::addAudioStream( const AudioCodec& audioDesc )
7373

7474
stream.codec->sample_rate = audioDesc.getAVCodecContext().sample_rate;
7575
stream.codec->channels = audioDesc.getAVCodecContext().channels;
76+
stream.codec->channel_layout = audioDesc.getAVCodecContext().channel_layout;
7677
stream.codec->sample_fmt = audioDesc.getAVCodecContext().sample_fmt;
78+
stream.codec->frame_size = audioDesc.getAVCodecContext().frame_size;
7779

7880
// need to set the time_base on the AVCodecContext of the AVStream
7981
av_reduce(
@@ -99,11 +101,11 @@ IOutputStream& OutputFile::addDataStream( const DataCodec& dataDesc )
99101
return *outputStream;
100102
}
101103

102-
IOutputStream& OutputFile::getStream( const size_t streamId )
104+
IOutputStream& OutputFile::getStream( const size_t streamIndex )
103105
{
104-
if( streamId >= _outputStreams.size() )
106+
if( streamIndex >= _outputStreams.size() )
105107
throw std::runtime_error( "unable to get output stream (out of range)" );
106-
return *_outputStreams.at( streamId );
108+
return *_outputStreams.at( streamIndex );
107109
}
108110

109111
std::string OutputFile::getFilename() const
@@ -157,16 +159,16 @@ bool OutputFile::beginWrap( )
157159
return true;
158160
}
159161

160-
IOutputStream::EWrappingStatus OutputFile::wrap( const CodedData& data, const size_t streamId )
162+
IOutputStream::EWrappingStatus OutputFile::wrap( const CodedData& data, const size_t streamIndex )
161163
{
162164
if( ! data.getSize() )
163165
return IOutputStream::eWrappingSuccess;
164166

165-
LOG_DEBUG( "Wrap on stream " << streamId << " (" << data.getSize() << " bytes for frame " << _frameCount.at( streamId ) << ")" )
167+
LOG_DEBUG( "Wrap on stream " << streamIndex << " (" << data.getSize() << " bytes for frame " << _frameCount.at( streamIndex ) << ")" )
166168

167169
AVPacket packet;
168170
av_init_packet( &packet );
169-
packet.stream_index = streamId;
171+
packet.stream_index = streamIndex;
170172
packet.data = (uint8_t*)data.getData();
171173
packet.size = data.getSize();
172174

@@ -175,15 +177,15 @@ IOutputStream::EWrappingStatus OutputFile::wrap( const CodedData& data, const si
175177
// free packet.side_data, set packet.data to NULL and packet.size to 0
176178
av_free_packet( &packet );
177179

178-
const double currentStreamDuration = _outputStreams.at( streamId )->getStreamDuration();
180+
const double currentStreamDuration = _outputStreams.at( streamIndex )->getStreamDuration();
179181
if( currentStreamDuration < _previousProcessedStreamDuration )
180182
{
181183
// if the current stream is strictly shorter than the previous, wait for more data
182184
return IOutputStream::eWrappingWaitingForData;
183185
}
184186

185187
_previousProcessedStreamDuration = currentStreamDuration;
186-
_frameCount.at( streamId )++;
188+
_frameCount.at( streamIndex )++;
187189

188190
return IOutputStream::eWrappingSuccess;
189191
}
@@ -221,7 +223,10 @@ void OutputFile::setupWrapping( const ProfileLoader::Profile& profile )
221223
throw std::runtime_error( msg );
222224
}
223225

224-
LOG_INFO( "Setup wrapping with:\n" << profile )
226+
if( ! profile.empty() )
227+
{
228+
LOG_INFO( "Setup wrapping with:\n" << profile )
229+
}
225230

226231
// check if output format indicated is valid with the filename extension
227232
if( ! matchFormat( profile.find( constants::avProfileFormat )->second, getFilename() ) )

src/AvTranscoder/file/OutputFile.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class AvExport OutputFile : public IOutputFile
3737
* @brief Open ressource, write header, and setup specific wrapping options given when call setupWrapping.
3838
* @note Need to add the streams to mux before calling this method.
3939
* @note After this call, a new list of AVOption, relative to the format choosen, will be available for the OutputFile.
40-
*/
40+
*/
4141
bool beginWrap();
4242

43-
IOutputStream::EWrappingStatus wrap( const CodedData& data, const size_t streamId );
43+
IOutputStream::EWrappingStatus wrap( const CodedData& data, const size_t streamIndex );
4444

4545
/**
4646
* @brief Close ressource and write trailer.
@@ -54,7 +54,7 @@ class AvExport OutputFile : public IOutputFile
5454
void addMetadata( const PropertyVector& data );
5555
void addMetadata( const std::string& key, const std::string& value );
5656

57-
IOutputStream& getStream( const size_t streamId );
57+
IOutputStream& getStream( const size_t streamIndex );
5858

5959
std::string getFilename() const;
6060

src/AvTranscoder/log.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace avtranscoder
44
{
55

6+
std::string Logger::logHeaderMessage = "";
7+
68
void callbackToWriteInFile( void *ptr, int level, const char *fmt, va_list vl )
79
{
810
std::ofstream outputFile;
@@ -23,13 +25,10 @@ void callbackToWriteInFile( void *ptr, int level, const char *fmt, va_list vl )
2325

2426
void Logger::setLogLevel( const int level )
2527
{
28+
// set ffmpeg log level
2629
av_log_set_level( level );
27-
}
28-
29-
void Logger::log( const int level, const std::string& msg )
30-
{
31-
std::string avTranscoderMsg( "[avTranscoder - " );
3230

31+
// set avtranscoder header message
3332
std::string levelStr;
3433
switch( level )
3534
{
@@ -48,12 +47,15 @@ void Logger::log( const int level, const std::string& msg )
4847
default:
4948
break;
5049
}
50+
Logger::logHeaderMessage = "[avTranscoder - " + levelStr + "] ";
51+
}
5152

52-
avTranscoderMsg += levelStr;
53-
avTranscoderMsg += "] ";
54-
avTranscoderMsg += msg;
55-
avTranscoderMsg += "\n";
56-
av_log( NULL, level, avTranscoderMsg.c_str() );
53+
void Logger::log( const int level, const std::string& msg )
54+
{
55+
std::string logMessage = Logger::logHeaderMessage;
56+
logMessage += msg;
57+
logMessage += "\n";
58+
av_log( NULL, level, logMessage.c_str() );
5759
}
5860

5961
void Logger::logInFile()

src/AvTranscoder/log.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class AvExport Logger
4444
* @note log filename is avtranscoder.log
4545
*/
4646
static void logInFile();
47+
48+
private:
49+
static std::string logHeaderMessage; ///< First caracters present for each logging message
4750
};
4851

4952
}

src/AvTranscoder/mediaProperty/StreamProperties.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ float StreamProperties::getDuration() const
4343
return ( timeBase.num / (float) timeBase.den ) * _formatContext->streams[_streamIndex]->duration;
4444
}
4545

46+
AVMediaType StreamProperties::getStreamType() const
47+
{
48+
if( ! _formatContext )
49+
throw std::runtime_error( "unknown format context" );
50+
return _formatContext->streams[_streamIndex]->codec->codec_type;
51+
}
52+
4653
PropertyVector StreamProperties::getPropertiesAsVector() const
4754
{
4855
PropertyVector data;

src/AvTranscoder/mediaProperty/StreamProperties.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ class AvExport StreamProperties
1919
size_t getStreamId() const;
2020
Rational getTimeBase() const;
2121
float getDuration() const; ///< in seconds
22+
AVMediaType getStreamType() const;
2223
const PropertyVector& getMetadatas() const { return _metadatas; }
2324

2425
#ifndef SWIG
25-
const AVFormatContext& getAVFormatContext() { return *_formatContext; }
26+
const AVFormatContext& getAVFormatContext() const { return *_formatContext; }
2627
#endif
2728

2829
PropertyMap getPropertiesAsMap() const; ///< Return all properties as a map (name of property, value)

0 commit comments

Comments
 (0)