Fixes video preview in configuration.

cusax-fix
Damian Minkov 14 years ago
parent b52eb04fc4
commit 45aeeeaee6

@ -491,7 +491,11 @@ public void actionPerformed(ActionEvent event)
if ((deviceComboBox.getSelectedItem() != null)
&& deviceComboBox.isShowing())
preview = createPreview(type, deviceComboBox);
{
preview = createPreview(type, deviceComboBox,
deviceAndPreviewPanel.getPreferredSize());
}
if (preview != null)
{
deviceAndPreviewPanel.add(preview, BorderLayout.CENTER);
@ -697,7 +701,7 @@ private static void createVideoPreview(
if(((MediaDeviceImpl) mediaDevice).getCaptureDeviceInfo().equals(
device))
{
Dimension videoContainerSize = videoContainer.getSize();
Dimension videoContainerSize = videoContainer.getPreferredSize();
Component preview
= (Component)
mediaService.getVideoPreviewComponent(
@ -716,9 +720,11 @@ private static void createVideoPreview(
* Create preview component.
* @param type type
* @param comboBox the options.
* @param prefSize the preferred size
* @return the component.
*/
private static Component createPreview(int type, final JComboBox comboBox)
private static Component createPreview(int type, final JComboBox comboBox,
Dimension prefSize)
{
JComponent preview = null;
@ -749,6 +755,7 @@ else if (type == DeviceConfigurationComboBoxModel.VIDEO)
noPreview.setVerticalAlignment(SwingConstants.CENTER);
preview = createVideoContainer(noPreview);
preview.setPreferredSize(prefSize);
Object selectedItem = comboBox.getSelectedItem();
CaptureDeviceInfo device = null;

@ -916,8 +916,8 @@ public Object getVideoPreviewComponent(
*/
if ((preferredWidth < 128) || (preferredHeight < 96))
{
preferredHeight = 128;
preferredWidth = 96;
preferredWidth = 128;
preferredHeight = 96;
}
VideoMediaStreamImpl.selectVideoSize(
dataSource,

@ -119,12 +119,28 @@ class FormatInfo
public final double difference;
public final Dimension dimension;
public FormatInfo(VideoFormat format)
{
this.format = format;
Dimension size = format.getSize();
this.dimension = format.getSize();
this.difference = getDifference(this.dimension);
}
public FormatInfo(Dimension size)
{
this.format = null;
this.dimension = size;
this.difference = getDifference(this.dimension);
}
private double getDifference(Dimension size)
{
int width = (size == null) ? 0 : size.width;
double xScale;
@ -145,7 +161,7 @@ else if (height == preferredHeight)
else
yScale = (preferredHeight / (double) height);
difference = Math.abs(1 - Math.min(xScale, yScale));
return Math.abs(1 - Math.min(xScale, yScale));
}
}
@ -193,15 +209,49 @@ public int compare(FormatInfo info0, FormatInfo info1)
if (currentFormat != null)
currentSize = currentFormat.getSize();
// lets choose the closest size to the preferred one
for(Dimension supported :
DeviceConfiguration.SUPPORTED_RESOLUTIONS)
// sort supported resolutions by aspect
FormatInfo[] supportedInfos
= new FormatInfo[
DeviceConfiguration.SUPPORTED_RESOLUTIONS.length];
for (int i = 0; i < supportedInfos.length; i++)
{
supportedInfos[i]
= new FormatInfo(
DeviceConfiguration.SUPPORTED_RESOLUTIONS[i]);
}
Arrays.sort(infos, new Comparator<FormatInfo>()
{
public int compare(FormatInfo info0, FormatInfo info1)
{
return
Double.compare(info0.difference, info1.difference);
}
});
FormatInfo preferredFormat =
new FormatInfo(new Dimension(preferredWidth, preferredHeight));
Dimension closestAspect = null;
// lets choose the closest size to the preferred one,
// finding the first sutable aspect
for(FormatInfo supported : supportedInfos)
{
if(supported.height <= preferredHeight
&& supported.width <= preferredWidth)
currentSize = supported;
// find the first matching aspect
if(preferredFormat.difference > supported.difference)
continue;
else if(closestAspect == null)
closestAspect = supported.dimension;
if(supported.dimension.height <= preferredHeight
&& supported.dimension.width <= preferredWidth)
{
currentSize = supported.dimension;
}
}
if(currentSize == null)
currentSize = closestAspect;
if ((currentSize.width > 0) && (currentSize.height > 0))
{
width = currentSize.width;

Loading…
Cancel
Save