Skip to content

Commit 06a1c3a

Browse files
authored
Ensure input source is open before sending -supportsSeeking (#649)
1 parent 5275095 commit 06a1c3a

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

Sources/CSFBAudioEngine/Decoders/SFBAudioDecoder.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,17 @@ - (instancetype)initWithInputSource:(SFBInputSource *)inputSource detectContentT
171171
NSString *lowercaseExtension = inputSource.url.pathExtension.lowercaseString;
172172
NSString *lowercaseMIMEType = mimeTypeHint.lowercaseString;
173173

174-
// Instead of failing for non-seekable inputs just skip content type detection
175-
if(detectContentType && !inputSource.supportsSeeking) {
176-
os_log_error(gSFBAudioDecoderLog, "Unable to detect content type for non-seekable input source %{public}@", inputSource);
177-
detectContentType = NO;
174+
if(detectContentType) {
175+
// If the input source can't be opened decoding is destined to fail; give up now
176+
if(!inputSource.isOpen && ![inputSource openReturningError:error])
177+
return nil;
178+
// Instead of failing for non-seekable inputs just skip content type detection
179+
if(!inputSource.supportsSeeking) {
180+
os_log_error(gSFBAudioDecoderLog, "Unable to detect content type for non-seekable input source %{public}@", inputSource);
181+
detectContentType = NO;
182+
}
178183
}
179184

180-
// If the input source can't be opened decoding is destined to fail; give up now
181-
if(detectContentType && !inputSource.isOpen && ![inputSource openReturningError:error])
182-
return nil;
183-
184185
int score = 10;
185186
Class subclass = nil;
186187

Sources/CSFBAudioEngine/Decoders/SFBDSDDecoder.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,17 @@ - (instancetype)initWithInputSource:(SFBInputSource *)inputSource detectContentT
171171
NSString *lowercaseExtension = inputSource.url.pathExtension.lowercaseString;
172172
NSString *lowercaseMIMEType = mimeTypeHint.lowercaseString;
173173

174-
// Instead of failing for non-seekable inputs just skip content type detection
175-
if(detectContentType && !inputSource.supportsSeeking) {
176-
os_log_error(gSFBDSDDecoderLog, "Unable to detect content type for non-seekable input source %{public}@", inputSource);
177-
detectContentType = NO;
174+
if(detectContentType) {
175+
// If the input source can't be opened decoding is destined to fail; give up now
176+
if(!inputSource.isOpen && ![inputSource openReturningError:error])
177+
return nil;
178+
// Instead of failing for non-seekable inputs just skip content type detection
179+
if(!inputSource.supportsSeeking) {
180+
os_log_error(gSFBDSDDecoderLog, "Unable to detect content type for non-seekable input source %{public}@", inputSource);
181+
detectContentType = NO;
182+
}
178183
}
179184

180-
// If the input source can't be opened decoding is destined to fail; give up now
181-
if(detectContentType && !inputSource.isOpen && ![inputSource openReturningError:error])
182-
return nil;
183-
184185
int score = 10;
185186
Class subclass = nil;
186187

Sources/CSFBAudioEngine/Input/SFBFileInputSource.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ - (BOOL)getLength:(NSInteger *)length error:(NSError **)error
125125

126126
- (BOOL)supportsSeeking
127127
{
128-
return YES;
128+
// Regular files are always seekable.
129+
// Punt on testing whether ftello() and fseeko() actually work.
130+
return S_ISREG(_filestats.st_mode);
129131
}
130132

131133
- (BOOL)seekToOffset:(NSInteger)offset error:(NSError **)error

0 commit comments

Comments
 (0)