Bring back local video in video calls.

cusax-fix
Sebastien Vincent 17 years ago
parent 2182206795
commit fcc49f357e

@ -310,6 +310,33 @@ protected boolean fireVideoEvent(
videoNotifierSupport.fireVideoEvent(type, visualComponent, origin);
}
/**
* Gets local visual <tt>Component</tt> of the local peer.
*
* @return visual <tt>Component</tt>
*/
public Component createLocalVisualComponent()
{
MediaDeviceSession deviceSession = getDeviceSession();
return
(deviceSession instanceof VideoMediaDeviceSession)
? ((VideoMediaDeviceSession) deviceSession).createLocalVisualComponent()
: null;
}
/**
* Dispose local visual <tt>Component</tt> of the local peer.
*/
public void disposeLocalVisualComponent()
{
MediaDeviceSession deviceSession = getDeviceSession();
if(deviceSession instanceof VideoMediaDeviceSession)
{
((VideoMediaDeviceSession) deviceSession).disposeLocalVisualComponent();
}
}
/**
* Returns a reference to the visual <tt>Component</tt> where video from the
* remote peer is being rendered or <tt>null</tt> if no video is currently

@ -9,7 +9,9 @@
import java.awt.*;
import javax.media.*;
import javax.media.protocol.*;
import net.java.sip.communicator.impl.neomedia.*;
import net.java.sip.communicator.service.neomedia.*;
import net.java.sip.communicator.service.neomedia.event.*;
import net.java.sip.communicator.util.*;
@ -37,6 +39,11 @@ public class VideoMediaDeviceSession
private final VideoNotifierSupport videoNotifierSupport
= new VideoNotifierSupport(this);
/**
* Local <tt>Player</tt> for the local video.
*/
private Player localPlayer = null;
/**
* Initializes a new <tt>VideoMediaDeviceSession</tt> instance which is to
* represent the work of a <tt>MediaStream</tt> with a specific video
@ -69,6 +76,23 @@ public void addVideoListener(VideoListener listener)
videoNotifierSupport.addVideoListener(listener);
}
/**
* Creates the <tt>DataSource</tt> that this instance is to read captured
* media from.
*
* @return the <tt>DataSource</tt> that this instance is to read captured
* media from
*/
@Override
protected DataSource createCaptureDevice()
{
/* create our DataSource as Cloneable so we can both use it
* to display local video and stream to remote peer
*/
DataSource captureDevice = Manager.createCloneableDataSource(getDevice().createOutputDataSource());
return captureDevice;
}
/**
* Asserts that a specific <tt>MediaDevice</tt> is acceptable to be set as
* the <tt>MediaDevice</tt> of this instance. Makes sure that its
@ -149,6 +173,148 @@ protected boolean fireVideoEvent(
videoNotifierSupport.fireVideoEvent(type, visualComponent, origin);
}
/**
* Get the local <tt>Player</tt> if it exists,
* create it otherwise
* @return local <tt>Player</tt>
*/
private Player getLocalPlayer()
{
DataSource dataSource = ((SourceCloneable)getCaptureDevice()).createClone();
/* create local player */
if (localPlayer == null && dataSource != null)
{
Exception excpt = null;
try
{
localPlayer = Manager.createPlayer(dataSource);
}
catch (Exception ex)
{
excpt = ex;
}
if(excpt == null)
{
localPlayer.addControllerListener(new ControllerListener()
{
public void controllerUpdate(ControllerEvent event)
{
controllerUpdateForCreateLocalVisualComponent(event);
}
});
localPlayer.start();
}
else
{
logger.error("Failed to connect to "
+ MediaStreamImpl.toString(dataSource),
excpt);
}
}
return localPlayer;
}
/**
* Gets notified about <tt>ControllerEvent</tt>s generated by
* {@link #player}.
*
* @param event the <tt>ControllerEvent</tt> specifying the
* <tt>Controller</tt> which is the source of the event and the very type of
* the event
*/
private void controllerUpdateForCreateLocalVisualComponent(
ControllerEvent controllerEvent)
{
if (controllerEvent instanceof RealizeCompleteEvent)
{
Player player = (Player) controllerEvent.getSourceController();
Component visualComponent = player.getVisualComponent();
if (visualComponent != null)
{
if(!fireVideoEvent(
VideoEvent.VIDEO_ADDED,
visualComponent,
VideoEvent.LOCAL))
{
/* no listener interrested by our event
* free resources
*/
if(player == localPlayer)
{
localPlayer = null;
}
player.stop();
player.deallocate();
player.close();
}
}
}
}
/**
* Gets local visual <tt>Component</tt> of the local peer.
*
* @return visual <tt>Component</tt>
*/
public Component createLocalVisualComponent()
{
Player player = getLocalPlayer();
return null;
}
/**
* Dispose local visual <tt>Component</tt> of the local peer.
*/
public void disposeLocalVisualComponent()
{
Player player = getLocalPlayer();
if(player != null)
{
disposeLocalPlayer(player);
}
}
/**
* Releases the resources allocated by a specific local <tt>Player</tt> in the
* course of its execution and prepares it to be garbage collected. If the
* specified <tt>Player</tt> is rendering video, notifies the
* <tt>VideoListener</tt>s of this instance that its visual
* <tt>Component</tt> is to no longer be used by firing a
* {@link VideoEvent#VIDEO_REMOVED} <tt>VideoEvent</tt>.
*
* @param player the <tt>Player</tt> to dispose of
* @see MediaDeviceSession#disposePlayer(Player)
*/
protected void disposeLocalPlayer(Player player)
{
/*
* The player is being disposed so let the (interested) listeners know
* its Player#getVisualComponent() (if any) should be released.
*/
Component visualComponent = getVisualComponent(player);
if(localPlayer == player)
{
localPlayer = null;
}
player.stop();
player.deallocate();
player.close();
if (visualComponent != null)
fireVideoEvent(
VideoEvent.VIDEO_REMOVED,
visualComponent,
VideoEvent.LOCAL);
}
/**
* Returns the visual <tt>Component</tt> where video from the remote peer
* is being rendered or <tt>null</tt> if no video is currently rendered.

@ -344,8 +344,15 @@ public CallPeerMediaHandler(CallPeerSipImpl peer)
*/
public void setLocalVideoTransmissionEnabled(boolean enabled)
{
MediaDirection oldValue = videoDirectionUserPreference;
MediaDirection newValue = null;
videoDirectionUserPreference
= enabled ? MediaDirection.SENDRECV : MediaDirection.RECVONLY;
newValue = videoDirectionUserPreference;
firePropertyChange(OperationSetVideoTelephony.LOCAL_VIDEO_STREAMING, oldValue, newValue);
}
/**
@ -1886,6 +1893,29 @@ protected boolean fireVideoEvent(
return consumed;
}
/**
* Gets local visual <tt>Component</tt> of the local peer.
*
* @return visual <tt>Component</tt>
*/
public Component createLocalVisualComponent()
{
return (videoStream == null || !isLocalVideoTransmissionEnabled()) ? null : videoStream.createLocalVisualComponent();
}
/**
* Dispose local visual <tt>Component</tt> of the local peer.
*
* @return visual <tt>Component</tt>
*/
public void disposeLocalVisualComponent()
{
if(videoStream != null)
{
videoStream.disposeLocalVisualComponent();
}
}
/**
* Gets the visual <tt>Component</tt> in which video from the remote peer is
* currently being rendered or <tt>null</tt> if there is currently no video

@ -1507,9 +1507,9 @@ public void propertyChange(PropertyChangeEvent event)
listener.propertyChange(thisEvent);
}
};
// getMediaHandler()
// .addPropertyChangeListener(
// mediaHandlerPropertyChangeListener);
getMediaHandler()
.addPropertyChangeListener(
mediaHandlerPropertyChangeListener);
}
}
}

@ -89,26 +89,8 @@ public Component createLocalVisualComponent(
VideoListener listener)
throws OperationFailedException
{
/**
* @todo update to neomedia.
CallSession callSession =((CallPeerSipImpl) peer).getMediaCallSession();
if (callSession != null)
{
try
{
return callSession.createLocalVisualComponent(listener);
}
catch (MediaException ex)
{
throw new OperationFailedException(
"Failed to create visual Component for local "
+"video (capture).",
OperationFailedException.INTERNAL_ERROR, ex);
}
}
*/
return null;
CallPeerMediaHandler mediaHandler = ((CallPeerSipImpl) peer).getMediaHandler();
return mediaHandler.createLocalVisualComponent();
}
/**
@ -122,13 +104,8 @@ public Component createLocalVisualComponent(
*/
public void disposeLocalVisualComponent(CallPeer peer, Component component)
{
/**
* @todo update to neomedia.
CallSession callSession =((CallPeerSipImpl) peer).getMediaCallSession();
if (callSession != null)
callSession.disposeLocalVisualComponent(component);
*/
CallPeerMediaHandler mediaHandler = ((CallPeerSipImpl) peer).getMediaHandler();
mediaHandler.disposeLocalVisualComponent();
}
/**

@ -20,6 +20,18 @@
public interface VideoMediaStream
extends MediaStream
{
/**
* Gets local visual <tt>Component</tt> of the local peer.
*
* @return visual <tt>Component</tt>
*/
public Component createLocalVisualComponent();
/**
* Dispose local visual <tt>Component</tt> of the local peer.
*/
public void disposeLocalVisualComponent();
/**
* Returns a reference to the visual <tt>Component</tt> where video from the
* remote peer is being rendered or <tt>null</tt> if no video is currently

Loading…
Cancel
Save