Skip to content

Commit eaf480e

Browse files
author
Clement Champetier
committed
Manage duration as a float
Double type is not constructed the same way in C++ and Java, and does not exist in python. Our bindings of 'C++ double' could create issues, and since a fps with a simple precision is enough, we decided to return fps as float.
1 parent c619856 commit eaf480e

17 files changed

+33
-36
lines changed

src/AvTranscoder/mediaProperty/FileProperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ double FileProperties::getStartTime() const
157157
return 1.0 * (unsigned int)_avFormatContext->start_time / AV_TIME_BASE;
158158
}
159159

160-
double FileProperties::getDuration() const
160+
float FileProperties::getDuration() const
161161
{
162162
if( ! _avFormatContext )
163163
throw std::runtime_error( "unknown format context" );

src/AvTranscoder/mediaProperty/FileProperties.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class AvExport FileProperties
4444

4545
size_t getProgramsCount() const;
4646
double getStartTime() const;
47-
double getDuration() const; ///< in seconds
47+
float getDuration() const; ///< in seconds
4848
size_t getBitRate() const; ///< total stream bitrate in bit/s, 0 if not available (result of a computation by ffmpeg)
4949
size_t getPacketSize() const;
5050

src/AvTranscoder/mediaProperty/StreamProperties.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ Rational StreamProperties::getTimeBase() const
3737
return timeBase;
3838
}
3939

40-
double StreamProperties::getDuration() const
40+
float StreamProperties::getDuration() const
4141
{
4242
Rational timeBase = getTimeBase();
43-
double duration = ( timeBase.num / (double) timeBase.den ) * _formatContext->streams[_streamIndex]->duration;
44-
return duration;
43+
return ( timeBase.num / (float) timeBase.den ) * _formatContext->streams[_streamIndex]->duration;
4544
}
4645

4746
PropertyVector StreamProperties::getPropertiesAsVector() const

src/AvTranscoder/mediaProperty/StreamProperties.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AvExport StreamProperties
1818
size_t getStreamIndex() const { return _streamIndex; }
1919
size_t getStreamId() const;
2020
Rational getTimeBase() const;
21-
double getDuration() const; ///< in seconds
21+
float getDuration() const; ///< in seconds
2222
const PropertyVector& getMetadatas() const { return _metadatas; }
2323

2424
#ifndef SWIG

src/AvTranscoder/mediaProperty/VideoProperties.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ float VideoProperties::getFps() const
523523
const size_t nbFrames = getNbFrames();
524524
if( nbFrames )
525525
{
526-
double duration = getDuration();
527-
double epsilon = std::numeric_limits<double>::epsilon();
526+
const float duration = getDuration();
527+
const float epsilon = std::numeric_limits<float>::epsilon();
528528
if( duration > epsilon )
529529
return nbFrames / duration;
530530
}

src/AvTranscoder/stat/AudioStat.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ namespace avtranscoder
1212
class AvExport AudioStat
1313
{
1414
public:
15-
AudioStat( const double duration, const size_t nbPackets )
15+
AudioStat( const float duration, const size_t nbPackets )
1616
: _duration( duration )
1717
, _nbPackets( nbPackets )
1818
{}
1919

2020
public:
21-
double _duration;
21+
float _duration;
2222
size_t _nbPackets;
2323
};
2424

