Skip to content

Commit b88569e

Browse files
author
Clement Champetier
committed
OutputFile: refactore addVideo/Audio/DataStream
Remove AVStream attribute. Instead, use local variable in the corresponding function.
1 parent 3da7f00 commit b88569e

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace avtranscoder
1717
OutputFile::OutputFile( const std::string& filename )
1818
: _formatContext ( NULL )
1919
, _outputFormat ( NULL )
20-
, _stream ( NULL )
2120
, _filename ( filename )
2221
, _previousProcessedStreamDuration( 0.0 )
2322
, _verbose ( false )
@@ -58,32 +57,32 @@ IOutputStream& OutputFile::addVideoStream( const VideoCodec& videoDesc )
5857
{
5958
assert( _formatContext != NULL );
6059

61-
if( ( _stream = avformat_new_stream( _formatContext, videoDesc.getAVCodec() ) ) == NULL )
60+
AVStream* stream = avformat_new_stream( _formatContext, videoDesc.getAVCodec() );
61+
if( stream == NULL )
6262
{
6363
throw std::runtime_error( "unable to add new video stream" );
6464
}
6565

66-
_stream->codec->width = videoDesc.getAVCodecContext()->width;
67-
_stream->codec->height = videoDesc.getAVCodecContext()->height;
68-
_stream->codec->bit_rate = videoDesc.getAVCodecContext()->bit_rate;
69-
_stream->codec->pix_fmt = videoDesc.getAVCodecContext()->pix_fmt;
70-
_stream->codec->profile = videoDesc.getAVCodecContext()->profile;
71-
_stream->codec->level = videoDesc.getAVCodecContext()->level;
66+
stream->codec->width = videoDesc.getAVCodecContext()->width;
67+
stream->codec->height = videoDesc.getAVCodecContext()->height;
68+
stream->codec->bit_rate = videoDesc.getAVCodecContext()->bit_rate;
69+
stream->codec->pix_fmt = videoDesc.getAVCodecContext()->pix_fmt;
70+
stream->codec->profile = videoDesc.getAVCodecContext()->profile;
71+
stream->codec->level = videoDesc.getAVCodecContext()->level;
7272

7373
// need to set the time_base on the AVCodecContext and the AVStream
7474
// compensating the frame rate with the ticks_per_frame and keeping
7575
// a coherent reading speed.
7676
av_reduce(
77-
&_stream->codec->time_base.num,
78-
&_stream->codec->time_base.den,
77+
&stream->codec->time_base.num,
78+
&stream->codec->time_base.den,
7979
videoDesc.getAVCodecContext()->time_base.num * videoDesc.getAVCodecContext()->ticks_per_frame,
8080
videoDesc.getAVCodecContext()->time_base.den,
8181
INT_MAX );
8282

83-
_stream->time_base = _stream->codec->time_base;
84-
85-
AvOutputStream* avOutputStream = new AvOutputStream( *this, _formatContext->nb_streams - 1 );
83+
stream->time_base = stream->codec->time_base;
8684

85+
AvOutputStream* avOutputStream = new AvOutputStream( *this, _formatContext->nb_streams - 1 );
8786
_outputStreams.push_back( avOutputStream );
8887

8988
return *_outputStreams.back();
@@ -93,14 +92,15 @@ IOutputStream& OutputFile::addAudioStream( const AudioCodec& audioDesc )
9392
{
9493
assert( _formatContext != NULL );
9594

96-
if( ( _stream = avformat_new_stream( _formatContext, audioDesc.getAVCodec() ) ) == NULL )
95+
AVStream* stream = avformat_new_stream( _formatContext, audioDesc.getAVCodec() );
96+
if( stream == NULL )
9797
{
9898
throw std::runtime_error( "unable to add new audio stream" );
9999
}
100100

101-
_stream->codec->sample_rate = audioDesc.getAVCodecContext()->sample_rate;
102-
_stream->codec->channels = audioDesc.getAVCodecContext()->channels;
103-
_stream->codec->sample_fmt = audioDesc.getAVCodecContext()->sample_fmt;
101+
stream->codec->sample_rate = audioDesc.getAVCodecContext()->sample_rate;
102+
stream->codec->channels = audioDesc.getAVCodecContext()->channels;
103+
stream->codec->sample_fmt = audioDesc.getAVCodecContext()->sample_fmt;
104104

105105
AvOutputStream* avOutputStream = new AvOutputStream( *this, _formatContext->nb_streams - 1 );
106106
_outputStreams.push_back( avOutputStream );
@@ -112,7 +112,8 @@ IOutputStream& OutputFile::addDataStream( const DataCodec& dataDesc )
112112
{
113113
assert( _formatContext != NULL );
114114

115-
if( ( _stream = avformat_new_stream( _formatContext, dataDesc.getAVCodec() ) ) == NULL )
115+
AVStream* stream = avformat_new_stream( _formatContext, dataDesc.getAVCodec() );
116+
if( stream == NULL )
116117
{
117118
throw std::runtime_error( "unable to add new data stream" );
118119
}

src/AvTranscoder/file/OutputFile.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
struct AVOutputFormat;
2020
struct AVFormatContext;
21-
struct AVCodec;
22-
struct AVCodecContext;
23-
struct AVStream;
2421

2522
namespace avtranscoder
2623
{
@@ -115,8 +112,7 @@ class AvExport OutputFile
115112
private:
116113
std::vector<AvOutputStream*> _outputStreams; ///< Has ownership
117114
AVFormatContext* _formatContext; ///< Has ownership
118-
AVOutputFormat* _outputFormat; ///< Output format (has link, no ownership)
119-
AVStream* _stream;
115+
AVOutputFormat* _outputFormat; ///< Output format (has link, no ownership)
120116

121117
std::vector<size_t> _frameCount; ///< Number of wrapped frames
122118

0 commit comments

Comments
 (0)