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