Changes the EncodingConfiguration instance stored in MediaServiceImpl to one which contains global settings. Changes the names of some methods in EncodingConfiguration and MediaService to make their meaning more clear. Adds storeProperties() methods to EncodingConfiguration, makes EncodingsPanel use them.

cusax-fix
Boris Grozev 13 years ago
parent 7a196cf51a
commit 296e39ad9b

@ -13,7 +13,6 @@
import net.java.sip.communicator.util.swing.*;
import org.jitsi.impl.neomedia.*;
import org.jitsi.impl.neomedia.codec.*;
import org.jitsi.impl.neomedia.format.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.service.neomedia.codec.*;
@ -89,7 +88,7 @@ private MediaFormat[] getEncodings()
return encodings;
MediaFormat[] availableEncodings
= encodingConfiguration.getAvailableEncodings(type);
= encodingConfiguration.getAllEncodings(type);
int encodingCount = availableEncodings.length;
if (encodingCount < 1)

@ -639,10 +639,10 @@ public Component createEncodingControls(MediaType mediaType,
{
if(encodingConfiguration == null)
{
encodingConfiguration = getNewEncodingConfiguration();
encodingConfiguration.loadConfig();
encodingConfiguration =
mediaService.getCurrentEncodingConfiguration();
}
if(mediaType == MediaType.AUDIO)
{
return createEncodingControls(
@ -671,10 +671,10 @@ private Component createEncodingControls(int type,
{
if(encodingConfiguration == null)
{
encodingConfiguration = getNewEncodingConfiguration();
encodingConfiguration.loadConfig();
encodingConfiguration
= mediaService.getCurrentEncodingConfiguration();
}
ResourceManagementService resources = NeomediaActivator.getResources();
String key;
@ -1127,11 +1127,16 @@ public void actionPerformed(ActionEvent e)
return centerAdvancedPanel;
}
public EncodingConfiguration getNewEncodingConfiguration()
/**
* Returns the <tt>MediaService</tt> instance
*
* @return the <tt>MediaService</tt> instance
*/
public MediaService getMediaService()
{
return NeomediaServiceUtils
.getMediaServiceImpl().getNewEncodingConfiguration();
return mediaService;
}
/**
* Renders the available resolutions in the combo box.
*/

@ -141,12 +141,12 @@ private SessionDescription createFirstOffer()
}
/**
* Creates a <tt>Vector</tt> containing the <tt>MediaSescription</tt> of
* Creates a <tt>Vector</tt> containing the <tt>MediaDescription</tt>s of
* streams that this handler is prepared to initiate depending on available
* <tt>MediaDevice</tt>s and local on-hold and video transmission
* preferences.
*
* @return a <tt>Vector</tt> containing the <tt>MediaSescription</tt> of
* @return a <tt>Vector</tt> containing the <tt>MediaDescription</tt>s of
* streams that this handler is prepared to initiate.
*
* @throws OperationFailedException if we fail to create the descriptions
@ -176,7 +176,7 @@ private Vector<MediaDescription> createMediaDescriptions()
{
MediaDevice dev = getDefaultDevice(mediaType);
if (dev == null)
if (!isDeviceActive(dev, sendQualityPreset, receiveQualityPreset))
continue;
MediaDirection direction = dev.getDirection().and(
@ -895,7 +895,7 @@ private synchronized void processAnswer(SessionDescription answer)
MediaDevice dev = getDefaultDevice(mediaType);
if(dev == null)
if(!isDeviceActive(dev))
{
closeStream(mediaType);
continue;

@ -1613,17 +1613,22 @@ public boolean isRTPTranslationEnabled()
}
return false;
}
/**
* Returns a list of locally supported <tt>MediaFormat</tt>s for the
* Returns a list of locally supported <tt>MediaFormat</tt>s for the
* given <tt>MediaDevice</tt>, ordered in descending priority. Takes into
* account the configuration obtained from the <tt>ProtocolProvider</tt>
* instance associated this media handler -- if its set up to override the
* global encoding settings, uses that configuration, otherwise uses the
* instance associated this media handler -- if its set up to override the
* global encoding settings, uses that configuration, otherwise uses the
* global configuration.
*
* @param mediaDevice the <tt>MediaDevice</tt>.
* @return a list of locally supported <tt>MediaFormat</tt>s for the
* <tt>MediaDevice</tt> given, in order of priority.
*
* @return a non-null list of locally supported <tt>MediaFormat</tt>s for
* <tt>mediaDevice</tt>, in decreasing order of priority.
*
* @see CallPeerMediaHandler#getLocallySupportedFormats(MediaDevice,
* QualityPreset, QualityPreset)
*/
public List<MediaFormat> getLocallySupportedFormats(MediaDevice mediaDevice)
{
@ -1637,55 +1642,85 @@ public List<MediaFormat> getLocallySupportedFormats(MediaDevice mediaDevice)
* instance associated this media handler -- if its set up to override the
* global encoding settings, uses that configuration, otherwise uses the
* global configuration.
*
* @param mediaDevice the <tt>MediaDevice</tt>.
* @param sendPreset the preset used to set some of the format parameters,
* used for video and settings.
* @param receivePreset the preset used to set the receive format
* parameters, used for video and settings.
* @return a list of locally supported <tt>MediaFormat</tt>s for the
* <tt>MediaDevice</tt> given, in order of priority.
*
* @return a non-null list of locally supported <tt>MediaFormat</tt>s for
* <tt>mediaDevice</tt>, in decreasing order of priority.
*/
public List<MediaFormat> getLocallySupportedFormats(MediaDevice mediaDevice,
QualityPreset sendPreset,
QualityPreset receivePreset)
{
if(mediaDevice == null)
return new LinkedList<MediaFormat>();
boolean accountOverridesEncodings = false;
EncodingConfiguration encodingConfiguration
= ProtocolMediaActivator.getMediaService()
.getNewEncodingConfiguration();
Map<String, String> properties
Map<String, String> accountProperties
= getPeer().getProtocolProvider()
.getAccountID().getAccountProperties();
if(properties.containsKey(ProtocolProviderFactory.OVERRIDE_ENCODINGS)
&& Boolean.parseBoolean(properties.get
(ProtocolProviderFactory.OVERRIDE_ENCODINGS)))
.getAccountID().getAccountProperties();
if(accountProperties.containsKey(ProtocolProviderFactory.OVERRIDE_ENCODINGS)
&& Boolean.parseBoolean(accountProperties.get
(ProtocolProviderFactory.OVERRIDE_ENCODINGS)))
{
accountOverridesEncodings = true;
}
if(accountOverridesEncodings)
if(accountOverridesEncodings) /* use account configuration */
{
Map<String, String> encodingProperties
= new HashMap<String, String>();
for(String key : properties.keySet())
{
if(key.startsWith(ProtocolProviderFactory.ENCODING_PROP_PREFIX
+ "."))
{
encodingProperties.put(key.substring(key.indexOf(".") + 1),
properties.get(key));
}
}
encodingConfiguration.loadProperties(encodingProperties);
EncodingConfiguration encodingConfiguration
= ProtocolMediaActivator.getMediaService().
createEmptyEncodingConfiguration();
encodingConfiguration.loadProperties(accountProperties,
ProtocolProviderFactory.ENCODING_PROP_PREFIX);
return mediaDevice.getSupportedFormats(sendPreset, receivePreset,
encodingConfiguration);
}
else
else /* use global configuration */
{
return mediaDevice.getSupportedFormats(sendPreset, receivePreset);
}
}
/**
* Checks whether <tt>dev</tt> can be used for a call.
*
* @return <tt>true</tt> if the device is not null, and it has at least
* one enabled format. Otherwise <tt>false</tt>
*/
public boolean isDeviceActive(MediaDevice dev)
{
if (dev != null && !getLocallySupportedFormats(dev).isEmpty())
{
encodingConfiguration.loadConfig();
return true;
}
return false;
}
return mediaDevice.getSupportedFormats(sendPreset,
receivePreset,
encodingConfiguration);
/**
* Checks whether <tt>dev</tt> can be used for a call, using
* <tt>sendPreset</tt> and <tt>reveicePreset</tt>
*
* @return <tt>true</tt> if the device is not null, and it has at least
* one enabled format. Otherwise <tt>false</tt>
*/
public boolean isDeviceActive(MediaDevice dev, QualityPreset sendPreset,
QualityPreset receivePreset)
{
if (dev != null &&
!getLocallySupportedFormats(dev,
sendPreset, receivePreset)
.isEmpty())
{
return true;
}
return false;
}
}

@ -30,61 +30,62 @@ public class EncodingsPanel extends TransparentPanel
* logging output.
*/
private static final Logger logger = Logger.getLogger(EncodingsPanel.class);
/**
* The <tt>ResourceManagementService</tt> used by this class
*/
private static ResourceManagementService resourceService
= UtilActivator.getResources();
/**
* The "override global settings" checkbox.
*/
private final JCheckBox overrideCheckBox;
/**
* The <tt>MediaConfiguration</tt> instance we'll use to obtain most of the
* <tt>Component</tt>s for the panel
*/
private final MediaConfigurationService mediaConfiguration;
/**
* A panel to hold the audio encodings table
*/
private JPanel audioPanel;
/**
* The audio encodings table (and "up"/"down" buttons)
*/
private Component audioControls;
/**
* A panel to hold the video encodings table
*/
private JPanel videoPanel;
/**
* The video encodings table (and "up"/"down" buttons)
*/
private Component videoControls;
/**
* Holds the properties we need to get/set for the encoding preferences
*/
private Map<String, String> encodingProperties;
private Map<String, String> encodingProperties
= new HashMap<String, String>();
/**
* An <tt>EncodingConfiguration</tt> we'll be using to manage preferences
* for us
*/
private EncodingConfiguration encodingConfiguration;
/**
* The "reset" button
*/
private JButton resetButton = new JButton(resourceService.getI18NString(
"plugin.jabberaccregwizz.RESET"));
/**
* Builds an object, loads the tables with the global configuration..
*/
@ -98,26 +99,25 @@ public EncodingsPanel()
mediaConfiguration
= UtilActivator.getMediaConfiguration();
//by default (on account creation) use an <tt>EncodingConfiguration</tt>
//loaded with the global preferences
encodingConfiguration
= mediaConfiguration.getNewEncodingConfiguration();
encodingConfiguration.loadConfig();
encodingProperties = encodingConfiguration.getEncodingProperties();
//loaded with the global preferences. But make a new instance, because
//we do not want to change the current one
encodingConfiguration = mediaConfiguration.getMediaService()
.createEmptyEncodingConfiguration();
encodingConfiguration.loadEncodingConfiguration(mediaConfiguration
.getMediaService().getCurrentEncodingConfiguration());
audioControls = mediaConfiguration.
createEncodingControls(MediaType.AUDIO,
encodingConfiguration, false);
videoControls = mediaConfiguration.
createEncodingControls(MediaType.VIDEO,
encodingConfiguration, false);
JPanel mainPanel = new TransparentPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
add(mainPanel, BorderLayout.NORTH);
JPanel checkBoxPanel
= new TransparentPanel(new BorderLayout());
@ -130,13 +130,15 @@ public EncodingsPanel()
{
public void actionPerformed(ActionEvent e)
{
encodingConfiguration =
mediaConfiguration.getNewEncodingConfiguration();
encodingConfiguration.loadConfig();
resetTables(encodingConfiguration);
encodingConfiguration.loadEncodingConfiguration(
mediaConfiguration.getMediaService()
.getCurrentEncodingConfiguration());
encodingConfiguration.storeProperties(encodingProperties,
ProtocolProviderFactory.ENCODING_PROP_PREFIX+".");
resetTables();
}
});
audioPanel = new TransparentPanel(new BorderLayout(10, 10));
audioPanel.setBorder(BorderFactory.createTitledBorder(
resourceService.getI18NString("plugin.jabberaccregwizz.AUDIO")));
@ -151,7 +153,7 @@ public void actionPerformed(ActionEvent e)
mainPanel.add(audioPanel);
mainPanel.add(videoPanel);
}
/**
* Saves the settings we hold in <tt>registration</tt>
* @param registration the <tt>EncodingsRegistration</tt> to use
@ -160,17 +162,12 @@ public void commitPanel(EncodingsRegistration registration)
{
registration.setOverrideEncodings(overrideCheckBox.isSelected());
encodingProperties = encodingConfiguration.getEncodingProperties();
Map<String, String> enc = new HashMap<String, String>();
for(String key : encodingProperties.keySet())
{
enc.put(ProtocolProviderFactory.ENCODING_PROP_PREFIX
+ "." + key,
encodingProperties.get(key));
}
registration.setEncodingProperties(enc);
encodingConfiguration.storeProperties(encodingProperties,
ProtocolProviderFactory.ENCODING_PROP_PREFIX+".");
registration.setEncodingProperties(encodingProperties);
}
/**
* Checks the given <tt>accountProperties</tt> for encoding configuration
* and loads it.
@ -182,44 +179,23 @@ public void loadAccount(Map<String, String> accountProperties)
ProtocolProviderFactory.OVERRIDE_ENCODINGS);
boolean isOverrideEncodings = Boolean.parseBoolean(overrideEncodings);
overrideCheckBox.setSelected(isOverrideEncodings);
encodingProperties = new HashMap<String, String>();
for(String key : accountProperties.keySet())
{
if(key.startsWith(ProtocolProviderFactory.ENCODING_PROP_PREFIX
+ "."))
{
encodingProperties.put(
key.substring(key.indexOf(".") + 1),
accountProperties.get(key));
}
}
if(encodingProperties.isEmpty())
{
//no encoding properties found for this account, leave the table
//as it is (with the global preferences)
}
else
{
//found encodings properties for the account, use them
//get a clean EncodingConfiguration
encodingConfiguration = mediaConfiguration.
getNewEncodingConfiguration();
//load what we found in accountProperties
encodingConfiguration.loadProperties(encodingProperties);
resetTables(encodingConfiguration);
}
encodingConfiguration = mediaConfiguration.getMediaService()
.createEmptyEncodingConfiguration();
encodingConfiguration.loadProperties(accountProperties,
ProtocolProviderFactory.ENCODING_PROP_PREFIX);
encodingConfiguration.storeProperties(encodingProperties,
ProtocolProviderFactory.ENCODING_PROP_PREFIX+".");
resetTables();
}
/**
* Recreates the audio and video controls, necessary when
* Recreates the audio and video controls. Necessary when
* our encodingConfiguration reference has changed.
* @param encodingConfiguration
*/
private void resetTables(EncodingConfiguration encodingConfiguration)
private void resetTables()
{
audioPanel.remove(audioControls);
videoPanel.remove(videoControls);

Loading…
Cancel
Save