001/**
002 *
003 * Copyright 2003-2006 Jive Software.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.jingleold.mediaimpl.sshare;
018
019import java.util.ArrayList;
020import java.util.List;
021
022import org.jivesoftware.smackx.jingleold.JingleSession;
023import org.jivesoftware.smackx.jingleold.media.JingleMediaManager;
024import org.jivesoftware.smackx.jingleold.media.JingleMediaSession;
025import org.jivesoftware.smackx.jingleold.media.PayloadType;
026import org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.ImageDecoder;
027import org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.ImageEncoder;
028import org.jivesoftware.smackx.jingleold.nat.JingleTransportManager;
029import org.jivesoftware.smackx.jingleold.nat.TransportCandidate;
030
031/**
032 * Implements a JingleMediaManager for ScreenSharing.
033 * It currently uses an Audio payload Type. Which needs to be fixed in the next version.
034 *
035 * @author Thiago Camargo
036 */
037
038public class ScreenShareMediaManager extends JingleMediaManager {
039
040    public static final String MEDIA_NAME = "ScreenShare";
041
042    private List<PayloadType> payloads = new ArrayList<>();
043
044    private ImageDecoder decoder = null;
045    private ImageEncoder encoder = null;
046
047    public ScreenShareMediaManager(JingleTransportManager transportManager) {
048        super(transportManager);
049        setupPayloads();
050    }
051
052    /**
053     * Setup API supported Payloads
054     */
055    private void setupPayloads() {
056        payloads.add(new PayloadType.Audio(30, "sshare"));
057    }
058
059    /**
060     * Return all supported Payloads for this Manager.
061     *
062     * @return The Payload List
063     */
064    @Override
065    public List<PayloadType> getPayloads() {
066        return payloads;
067    }
068
069    /**
070     * Returns a new JingleMediaSession.
071     *
072     * @param payloadType payloadType
073     * @param remote      remote Candidate
074     * @param local       local Candidate
075     * @return JingleMediaSession JingleMediaSession
076     */
077    @Override
078    public JingleMediaSession createMediaSession(PayloadType payloadType, final TransportCandidate remote, final TransportCandidate local, final JingleSession jingleSession) {
079        ScreenShareSession session = null;
080        session = new ScreenShareSession(payloadType, remote, local, "Screen", jingleSession);
081        if (encoder != null) {
082            session.setEncoder(encoder);
083        }
084        if (decoder != null) {
085            session.setDecoder(decoder);
086        }
087        return session;
088    }
089
090    @Override
091    public PayloadType getPreferredPayloadType() {
092        return super.getPreferredPayloadType();
093    }
094
095    public ImageDecoder getDecoder() {
096        return decoder;
097    }
098
099    public void setDecoder(ImageDecoder decoder) {
100        this.decoder = decoder;
101    }
102
103    public ImageEncoder getEncoder() {
104        return encoder;
105    }
106
107    public void setEncoder(ImageEncoder encoder) {
108        this.encoder = encoder;
109    }
110
111    @Override
112    public  String getName() {
113        return MEDIA_NAME;
114    }
115}