Commit de98309d authored by Ghislain MARY's avatar Ghislain MARY

Handle device orientation of ms2-tester for Windows 10.

parent 8d449b72
......@@ -13,62 +13,64 @@
</CommandBar>
</Page.BottomAppBar>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ScrollViewer>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="CameraLabel" Grid.Row="0" Grid.Column="0" Text="Camera:" VerticalAlignment="Center" Margin="8"/>
<ComboBox x:Name="CameraComboBox" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="8"/>
<TextBlock x:Name="CodecLabel" Grid.Row="1" Grid.Column="0" Text="Codec:" VerticalAlignment="Center" Margin="8"/>
<ComboBox x:Name="CodecComboBox" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="8">
<ComboBoxItem Content="H264" IsSelected="True"/>
<ComboBoxItem Content="VP8"/>
</ComboBox>
<TextBlock x:Name="VideoSizeLabel" Grid.Row="2" Grid.Column="0" Text="Video size:" VerticalAlignment="Center" Margin="8"/>
<ComboBox x:Name="VideoSizeComboBox" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="8">
<ComboBoxItem Content="720P"/>
<ComboBoxItem Content="VGA" IsSelected="True"/>
<ComboBoxItem Content="CIF"/>
<ComboBoxItem Content="QVGA"/>
<ComboBoxItem Content="QCIF"/>
</ComboBox>
<TextBlock x:Name="FramerateLabel" Grid.Row="3" Grid.Column="0" Text="FPS:" VerticalAlignment="Center" Margin="8"/>
<ComboBox x:Name="FramerateComboBox" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="8">
<ComboBoxItem Content="30"/>
<ComboBoxItem Content="25" IsSelected="True"/>
<ComboBoxItem Content="20"/>
<ComboBoxItem Content="15"/>
<ComboBoxItem Content="10"/>
<ComboBoxItem Content="5"/>
</ComboBox>
<TextBlock x:Name="BitrateLabel" Grid.Row="4" Grid.Column="0" Text="Bitrate:" VerticalAlignment="Center" Margin="8"/>
<TextBox x:Name="BitrateTextBox" Grid.Row="4" Grid.Column="1" Margin="8" IsSpellCheckEnabled="False" IsTextPredictionEnabled="False" InputScope="Number" Text="1500"/>
<ToggleButton x:Name="VideoToggleButton" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Content="Toggle video" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="8" Checked="VideoToggleButton_Checked" Unchecked="VideoToggleButton_Checked"/>
</Grid>
<Grid Grid.Row="1" MaxHeight="320">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Name="CameraLabel" Grid.Row="0" Grid.Column="0" Text="Camera:" VerticalAlignment="Center" Margin="8"/>
<ComboBox x:Name="CameraComboBox" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="8"/>
<TextBlock x:Name="CodecLabel" Grid.Row="1" Grid.Column="0" Text="Codec:" VerticalAlignment="Center" Margin="8"/>
<ComboBox x:Name="CodecComboBox" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="8">
<ComboBoxItem Content="H264"/>
<ComboBoxItem Content="VP8" IsSelected="True"/>
</ComboBox>
<TextBlock x:Name="VideoSizeLabel" Grid.Row="2" Grid.Column="0" Text="Video size:" VerticalAlignment="Center" Margin="8"/>
<ComboBox x:Name="VideoSizeComboBox" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="8">
<ComboBoxItem Content="720P"/>
<ComboBoxItem Content="VGA"/>
<ComboBoxItem Content="CIF"/>
<ComboBoxItem Content="QVGA" IsSelected="True"/>
<ComboBoxItem Content="QCIF"/>
</ComboBox>
<TextBlock x:Name="FramerateLabel" Grid.Row="3" Grid.Column="0" Text="FPS:" VerticalAlignment="Center" Margin="8"/>
<ComboBox x:Name="FramerateComboBox" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="8">
<ComboBoxItem Content="30"/>
<ComboBoxItem Content="25"/>
<ComboBoxItem Content="20"/>
<ComboBoxItem Content="15" IsSelected="True"/>
<ComboBoxItem Content="10"/>
<ComboBoxItem Content="5"/>
</ComboBox>
<TextBlock x:Name="BitrateLabel" Grid.Row="4" Grid.Column="0" Text="Bitrate:" VerticalAlignment="Center" Margin="8"/>
<TextBox x:Name="BitrateTextBox" Grid.Row="4" Grid.Column="1" Margin="8" IsSpellCheckEnabled="False" IsTextPredictionEnabled="False" InputScope="Number" Text="1500"/>
<ToggleButton x:Name="VideoToggleButton" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Content="Toggle video" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="8" Checked="VideoToggleButton_Checked" Unchecked="VideoToggleButton_Checked"/>
</Grid>
<Grid Grid.Row="1" MaxHeight="320">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<CaptureElement x:Name="LocalVideo" Stretch="Uniform" Grid.Column="0"/>
<MediaElement x:Name="RemoteVideo" Stretch="Uniform" MediaFailed="RemoteVideo_MediaFailed" MediaEnded="RemoteVideo_MediaEnded" MediaOpened="RemoteVideo_MediaOpened" PartialMediaFailureDetected="RemoteVideo_PartialMediaFailureDetected" RateChanged="RemoteVideo_RateChanged" SizeChanged="RemoteVideo_SizeChanged" CurrentStateChanged="RemoteVideo_CurrentStateChanged" Grid.Column="1"/>
<CaptureElement x:Name="LocalVideo" Stretch="Uniform" Grid.Column="0"/>
<MediaElement x:Name="RemoteVideo" Stretch="Uniform" MediaFailed="RemoteVideo_MediaFailed" MediaEnded="RemoteVideo_MediaEnded" MediaOpened="RemoteVideo_MediaOpened" PartialMediaFailureDetected="RemoteVideo_PartialMediaFailureDetected" RateChanged="RemoteVideo_RateChanged" SizeChanged="RemoteVideo_SizeChanged" CurrentStateChanged="RemoteVideo_CurrentStateChanged" Grid.Column="1"/>
</Grid>
</Grid>
</Grid>
</ScrollViewer>
</Page>
......@@ -4,8 +4,11 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Devices.Sensors;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.Display;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
......@@ -38,6 +41,47 @@ namespace ms2_tester
}
}
override protected void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
displayOrientation = ApplicationView.GetForCurrentView().Orientation;
displayInformation = DisplayInformation.GetForCurrentView();
deviceOrientation = SimpleOrientation.NotRotated;
orientationSensor = SimpleOrientationSensor.GetDefault();
if (orientationSensor != null)
{
deviceOrientation = orientationSensor.GetCurrentOrientation();
orientationSensor.OrientationChanged += OrientationSensor_OrientationChanged;
}
Window.Current.SizeChanged += Current_SizeChanged;
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
if (orientationSensor != null)
{
orientationSensor.OrientationChanged -= OrientationSensor_OrientationChanged;
}
Window.Current.SizeChanged -= Current_SizeChanged;
}
private async void OrientationSensor_OrientationChanged(SimpleOrientationSensor sender, SimpleOrientationSensorOrientationChangedEventArgs args)
{
// Keep previous orientation when the user puts its device faceup or facedown
if ((args.Orientation != SimpleOrientation.Faceup) && (args.Orientation != SimpleOrientation.Facedown))
{
deviceOrientation = args.Orientation;
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => SetVideoOrientation());
}
}
private async void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
{
displayOrientation = ApplicationView.GetForCurrentView().Orientation;
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => SetVideoOrientation());
}
private void BackButton_Click(object sender, RoutedEventArgs e)
{
MS2Tester.Instance.uninitVideo();
......@@ -99,5 +143,54 @@ namespace ms2_tester
MS2Tester.Instance.stopVideoStream();
}
}
private void SetVideoOrientation()
{
SimpleOrientation orientation = deviceOrientation;
if (displayInformation.NativeOrientation == DisplayOrientations.Portrait)
{
switch (orientation)
{
case SimpleOrientation.Rotated90DegreesCounterclockwise:
orientation = SimpleOrientation.NotRotated;
break;
case SimpleOrientation.Rotated180DegreesCounterclockwise:
orientation = SimpleOrientation.Rotated90DegreesCounterclockwise;
break;
case SimpleOrientation.Rotated270DegreesCounterclockwise:
orientation = SimpleOrientation.Rotated180DegreesCounterclockwise;
break;
case SimpleOrientation.NotRotated:
default:
orientation = SimpleOrientation.Rotated270DegreesCounterclockwise;
break;
}
}
int degrees = 0;
switch (orientation)
{
case SimpleOrientation.Rotated90DegreesCounterclockwise:
degrees = 90;
break;
case SimpleOrientation.Rotated180DegreesCounterclockwise:
degrees = 180;
break;
case SimpleOrientation.Rotated270DegreesCounterclockwise:
degrees = 270;
break;
case SimpleOrientation.NotRotated:
default:
degrees = 0;
break;
}
MS2Tester.Instance.setOrientation(degrees);
}
private ApplicationViewOrientation displayOrientation;
private DisplayInformation displayInformation;
private SimpleOrientationSensor orientationSensor;
private SimpleOrientation deviceOrientation;
}
}
......@@ -10,6 +10,7 @@ using namespace Platform::Collections;
using namespace Windows::Foundation;
using namespace Windows::Storage;
using namespace Windows::System::Threading;
using namespace Windows::UI::ViewManagement;
#define MAX_TRACE_SIZE 2048
#define MAX_SUITE_NAME_SIZE 128
......@@ -59,6 +60,7 @@ static void ms2NativeOutputTraceHandler(OrtpLogLevel lev, const char *fmt, va_li
MS2Tester::MS2Tester()
: _deviceRotation(0)
{
mediastreamer2_tester_init(nativeOutputTraceHandler);
bc_tester_set_resource_dir_prefix("Assets");
......@@ -243,8 +245,8 @@ void MS2Tester::startVideoStream(Platform::Object^ CaptureElement, Platform::Obj
video_stream_use_video_preset(_videoStream, "custom");
video_stream_set_sent_video_size(_videoStream, vsize);
video_stream_set_fps(_videoStream, frameRate);
//video_stream_set_device_rotation(_videoStream, 90);
video_stream_start(_videoStream, &av_profile, "127.0.0.1", 20000, NULL, 0, payload, 0, cam);
video_stream_set_device_rotation(_videoStream, _deviceRotation);
video_stream_start(_videoStream, &av_profile, "192.168.0.217", 20000, NULL, 0, payload, 0, cam);
}
void MS2Tester::stopVideoStream()
......@@ -253,3 +255,12 @@ void MS2Tester::stopVideoStream()
video_stream_stop(_videoStream);
_videoStream = NULL;
}
void MS2Tester::setOrientation(int degrees)
{
_deviceRotation = degrees;
if (_videoStream != NULL) {
video_stream_set_device_rotation(_videoStream, _deviceRotation);
video_stream_update_video_params(_videoStream);
}
}
......@@ -26,6 +26,7 @@ namespace ms2_tester_runtime_component
void uninitVideo();
void startVideoStream(Platform::Object^ CaptureElement, Platform::Object^ MediaElement, Platform::String^ camera, Platform::String^ codec, Platform::String^ videoSize, unsigned int frameRate, unsigned int bitRate);
void stopVideoStream();
void setOrientation(int degrees);
static property MS2Tester^ Instance
{
......@@ -47,5 +48,6 @@ namespace ms2_tester_runtime_component
static MS2Tester^ _instance;
Windows::Foundation::IAsyncAction^ _asyncAction;
VideoStream *_videoStream;
int _deviceRotation;
};
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment