Skip to content
Snippets Groups Projects
Commit 03ac531f authored by Boris Grozev's avatar Boris Grozev
Browse files

Allows the MP3 encoder's buffer to be flushed.

parent c2e05556
No related branches found
No related tags found
No related merge requests found
...@@ -12,15 +12,20 @@ ...@@ -12,15 +12,20 @@
import net.sf.fmj.media.*; import net.sf.fmj.media.*;
import org.jitsi.impl.neomedia.codec.*; import org.jitsi.impl.neomedia.codec.*;
import org.jitsi.service.neomedia.control.*;
import org.jitsi.util.*; import org.jitsi.util.*;
import java.awt.*;
/** /**
* Implements a MP3 encoder using the native FFmpeg library. * Implements a MP3 encoder using the native FFmpeg library.
* *
* @author Lyubomir Marinov * @author Lyubomir Marinov
* @author Boris Grozev
*/ */
public class JNIEncoder public class JNIEncoder
extends AbstractCodec2 extends AbstractCodec2
implements FlushableControl
{ {
/** /**
* The <tt>Logger</tt> used by the <tt>JNIEncoder</tt> class and its * The <tt>Logger</tt> used by the <tt>JNIEncoder</tt> class and its
...@@ -89,6 +94,11 @@ public class JNIEncoder ...@@ -89,6 +94,11 @@ public class JNIEncoder
*/ */
private int prevInputLength; private int prevInputLength;
/**
* Synchronize access to <tt>prevInput</tt> and <tt>prevInputLength</tt>
*/
private Object prevInputSyncRoot = new Object();
/** /**
* Initializes a new <tt>JNIEncoder</tt> instance. * Initializes a new <tt>JNIEncoder</tt> instance.
*/ */
...@@ -97,12 +107,14 @@ public JNIEncoder() ...@@ -97,12 +107,14 @@ public JNIEncoder()
super("MP3 JNI Encoder", AudioFormat.class, SUPPORTED_OUTPUT_FORMATS); super("MP3 JNI Encoder", AudioFormat.class, SUPPORTED_OUTPUT_FORMATS);
inputFormats = SUPPORTED_INPUT_FORMATS; inputFormats = SUPPORTED_INPUT_FORMATS;
addControl(this);
} }
/** /**
* Implements {@link AbstractCodecExt#doClose()}. * Implements {@link AbstractCodec2#doClose()}.
* *
* @see AbstractCodecExt#doClose() * @see AbstractCodec2#doClose()
*/ */
@Override @Override
protected synchronized void doClose() protected synchronized void doClose()
...@@ -127,7 +139,7 @@ protected synchronized void doClose() ...@@ -127,7 +139,7 @@ protected synchronized void doClose()
* *
* @throws ResourceUnavailableException if any of the resources that this * @throws ResourceUnavailableException if any of the resources that this
* <tt>Codec</tt> needs to operate cannot be acquired * <tt>Codec</tt> needs to operate cannot be acquired
* @see AbstractCodecExt#doOpen() * @see AbstractCodec2#doOpen()
*/ */
@Override @Override
protected synchronized void doOpen() protected synchronized void doOpen()
...@@ -200,11 +212,11 @@ protected synchronized void doOpen() ...@@ -200,11 +212,11 @@ protected synchronized void doOpen()
} }
/** /**
* Implements {@link AbstractCodecExt#doProcess(Buffer, Buffer)}. * Implements {@link AbstractCodec2#doProcess(Buffer, Buffer)}.
* *
* @param inputBuffer * @param inputBuffer
* @param outputBuffer * @param outputBuffer
* @see AbstractCodecExt#doProcess(Buffer, Buffer) * @see AbstractCodec2#doProcess(Buffer, Buffer)
*/ */
@Override @Override
protected synchronized int doProcess( protected synchronized int doProcess(
...@@ -215,6 +227,8 @@ protected synchronized int doProcess( ...@@ -215,6 +227,8 @@ protected synchronized int doProcess(
int inputLength = inputBuffer.getLength(); int inputLength = inputBuffer.getLength();
int inputOffset = inputBuffer.getOffset(); int inputOffset = inputBuffer.getOffset();
synchronized (prevInputSyncRoot)
{
if ((prevInputLength > 0) || (inputLength < frameSizeInBytes)) if ((prevInputLength > 0) || (inputLength < frameSizeInBytes))
{ {
int newPrevInputLength int newPrevInputLength
...@@ -288,5 +302,24 @@ protected synchronized int doProcess( ...@@ -288,5 +302,24 @@ protected synchronized int doProcess(
else else
return BUFFER_PROCESSED_OK; return BUFFER_PROCESSED_OK;
} }
} //synchronized
}
@Override
public void flush()
{
synchronized (prevInputSyncRoot)
{
prevInputLength = 0;
}
}
/**
* Implements {@link javax.media.Control#getControlComponent()}.
*/
@Override
public Component getControlComponent()
{
return null;
} }
} }
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jitsi.service.neomedia.control;
import javax.media.*;
/**
* An interface which allows to flush a buffer.
*
* @author Boris Grozev
*/
public interface FlushableControl extends Control
{
/**
* Flushes the buffer.
*/
public void flush();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment