@@ -55,7 +55,13 @@ extern "C" {
55
55
#include " output.hpp"
56
56
#include " tag.hpp"
57
57
58
- #define output_fferror (e, msg ) char errbuf[256 ]; av_strerror(e, errbuf, sizeof (errbuf)); output_error(msg " : {}" , errbuf)
58
+ template <typename T>
59
+ constexpr void output_fferror (int error, T&& msg)
60
+ {
61
+ char errbuf[512 ];
62
+ av_strerror (error, errbuf, sizeof (errbuf));
63
+ output_error (" {}: {}" , msg, errbuf);
64
+ }
59
65
#define OLD_CHANNEL_LAYOUT LIBAVUTIL_VERSION_MAJOR < 57 || (LIBAVUTIL_VERSION_MAJOR == 57 && LIBAVUTIL_VERSION_MINOR < 18 )
60
66
#define OUTPUT_FORMAT AV_SAMPLE_FMT_S16
61
67
@@ -223,7 +229,8 @@ bool ScanJob::Track::scan(const Config &config, std::mutex *m)
223
229
lk->lock ();
224
230
rc = avformat_open_input (&format_ctx, rsgain::format (" file:{}" , path.string ()).c_str (), nullptr , nullptr );
225
231
if (rc < 0 ) {
226
- output_fferror (rc, " Could not open input" );
232
+ if (!multithread)
233
+ output_fferror (rc, " Could not open input" );
227
234
goto end;
228
235
}
229
236
@@ -233,14 +240,16 @@ bool ScanJob::Track::scan(const Config &config, std::mutex *m)
233
240
234
241
rc = avformat_find_stream_info (format_ctx, nullptr );
235
242
if (rc < 0 ) {
236
- output_fferror (rc, " Could not find stream info" );
243
+ if (!multithread)
244
+ output_fferror (rc, " Could not find stream info" );
237
245
goto end;
238
246
}
239
247
240
248
// Select the best audio stream
241
249
stream_id = av_find_best_stream (format_ctx, AVMEDIA_TYPE_AUDIO, -1 , -1 , &codec, 0 );
242
250
if (stream_id < 0 ) {
243
- output_error (" Could not find audio stream" );
251
+ if (!multithread)
252
+ output_error (" Could not find audio stream" );
244
253
goto end;
245
254
}
246
255
stream = format_ctx->streams [stream_id];
@@ -250,7 +259,8 @@ bool ScanJob::Track::scan(const Config &config, std::mutex *m)
250
259
do {
251
260
codec_ctx = avcodec_alloc_context3 (codec);
252
261
if (!codec_ctx) {
253
- output_error (" Could not allocate audio codec context" );
262
+ if (!multithread)
263
+ output_error (" Could not allocate audio codec context" );
254
264
goto end;
255
265
}
256
266
avcodec_parameters_to_context (codec_ctx, stream->codecpar );
@@ -274,7 +284,8 @@ bool ScanJob::Track::scan(const Config &config, std::mutex *m)
274
284
}
275
285
}
276
286
}
277
- output_fferror (rc, " Could not open codec" );
287
+ if (!multithread)
288
+ output_fferror (rc, " Could not open codec" );
278
289
goto end;
279
290
}
280
291
repeat = false ;
@@ -324,13 +335,15 @@ bool ScanJob::Track::scan(const Config &config, std::mutex *m)
324
335
);
325
336
#endif
326
337
if (!swr) {
327
- output_error (" Could not allocate libswresample context" );
338
+ if (!multithread)
339
+ output_error (" Could not allocate libswresample context" );
328
340
goto end;
329
341
}
330
342
331
343
rc = swr_init (swr);
332
344
if (rc < 0 ) {
333
- output_fferror (rc, " Could not open libswresample context" );
345
+ if (!multithread)
346
+ output_fferror (rc, " Could not open libswresample context" );
334
347
goto end;
335
348
}
336
349
}
@@ -345,21 +358,24 @@ bool ScanJob::Track::scan(const Config &config, std::mutex *m)
345
358
EBUR128_MODE_I | peak_mode
346
359
);
347
360
if (!ebur128) {
348
- output_error (" Could not initialize libebur128 scanner" );
361
+ if (!multithread)
362
+ output_error (" Could not initialize libebur128 scanner" );
349
363
goto end;
350
364
}
351
365
352
366
// Allocate AVPacket structure
353
367
packet = av_packet_alloc ();
354
368
if (!packet) {
355
- output_error (" Could not allocate packet" );
369
+ if (!multithread)
370
+ output_error (" Could not allocate packet" );
356
371
goto end;
357
372
}
358
373
359
374
// Alocate AVFrame structure
360
375
frame = av_frame_alloc ();
361
376
if (!frame) {
362
- output_error (" Could not allocate frame" );
377
+ if (!multithread)
378
+ output_error (" Could not allocate frame" );
363
379
goto end;
364
380
}
365
381
@@ -395,7 +411,8 @@ bool ScanJob::Track::scan(const Config &config, std::mutex *m)
395
411
);
396
412
swr_out_data[0 ] = (uint8_t *) av_malloc (out_size);
397
413
if (swr_convert (swr, swr_out_data, frame->nb_samples , (const uint8_t **) frame->data , frame->nb_samples ) < 0 ) {
398
- output_error (" Could not convert audio frame" );
414
+ if (!multithread)
415
+ output_error (" Could not convert audio frame" );
399
416
av_free (swr_out_data[0 ]);
400
417
goto end;
401
418
}
0 commit comments