All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.fmj.media.MergingPushBufferDataSource Maven / Gradle / Ivy

There is a newer version: 1.0.2-jitsi
Show newest version
package net.sf.fmj.media;

import java.io.*;
import java.util.*;

import javax.media.*;
import javax.media.protocol.*;

/**
 * Merges multiple {@link PushBufferDataSource}.
 *
 * @author Ken Larson
 *
 */
public class MergingPushBufferDataSource extends PushBufferDataSource
{
    protected final List sources;

    public MergingPushBufferDataSource(List sources)
    {
        super();
        this.sources = sources;
    }

    @Override
    public void connect() throws IOException
    {
        for (PushBufferDataSource source : sources)
            source.connect();
    }

    @Override
    public void disconnect()
    {
        for (PushBufferDataSource source : sources)
            source.disconnect();
    }

    @Override
    public String getContentType()
    {
        // if all content types the same, use it, otherwise,
        // ContentDescriptor.MIXED.
        for (int i = 0; i < sources.size(); ++i)
        {
            if (!sources.get(i).getContentType()
                    .equals(sources.get(0).getContentType()))
                return ContentDescriptor.MIXED;
        }
        return sources.get(0).getContentType();
    }

    @Override
    public Object getControl(String controlType)
    {
        for (PushBufferDataSource source : sources)
        {
            Object control = source.getControl(controlType);
            if (control != null)
                return control;
        }
        return null;
    }

    @Override
    public Object[] getControls()
    {
        final List controls = new ArrayList();
        for (PushBufferDataSource source : sources)
        {
            for (Object control : source.getControls())
                controls.add(control);
        }
        return controls.toArray(new Object[0]);
    }

    @Override
    public Time getDuration()
    {
        final List