diff options
-rw-r--r-- | media/audio/linux/cras_output.cc | 18 | ||||
-rw-r--r-- | media/audio/linux/cras_output.h | 3 |
2 files changed, 14 insertions, 7 deletions
diff --git a/media/audio/linux/cras_output.cc b/media/audio/linux/cras_output.cc index 4de1256..a04388a 100644 --- a/media/audio/linux/cras_output.cc +++ b/media/audio/linux/cras_output.cc @@ -65,6 +65,7 @@ CrasOutputStream::CrasOutputStream(const AudioParameters& params, : client_(NULL), stream_id_(0), samples_per_packet_(params.frames_per_buffer()), + bytes_per_frame_(0), frame_rate_(params.sample_rate()), num_channels_(params.channels()), pcm_format_(alsa_util::BitsToFormat(params.bits_per_sample())), @@ -195,6 +196,10 @@ void CrasOutputStream::Start(AudioSourceCallback* callback) { return; } + // Before starting the stream, save the number of bytes in a frame for use in + // the callback. + bytes_per_frame_ = cras_client_format_bytes_per_frame(audio_format); + // Adding the stream will start the audio callbacks requesting data. int err = cras_client_add_stream(client_, &stream_id_, stream_params); if (err < 0) { @@ -208,6 +213,7 @@ void CrasOutputStream::Start(AudioSourceCallback* callback) { // Set initial volume. cras_client_set_stream_volume(client_, stream_id_, volume_); + // Done with config params. cras_audio_format_destroy(audio_format); cras_client_stream_params_destroy(stream_params); @@ -257,20 +263,18 @@ int CrasOutputStream::StreamError(cras_client* client, uint32 CrasOutputStream::Render(size_t frames, uint8* buffer, const timespec* sample_ts) { - uint32 bytes_per_frame = cras_client_bytes_per_frame(client_, stream_id_); timespec latency_ts = {0, 0}; // Determine latency and pass that on to the source. - cras_client_calc_latency(client_, stream_id_, sample_ts, &latency_ts); + cras_client_calc_playback_latency(sample_ts, &latency_ts); uint32 latency_usec = (latency_ts.tv_sec * 1000000) + latency_ts.tv_nsec / 1000; uint32 frames_latency = latency_usec * frame_rate_ / 1000000; - uint32 bytes_latency = frames_latency * bytes_per_frame; - uint32 rendered = source_callback_->OnMoreData(buffer, - frames * bytes_per_frame, - AudioBuffersState(0, bytes_latency)); - return rendered / bytes_per_frame; + uint32 bytes_latency = frames_latency * bytes_per_frame_; + uint32 rendered = source_callback_->OnMoreData( + buffer, frames * bytes_per_frame_, AudioBuffersState(0, bytes_latency)); + return rendered / bytes_per_frame_; } void CrasOutputStream::NotifyStreamError(int err) { diff --git a/media/audio/linux/cras_output.h b/media/audio/linux/cras_output.h index 1b33e4c..7d6034b 100644 --- a/media/audio/linux/cras_output.h +++ b/media/audio/linux/cras_output.h @@ -92,6 +92,9 @@ class MEDIA_EXPORT CrasOutputStream : public AudioOutputStream { // Packet size in samples. uint32 samples_per_packet_; + // Size of frame in bytes. + uint32 bytes_per_frame_; + // Rate in Hz. size_t frame_rate_; |