Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.neomedia.jmfext.media.renderer.video
Class JAWTRenderer

java.lang.Object
  extended by net.java.sip.communicator.impl.neomedia.control.AbstractControls
      extended by net.java.sip.communicator.impl.neomedia.control.ControlsAdapter
          extended by net.java.sip.communicator.impl.neomedia.jmfext.media.renderer.AbstractRenderer<javax.media.format.VideoFormat>
              extended by net.java.sip.communicator.impl.neomedia.jmfext.media.renderer.video.JAWTRenderer
All Implemented Interfaces:
javax.media.Controls, javax.media.PlugIn, javax.media.Renderer, javax.media.renderer.VideoRenderer

public class JAWTRenderer
extends AbstractRenderer<javax.media.format.VideoFormat>
implements javax.media.renderer.VideoRenderer

Implements a VideoRenderer which uses JAWT to perform native painting in an AWT or Swing Component.

Author:
Lyubomir Marinov

Field Summary
 
Fields inherited from class net.java.sip.communicator.impl.neomedia.jmfext.media.renderer.AbstractRenderer
inputFormat
 
Fields inherited from class net.java.sip.communicator.impl.neomedia.control.ControlsAdapter
EMPTY_CONTROLS
 
Fields inherited from interface javax.media.PlugIn
BUFFER_PROCESSED_FAILED, BUFFER_PROCESSED_OK, INPUT_BUFFER_NOT_CONSUMED, OUTPUT_BUFFER_NOT_FILLED, PLUGIN_TERMINATED
 
Constructor Summary
JAWTRenderer()
          Initializes a new JAWTRenderer instance.
 
Method Summary
(package private) static void addNotifyLightweightComponent(long handle, Component component, long parentHandle)
           
 void close()
          Closes this PlugIn and releases the resources it has retained during its execution.
(package private) static void close(long handle, Component component)
          Closes the native counterpart of a JAWTRenderer specified by its handle as returned by open(Component) and rendering into a specific AWT Component.
 Rectangle getBounds()
          Gets the region in the component of this VideoRenderer where the video is rendered.
 Component getComponent()
          Gets the AWT Component into which this VideoRenderer draws.
(package private)  long getHandle()
          Gets the handle to the native counterpart of this JAWTRenderer.
(package private)  Object getHandleLock()
          Gets the Object which synchronizes the access to the handle to the native counterpart of this JAWTRenderer.
 String getName()
          Gets the human-readable name of this PlugIn.
 javax.media.Format[] getSupportedInputFormats()
          Gets the list of input Formats supported by this Renderer.
 void open()
          Opens this PlugIn and acquires the resources that it needs to operate.
(package private) static long open(Component component)
          Opens a handle to a native counterpart of a JAWTRenderer which is to draw into a specific AWT Component.
(package private) static boolean paint(long handle, Component component, Graphics g)
          Paints a specific Component which is the AWT Component of a JAWTRenderer specified by the handle to its native counterpart.
(package private) static boolean paintLightweightComponent(long handle, Component component, Graphics g)
           
 int process(javax.media.Buffer buffer)
          Processes the data provided in a specific Buffer and renders it to the output device represented by this Renderer.
(package private) static boolean process(long handle, Component component, int[] data, int offset, int length, int width, int height)
          Processes the data provided in a specific int array with a specific offset and length and renders it to the output device represented by a JAWTRenderer specified by the handle to it native counterpart.
(package private) static void processLightweightComponentEvent(long handle, int x, int y, int width, int height)
           
(package private) static void removeNotifyLightweightComponent(long handle, Component component)
           
 void setBounds(Rectangle bounds)
          Sets the region in the component of this VideoRenderer where the video is to be rendered.
 boolean setComponent(Component component)
          Sets the AWT Component into which this VideoRenderer is to draw.
 javax.media.Format setInputFormat(javax.media.Format format)
          Sets the Format of the input to be processed by this Renderer.
 void start()
          Starts the rendering process.
 void stop()
          Stops the rendering process.
 
