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 */
017
018package org.jivesoftware.smackx.jingleold.media;
019
020import java.util.List;
021
022import org.jivesoftware.smackx.jingleold.JingleSession;
023import org.jivesoftware.smackx.jingleold.nat.JingleTransportManager;
024import org.jivesoftware.smackx.jingleold.nat.TransportCandidate;
025
026/**
027 * This class provides necessary Jingle Session jmf methods and behavior.
028 * <p>
029 * The goal of this class is to provide a flexible way to make JingleManager control jmf streaming APIs without implement them.
030 * For instance you can implement a file transfer using java sockets or a VOIP Media Manager using JMF.
031 * You can implement many JingleMediaManager according to you necessity.
032 * </p>
033 *
034 * @author Thiago Camargo
035 */
036public abstract class JingleMediaManager {
037
038    public static final String MEDIA_NAME = "JingleMediaManager";
039
040    // Each media manager must keep track of the transport manager that it uses.
041    private final JingleTransportManager transportManager;
042
043    public JingleMediaManager(JingleTransportManager transportManager) {
044        this.transportManager = transportManager;
045    }
046
047    /**
048     * Returns the transport manager that goes with this media manager.
049     *
050     * @return the transport manager.
051     */
052    public JingleTransportManager getTransportManager() {
053        return transportManager;
054    }
055
056    /**
057     * Return all supported Payloads for this Manager.
058     *
059     * @return The Payload List
060     */
061    public abstract List<PayloadType> getPayloads();
062
063    /**
064     * Returns the Preferred PayloadType of the Media Manager.
065     *
066     * @return The PayloadType
067     */
068    public PayloadType getPreferredPayloadType() {
069        return getPayloads().size() > 0 ? getPayloads().get(0) : null;
070    }
071
072    /**
073     * Create a Media Session Implementation.
074     *
075     * @param payloadType TODO javadoc me please
076     * @param remote TODO javadoc me please
077     * @param local TODO javadoc me please
078     * @param jingleSession the jingle session.
079     * @return the media session
080     */
081    public abstract JingleMediaSession createMediaSession(PayloadType payloadType, TransportCandidate remote,
082            TransportCandidate local, JingleSession jingleSession);
083
084    // This is to set the attributes of the <content> element of the Jingle packet.
085    public String getName() {
086        return MEDIA_NAME;
087    }
088
089}