decoder/Client: use std::chrono::duration<double> instead of raw double
This commit is contained in:
parent
d1bcd98f79
commit
90f4e97751
@ -290,7 +290,7 @@ DecoderBridge::CommandFinished()
|
|||||||
assert(dc.pipe->IsEmpty());
|
assert(dc.pipe->IsEmpty());
|
||||||
|
|
||||||
initial_seek_running = false;
|
initial_seek_running = false;
|
||||||
timestamp = dc.start_time.ToDoubleS();
|
timestamp = std::chrono::duration_cast<FloatDuration>(dc.start_time);
|
||||||
absolute_frame = dc.start_time.ToScale<uint64_t>(dc.in_audio_format.sample_rate);
|
absolute_frame = dc.start_time.ToScale<uint64_t>(dc.in_audio_format.sample_rate);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -307,7 +307,7 @@ DecoderBridge::CommandFinished()
|
|||||||
if (convert != nullptr)
|
if (convert != nullptr)
|
||||||
convert->Reset();
|
convert->Reset();
|
||||||
|
|
||||||
timestamp = dc.seek_time.ToDoubleS();
|
timestamp = std::chrono::duration_cast<FloatDuration>(dc.seek_time);
|
||||||
absolute_frame = dc.seek_time.ToScale<uint64_t>(dc.in_audio_format.sample_rate);
|
absolute_frame = dc.seek_time.ToScale<uint64_t>(dc.in_audio_format.sample_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,12 +413,12 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DecoderBridge::SubmitTimestamp(double t)
|
DecoderBridge::SubmitTimestamp(FloatDuration t)
|
||||||
{
|
{
|
||||||
assert(t >= 0);
|
assert(t.count() >= 0);
|
||||||
|
|
||||||
timestamp = t;
|
timestamp = t;
|
||||||
absolute_frame = uint64_t(t * dc.in_audio_format.sample_rate);
|
absolute_frame = uint64_t(t.count() * dc.in_audio_format.sample_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
DecoderCommand
|
DecoderCommand
|
||||||
@ -506,7 +506,7 @@ DecoderBridge::SubmitData(InputStream *is,
|
|||||||
|
|
||||||
const auto dest =
|
const auto dest =
|
||||||
chunk->Write(dc.out_audio_format,
|
chunk->Write(dc.out_audio_format,
|
||||||
SongTime::FromS(timestamp) -
|
SongTime::Cast(timestamp) -
|
||||||
dc.song->GetStartTime(),
|
dc.song->GetStartTime(),
|
||||||
kbit_rate);
|
kbit_rate);
|
||||||
if (dest.empty()) {
|
if (dest.empty()) {
|
||||||
@ -532,8 +532,8 @@ DecoderBridge::SubmitData(InputStream *is,
|
|||||||
data = (const uint8_t *)data + nbytes;
|
data = (const uint8_t *)data + nbytes;
|
||||||
length -= nbytes;
|
length -= nbytes;
|
||||||
|
|
||||||
timestamp += (double)nbytes /
|
timestamp += FloatDuration((double)nbytes /
|
||||||
dc.out_audio_format.GetTimeToSize();
|
dc.out_audio_format.GetTimeToSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
absolute_frame += data_frames;
|
absolute_frame += data_frames;
|
||||||
|
@ -49,7 +49,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* The time stamp of the next data chunk, in seconds.
|
* The time stamp of the next data chunk, in seconds.
|
||||||
*/
|
*/
|
||||||
double timestamp = 0;
|
FloatDuration timestamp = FloatDuration::zero();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time stamp of the next data chunk, in PCM frames.
|
* The time stamp of the next data chunk, in PCM frames.
|
||||||
@ -148,7 +148,7 @@ public:
|
|||||||
void SeekError() override;
|
void SeekError() override;
|
||||||
InputStreamPtr OpenUri(const char *uri) override;
|
InputStreamPtr OpenUri(const char *uri) override;
|
||||||
size_t Read(InputStream &is, void *buffer, size_t length) override;
|
size_t Read(InputStream &is, void *buffer, size_t length) override;
|
||||||
void SubmitTimestamp(double t) override;
|
void SubmitTimestamp(FloatDuration t) override;
|
||||||
DecoderCommand SubmitData(InputStream *is,
|
DecoderCommand SubmitData(InputStream *is,
|
||||||
const void *data, size_t length,
|
const void *data, size_t length,
|
||||||
uint16_t kbit_rate) override;
|
uint16_t kbit_rate) override;
|
||||||
|
@ -115,7 +115,7 @@ public:
|
|||||||
* use this function if it thinks that adding to the time stamp based
|
* use this function if it thinks that adding to the time stamp based
|
||||||
* on the buffer size won't work.
|
* on the buffer size won't work.
|
||||||
*/
|
*/
|
||||||
virtual void SubmitTimestamp(double t) = 0;
|
virtual void SubmitTimestamp(FloatDuration t) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is called by the decoder plugin when it has
|
* This function is called by the decoder plugin when it has
|
||||||
|
@ -264,7 +264,8 @@ mpd_mpg123_file_decode(DecoderClient &client, Path path_fs)
|
|||||||
client.SeekError();
|
client.SeekError();
|
||||||
else {
|
else {
|
||||||
client.CommandFinished();
|
client.CommandFinished();
|
||||||
client.SubmitTimestamp(c / (double)audio_format.sample_rate);
|
client.SubmitTimestamp(FloatDuration(c)
|
||||||
|
/ audio_format.sample_rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = DecoderCommand::NONE;
|
cmd = DecoderCommand::NONE;
|
||||||
|
@ -243,7 +243,7 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
|
|||||||
throw cmd;
|
throw cmd;
|
||||||
|
|
||||||
if (packet.granulepos > 0)
|
if (packet.granulepos > 0)
|
||||||
client.SubmitTimestamp(double(packet.granulepos)
|
client.SubmitTimestamp(FloatDuration(packet.granulepos)
|
||||||
/ opus_sample_rate);
|
/ opus_sample_rate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -403,7 +403,7 @@ sidplay_file_decode(DecoderClient &client, Path path_fs)
|
|||||||
const size_t nbytes = result;
|
const size_t nbytes = result;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
client.SubmitTimestamp((double)player.time() / timebase);
|
client.SubmitTimestamp(FloatDuration(player.time()) / timebase);
|
||||||
|
|
||||||
cmd = client.SubmitData(nullptr, buffer, nbytes, 0);
|
cmd = client.SubmitData(nullptr, buffer, nbytes, 0);
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ VorbisDecoder::OnOggPacket(const ogg_packet &_packet)
|
|||||||
|
|
||||||
#ifndef HAVE_TREMOR
|
#ifndef HAVE_TREMOR
|
||||||
if (packet.granulepos > 0)
|
if (packet.granulepos > 0)
|
||||||
client.SubmitTimestamp(vorbis_granule_time(&dsp, packet.granulepos));
|
client.SubmitTimestamp(FloatDuration(vorbis_granule_time(&dsp, packet.granulepos)));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,13 +40,13 @@ extern "C" {
|
|||||||
* Convert a FFmpeg time stamp to a floating point value (in seconds).
|
* Convert a FFmpeg time stamp to a floating point value (in seconds).
|
||||||
*/
|
*/
|
||||||
gcc_const
|
gcc_const
|
||||||
static inline double
|
static inline FloatDuration
|
||||||
FfmpegTimeToDouble(int64_t t, const AVRational time_base) noexcept
|
FfmpegTimeToDouble(int64_t t, const AVRational time_base) noexcept
|
||||||
{
|
{
|
||||||
assert(t != (int64_t)AV_NOPTS_VALUE);
|
assert(t != (int64_t)AV_NOPTS_VALUE);
|
||||||
|
|
||||||
return (double)av_rescale_q(t, time_base, (AVRational){1, 1024})
|
return FloatDuration(av_rescale_q(t, time_base, (AVRational){1, 1024}))
|
||||||
/ (double)1024;
|
/ 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,7 +87,7 @@ DumpDecoderClient::Read(InputStream &is, void *buffer, size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DumpDecoderClient::SubmitTimestamp(gcc_unused double t)
|
DumpDecoderClient::SubmitTimestamp(gcc_unused FloatDuration t)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public:
|
|||||||
void SeekError() override;
|
void SeekError() override;
|
||||||
InputStreamPtr OpenUri(const char *uri) override;
|
InputStreamPtr OpenUri(const char *uri) override;
|
||||||
size_t Read(InputStream &is, void *buffer, size_t length) override;
|
size_t Read(InputStream &is, void *buffer, size_t length) override;
|
||||||
void SubmitTimestamp(double t) override;
|
void SubmitTimestamp(FloatDuration t) override;
|
||||||
DecoderCommand SubmitData(InputStream *is,
|
DecoderCommand SubmitData(InputStream *is,
|
||||||
const void *data, size_t length,
|
const void *data, size_t length,
|
||||||
uint16_t kbit_rate) override;
|
uint16_t kbit_rate) override;
|
||||||
|
Loading…
Reference in New Issue
Block a user