OLD | NEW |
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 <windows.h> | 5 #include <windows.h> |
6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <memory> |
| 11 |
10 #include "base/base_paths.h" | 12 #include "base/base_paths.h" |
11 #include "base/memory/aligned_memory.h" | 13 #include "base/memory/aligned_memory.h" |
12 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
13 #include "base/sync_socket.h" | 15 #include "base/sync_socket.h" |
14 #include "base/win/scoped_com_initializer.h" | 16 #include "base/win/scoped_com_initializer.h" |
15 #include "base/win/windows_version.h" | 17 #include "base/win/windows_version.h" |
16 #include "media/audio/audio_io.h" | 18 #include "media/audio/audio_io.h" |
17 #include "media/audio/audio_manager.h" | 19 #include "media/audio/audio_manager.h" |
18 #include "media/audio/audio_unittest_util.h" | 20 #include "media/audio/audio_unittest_util.h" |
19 #include "media/audio/mock_audio_source_callback.h" | 21 #include "media/audio/mock_audio_source_callback.h" |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 audio_bus_->CopyTo(audio_bus); | 544 audio_bus_->CopyTo(audio_bus); |
543 return audio_bus_->frames(); | 545 return audio_bus_->frames(); |
544 } | 546 } |
545 | 547 |
546 // AudioSourceCallback::OnError implementation: | 548 // AudioSourceCallback::OnError implementation: |
547 void OnError(AudioOutputStream* stream) override {} | 549 void OnError(AudioOutputStream* stream) override {} |
548 | 550 |
549 private: | 551 private: |
550 base::SyncSocket* socket_; | 552 base::SyncSocket* socket_; |
551 int data_size_; | 553 int data_size_; |
552 scoped_ptr<float, base::AlignedFreeDeleter> data_; | 554 std::unique_ptr<float, base::AlignedFreeDeleter> data_; |
553 scoped_ptr<AudioBus> audio_bus_; | 555 std::unique_ptr<AudioBus> audio_bus_; |
554 }; | 556 }; |
555 | 557 |
556 struct SyncThreadContext { | 558 struct SyncThreadContext { |
557 base::SyncSocket* socket; | 559 base::SyncSocket* socket; |
558 int sample_rate; | 560 int sample_rate; |
559 int channels; | 561 int channels; |
560 int frames; | 562 int frames; |
561 double sine_freq; | 563 double sine_freq; |
562 uint32_t packet_size_bytes; | 564 uint32_t packet_size_bytes; |
563 }; | 565 }; |
564 | 566 |
565 // This thread provides the data that the SyncSocketSource above needs | 567 // This thread provides the data that the SyncSocketSource above needs |
566 // using the other end of a SyncSocket. The protocol is as follows: | 568 // using the other end of a SyncSocket. The protocol is as follows: |
567 // | 569 // |
568 // SyncSocketSource ---send 4 bytes ------------> SyncSocketThread | 570 // SyncSocketSource ---send 4 bytes ------------> SyncSocketThread |
569 // <--- audio packet ---------- | 571 // <--- audio packet ---------- |
570 // | 572 // |
571 DWORD __stdcall SyncSocketThread(void* context) { | 573 DWORD __stdcall SyncSocketThread(void* context) { |
572 SyncThreadContext& ctx = *(reinterpret_cast<SyncThreadContext*>(context)); | 574 SyncThreadContext& ctx = *(reinterpret_cast<SyncThreadContext*>(context)); |
573 | 575 |
574 // Setup AudioBus wrapping data we'll pass over the sync socket. | 576 // Setup AudioBus wrapping data we'll pass over the sync socket. |
575 scoped_ptr<float, base::AlignedFreeDeleter> data(static_cast<float*>( | 577 std::unique_ptr<float, base::AlignedFreeDeleter> data(static_cast<float*>( |
576 base::AlignedAlloc(ctx.packet_size_bytes, AudioBus::kChannelAlignment))); | 578 base::AlignedAlloc(ctx.packet_size_bytes, AudioBus::kChannelAlignment))); |
577 scoped_ptr<AudioBus> audio_bus = AudioBus::WrapMemory( | 579 std::unique_ptr<AudioBus> audio_bus = |
578 ctx.channels, ctx.frames, data.get()); | 580 AudioBus::WrapMemory(ctx.channels, ctx.frames, data.get()); |
579 | 581 |
580 SineWaveAudioSource sine(1, ctx.sine_freq, ctx.sample_rate); | 582 SineWaveAudioSource sine(1, ctx.sine_freq, ctx.sample_rate); |
581 const int kTwoSecFrames = ctx.sample_rate * 2; | 583 const int kTwoSecFrames = ctx.sample_rate * 2; |
582 | 584 |
583 uint32_t total_bytes_delay = 0; | 585 uint32_t total_bytes_delay = 0; |
584 int times = 0; | 586 int times = 0; |
585 for (int ix = 0; ix < kTwoSecFrames; ix += ctx.frames) { | 587 for (int ix = 0; ix < kTwoSecFrames; ix += ctx.frames) { |
586 if (ctx.socket->Receive(&total_bytes_delay, sizeof(total_bytes_delay)) == 0) | 588 if (ctx.socket->Receive(&total_bytes_delay, sizeof(total_bytes_delay)) == 0) |
587 break; | 589 break; |
588 if ((times > 0) && (total_bytes_delay < 1000)) __debugbreak(); | 590 if ((times > 0) && (total_bytes_delay < 1000)) __debugbreak(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 oas->Start(&source); | 637 oas->Start(&source); |
636 | 638 |
637 ::WaitForSingleObject(thread, INFINITE); | 639 ::WaitForSingleObject(thread, INFINITE); |
638 ::CloseHandle(thread); | 640 ::CloseHandle(thread); |
639 | 641 |
640 oas->Stop(); | 642 oas->Stop(); |
641 oas->Close(); | 643 oas->Close(); |
642 } | 644 } |
643 | 645 |
644 } // namespace media | 646 } // namespace media |
OLD | NEW |