Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Side by Side Diff: media/audio/win/audio_low_latency_output_win.cc

Issue 481193003: Remove AudioBuffersState usage in Chromium (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix audio muter build buster. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/audio/win/audio_low_latency_output_win.h" 5 #include "media/audio/win/audio_low_latency_output_win.h"
6 6
7 #include <Functiondiscoverykeys_devpkey.h> 7 #include <Functiondiscoverykeys_devpkey.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 << std::hex << hr; 469 << std::hex << hr;
470 return false; 470 return false;
471 } 471 }
472 472
473 // Derive the audio delay which corresponds to the delay between 473 // Derive the audio delay which corresponds to the delay between
474 // a render event and the time when the first audio sample in a 474 // a render event and the time when the first audio sample in a
475 // packet is played out through the speaker. This delay value 475 // packet is played out through the speaker. This delay value
476 // can typically be utilized by an acoustic echo-control (AEC) 476 // can typically be utilized by an acoustic echo-control (AEC)
477 // unit at the render side. 477 // unit at the render side.
478 UINT64 position = 0; 478 UINT64 position = 0;
479 int audio_delay_bytes = 0; 479 uint32 audio_delay_bytes = 0;
480 hr = audio_clock_->GetPosition(&position, NULL); 480 hr = audio_clock_->GetPosition(&position, NULL);
481 if (SUCCEEDED(hr)) { 481 if (SUCCEEDED(hr)) {
482 // Stream position of the sample that is currently playing 482 // Stream position of the sample that is currently playing
483 // through the speaker. 483 // through the speaker.
484 double pos_sample_playing_frames = format_.Format.nSamplesPerSec * 484 double pos_sample_playing_frames = format_.Format.nSamplesPerSec *
485 (static_cast<double>(position) / device_frequency); 485 (static_cast<double>(position) / device_frequency);
486 486
487 // Stream position of the last sample written to the endpoint 487 // Stream position of the last sample written to the endpoint
488 // buffer. Note that, the packet we are about to receive in 488 // buffer. Note that, the packet we are about to receive in
489 // the upcoming callback is also included. 489 // the upcoming callback is also included.
490 size_t pos_last_sample_written_frames = 490 size_t pos_last_sample_written_frames =
491 num_written_frames_ + packet_size_frames_; 491 num_written_frames_ + packet_size_frames_;
492 492
493 // Derive the actual delay value which will be fed to the 493 // Derive the actual delay value which will be fed to the
494 // render client using the OnMoreData() callback. 494 // render client using the OnMoreData() callback.
495 audio_delay_bytes = (pos_last_sample_written_frames - 495 audio_delay_bytes = (pos_last_sample_written_frames -
496 pos_sample_playing_frames) * format_.Format.nBlockAlign; 496 pos_sample_playing_frames) * format_.Format.nBlockAlign;
497 } 497 }
498 498
499 // Read a data packet from the registered client source and 499 // Read a data packet from the registered client source and
500 // deliver a delay estimate in the same callback to the client. 500 // deliver a delay estimate in the same callback to the client.
501 // A time stamp is also stored in the AudioBuffersState. This
502 // time stamp can be used at the client side to compensate for
503 // the delay between the usage of the delay value and the time
504 // of generation.
505 501
506 int frames_filled = source_->OnMoreData( 502 int frames_filled = source_->OnMoreData(
507 audio_bus_.get(), AudioBuffersState(0, audio_delay_bytes)); 503 audio_bus_.get(), audio_delay_bytes);
508 uint32 num_filled_bytes = frames_filled * format_.Format.nBlockAlign; 504 uint32 num_filled_bytes = frames_filled * format_.Format.nBlockAlign;
509 DCHECK_LE(num_filled_bytes, packet_size_bytes_); 505 DCHECK_LE(num_filled_bytes, packet_size_bytes_);
510 506
511 // Note: If this ever changes to output raw float the data must be 507 // Note: If this ever changes to output raw float the data must be
512 // clipped and sanitized since it may come from an untrusted 508 // clipped and sanitized since it may come from an untrusted
513 // source such as NaCl. 509 // source such as NaCl.
514 const int bytes_per_sample = format_.Format.wBitsPerSample >> 3; 510 const int bytes_per_sample = format_.Format.wBitsPerSample >> 3;
515 audio_bus_->Scale(volume_); 511 audio_bus_->Scale(volume_);
516 audio_bus_->ToInterleaved( 512 audio_bus_->ToInterleaved(
517 frames_filled, bytes_per_sample, audio_data); 513 frames_filled, bytes_per_sample, audio_data);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 616
621 // Ensure that we don't quit the main thread loop immediately next 617 // Ensure that we don't quit the main thread loop immediately next
622 // time Start() is called. 618 // time Start() is called.
623 ResetEvent(stop_render_event_.Get()); 619 ResetEvent(stop_render_event_.Get());
624 } 620 }
625 621
626 source_ = NULL; 622 source_ = NULL;
627 } 623 }
628 624
629 } // namespace media 625 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/virtual_audio_output_stream.cc ('k') | media/audio/win/audio_low_latency_output_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698