Methods inherited from class net.java.sip.communicator.impl.neomedia.jmfext.media.renderer.AbstractRenderer
reset
 
Methods inherited from class net.java.sip.communicator.impl.neomedia.control.ControlsAdapter
getControls
 
Methods inherited from class net.java.sip.communicator.impl.neomedia.control.AbstractControls
getControl, getControl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.media.PlugIn
reset
 
Methods inherited from interface javax.media.Controls
getControl, getControls
 

Constructor Detail

JAWTRenderer

public JAWTRenderer()
Initializes a new JAWTRenderer instance.

Method Detail

addNotifyLightweightComponent

static void addNotifyLightweightComponent(long handle,
                                          Component component,
                                          long parentHandle)

close

public void close()
Closes this PlugIn and releases the resources it has retained during its execution. No more data will be accepted by this PlugIn afterwards. A closed PlugIn can be reinstated by calling open again.

Specified by:
close in interface javax.media.PlugIn

close

static void close(long handle,
                  Component component)
Closes the native counterpart of a JAWTRenderer specified by its handle as returned by open(Component) and rendering into a specific AWT Component. Releases the resources which the specified native counterpart has retained during its execution and its handle is considered to be invalid afterwards.

Parameters:
handle - the handle to the native counterpart of a JAWTRenderer as returned by open(Component) which is to be closed
component - the AWT Component into which the JAWTRenderer and its native counterpart are drawing. The platform-specific info of component is not guaranteed to be valid.

getBounds

public Rectangle getBounds()
Gets the region in the component of this VideoRenderer where the video is rendered.

Specified by:
getBounds in interface javax.media.renderer.VideoRenderer
Returns:
the region in the component of this VideoRenderer where the video is rendered; null if the entire component is used

getComponent

public Component getComponent()
Gets the AWT Component into which this VideoRenderer draws.

Specified by:
getComponent in interface javax.media.renderer.VideoRenderer
Returns:
the AWT Component into which this VideoRenderer draws

getHandle

long getHandle()
Gets the handle to the native counterpart of this JAWTRenderer.

Returns:
the handle to the native counterpart of this JAWTRenderer

getHandleLock

Object getHandleLock()
Gets the Object which synchronizes the access to the handle to the native counterpart of this JAWTRenderer.

Returns:
the Object which synchronizes the access to the handle to the native counterpart of this JAWTRenderer

getName

public String getName()
Gets the human-readable name of this PlugIn.

Specified by:
getName in interface javax.media.PlugIn
Returns:
the human-readable name of this PlugIn

getSupportedInputFormats

public javax.media.Format[] getSupportedInputFormats()
Gets the list of input Formats supported by this Renderer.

Specified by:
getSupportedInputFormats in interface javax.media.Renderer
Returns:
an array of Format elements which represent the input Formats supported by this Renderer

open

public void open()
          throws javax.media.ResourceUnavailableException
Opens this PlugIn and acquires the resources that it needs to operate. The input format of this Renderer has to be set before open is called. Buffers should not be passed into this PlugIn without first calling open.

Specified by:
open in interface javax.media.PlugIn
Throws:
javax.media.ResourceUnavailableException - if there is a problem during opening

open

static long open(Component component)
          throws javax.media.ResourceUnavailableException
Opens a handle to a native counterpart of a JAWTRenderer which is to draw into a specific AWT Component.

Parameters:
component - the AWT Component into which a JAWTRenderer and the native counterpart to be opened are to draw. The platform-specific info of component is not guaranteed to be valid.
Returns:
a handle to a native counterpart of a JAWTRenderer which is to draw into the specified AWT Component
Throws:
javax.media.ResourceUnavailableException - if there is a problem during opening

paint

static boolean paint(long handle,
                     Component component,
                     Graphics g)
