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

Side by Side Diff: media/midi/midi_manager_winrt.cc

Issue 2422163002: Web MIDI: use midi_service.mojom for media::midi::PortState (Closed)
Patch Set: gn --check fix Created 4 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
« no previous file with comments | « media/midi/midi_manager_win.cc ('k') | media/midi/midi_port_info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/midi/midi_manager_winrt.h" 5 #include "media/midi/midi_manager_winrt.h"
6 6
7 #pragma warning(disable : 4467) 7 #pragma warning(disable : 4467)
8 8
9 #include <initguid.h> // Required by <devpkey.h> 9 #include <initguid.h> // Required by <devpkey.h>
10 10
(...skipping 24 matching lines...) Expand all
35 namespace { 35 namespace {
36 36
37 namespace WRL = Microsoft::WRL; 37 namespace WRL = Microsoft::WRL;
38 38
39 using namespace ABI::Windows::Devices::Enumeration; 39 using namespace ABI::Windows::Devices::Enumeration;
40 using namespace ABI::Windows::Devices::Midi; 40 using namespace ABI::Windows::Devices::Midi;
41 using namespace ABI::Windows::Foundation; 41 using namespace ABI::Windows::Foundation;
42 using namespace ABI::Windows::Storage::Streams; 42 using namespace ABI::Windows::Storage::Streams;
43 43
44 using base::win::ScopedComPtr; 44 using base::win::ScopedComPtr;
45 using mojom::PortState;
45 using mojom::Result; 46 using mojom::Result;
46 47
47 // Helpers for printing HRESULTs. 48 // Helpers for printing HRESULTs.
48 struct PrintHr { 49 struct PrintHr {
49 PrintHr(HRESULT hr) : hr(hr) {} 50 PrintHr(HRESULT hr) : hr(hr) {}
50 HRESULT hr; 51 HRESULT hr;
51 }; 52 };
52 53
53 std::ostream& operator<<(std::ostream& os, const PrintHr& phr) { 54 std::ostream& operator<<(std::ostream& os, const PrintHr& phr) {
54 std::ios_base::fmtflags ff = os.flags(); 55 std::ios_base::fmtflags ff = os.flags();
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 CHECK(is_initialized_); 643 CHECK(is_initialized_);
643 644
644 // Note: in case Microsoft GS Wavetable Synth triggers this event for some 645 // Note: in case Microsoft GS Wavetable Synth triggers this event for some
645 // reason, it will be ignored here with log emitted. 646 // reason, it will be ignored here with log emitted.
646 MidiPort<InterfaceType>* port = GetPortByDeviceId(dev_id); 647 MidiPort<InterfaceType>* port = GetPortByDeviceId(dev_id);
647 if (!port) { 648 if (!port) {
648 VLOG(1) << "Removing non-existent port " << dev_id; 649 VLOG(1) << "Removing non-existent port " << dev_id;
649 return; 650 return;
650 } 651 }
651 652
652 SetPortState(port->index, MIDI_PORT_DISCONNECTED); 653 SetPortState(port->index, PortState::DISCONNECTED);
653 654
654 RemovePortEventHandlers(port); 655 RemovePortEventHandlers(port);
655 port->handle = nullptr; 656 port->handle = nullptr;
656 } 657 }
657 658
658 void OnCompletedGetPortFromIdAsync(IAsyncOperation<RuntimeType*>* async_op) { 659 void OnCompletedGetPortFromIdAsync(IAsyncOperation<RuntimeType*>* async_op) {
659 DCHECK(thread_checker_.CalledOnValidThread()); 660 DCHECK(thread_checker_.CalledOnValidThread());
660 CHECK(is_initialized_); 661 CHECK(is_initialized_);
661 662
662 InterfaceType* handle = nullptr; 663 InterfaceType* handle = nullptr;
(...skipping 21 matching lines...) Expand all
684 685
685 std::string dev_id = GetDeviceIdString(handle); 686 std::string dev_id = GetDeviceIdString(handle);
686 687
687 MidiPort<InterfaceType>* port = GetPortByDeviceId(dev_id); 688 MidiPort<InterfaceType>* port = GetPortByDeviceId(dev_id);
688 689
689 if (port == nullptr) { 690 if (port == nullptr) {
690 std::string manufacturer = "Unknown", driver_version = "Unknown"; 691 std::string manufacturer = "Unknown", driver_version = "Unknown";
691 GetDriverInfoFromDeviceId(dev_id, &manufacturer, &driver_version); 692 GetDriverInfoFromDeviceId(dev_id, &manufacturer, &driver_version);
692 693
693 AddPort(MidiPortInfo(dev_id, manufacturer, port_names_[dev_id], 694 AddPort(MidiPortInfo(dev_id, manufacturer, port_names_[dev_id],
694 driver_version, MIDI_PORT_OPENED)); 695 driver_version, PortState::OPENED));
695 696
696 port = new MidiPort<InterfaceType>; 697 port = new MidiPort<InterfaceType>;
697 port->index = static_cast<uint32_t>(port_ids_.size()); 698 port->index = static_cast<uint32_t>(port_ids_.size());
698 699
699 ports_[dev_id].reset(port); 700 ports_[dev_id].reset(port);
700 port_ids_.push_back(dev_id); 701 port_ids_.push_back(dev_id);
701 } else { 702 } else {
702 SetPortState(port->index, MIDI_PORT_CONNECTED); 703 SetPortState(port->index, PortState::CONNECTED);
703 } 704 }
704 705
705 port->handle = handle; 706 port->handle = handle;
706 port->token_MessageReceived = token; 707 port->token_MessageReceived = token;
707 708
708 if (enumeration_completed_not_ready_ && async_ops_.empty()) { 709 if (enumeration_completed_not_ready_ && async_ops_.empty()) {
709 midi_manager_->OnPortManagerReady(); 710 midi_manager_->OnPortManagerReady();
710 enumeration_completed_not_ready_ = false; 711 enumeration_completed_not_ready_ = false;
711 } 712 }
712 } 713 }
713 714
714 // Overrided by MidiInPortManager to listen to input ports. 715 // Overrided by MidiInPortManager to listen to input ports.
715 virtual bool RegisterOnMessageReceived(InterfaceType* handle, 716 virtual bool RegisterOnMessageReceived(InterfaceType* handle,
716 EventRegistrationToken* p_token) { 717 EventRegistrationToken* p_token) {
717 return true; 718 return true;
718 } 719 }
719 720
720 // Overrided by MidiInPortManager to remove MessageReceived event handler. 721 // Overrided by MidiInPortManager to remove MessageReceived event handler.
721 virtual void RemovePortEventHandlers(MidiPort<InterfaceType>* port) {} 722 virtual void RemovePortEventHandlers(MidiPort<InterfaceType>* port) {}
722 723
723 // Calls midi_manager_->Add{Input,Output}Port. 724 // Calls midi_manager_->Add{Input,Output}Port.
724 virtual void AddPort(MidiPortInfo info) = 0; 725 virtual void AddPort(MidiPortInfo info) = 0;
725 726
726 // Calls midi_manager_->Set{Input,Output}PortState. 727 // Calls midi_manager_->Set{Input,Output}PortState.
727 virtual void SetPortState(uint32_t port_index, MidiPortState state) = 0; 728 virtual void SetPortState(uint32_t port_index, PortState state) = 0;
728 729
729 // WeakPtrFactory has to be declared in derived class, use this method to 730 // WeakPtrFactory has to be declared in derived class, use this method to
730 // retrieve upcasted WeakPtr for posting tasks. 731 // retrieve upcasted WeakPtr for posting tasks.
731 virtual base::WeakPtr<MidiPortManager> GetWeakPtrFromFactory() = 0; 732 virtual base::WeakPtr<MidiPortManager> GetWeakPtrFromFactory() = 0;
732 733
733 // Midi{In,Out}PortStatics instance. 734 // Midi{In,Out}PortStatics instance.
734 ScopedComPtr<StaticsInterfaceType> midi_port_statics_; 735 ScopedComPtr<StaticsInterfaceType> midi_port_statics_;
735 736
736 // DeviceWatcher instance and event registration tokens for unsubscribing 737 // DeviceWatcher instance and event registration tokens for unsubscribing
737 // events in destructor. 738 // events in destructor.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 return; 843 return;
843 844
844 HRESULT hr = 845 HRESULT hr =
845 port->handle->remove_MessageReceived(port->token_MessageReceived); 846 port->handle->remove_MessageReceived(port->token_MessageReceived);
846 VLOG_IF(1, FAILED(hr)) << "remove_MessageReceived failed: " << PrintHr(hr); 847 VLOG_IF(1, FAILED(hr)) << "remove_MessageReceived failed: " << PrintHr(hr);
847 port->token_MessageReceived.value = kInvalidTokenValue; 848 port->token_MessageReceived.value = kInvalidTokenValue;
848 } 849 }
849 850
850 void AddPort(MidiPortInfo info) final { midi_manager_->AddInputPort(info); } 851 void AddPort(MidiPortInfo info) final { midi_manager_->AddInputPort(info); }
851 852
852 void SetPortState(uint32_t port_index, MidiPortState state) final { 853 void SetPortState(uint32_t port_index, PortState state) final {
853 midi_manager_->SetInputPortState(port_index, state); 854 midi_manager_->SetInputPortState(port_index, state);
854 } 855 }
855 856
856 base::WeakPtr<MidiPortManager> GetWeakPtrFromFactory() final { 857 base::WeakPtr<MidiPortManager> GetWeakPtrFromFactory() final {
857 DCHECK(thread_checker_.CalledOnValidThread()); 858 DCHECK(thread_checker_.CalledOnValidThread());
858 859
859 return weak_factory_.GetWeakPtr(); 860 return weak_factory_.GetWeakPtr();
860 } 861 }
861 862
862 // Callback on receiving MIDI input message. 863 // Callback on receiving MIDI input message.
(...skipping 20 matching lines...) Expand all
883 IMidiOutPortStatics, 884 IMidiOutPortStatics,
884 RuntimeClass_Windows_Devices_Midi_MidiOutPort> { 885 RuntimeClass_Windows_Devices_Midi_MidiOutPort> {
885 public: 886 public:
886 MidiOutPortManager(MidiManagerWinrt* midi_manager) 887 MidiOutPortManager(MidiManagerWinrt* midi_manager)
887 : MidiPortManager(midi_manager), weak_factory_(this) {} 888 : MidiPortManager(midi_manager), weak_factory_(this) {}
888 889
889 private: 890 private:
890 // MidiPortManager overrides: 891 // MidiPortManager overrides:
891 void AddPort(MidiPortInfo info) final { midi_manager_->AddOutputPort(info); } 892 void AddPort(MidiPortInfo info) final { midi_manager_->AddOutputPort(info); }
892 893
893 void SetPortState(uint32_t port_index, MidiPortState state) final { 894 void SetPortState(uint32_t port_index, PortState state) final {
894 midi_manager_->SetOutputPortState(port_index, state); 895 midi_manager_->SetOutputPortState(port_index, state);
895 } 896 }
896 897
897 base::WeakPtr<MidiPortManager> GetWeakPtrFromFactory() final { 898 base::WeakPtr<MidiPortManager> GetWeakPtrFromFactory() final {
898 DCHECK(thread_checker_.CalledOnValidThread()); 899 DCHECK(thread_checker_.CalledOnValidThread());
899 900
900 return weak_factory_.GetWeakPtr(); 901 return weak_factory_.GetWeakPtr();
901 } 902 }
902 903
903 // Last member to ensure destructed first. 904 // Last member to ensure destructed first.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 1040
1040 void MidiManagerWinrt::OnPortManagerReady() { 1041 void MidiManagerWinrt::OnPortManagerReady() {
1041 DCHECK(com_thread_checker_->CalledOnValidThread()); 1042 DCHECK(com_thread_checker_->CalledOnValidThread());
1042 DCHECK(port_manager_ready_count_ < 2); 1043 DCHECK(port_manager_ready_count_ < 2);
1043 1044
1044 if (++port_manager_ready_count_ == 2) 1045 if (++port_manager_ready_count_ == 2)
1045 CompleteInitialization(Result::OK); 1046 CompleteInitialization(Result::OK);
1046 } 1047 }
1047 1048
1048 } // namespace midi 1049 } // namespace midi
OLDNEW
« no previous file with comments | « media/midi/midi_manager_win.cc ('k') | media/midi/midi_port_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698