Skip to content

Commit a19517f

Browse files
committed
Fixed auto zoom option when stdin is a socket
See #176
1 parent 78126bd commit a19517f

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/FileUtil.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//------------------------------------------------------------------------------
22
//
3-
// Copyright 2022 BBC Research and Development
3+
// Copyright 2023 BBC Research and Development
44
//
55
// Author: Chris Needham
66
//
@@ -45,18 +45,19 @@ bool isStdioFilename(const char* filename)
4545

4646
//------------------------------------------------------------------------------
4747

48-
bool isStdinFifo() {
48+
bool isStdinSeekable()
49+
{
4950
struct stat stat_buf;
5051

5152
int result = fstat(fileno(stdin), &stat_buf);
5253

5354
if (result >= 0) {
54-
if (S_ISFIFO(stat_buf.st_mode)) {
55-
return true;
55+
if (S_ISFIFO(stat_buf.st_mode) || S_ISSOCK(stat_buf.st_mode)) {
56+
return false;
5657
}
5758
}
5859

59-
return false;
60+
return true;
6061
}
6162

6263
//------------------------------------------------------------------------------

src/FileUtil.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//------------------------------------------------------------------------------
22
//
3-
// Copyright 2022 BBC Research and Development
3+
// Copyright 2023 BBC Research and Development
44
//
55
// Author: Chris Needham
66
//
@@ -28,7 +28,7 @@
2828

2929
namespace FileUtil {
3030
bool isStdioFilename(const char* filename);
31-
bool isStdinFifo();
31+
bool isStdinSeekable();
3232
const char* getInputFilename(const char* filename);
3333
const char* getOutputFilename(const char* filename);
3434
}

src/OptionHandler.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,13 @@ bool OptionHandler::renderWaveformImage(
388388
);
389389
}
390390
else {
391+
// Seeking to the start of the audio won't work if reading from a pipe
392+
// or a socket, so we buffer the entire audio data in memory.
393+
391394
if (FileUtil::isStdioFilename(input_filename.string().c_str()) &&
392-
FileUtil::isStdinFifo() &&
395+
!FileUtil::isStdinSeekable() &&
393396
calculate_duration) {
397+
394398
std::unique_ptr<AudioFileReader> audio_file_reader(
395399
createAudioFileReader(input_filename, input_format)
396400
);
@@ -420,7 +424,6 @@ bool OptionHandler::renderWaveformImage(
420424
}
421425

422426
output_samples_per_pixel = input_buffer.getSamplesPerPixel();
423-
424427
}
425428
else {
426429
if (calculate_duration) {

0 commit comments

Comments
 (0)