Skip to content

Commit e960a1b

Browse files
author
Clement Champetier
committed
Transcoder: clean add functions
* Update verbose: upper case when start new sentences. * Throw exception if invalid operation (instead of print something in verbose on just return without doing nothing). * Add comments.
1 parent 1dd2f6e commit e960a1b

File tree

1 file changed

+90
-57
lines changed

1 file changed

+90
-57
lines changed

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 90 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -34,159 +34,192 @@ Transcoder::~Transcoder()
3434

3535
void Transcoder::add( const std::string& filename, const size_t streamIndex, const std::string& profileName, const size_t offset )
3636
{
37-
if( profileName.length() == 0 ) // no profile, only re-wrap stream
37+
// Re-wrap
38+
if( profileName.length() == 0 )
3839
{
3940
if( _verbose )
40-
std::cout << "add re-wrap stream" << std::endl;
41+
std::cout << "Add re-wrap stream" << std::endl;
42+
43+
// Check filename
44+
if( filename.length() == 0 )
45+
throw std::runtime_error( "Can't re-wrap a stream without filename indicated" );
46+
4147
addRewrapStream( filename, streamIndex );
42-
return;
4348
}
44-
45-
ProfileLoader::Profile& transcodeProfile = _profileLoader.getProfile( profileName );
46-
add( filename, streamIndex, transcodeProfile, offset );
49+
// Transcode
50+
else
51+
{
52+
ProfileLoader::Profile& transcodeProfile = _profileLoader.getProfile( profileName );
53+
add( filename, streamIndex, transcodeProfile, offset );
54+
}
4755
}
4856

4957
void Transcoder::add( const std::string& filename, const size_t streamIndex, const std::string& profileName, ICodec& codec, const size_t offset )
5058
{
51-
if( profileName.length() == 0 ) // no profile, only re-wrap stream
59+
// Re-wrap
60+
if( profileName.length() == 0 )
5261
{
5362
if( _verbose )
54-
std::cout << "add re-wrap stream" << std::endl;
55-
63+
std::cout << "Add re-wrap stream" << std::endl;
64+
65+
// Check filename
5666
if( filename.length() == 0 )
57-
{
58-
std::cerr << "can't add a generated stream with no profileName indicated" << std::endl;
59-
return;
60-
}
67+
throw std::runtime_error( "Can't re-wrap a stream without filename indicated" );
6168

6269
addRewrapStream( filename, streamIndex );
63-
return;
6470
}
65-
66-
ProfileLoader::Profile& transcodeProfile = _profileLoader.getProfile( profileName );
67-
add( filename, streamIndex, transcodeProfile, codec, offset );
71+
// Transcode
72+
else
73+
{
74+
ProfileLoader::Profile& transcodeProfile = _profileLoader.getProfile( profileName );
75+
add( filename, streamIndex, transcodeProfile, codec, offset );
76+
}
6877
}
6978

7079
void Transcoder::add( const std::string& filename, const size_t streamIndex, ProfileLoader::Profile& profile, const size_t offset )
7180
{
81+
// Add profile if new
7282
_profileLoader.update( profile );
83+
84+
// Check filename
7385
if( ! filename.length() )
7486
{
75-
std::cerr << "can't add a stream with no filename indicated" << std::endl;
76-
return;
87+
throw std::runtime_error( "Can't transcode a stream without filename indicated" );
7788
}
7889

7990
if( _verbose )
80-
std::cout << "add transcoding stream" << std::endl;
91+
std::cout << "Add transcoded stream" << std::endl;
8192
addTranscodeStream( filename, streamIndex, profile, offset );
8293
}
8394

8495
void Transcoder::add( const std::string& filename, const size_t streamIndex, ProfileLoader::Profile& profile, ICodec& codec, const size_t offset )
8596
{
97+
// Add profile if new
8698
_profileLoader.update( profile );
99+
100+
// Generator
87101
if( ! filename.length() )
88102
{
89103
if( _verbose )
90-
std::cout << "add a generated stream" << std::endl;
104+
std::cout << "Add generated stream" << std::endl;
91105
addDummyStream( profile, codec );
92-
return;
93106
}
94-
95-
if( _verbose )
96-
std::cout << "add transcoding stream" << std::endl;
97-
addTranscodeStream( filename, streamIndex, profile, offset );
107+
// Transcode
108+
else
109+
{
110+
if( _verbose )
111+
std::cout << "Add transcoded stream" << std::endl;
112+
addTranscodeStream( filename, streamIndex, profile, offset );
113+
}
98114
}
99115

