[sip-comm-dev] Re: svn commit: r4757 - trunk/src/net/java/sip/communicator/impl/media: . codec


#1

Hi,

As I saw the changes I have tested the video preview in the config form. And I can tell
that under macosx the cpu usage is decreased by half.

damencho

Emil Ivov wrote:

···

Hey Lubo,

I was wondering if this helped. Do we have better video performance now?

Emil

--sent from my mobile

On 27 nov. 08, at 11:10, lubomir_m@dev.java.net wrote:

Author: lubomir_m
Date: 2008-11-27 10:10:46+0000
New Revision: 4757

Modified:
  trunk/src/net/java/sip/communicator/impl/media/MediaConfigurationPanel.java

  trunk/src/net/java/sip/communicator/impl/media/MediaControl.java
  trunk/src/net/java/sip/communicator/impl/media/codec/Constants.java

Log:
Sets the size of the video capture according to the size of the area in which it is to be previewed in the Media ConfigurationForm in hope of getting better performance.

Modified: trunk/src/net/java/sip/communicator/impl/media/MediaConfigurationPanel.java

Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/media/MediaConfigurationPanel.java?view=diff&rev=4757&p1=trunk/src/net/java/sip/communicator/impl/media/MediaConfigurationPanel.java&p2=trunk/src/net/java/sip/communicator/impl/media/MediaConfigurationPanel.java&r1=4756&r2=4757

==============================================================================

--- trunk/src/net/java/sip/communicator/impl/media/MediaConfigurationPanel.java (original)
+++ trunk/src/net/java/sip/communicator/impl/media/MediaConfigurationPanel.java 2008-11-27 10:10:46+0000
@@ -11,6 +11,7 @@
import java.io.*;

import javax.media.*;
+import javax.media.protocol.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
@@ -271,11 +272,34 @@
        if (device == null)
            return;