src/AvTranscoder/stat/VideoStat.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace avtranscoder
1212
class AvExport VideoStat
1313
{
1414
public:
15-
VideoStat( const double duration, const size_t nbFrames )
15+
VideoStat( const float duration, const size_t nbFrames )
1616
: _duration( duration )
1717
, _nbFrames( nbFrames )
1818
, _quality( 0 )
@@ -23,7 +23,7 @@ class AvExport VideoStat
2323
static double psnr( const double d );
2424

2525
public:
26-
double _duration;
26+
float _duration;
2727
size_t _nbFrames;
2828
size_t _quality; ///< Between 1 (good) and FF_LAMBDA_MAX (bad). 0 if unknown.
2929
double _psnr; ///< 0 if unknown.

src/AvTranscoder/stream/IInputStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AvExport IInputStream
2222
virtual bool readNextPacket( CodedData& data ) = 0;
2323

2424
virtual size_t getStreamIndex() const = 0;
25-
virtual double getDuration() const = 0;
25+
virtual float getDuration() const = 0;
2626
virtual AVMediaType getStreamType() const = 0;
2727

2828
//@{

src/AvTranscoder/stream/IOutputStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AvExport IOutputStream
2525
virtual ~IOutputStream() {};
2626

2727
virtual size_t getStreamIndex() const = 0;
28-
virtual double getStreamDuration() const = 0;
28+
virtual float getStreamDuration() const = 0;
2929
virtual size_t getNbFrames() const = 0;
3030

3131
virtual EWrappingStatus wrap( const CodedData& data ) = 0;

src/AvTranscoder/stream/InputStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ AVMediaType InputStream::getStreamType() const
111111
return _inputFile->getFormatContext().getAVStream( _streamIndex ).codec->codec_type;
112112
}
113113

114-
double InputStream::getDuration() const
114+
float InputStream::getDuration() const
115115
{
116116
return _inputFile->getProperties().getStreamPropertiesWithIndex( _streamIndex ).getDuration();
117117
}

src/AvTranscoder/stream/InputStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AvExport InputStream : public IInputStream
2626

2727
size_t getStreamIndex() const { return _streamIndex; }
2828
/// Get duration of the stream, in seconds
29-
double getDuration() const;
29+
float getDuration() const;
3030
AVMediaType getStreamType() const;
3131

3232
VideoCodec& getVideoCodec();

src/AvTranscoder/stream/OutputStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ OutputStream::OutputStream( OutputFile& outputFile, const size_t streamIndex )
1414
{
1515
}
1616

17-
double OutputStream::getStreamDuration() const
17+
float OutputStream::getStreamDuration() const
1818
{
1919
AVStream& outputStream = _outputFile->getFormatContext().getAVStream( _streamIndex );
2020
#if AVTRANSCODER_FFMPEG_DEPENDENCY && LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(55, 40, 100)

src/AvTranscoder/stream/OutputStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AvExport OutputStream : public IOutputStream
1414
OutputStream( OutputFile& outputFile, const size_t streamIndex );
1515

1616
size_t getStreamIndex() const { return _streamIndex; }
17-
double getStreamDuration() const;
17+
float getStreamDuration() const;
1818
size_t getNbFrames() const; ///< If audio stream, returns number of packets
1919

2020
IOutputStream::EWrappingStatus wrap( const CodedData& data );

src/AvTranscoder/transcoder/StreamTranscoder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,11 @@ void StreamTranscoder::switchToInputDecoder()
482482
assert( _currentDecoder != NULL );
483483
}
484484

