
org.jitsi.impl.neomedia.protocol.StreamSubstituteBufferTransferHandler Maven / Gradle / Ivy
/*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jitsi.impl.neomedia.protocol;
import javax.media.protocol.*;
/**
* Implements a BufferTransferHandler wrapper which doesn't
* expose a PushBufferStream but rather a specific substitute in order
* to give full control to the {@link PushBufferStream#read(javax.media.Buffer)}
* method of the substitute.
*
* The purpose is achieved in #transferData(PushBufferStream)
* where the method argument stream
is ignored and the substitute
* is used instead.
*
* @author Lubomir Marinov
*/
public class StreamSubstituteBufferTransferHandler
implements BufferTransferHandler
{
/**
* The PushBufferStream
to be overridden for
* transferHandler
with the substitute
of this
* instance.
*/
private final PushBufferStream stream;
/**
* The PushBufferStream
to override the stream
of
* this instance for transferHandler
.
*/
private final PushBufferStream substitute;
/**
* The wrapped BufferTransferHandler which receives the
* actual events from the wrapped PushBufferStream.
*/
private final BufferTransferHandler transferHandler;
/**
* Initializes a new StreamSubstituteBufferTransferHandler instance
* which is to overwrite the source PushBufferStream of a specific
* BufferTransferHandler.
*
* @param transferHandler the BufferTransferHandler the new
* instance is to overwrite the source PushBufferStream
* of
* @param stream the PushBufferStream
to be overridden for the
* specified transferHandler
with the specified
* substitute
* @param substitute the PushBufferStream
to override the
* specified stream
for the specified
* transferHandler
*/
public StreamSubstituteBufferTransferHandler(
BufferTransferHandler transferHandler,
PushBufferStream stream,
PushBufferStream substitute)
{
this.transferHandler = transferHandler;
this.stream = stream;
this.substitute = substitute;
}
/**
* Implements BufferTransferHandler#transferData(PushBufferStream). Puts in
* place the essence of the StreamSubstituteBufferTransferHandler class
* which is to report to the transferHandler from the same PushBufferStream
* to which it was set so that the substitute can gain full control.
*
* @param stream the PushBufferStream to transfer
*/
public void transferData(PushBufferStream stream)
{
transferHandler.transferData(
(stream == this.stream) ? substitute : stream);
}
}