Skip to content

Commit 470d64b

Browse files
trying to get two mediacaptures at once
1 parent 1234ddf commit 470d64b

File tree

3 files changed

+46
-37
lines changed

3 files changed

+46
-37
lines changed

Samples/StyleTransfer/AppModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AppModel : INotifyPropertyChanged
1919
public AppModel()
2020
{
2121
this._useGPU = true;
22-
this._selectedCameraIndex = 0;
22+
//this._selectedCameraIndex = 0;
2323
this._modelSource = "candy";
2424
}
2525

Samples/StyleTransfer/AppViewModel.cs

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public AppViewModel()
2828
SaveCommand = new RelayCommand(this.SaveOutput);
2929
MediaSourceCommand = new RelayCommand<string>(SetMediaSource);
3030
LiveStreamCommand = new RelayCommand(async () => await StartWebcamStream());
31+
ChangeMediaInputCommand = new RelayCommand(async () => await ChangeMediaInput());
3132
}
3233

3334
Windows.Media.Capture.MediaCapture _mediaCapture;
@@ -60,6 +61,7 @@ public ICommand SaveCommand
6061

6162
public ICommand MediaSourceCommand { get; set; }
6263
public ICommand LiveStreamCommand { get; set; }
64+
public ICommand ChangeMediaInputCommand { get; set; }
6365

6466
public event PropertyChangedEventHandler PropertyChanged;
6567

@@ -93,42 +95,7 @@ public async Task StartWebcamStream()
9395
}
9496

9597
_appModel.CameraNamesList = _mediaFrameSourceGroupList.Select(group => group.DisplayName);
96-
97-
// UICmbCamera_SelectionChanged
98-
try
99-
{
100-
_selectedMediaFrameSourceGroup = _mediaFrameSourceGroupList[_appModel.SelectedCameraIndex];
101-
102-
// Create MediaCapture and its settings
103-
_mediaCapture = new MediaCapture();
104-
var settings = new MediaCaptureInitializationSettings
105-
{
106-
SourceGroup = _selectedMediaFrameSourceGroup,
107-
PhotoCaptureSource = PhotoCaptureSource.Auto,
108-
MemoryPreference = MediaCaptureMemoryPreference.Cpu,
109-
StreamingCaptureMode = StreamingCaptureMode.Video
110-
};
111-
112-
// Initialize MediaCapture
113-
await _mediaCapture.InitializeAsync(settings);
114-
await LoadModelAsync();
115-
116-
// Initialize VideoEffect
117-
var videoEffectDefinition = new VideoEffectDefinition("StyleTransferEffectComponent.StyleTransferVideoEffect");
118-
IMediaExtension videoEffect = await _mediaCapture.AddVideoEffectAsync(videoEffectDefinition, MediaStreamType.VideoPreview);
119-
// Try loading the model here and passing as a property instead
120-
videoEffect.SetProperties(new PropertySet() {
121-
{ "Model", m_model},
122-
{ "Session", m_session },
123-
{ "InputImageDescription", _inputImageDescription },
124-
{ "OutputImageDescription", _outputImageDescription } });
125-
126-
StartPreview();
127-
}
128-
catch (Exception ex)
129-
{
130-
Debug.WriteLine(ex.ToString());
131-
}
98+
_appModel.SelectedCameraIndex = 0;
13299
}
133100

134101
private async Task LoadModelAsync()
@@ -245,5 +212,44 @@ private void StartPreview()
245212
UIOutputMediaPlayerElement.Visibility = Visibility.Visible;*/
246213

247214
}
215+
216+
private async Task ChangeMediaInput()
217+
{
218+
// UICmbCamera_SelectionChanged
219+
try
220+
{
221+
_selectedMediaFrameSourceGroup = _mediaFrameSourceGroupList[_appModel.SelectedCameraIndex];
222+
223+
// Create MediaCapture and its settings
224+
_mediaCapture = new MediaCapture();
225+
var settings = new MediaCaptureInitializationSettings
226+
{
227+
SourceGroup = _selectedMediaFrameSourceGroup,
228+
PhotoCaptureSource = PhotoCaptureSource.Auto,
229+
MemoryPreference = MediaCaptureMemoryPreference.Cpu,
230+
StreamingCaptureMode = StreamingCaptureMode.Video
231+
};
232+
233+
// Initialize MediaCapture
234+
await _mediaCapture.InitializeAsync(settings);
235+
await LoadModelAsync();
236+
237+
// Initialize VideoEffect
238+
var videoEffectDefinition = new VideoEffectDefinition("StyleTransferEffectComponent.StyleTransferVideoEffect");
239+
IMediaExtension videoEffect = await _mediaCapture.AddVideoEffectAsync(videoEffectDefinition, MediaStreamType.VideoPreview);
240+
// Try loading the model here and passing as a property instead
241+
videoEffect.SetProperties(new PropertySet() {
242+
{ "Model", m_model},
243+
{ "Session", m_session },
244+
{ "InputImageDescription", _inputImageDescription },
245+
{ "OutputImageDescription", _outputImageDescription } });
246+
247+
StartPreview();
248+
}
249+
catch (Exception ex)
250+
{
251+
Debug.WriteLine(ex.ToString());
252+
}
253+
}
248254
}
249255
}

Samples/StyleTransfer/MainPage.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public MainPage()
5454
DisplayRequest displayRequest = new DisplayRequest();
5555
private async void UIButtonLiveStream_Click(object sender, RoutedEventArgs e)
5656
{
57+
var btn = sender as Button;
58+
btn.Command.Execute(btn.CommandParameter);
59+
5760
// Need to have separate thread ? for style transfer section
5861
try
5962
{

0 commit comments

Comments
 (0)