/// <summary> /// Asynchronously sets the media format for the <paramref name="streamType"/> given. /// </summary> /// <param name="streamType">Type of the stream to set format for.</param> /// <param name="formatSelector"> /// Predicate that selects the most suitable format from the collection provided. /// </param> /// <returns>Format set.</returns> /// <exception cref="ArgumentNullException"><paramref name="formatSelector"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentException"><paramref name="streamType"/> is not supported.</exception> /// <exception cref="InvalidOperationException"> /// No suitable media formats found for the <paramref name="streamType"/> given. /// </exception> private async Task <VideoEncodingProperties> DoSetMediaFormatAsync(MediaStreamType streamType, Func <IEnumerable <VideoEncodingProperties>, VideoEncodingProperties> formatSelector) { if (formatSelector == null) { throw new ArgumentNullException("formatSelector"); } IEnumerable <VideoEncodingProperties> availableFormats; switch (streamType) { case MediaStreamType.Photo: availableFormats = this.AvailablePhotoEncodings; break; case MediaStreamType.VideoPreview: availableFormats = this.AvailablePreviewEncodings; break; case MediaStreamType.VideoRecord: availableFormats = this.AvailableVideoEncodings; break; default: throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Stream type {0} is not supported.", streamType)); } VideoEncodingProperties format = formatSelector(availableFormats); if (format == null) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "No suitable media formats found for stream type {0}.", streamType)); } Tracing.Trace("CameraController: Setting media format ({0}) Width: {1}, Height: {2}, Type: {3}.", streamType, format.Width, format.Height, format.Subtype); await this.MediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(streamType, format); return(format); }
/// <summary> /// Sets the media format for the <paramref name="streamType"/> given. /// </summary> /// <param name="streamType">Type of the stream to set format for.</param> /// <param name="formatSize">The desired format area size.</param> /// <returns>Awaitable task.</returns> /// <exception cref="ArgumentOutOfRangeException"><paramref name="formatSize"/> is invalid.</exception> /// <exception cref="ArgumentException"><paramref name="streamType"/> is not supported.</exception> /// <exception cref="InvalidOperationException"> /// No suitable media formats found for the <paramref name="streamType"/> given. /// </exception> public Task SetMediaFormatAsync(MediaStreamType streamType, Size formatSize) { if (formatSize.Height <= 0.0 || formatSize.Width <= 0.0) { throw new ArgumentOutOfRangeException("formatSize", formatSize, "Format size is invalid."); } switch (streamType) { case MediaStreamType.Photo: case MediaStreamType.VideoRecord: // Valid stream types. break; case MediaStreamType.VideoPreview: throw new ArgumentException("Unable to set video preview format. Use 'StartPreviewAsync' methods instead."); default: throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Stream type {0} is not supported.", streamType)); } return(this.DoSetMediaFormatAsync(streamType, CameraController.CreateMediaFormatSelector(formatSize))); }
/// <summary> /// Asynchronously sets the media format for the <paramref name="streamType"/> given. /// </summary> /// <param name="streamType">Type of the stream to set format for.</param> /// <param name="formatSelector"> /// Predicate that selects the most suitable format from the collection provided. /// </param> /// <returns>Format set.</returns> /// <exception cref="ArgumentNullException"><paramref name="formatSelector"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentException"><paramref name="streamType"/> is not supported.</exception> /// <exception cref="InvalidOperationException"> /// No suitable media formats found for the <paramref name="streamType"/> given. /// </exception> private async Task<VideoEncodingProperties> DoSetMediaFormatAsync(MediaStreamType streamType, Func<IEnumerable<VideoEncodingProperties>, VideoEncodingProperties> formatSelector) { if (formatSelector == null) { throw new ArgumentNullException("formatSelector"); } IEnumerable<VideoEncodingProperties> availableFormats; switch (streamType) { case MediaStreamType.Photo: availableFormats = this.AvailablePhotoEncodings; break; case MediaStreamType.VideoPreview: availableFormats = this.AvailablePreviewEncodings; break; case MediaStreamType.VideoRecord: availableFormats = this.AvailableVideoEncodings; break; default: throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Stream type {0} is not supported.", streamType)); } VideoEncodingProperties format = formatSelector(availableFormats); if (format == null) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "No suitable media formats found for stream type {0}.", streamType)); } Tracing.Trace("CameraController: Setting media format ({0}) Width: {1}, Height: {2}, Type: {3}.", streamType, format.Width, format.Height, format.Subtype); await this.MediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(streamType, format); return format; }
/// <summary> /// Sets the media format for the <paramref name="streamType"/> given. /// </summary> /// <param name="streamType">Type of the stream to set format for.</param> /// <param name="formatSize">The desired format area size.</param> /// <returns>Awaitable task.</returns> /// <exception cref="ArgumentOutOfRangeException"><paramref name="formatSize"/> is invalid.</exception> /// <exception cref="ArgumentException"><paramref name="streamType"/> is not supported.</exception> /// <exception cref="InvalidOperationException"> /// No suitable media formats found for the <paramref name="streamType"/> given. /// </exception> public Task SetMediaFormatAsync(MediaStreamType streamType, Size formatSize) { if (formatSize.Height <= 0.0 || formatSize.Width <= 0.0) { throw new ArgumentOutOfRangeException("formatSize", formatSize, "Format size is invalid."); } switch (streamType) { case MediaStreamType.Photo: case MediaStreamType.VideoRecord: // Valid stream types. break; case MediaStreamType.VideoPreview: throw new ArgumentException("Unable to set video preview format. Use 'StartPreviewAsync' methods instead."); default: throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Stream type {0} is not supported.", streamType)); } return this.DoSetMediaFormatAsync(streamType, CameraController.CreateMediaFormatSelector(formatSize)); }