diff options
author | dgreid@chromium.org <dgreid@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-29 10:03:53 +0000 |
---|---|---|
committer | dgreid@chromium.org <dgreid@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-29 10:03:53 +0000 |
commit | c77b767e7d9cc1febf75b506e8b4cb6f691345d0 (patch) | |
tree | d3de8271298b2470306b0917525477a2a445550f | |
parent | d2db596adffad92a5ad23959b314188e5841dacf (diff) | |
download | chromium_src-c77b767e7d9cc1febf75b506e8b4cb6f691345d0.zip chromium_src-c77b767e7d9cc1febf75b506e8b4cb6f691345d0.tar.gz chromium_src-c77b767e7d9cc1febf75b506e8b4cb6f691345d0.tar.bz2 |
CrasOutput: Use new client api to get latency and bytes per frame.
Two new functions were added to the client API that avoid looking up the
stream from the ID. This is safer and saves a lookup from the audio
thread.
BUG=chromium:125750
TEST=media_unittests and Build and run with --use-cras on Linux and
ChromeOS.
Review URL: https://chromiumcodereview.appspot.com/10455013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139285 0039d316-1c4b-4281-b951-d872f2087c98
-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_; |