Implement IAudioSource.Duration property and IAudioDecoderSettings.Open extension method.

This commit is contained in:
Grigory Chudov
2018-04-07 23:02:01 -04:00
parent be881945ac
commit deb3448a55
27 changed files with 817 additions and 75 deletions

View File

@@ -191,7 +191,7 @@ namespace CUETools.Codecs.ffmpegdll
//if (stream->duration > 0)
// _sampleCount = stream->duration;
//else
_sampleCount = -1;
_sampleCount = -1;
int bps = stream->codecpar->bits_per_raw_sample != 0 ?
stream->codecpar->bits_per_raw_sample :
@@ -279,6 +279,21 @@ namespace CUETools.Codecs.ffmpegdll
public string Path => _path;
public TimeSpan Duration
{
get
{
// Sadly, duration is unreliable for most codecs.
if (stream->codecpar->codec_id == AVCodecID.AV_CODEC_ID_MLP)
return TimeSpan.Zero;
if (stream->duration > 0)
return TimeSpan.FromSeconds((double)stream->duration / stream->codecpar->sample_rate);
if (fmt_ctx->duration > 0)
return TimeSpan.FromSeconds((double)fmt_ctx->duration / ffmpeg.AV_TIME_BASE);
return TimeSpan.Zero;
}
}
public long Length => _sampleCount;
public long Position