100116
void Transcoder::add( const std::string& filename, const size_t streamIndex, const int subStreamIndex, const std::string& profileName, const size_t offset )
101117
{
118+
// No subStream selected
102119
if( subStreamIndex < 0 )
103120
{
104121
add( filename, streamIndex, profileName, offset );
105122
return;
106123
}
107124

108-
if( profileName.length() == 0 ) // no profile, only re-wrap stream
125+
if( profileName.length() == 0 )
109126
{
110-
if( _verbose )
111-
std::cout << "add re-wrap stream for substream " << subStreamIndex << std::endl;
112-
113-
addRewrapStream( filename, streamIndex );
114-
return;
127+
// Re-wrap
128+
if( subStreamIndex < 0 )
129+
{
130+
if( _verbose )
131+
std::cout << "Add re-wrap stream" << std::endl;
132+
addRewrapStream( filename, streamIndex );
133+
return;
134+
}
135+
else
136+
throw std::runtime_error( "Can't demultiplexing and re-wrap a stream" );
137+
}
138+
// Transcode
139+
else
140+
{
141+
ProfileLoader::Profile& transcodeProfile = _profileLoader.getProfile( profileName );
142+
add( filename, streamIndex, subStreamIndex, transcodeProfile, offset );
115143
}
116-
117-
ProfileLoader::Profile& transcodeProfile = _profileLoader.getProfile( profileName );
118-
add( filename, streamIndex, subStreamIndex, transcodeProfile, offset );
119144
}
120145

121146
void Transcoder::add( const std::string& filename, const size_t streamIndex, const int subStreamIndex, const std::string& profileName, ICodec& codec, const size_t offset )
122147
{
148+
// No subStream selected
123149
if( subStreamIndex < 0 )
124150
{
125151
add( filename, streamIndex, profileName, codec );
126152
return;
127153
}
128-
129-
if( profileName.length() == 0 ) // no profile, only re-wrap stream
130-
{
131-
if( _verbose )
132-
std::cout << "add re-wrap stream for substream " << subStreamIndex << std::endl;
133154

134-
if( filename.length() == 0 )
155+
// Re-wrap
156+
if( profileName.length() == 0 )
157+
{
158+
// Re-wrap
159+
if( subStreamIndex < 0 )
135160
{
136-
std::cerr << "can't add a generated stream with no profileName indicated" << std::endl;
161+
if( _verbose )
162+
std::cout << "Add re-wrap stream" << std::endl;
163+
addRewrapStream( filename, streamIndex );
137164
return;
138165
}
139-
140-
addRewrapStream( filename, streamIndex );
141-
return;
166+
else
167+
throw std::runtime_error( "Can't demultiplexing and re-wrap a stream" );
168+
}
169+
// Transcode
170+
else
171+
{
172+
ProfileLoader::Profile& transcodeProfile = _profileLoader.getProfile( profileName );
173+
add( filename, streamIndex, subStreamIndex, transcodeProfile, codec, offset );
142174
}
143-
144-
ProfileLoader::Profile& transcodeProfile = _profileLoader.getProfile( profileName );
145-
add( filename, streamIndex, subStreamIndex, transcodeProfile, codec, offset );
146175
}
147176

148177
void Transcoder::add( const std::string& filename, const size_t streamIndex, const int subStreamIndex, ProfileLoader::Profile& profile, const size_t offset )
149178
{
179+
// Add profile if new
150180
_profileLoader.update( profile );
151-
181+
182+
// No subStream selected
152183
if( subStreamIndex < 0 )
153184
{
154185
add( filename, streamIndex, profile, offset );
155186
return;
156187
}
157-
188+
189+
// Check filename
158190
if( ! filename.length() )
159191
{
160-
if( _verbose )
161-
std::cerr << "can't add a stream with no filename indicated" << std::endl;
162-
return;
192+
throw std::runtime_error( "Can't transcode a stream without filename indicated" );
163193
}
164194

165195
if( _verbose )
166-
std::cout << "add transcoding stream for substream " << subStreamIndex << std::endl;
196+
std::cout << "Add transcoded for substream " << subStreamIndex << std::endl;
167197
addTranscodeStream( filename, streamIndex, subStreamIndex, profile, offset );
168198
}
169199

170200
void Transcoder::add( const std::string& filename, const size_t streamIndex, const int subStreamIndex, ProfileLoader::Profile& profile, ICodec& codec, const size_t offset )
171201
{
202+
// Add profile if new
172203
_profileLoader.update( profile );
173204

205+
// No subStream selected
174206
if( subStreamIndex < 0 )
175207
{
176208
add( filename, streamIndex, profile );
177209
return;
178210
}
179-
211+
212+
// Generator
180213
if( ! filename.length() )
181214
{
182215
if( _verbose )
183-
std::cout << "add a generated stream" << std::endl;
216+
std::cout << "Add generated stream" << std::endl;
184217
addDummyStream( profile, codec );
185218
return;
186219
}
187220

188221
if( _verbose )
189-
std::cout << "add transcoding stream for substream " << subStreamIndex << std::endl;
222+
std::cout << "Add transcoded stream for substream " << subStreamIndex << std::endl;
190223
addTranscodeStream( filename, streamIndex, subStreamIndex, profile, offset );
191224
}
192225

0 commit comments

Comments
 (0)