Paints a specific Component which is the AWT Component of a JAWTRenderer specified by the handle to its native counterpart.

Parameters:
handle - the handle to the native counterpart of a JAWTRenderer which is to draw into the specified AWT Component
component - the AWT Component into which the JAWTRenderer and its native counterpart specified by handle are to draw. The platform-specific info of component is guaranteed to be valid only during the execution of paint.
g - the Graphics context into which the drawing is to be performed
Returns:
true if the native counterpart of a JAWTRenderer wants to continue receiving the paint calls on the AWT Component; otherwise, false. For example, after the native counterpart has been able to acquire the native handle of the AWT Component, it may be able to determine when the native handle needs painting without waiting for AWT to call paint on the Component. In such a scenario, the native counterpart may indicate with false that it does not need further paint deliveries.

paintLightweightComponent

static boolean paintLightweightComponent(long handle,
                                         Component component,
                                         Graphics g)

process

public int process(javax.media.Buffer buffer)
Processes the data provided in a specific Buffer and renders it to the output device represented by this Renderer.

Specified by:
process in interface javax.media.Renderer
Parameters:
buffer - a Buffer containing the data to be processed and rendered
Returns:
BUFFER_PROCESSED_OK if the processing is successful; otherwise, the other possible return codes defined in the PlugIn interface

process

static boolean process(long handle,
                       Component component,
                       int[] data,
                       int offset,
                       int length,
                       int width,
                       int height)
Processes the data provided in a specific int array with a specific offset and length and renders it to the output device represented by a JAWTRenderer specified by the handle to it native counterpart.

Parameters:
handle - the handle to the native counterpart of a JAWTRenderer to process the specified data and render it
component - the AWT component into which the specified JAWTRenderer and its native counterpart draw
data - an int array which contains the data to be processed and rendered
offset - the index in data at which the data to be processed and rendered starts
length - the number of elements in data starting at offset which represent the data to be processed and rendered
width - the width of the video frame in data
height - the height of the video frame in data
Returns:
true if data has been successfully processed

processLightweightComponentEvent

static void processLightweightComponentEvent(long handle,
                                             int x,
                                             int y,
                                             int width,
                                             int height)

removeNotifyLightweightComponent

static void removeNotifyLightweightComponent(long handle,
                                             Component component)

setBounds

public void setBounds(Rectangle bounds)
Sets the region in the component of this VideoRenderer where the video is to be rendered.

Specified by:
setBounds in interface javax.media.renderer.VideoRenderer
Parameters:
bounds - the region in the component of this VideoRenderer where the video is to be rendered; null if the entire component is to be used

setComponent

public boolean setComponent(Component component)
Sets the AWT Component into which this VideoRenderer is to draw. JAWTRenderer cannot draw into any other AWT Component but its own so it always returns false.

Specified by:
setComponent in interface javax.media.renderer.VideoRenderer
Parameters:
component - the AWT Component into which this VideoRenderer is to draw
Returns:
true if this VideoRenderer accepted the specified component as the AWT Component into which it is to draw; false, otherwise

setInputFormat

public javax.media.Format setInputFormat(javax.media.Format format)
Sets the Format of the input to be processed by this Renderer.

Specified by:
setInputFormat in interface javax.media.Renderer
Overrides:
setInputFormat in class AbstractRenderer<javax.media.format.VideoFormat>
Parameters:
format - the Format to be set as the Format of the input to be processed by this Renderer
Returns:
the Format of the input to be processed by this Renderer if the specified format is supported or null if the specified format is not supported by this Renderer. Typically, it is the supported input Format which most closely matches the specified Format.

start

public void start()
Starts the rendering process. Begins rendering any data available in the internal buffers of this Renderer.

Specified by:
start in interface javax.media.Renderer

stop

public void stop()
Stops the rendering process.

Specified by:
stop in interface javax.media.Renderer

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.