Skip to content
Snippets Groups Projects
VideoMediaStreamImpl.java 42.8 KiB
Newer Older
    @Override
    protected int getPriority()
    {
        return 5;
    }

    /**
     * Implements {@link VideoMediaStream#getKeyFrameControl()}.
     *
     * {@inheritDoc}
     * @see VideoMediaStream#getKeyFrameControl()
     */
    public KeyFrameControl getKeyFrameControl()
    {
        if (keyFrameControl == null)
            keyFrameControl = new KeyFrameControlAdapter();
        return keyFrameControl;
    }

    /**
     * Gets the <tt>QualityControl</tt> of this <tt>VideoMediaStream</tt>.
     *
     * @return the <tt>QualityControl</tt> of this <tt>VideoMediaStream</tt>
     */
    public QualityControl getQualityControl()
    {
        return qualityControl;
    }

    /**
     * Updates the <tt>QualityControl</tt> of this <tt>VideoMediaStream</tt>.
     *
     * @param advancedParams parameters of advanced attributes that may affect
     * quality control
     */
    public void updateQualityControl(
        Map<String, String> advancedParams)
    {
        for(Map.Entry<String, String> entry : advancedParams.entrySet())
        {
            if(entry.getKey().equals("imageattr"))
            {
                Dimension res[] = parseSendRecvResolution(entry.getValue());

                if(res != null)
                {
                    qualityControl.setRemoteSendMaxPreset(
                        new QualityPreset(res[0]));
                    qualityControl.setRemoteReceiveResolution(
                        res[1]);
                    outputSize = res[1];
                    ((VideoMediaDeviceSession)getDeviceSession()).
                        setOutputSize(outputSize);
                }
            }
        }
    }

    /**
     * Move origin of a partial desktop streaming <tt>MediaDevice</tt>.
     *
     * @param x new x coordinate origin
     * @param y new y coordinate origin
     */
    public void movePartialDesktopStreaming(int x, int y)
    {
        MediaDeviceImpl dev = (MediaDeviceImpl)getDevice();

        if(!dev.getCaptureDeviceInfo().getLocator().getProtocol().equals(
                DeviceSystem.LOCATOR_PROTOCOL_IMGSTREAMING))
            return;

        /* To move origin of the desktop capture, we need to access the
         * JMF DataSource of imgstreaming
         */
        VideoMediaDeviceSession session =
            (VideoMediaDeviceSession)getDeviceSession();

        DataSource ds = session.getCaptureDevice();
        if(ds instanceof RewritablePullBufferDataSource)
        {
            RewritablePullBufferDataSource ds2 =
                (RewritablePullBufferDataSource)ds;
            ds = ds2.getWrappedDataSource();
        }

        // Makes the screen detection with a point inside a real screen i.e.
        // x and y are both greater than or equal to 0.
        ScreenDevice screen
            = NeomediaServiceUtils.getMediaServiceImpl().getScreenForPoint(
                    new Point((x < 0) ? 0 : x, (y < 0) ? 0 : y));
        if (screen != null)
        {
            Rectangle bounds = ((ScreenDeviceImpl)screen).getBounds();
            x -= bounds.x;
            y -= bounds.y;
            ((org.jitsi.impl.neomedia.jmfext.media.protocol.imgstreaming.DataSource)
                    ds)
                .setOrigin(0, screen.getIndex(), x, y);
        }
    }

    /**
     * Implements the <tt>QualityControl</tt> of this <tt>VideoMediaStream</tt>.
     *
     * @author Damian Minkov
     */
    private class QualityControlImpl
        implements QualityControl
    {
        /**
         * The current used preset.
         */
        private QualityPreset preset;

        /**
         * The minimum values for resolution, framerate ...
         */
        private QualityPreset minPreset;

        /**
         * The maximum values for resolution, framerate ...
         */
        private QualityPreset maxPreset;

        /**
         * This is the local settings from the config panel.
         */
        private QualityPreset localSettingsPreset;

        /**
         * Sets the preset.
         * @param preset the desired video settings
         * @throws OperationFailedException
         */
        private void setRemoteReceivePreset(QualityPreset preset)
            throws OperationFailedException
        {
            if(preset.compareTo(getPreferredSendPreset()) > 0)
                this.preset = getPreferredSendPreset();
            else
            {
                this.preset = preset;

                if(logger.isInfoEnabled()
                    && preset != null && preset.getResolution() != null)
                {
                    logger.info("video send resolution: "
                        + preset.getResolution().width + "x"
                            + preset.getResolution().height);
                }
            }
        }

        /**
         * The current preset.
         * @return the current preset
         */
        public QualityPreset getRemoteReceivePreset()
        {
            return preset;
        }

        /**
         * The minimum resolution values for remote part.
         * @return minimum resolution values for remote part.
         */
        public QualityPreset getRemoteSendMinPreset()
        {
            return minPreset;
        }

        /**
         * The max resolution values for remote part.
         * @return max resolution values for remote part.
         */
        public QualityPreset getRemoteSendMaxPreset()
        {
            return maxPreset;
        }

        /**
         * Does nothing specific locally.
         *
         * @param preset the max preset
         * @throws OperationFailedException not thrown.
         */
        public void setPreferredRemoteSendMaxPreset(QualityPreset preset)
            throws OperationFailedException
        {
            setRemoteSendMaxPreset(preset);
        }

        /**
         * Changes remote send preset, the one we will receive.
         * @param preset
         */
        public void setRemoteSendMaxPreset(QualityPreset preset)
        {
            this.maxPreset = preset;
        }

        /**
         * Gets the local setting of capture.
         * @return the local setting of capture
         */
        private QualityPreset getPreferredSendPreset()
        {
            if(localSettingsPreset == null)
            {
                DeviceConfiguration deviceConfiguration
                    = NeomediaServiceUtils
                        .getMediaServiceImpl()
                            .getDeviceConfiguration();

                localSettingsPreset = new QualityPreset(
                        deviceConfiguration.getVideoSize(),
                        deviceConfiguration.getFrameRate());
            }
            return localSettingsPreset;
        }

        /**
         * Sets maximum resolution.
         * @param res
         */
        public void setRemoteReceiveResolution(Dimension res)
        {
            try
            {
                this.setRemoteReceivePreset(new QualityPreset(res));
            }
            catch(OperationFailedException ofe){}
        }
    }
}