* Adding a listener which has already been added does nothing i.e. it is * not added more than once and thus does not receive one and the same * VideoEvent multiple times. *
* * @param listener the VideoListener to be notified when * visual/video Components are being added or removed in this * VideoMediaStream */ public void addVideoListener(VideoListener listener) { videoNotifierSupport.addVideoListener(listener); } /** * Performs any optional configuration on the BufferControl of the * specified RTPManager which is to be used as the * RTPManager of this MediaStreamImpl. * * @param rtpManager the RTPManager which is to be used by this * MediaStreamImpl * @param bufferControl the BufferControl of rtpManager on * which any optional configuration is to be performed */ @Override protected void configureRTPManagerBufferControl( RTPManager rtpManager, BufferControl bufferControl) { bufferControl.setBufferLength(BufferControl.MAX_VALUE); } /** * Creates the visual Component depicting the video being streamed * from the local peer to the remote peer. * * @return the visual Component depicting the video being streamed * from the local peer to the remote peer if it was immediately created or * null if it was not immediately created and it is to be delivered * to the currently registered VideoListeners in a * VideoEvent with type {@link VideoEvent#VIDEO_ADDED} and origin * {@link VideoEvent#LOCAL} */ public Component createLocalVisualComponent() { MediaDeviceSession deviceSession = getDeviceSession(); return (deviceSession instanceof VideoMediaDeviceSession) ? ((VideoMediaDeviceSession) deviceSession) .createLocalVisualComponent() : null; } /** * Notifies this MediaStream that the MediaDevice (and * respectively the MediaDeviceSession with it) which this instance * uses for capture and playback of media has been changed. Makes sure that * the VideoListeners of this instance get VideoEvents for * the new/current VideoMediaDeviceSession and not for the old one. * * @param oldValue the MediaDeviceSession with the * MediaDevice this instance used work with * @param newValue the MediaDeviceSession with the * MediaDevice this instance is to work with * @see MediaStreamImpl#deviceSessionChanged(MediaDeviceSession, * MediaDeviceSession) */ @Override protected void deviceSessionChanged( MediaDeviceSession oldValue, MediaDeviceSession newValue) { super.deviceSessionChanged(oldValue, newValue); if ((oldValue instanceof VideoMediaDeviceSession) && (deviceSessionVideoListener != null)) ((VideoMediaDeviceSession) oldValue) .removeVideoListener(deviceSessionVideoListener); if (newValue instanceof VideoMediaDeviceSession) { if (deviceSessionVideoListener == null) deviceSessionVideoListener = new VideoListener() { /** * Notifies that a visual Component representing * video has been added to the provider this listener has * been added to. * * @param e a VideoEvent describing the added * visual Component representing video and the * provider it was added into * @see VideoListener#videoAdded(VideoEvent) */ public void videoAdded(VideoEvent e) { if (fireVideoEvent( e.getType(), e.getVisualComponent(), e.getOrigin())) e.consume(); } /** * Notifies that a visual Component representing * video has been removed from the provider this listener * has been added to. * * @param e a VideoEvent describing the removed * visual Component representing video and the * provider it was removed from * @see VideoListener#videoRemoved(VideoEvent) */ public void videoRemoved(VideoEvent e) { videoAdded(e); } public void videoUpdate(VideoEvent e) { fireVideoEvent(e); } }; ((VideoMediaDeviceSession) newValue) .addVideoListener(deviceSessionVideoListener); } } /** * Disposes of the visual Component of the local peer. */ public void disposeLocalVisualComponent() { MediaDeviceSession deviceSession = getDeviceSession(); if(deviceSession instanceof VideoMediaDeviceSession) ((VideoMediaDeviceSession) deviceSession) .disposeLocalVisualComponent(); } /** * Notifies the VideoListeners registered with this * VideoMediaStream about a specific type of change in the * availability of a specific visual Component depicting video. * * @param type the type of change as defined by VideoEvent in the * availability of the specified visual Component depicting video * @param visualComponent the visual Component depicting video * which has been added or removed in this VideoMediaStream * @param origin {@link VideoEvent#LOCAL} if the origin of the video is * local (e.g. it is being locally captured); {@link VideoEvent#REMOTE} if * the origin of the video is remote (e.g. a remote peer is streaming it) * @return true if this event and, more specifically, the visual * Component it describes have been consumed and should be * considered owned, referenced (which is important because * Components belong to a single Container at a time); * otherwise, false */ protected boolean fireVideoEvent( int type, Component visualComponent, int origin) { if (logger.isTraceEnabled()) logger .trace( "Firing VideoEvent with type " + VideoEvent.typeToString(type) + " and origin " + VideoEvent.originToString(origin)); return videoNotifierSupport.fireVideoEvent(type, visualComponent, origin); } /** * Notifies the VideoListeners registered with this instance about * a specific VideoEvent. * * @param event the VideoEvent to be fired to the * VideoListeners registered with this instance */ protected void fireVideoEvent(VideoEvent event) { videoNotifierSupport.fireVideoEvent(event); } /** * Returns a reference to the visual Component where video from the * remote peer is being rendered or null if no video is currently * rendered. * * @return a reference to the visual Component where video from * the remote peer is being rendered or null if no video is * currently rendered */ public Component getVisualComponent() { MediaDeviceSession deviceSession = getDeviceSession(); return (deviceSession instanceof VideoMediaDeviceSession) ? ((VideoMediaDeviceSession) deviceSession).getVisualComponent() : null; } /** * Registers {@link Constants#H264_RTP} with a specific RTPManager. * * @param rtpManager the RTPManager to register * {@link Constants#H264_RTP} with * @see MediaStreamImpl#registerCustomCodecFormats(RTPManager) */ @Override protected void registerCustomCodecFormats(RTPManager rtpManager) { super.registerCustomCodecFormats(rtpManager); // if we have already registered custom formats and we are running JMF // we bail out. if (!FMJConditionals.REGISTER_FORMATS_WITH_EVERY_RTP_MANAGER && formatsRegisteredOnce) return; // We do not have formats to register right now. formatsRegisteredOnce = true; } /** * Removes a specific VideoListener from this * VideoMediaStream in order to have to no longer receive * notifications when visual/video Components are being added and * removed. * * @param listener the VideoListener to no longer be notified when * visual/video Components are being added or removed in this * VideoMediaStream */ public void removeVideoListener(VideoListener listener) { videoNotifierSupport.removeVideoListener(listener); } /** * Sets the MediaDevice that this stream should use to play back * and capture media. ** Note: Also resets any previous direction set with * {@link #setDirection(MediaDirection)} to the direction of the specified * MediaDevice. *
* * @param device the MediaDevice that this stream should use to * play back and capture media * @see MediaStream#setDevice(MediaDevice) */ public void setDevice(MediaDevice device) { super.setDevice(device); ((VideoMediaDeviceSession)deviceSession).setOutputSize(outputSize); } /** * Set negociated output size. * * @param size output size of video stream */ public void setOutputSize(Dimension size) { outputSize = size; } }