fix: add validation that stream is seekable
This commit is contained in:
@@ -32,14 +32,9 @@ public sealed class AudioExtractor : IAudioExtractor
|
|||||||
throw new ArgumentNullException(nameof(video), "Video stream cannot be null");
|
throw new ArgumentNullException(nameof(video), "Video stream cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (video.CanRead is false)
|
if (IsVideoStreamUsable(video) is false)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Video stream must be readable", nameof(video));
|
throw new ArgumentException("Stream must be non-null, readable, and seekable", nameof(video));
|
||||||
}
|
|
||||||
|
|
||||||
if (video.CanSeek is false)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Video stream must be seekable", nameof(video));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (audio is null)
|
if (audio is null)
|
||||||
@@ -47,9 +42,9 @@ public sealed class AudioExtractor : IAudioExtractor
|
|||||||
throw new ArgumentNullException(nameof(audio), "Audio stream cannot be null");
|
throw new ArgumentNullException(nameof(audio), "Audio stream cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (audio.CanWrite is false)
|
if (IsAudioStreamUsable(audio) is false)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Audio stream must be writable", nameof(audio));
|
throw new ArgumentException("Stream must be non-null, writable, and seekable", nameof(audio));
|
||||||
}
|
}
|
||||||
|
|
||||||
var originalPosition = video.Position;
|
var originalPosition = video.Position;
|
||||||
@@ -75,4 +70,14 @@ public sealed class AudioExtractor : IAudioExtractor
|
|||||||
video.Position = originalPosition;
|
video.Position = originalPosition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsVideoStreamUsable(Stream stream)
|
||||||
|
{
|
||||||
|
return stream.CanRead && stream.CanSeek;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsAudioStreamUsable(Stream stream)
|
||||||
|
{
|
||||||
|
return stream.CanWrite && stream.CanSeek;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@ public interface IAudioExtractor
|
|||||||
/// <exception cref="ArgumentException">Thrown when the video stream is not seekable.</exception>
|
/// <exception cref="ArgumentException">Thrown when the video stream is not seekable.</exception>
|
||||||
/// <exception cref="ArgumentNullException">Thrown when the audio stream is null.</exception>
|
/// <exception cref="ArgumentNullException">Thrown when the audio stream is null.</exception>
|
||||||
/// <exception cref="ArgumentException">Thrown when the audio stream is not writable.</exception>
|
/// <exception cref="ArgumentException">Thrown when the audio stream is not writable.</exception>
|
||||||
|
/// <exception cref="ArgumentException">Thrown when the audio stream is not seekable.</exception>
|
||||||
/// <exception cref="FailedAudioExtractionException">Thrown when the audio extraction fails.</exception>
|
/// <exception cref="FailedAudioExtractionException">Thrown when the audio extraction fails.</exception>
|
||||||
/// <remarks>The method will preserve the passed video stream's data and position.</remarks>
|
/// <remarks>The method will preserve the passed video stream's data and position.</remarks>
|
||||||
Task<Stream> ExtractMp3FromMp4Async(Stream video, Stream audio);
|
Task<Stream> ExtractMp3FromMp4Async(Stream video, Stream audio);
|
||||||
|
|||||||
Reference in New Issue
Block a user