- Player player = null;
+ DataSource dataSource = null;
        Exception exception = null;
        try
        {
- player = Manager.createPlayer(device.getLocator());
+ dataSource = Manager.createDataSource(device.getLocator());
+ }
+ catch (IOException ex)
+ {
+ exception = ex;
+ }
+ catch (NoDataSourceException ex)
+ {
+ exception = ex;
+ }
+ if (exception != null)
+ {
+ logger.error("Failed to create preview for device " + device,
+ exception);
+ return;
+ }
+
+ Dimension size = videoContainer.getPreferredSize();
+ MediaControl.selectVideoSize(dataSource, size.width, size.height);
+
+ Player player = null;
+ try
+ {
+ player = Manager.createPlayer(dataSource);
        }
        catch (IOException ex)
        {

Modified: trunk/src/net/java/sip/communicator/impl/media/MediaControl.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/media/MediaControl.java?view=diff&rev=4757&p1=trunk/src/net/java/sip/communicator/impl/media/MediaControl.java&p2=trunk/src/net/java/sip/communicator/impl/media/MediaControl.java&r1=4756&r2=4757

==============================================================================

--- trunk/src/net/java/sip/communicator/impl/media/MediaControl.java (original)
+++ trunk/src/net/java/sip/communicator/impl/media/MediaControl.java 2008-11-27 10:10:46+0000
@@ -33,7 +33,7 @@
*/
public class MediaControl
{
- private final Logger logger = Logger.getLogger(MediaControl.class);
+ private static final Logger logger = Logger.getLogger(MediaControl.class);

    /**
     * Our device configuration helper.
@@ -997,48 +997,92 @@
    }

    /**
- * Selects the nearest size supported by the capture device,
- * to make drivers scale the images.
+ * Selects the nearest size supported by the capture device, to make drivers
+ * scale the images.
     *
- * @param videoDS the video datasource
+ * @param videoDS the video <code>DataSource</code>
     */
    private void selectVideoSize(DataSource videoDS)
    {
- FormatControl fControl =
- (FormatControl)videoDS.getControl(FormatControl.class.getName());
+ selectVideoSize(videoDS, Constants.VIDEO_WIDTH, Constants.VIDEO_HEIGHT);
+ }

- if(fControl == null)
- return;
+ public static Dimension selectVideoSize(DataSource videoDS,
+ final int preferredWidth, final int preferredHeight)
+ {
+ FormatControl formatControl =
+ (FormatControl) videoDS.getControl(FormatControl.class.getName());

- // On MacOSX isight camera reports two sizes 640x480 and 320x240
- // if we use the default size 352x288 we must use source format 640x480
- // in this situation we suffer from high cpu usage as every frame is
- // scaled, so we use the non standard format 320x240.
- String osName = System.getProperty("os.name");
- if (osName.startsWith("Mac"))
- {
- Constants.VIDEO_WIDTH = 320;
- Constants.VIDEO_HEIGHT = 240;
- }
+ if (formatControl == null)
+ return null;
+
+ Format[] formats = formatControl.getSupportedFormats();
+ final int count = formats.length;
+
+ if (count < 1)
+ return null;
+
+ Format selectedFormat = null;

- Format targetFormat = null;
- double targetWidth = Constants.VIDEO_WIDTH;
-
- Format[] fs = fControl.getSupportedFormats();
- for (int i = 0; i < fs.length; i++)
+ if (count == 1)
+ selectedFormat = formats[0];
+ else
        {
- VideoFormat format = (VideoFormat)fs[i];
+ class FormatInfo
+ {
+ public final VideoFormat format;
+
+ public final double difference;
+
+ public FormatInfo(VideoFormat format)
+ {
+ this.format = format;
+
+ Dimension size = format.getSize();

- Dimension size = format.getSize();
- if(size.getWidth() >= Constants.VIDEO_WIDTH
- && size.getWidth() <= targetWidth)
+ int width = size.width;
+ double xScale =
+ (width == preferredWidth) ? 1
+ : (preferredWidth / (double) width);
+
+ int height = size.height;
+ double yScale =
+ (height == preferredHeight) ? 1 : preferredHeight
+ / (double) height;
+
+ difference = Math.abs(1 - Math.min(xScale, yScale));
+ }
+ }
+
+ FormatInfo[] infos = new FormatInfo[count];
+
+ for (int i = 0; i < count; i++)
            {
- targetFormat = format;
+ FormatInfo info =
+ infos[i] = new FormatInfo((VideoFormat) formats[i]);
+
+ if (info.difference == 0)
+ {
+ selectedFormat = info.format;
+ break;
+ }
+ }
+ if (selectedFormat == null)
+ {
+ Arrays.sort(infos, new Comparator<FormatInfo>()
+ {
+ public int compare(FormatInfo info0, FormatInfo info1)
+ {
+ return Double.compare(info0.difference,
+ info1.difference);
+ }
+ });
+ selectedFormat = infos[0].format;
            }
        }

- if(targetFormat != null)
- fControl.setFormat(targetFormat);
+ formatControl.setFormat(selectedFormat);
+ return ((VideoFormat) selectedFormat).getSize();
    }

    public DataSource createLocalVideoDataSource()

Modified: trunk/src/net/java/sip/communicator/impl/media/codec/Constants.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/trunk/src/net/java/sip/communicator/impl/media/codec/Constants.java?view=diff&rev=4757&p1=trunk/src/net/java/sip/communicator/impl/media/codec/Constants.java&p2=trunk/src/net/java/sip/communicator/impl/media/codec/Constants.java&r1=4756&r2=4757

==============================================================================

--- trunk/src/net/java/sip/communicator/impl/media/codec/Constants.java (original)
+++ trunk/src/net/java/sip/communicator/impl/media/codec/Constants.java 2008-11-27 10:10:46+0000
@@ -28,6 +28,27 @@
     */
    public static int ILBC_MODE = 30;

- public static int VIDEO_WIDTH = 352;
- public static int VIDEO_HEIGHT = 288;
+ public static final int VIDEO_WIDTH;
+ public static final int VIDEO_HEIGHT;
+
+ static
+ {
+
+ /*
+ * On Mac OS X, the Apple iSight camera reports two sizes 640x480 and
+ * 320x240 if we use the default size 352x288 we must use source format
+ * 640x480 in this situation we suffer from high cpu usage as every
+ * frame is scaled, so we use the non standard format 320x240.
+ */
+ if (System.getProperty("os.name").startsWith("Mac"))
+ {
+ VIDEO_WIDTH = 320;
+ VIDEO_HEIGHT = 240;
+ }
+ else
+ {
+ VIDEO_WIDTH = 352;
+ VIDEO_HEIGHT = 288;
+ }
+ }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: commits-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net