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());
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
@ -307,7 +307,7 @@ DecoderBridge::CommandFinished()
|
||||
if (convert != nullptr)
|
||||
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);
|
||||
}
|
||||
|
||||
@ -413,12 +413,12 @@ try {
|
||||
}
|
||||
|
||||
void
|
||||
DecoderBridge::SubmitTimestamp(double t)
|
||||
DecoderBridge::SubmitTimestamp(FloatDuration t)
|
||||
{
|
||||
assert(t >= 0);
|
||||
assert(t.count() >= 0);
|
||||
|
||||
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
|
||||
@ -506,7 +506,7 @@ DecoderBridge::SubmitData(InputStream *is,
|
||||
|
||||
const auto dest =
|
||||
chunk->Write(dc.out_audio_format,
|
||||
SongTime::FromS(timestamp) -
|
||||
SongTime::Cast(timestamp) -
|
||||
dc.song->GetStartTime(),
|
||||
kbit_rate);
|
||||
if (dest.empty()) {
|
||||
@ -532,8 +532,8 @@ DecoderBridge::SubmitData(InputStream *is,
|
||||
data = (const uint8_t *)data + nbytes;
|
||||
length -= nbytes;
|
||||
|
||||
timestamp += (double)nbytes /
|
||||
dc.out_audio_format.GetTimeToSize();
|
||||
timestamp += FloatDuration((double)nbytes /
|
||||
dc.out_audio_format.GetTimeToSize());
|
||||
}
|
||||
|
||||
absolute_frame += data_frames;
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
/**
|
||||
* 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.
|
||||
@ -148,7 +148,7 @@ public:
|
||||
void SeekError() override;
|
||||
InputStreamPtr OpenUri(const char *uri) 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,
|
||||
const void *data, size_t length,
|
||||
uint16_t kbit_rate) override;
|
||||
|
@ -115,7 +115,7 @@ public:
|
||||
* use this function if it thinks that adding to the time stamp based
|
||||
* 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
|
||||
|
@ -264,7 +264,8 @@ mpd_mpg123_file_decode(DecoderClient &client, Path path_fs)
|
||||
client.SeekError();
|
||||
else {
|
||||
client.CommandFinished();
|
||||
client.SubmitTimestamp(c / (double)audio_format.sample_rate);
|
||||
client.SubmitTimestamp(FloatDuration(c)
|
||||
/ audio_format.sample_rate);
|
||||
}
|
||||
|
||||
cmd = DecoderCommand::NONE;
|
||||
|
@ -243,7 +243,7 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
|
||||
throw cmd;
|
||||
|
||||
if (packet.granulepos > 0)
|
||||
client.SubmitTimestamp(double(packet.granulepos)
|
||||
client.SubmitTimestamp(FloatDuration(packet.granulepos)
|
||||
/ opus_sample_rate);
|
||||
}
|
||||
}
|
||||
|
@ -403,7 +403,7 @@ sidplay_file_decode(DecoderClient &client, Path path_fs)
|
||||
const size_t nbytes = result;
|
||||
#endif
|
||||
|
||||
client.SubmitTimestamp((double)player.time() / timebase);
|
||||
client.SubmitTimestamp(FloatDuration(player.time()) / timebase);
|
||||
|
||||
cmd = client.SubmitData(nullptr, buffer, nbytes, 0);
|
||||
|
||||
|
@ -298,7 +298,7 @@ VorbisDecoder::OnOggPacket(const ogg_packet &_packet)
|
||||
|
||||
#ifndef HAVE_TREMOR
|
||||
if (packet.granulepos > 0)
|
||||
client.SubmitTimestamp(vorbis_granule_time(&dsp, packet.granulepos));
|
||||
client.SubmitTimestamp(FloatDuration(vorbis_granule_time(&dsp, packet.granulepos)));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -40,13 +40,13 @@ extern "C" {
|
||||
* Convert a FFmpeg time stamp to a floating point value (in seconds).
|
||||
*/
|
||||
gcc_const
|
||||
static inline double
|
||||
static inline FloatDuration
|
||||
FfmpegTimeToDouble(int64_t t, const AVRational time_base) noexcept
|
||||
{
|
||||
assert(t != (int64_t)AV_NOPTS_VALUE);
|
||||
|
||||
return (double)av_rescale_q(t, time_base, (AVRational){1, 1024})
|
||||
/ (double)1024;
|
||||
return FloatDuration(av_rescale_q(t, time_base, (AVRational){1, 1024}))
|
||||
/ 1024;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +87,7 @@ DumpDecoderClient::Read(InputStream &is, void *buffer, size_t length)
|
||||
}
|
||||
|
||||
void
|
||||
DumpDecoderClient::SubmitTimestamp(gcc_unused double t)
|
||||
DumpDecoderClient::SubmitTimestamp(gcc_unused FloatDuration t)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
void SeekError() override;
|
||||
InputStreamPtr OpenUri(const char *uri) 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,
|
||||
const void *data, size_t length,
|
||||
uint16_t kbit_rate) override;
|
||||
|
Loading…
Reference in New Issue
Block a user