485-
double StreamTranscoder::getDuration() const
485+
float StreamTranscoder::getDuration() const
486486
{
487487
if( _inputStream )
488488
{
489-
double totalDuration = _inputStream->getDuration() + _offset;
489+
const float totalDuration = _inputStream->getDuration() + _offset;
490490
if( totalDuration < 0 )
491491
{
492492
LOG_WARN( "Offset of " << _offset << "s applied to a stream with a duration of " << _inputStream->getDuration() << "s. Set its duration to 0s." )
@@ -495,7 +495,7 @@ double StreamTranscoder::getDuration() const
495495
return totalDuration;
496496
}
497497
else
498-
return std::numeric_limits<double>::max();
498+
return std::numeric_limits<float>::max();
499499
}
500500

501501
StreamTranscoder::EProcessCase StreamTranscoder::getProcessCase() const

src/AvTranscoder/transcoder/StreamTranscoder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class AvExport StreamTranscoder
6868
* @note if it's a generated stream, return limit of double.
6969
* @note if offset > duration of the stream, return 0
7070
*/
71-
double getDuration() const;
71+
float getDuration() const;
7272

7373
/// Returns a reference to the current decoder (from input file or from generator)
7474
IDecoder& getCurrentDecoder() const { return *_currentDecoder; }

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -435,34 +435,32 @@ ProfileLoader::Profile Transcoder::getProfileFromFile( InputFile& inputFile, con
435435
return profile;
436436
}
437437

438-
double Transcoder::getStreamDuration( size_t indexStream ) const
438+
float Transcoder::getStreamDuration( size_t indexStream ) const
439439
{
440440
return _streamTranscoders.at( indexStream )->getDuration();
441441
}
442442

443-
double Transcoder::getMinTotalDuration() const
443+
float Transcoder::getMinTotalDuration() const
444444
{
445-
double minTotalDuration = std::numeric_limits<double>::max();
446-
445+
float minTotalDuration = std::numeric_limits<float>::max();
447446
for( size_t i = 0; i < _streamTranscoders.size(); ++i )
448447
{
449448
minTotalDuration = std::min( getStreamDuration( i ), minTotalDuration );
450449
}
451450
return minTotalDuration;
452451
}
453452

454-
double Transcoder::getMaxTotalDuration() const
453+
float Transcoder::getMaxTotalDuration() const
455454
{
456-
double maxTotalDuration = 0;
457-
455+
float maxTotalDuration = 0;
458456
for( size_t i = 0; i < _streamTranscoders.size(); ++i )
459457
{
460458
maxTotalDuration = std::max( getStreamDuration( i ), maxTotalDuration );
461459
}
462460
return maxTotalDuration;
463461
}
464462

465-
double Transcoder::getOutputDuration() const
463+
float Transcoder::getOutputDuration() const
466464
{
467465
switch( _eProcessMethod )
468466
{
@@ -475,7 +473,7 @@ double Transcoder::getOutputDuration() const
475473
case eProcessMethodBasedOnDuration :
476474
return _outputDuration;
477475
case eProcessMethodInfinity :
478-
return std::numeric_limits<double>::max();
476+
return std::numeric_limits<float>::max();
479477
default:
480478
return getMaxTotalDuration();
481479
}

src/AvTranscoder/transcoder/Transcoder.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,23 @@ class AvExport Transcoder
167167
* @brief Get the duration of the stream, in seconds
168168
* @note If the stream is a generator, return limit of double.
169169
*/
170-
double getStreamDuration( size_t indexStream ) const;
170+
float getStreamDuration( size_t indexStream ) const;
171171

172172
/**
173173
* @brief Get the duration of the shortest stream, in seconds
174174
*/
175-
double getMinTotalDuration() const;
175+
float getMinTotalDuration() const;
176176

177177
/**
178178
* @brief Get the duration of the longest stream, in seconds
179179
*/
180-
double getMaxTotalDuration() const;
180+
float getMaxTotalDuration() const;
181181

182182
/**
183183
* @brief Get the duration of the output program
184184
* @note Depends on the streams, the process method, and the main stream index.
185185
*/
186-
double getOutputDuration() const;
186+
float getOutputDuration() const;
187187

188188
/**
189189
* @brief Set for each StreamTranscoder if it can switch to generator at the end.
@@ -206,7 +206,7 @@ class AvExport Transcoder
206206

207207
EProcessMethod _eProcessMethod; ///< Transcoding policy
208208
size_t _mainStreamIndex; ///< Index of stream used to stop the process of transcode in case of eProcessMethodBasedOnStream.
209-
double _outputDuration; ///< Duration of output media used to stop the process of transcode in case of eProcessMethodBasedOnDuration.
209+
float _outputDuration; ///< Duration of output media used to stop the process of transcode in case of eProcessMethodBasedOnDuration.
210210
};
211211

212212
}

0 commit comments

Comments
 (0)