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     * Return   The transport manager that goes with this media manager.
049     */
050    public JingleTransportManager getTransportManager() {
051        return transportManager;
052    }
053
054    /**
055     * Return all supported Payloads for this Manager.
056     *
057     * @return The Payload List
058     */
059    public abstract List<PayloadType> getPayloads();
060
061    /**
062     * Returns the Preferred PayloadType of the Media Manager.
063     *
064     * @return The PayloadType
065     */
066    public PayloadType getPreferredPayloadType() {
067        return getPayloads().size() > 0 ? getPayloads().get(0) : null;
068    }
069
070    /**
071     * Create a Media Session Implementation.
072     *
073     * @param payloadType
074     * @param remote
075     * @param local
076     * @return the media session
077     */
078    public abstract JingleMediaSession createMediaSession(PayloadType payloadType, TransportCandidate remote,
079            TransportCandidate local, JingleSession jingleSession);
080
081    // This is to set the attributes of the <content> element of the Jingle packet.
082    public String getName() {
083        return MEDIA_NAME;
084    }
085
086}