public abstract class

Encoder

extends Object
java.lang.Object
   ↳ org.opencdnunion.media.streamer.encoder.Encoder<I, O>
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Base class of encoder modules.

Summary

Nested Classes
interface Encoder.EncoderInfoListener  
interface Encoder.EncoderListener  
Constants
int ENCODER_ERROR_UNKNOWN
int ENCODER_ERROR_UNSUPPORTED
int ENCODER_STATE_ENCODING
int ENCODER_STATE_FLUSHED
int ENCODER_STATE_FLUSHING
int ENCODER_STATE_IDLE
int ENCODER_STATE_INITIALIZING
int ENCODER_STATE_STOPPING
int INFO_STARTED
int INFO_STOPPED
Fields
protected Object mEncodeConfig
protected Handler mEncodeHandler
protected HandlerThread mEncodeThread
protected boolean mForceKeyFrame
protected AtomicInteger mFrameDropped
protected AtomicInteger mFrameEncoded
protected boolean mMute
protected ConditionVariable mSig
public SinkPin<I> mSinkPin
public SrcPin<O> mSrcPin
protected AtomicInteger mState
protected boolean mTransWorkMode
protected int mType
Public Constructors
Encoder()
Public Methods
void adjustBitrate(int bitrate)
Adjust bitrate while encoding.
void configure(Object encodeConfig)
Configure encoder with given format.
void flush()
flush current encoder data.
void forceKeyFrame()
boolean getAutoWork()
Get if encoder start/stop by input frames.
Object getEncodeConfig()
Encoder.EncoderInfoListener getEncoderInfoListener()
Get encoder info listener.
Encoder.EncoderListener getEncoderListener()
Get encoder listener.
abstract int getEncoderType()
Implement by child class, to define what type of encoder this instance is.
AVPacketBase getExtra()
int getFrameDropped()
Get frame dropped number.
int getFrameEncoded()
Get frame encoded number.
SinkPin<I> getSinkPin()
SrcPin<O> getSrcPin()
int getState()
Get current state.
boolean getUseSyncMode()
Get if encoding frames in sync mode.
boolean isEncoding()
Is it in ENCODER_STATE_ENCODING state now.
void release()
void setAutoWork(boolean autoWork)
Set if encoder start/stop by input frames.
void setEnableTransWorkMode(boolean enable)
void setEncoderInfoListener(Encoder.EncoderInfoListener infoListener)
Set encoder info listener
void setEncoderListener(Encoder.EncoderListener listener)
Set encoder listener.
void setMute(boolean mute)
Set if encode mute audio data.
void setUseSyncMode(boolean useSyncMode)
Set if encoding frames in sync mode.
void start()
Start encoding.
void startRepeatLastFrame()
Repeating to send last video frame.
void stop()
Stop encoding.
void stopRepeatLastFrame()
Stop repeating last video frame.
Protected Methods
abstract void doAdjustBitrate(int bitrate)
void doFlush()
void doFormatChanged(Object format)
abstract int doFrameAvailable(I frame)
void doFrameDropped(I frame)
abstract int doStart(Object encodeConfig)
abstract void doStop()
void onEncodedFormatChanged(Object encodedFormat)
should be called by child class after output format changed.
void onEncodedFrame(O encodedFrame)
should be called by child class after a video frame encoded.
boolean onFrameAvailable(I frame)
Give child class a chance to handle onFrameAvailable
void sendError(int err)
void sendInfo(int type, int extra)
boolean updateEncodeFormat(Object src, Object dst)
Update encode format with input frame format.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int ENCODER_ERROR_UNKNOWN

Constant Value: -1001 (0xfffffc17)

public static final int ENCODER_ERROR_UNSUPPORTED

Constant Value: -1002 (0xfffffc16)

public static final int ENCODER_STATE_ENCODING

Constant Value: 2 (0x00000002)

public static final int ENCODER_STATE_FLUSHED

Constant Value: 5 (0x00000005)

public static final int ENCODER_STATE_FLUSHING

Constant Value: 4 (0x00000004)

public static final int ENCODER_STATE_IDLE

Constant Value: 0 (0x00000000)

public static final int ENCODER_STATE_INITIALIZING

Constant Value: 1 (0x00000001)

public static final int ENCODER_STATE_STOPPING

Constant Value: 3 (0x00000003)

public static final int INFO_STARTED

Constant Value: 1 (0x00000001)

public static final int INFO_STOPPED

Constant Value: 2 (0x00000002)

Fields

protected Object mEncodeConfig

protected Handler mEncodeHandler

protected HandlerThread mEncodeThread

protected boolean mForceKeyFrame

protected AtomicInteger mFrameDropped

protected AtomicInteger mFrameEncoded

protected boolean mMute

protected ConditionVariable mSig

public SinkPin<I> mSinkPin

public SrcPin<O> mSrcPin

protected AtomicInteger mState

protected boolean mTransWorkMode

protected int mType

Public Constructors

public Encoder ()

Public Methods

public void adjustBitrate (int bitrate)

Adjust bitrate while encoding.
Should be call on ENCODER_STATE_ENCODING.

Parameters
bitrate bitrate to adjust to, in bps

public void configure (Object encodeConfig)

Configure encoder with given format.
Should be set before start encoding.

Parameters
encodeConfig encode format to set

public void flush ()

flush current encoder data.
Should be call on ENCODER_STATE_ENCODING, and this call should always followed by stop().

public void forceKeyFrame ()

public boolean getAutoWork ()

Get if encoder start/stop by input frames.

Returns
  • is auto work

public Object getEncodeConfig ()

public Encoder.EncoderInfoListener getEncoderInfoListener ()

Get encoder info listener.

Returns
  • info listener previous set

public Encoder.EncoderListener getEncoderListener ()

Get encoder listener.

Returns
  • listener previous set

public abstract int getEncoderType ()

Implement by child class, to define what type of encoder this instance is.

Returns
  • type as AVConst.MEDIA_TYPE_XXX

public AVPacketBase getExtra ()

public int getFrameDropped ()

Get frame dropped number.
Should be call on ENCODER_STATE_ENCODING

Returns
  • dropped frame number on this session.

public int getFrameEncoded ()

Get frame encoded number.
Should be call on ENCODER_STATE_ENCODING.

Returns
  • encoded frame number on this session.

public SinkPin<I> getSinkPin ()

public SrcPin<O> getSrcPin ()

public int getState ()

public boolean getUseSyncMode ()

Get if encoding frames in sync mode.

Returns
  • sync mode

public boolean isEncoding ()

Is it in ENCODER_STATE_ENCODING state now.

Returns
  • true while encoding, false otherwise

public void release ()

public void setAutoWork (boolean autoWork)

Set if encoder start/stop by input frames. For example, onFormatChanged would start encoding if encoder not started, and frame with FLAG_END_OF_STREAM would stop encoding.

Parameters
autoWork true to enable, false to disable

public void setEnableTransWorkMode (boolean enable)

public void setEncoderInfoListener (Encoder.EncoderInfoListener infoListener)

Set encoder info listener

Parameters
infoListener listener to set

public void setEncoderListener (Encoder.EncoderListener listener)

Set encoder listener.

Parameters
listener listener to set

public void setMute (boolean mute)

Set if encode mute audio data.

Parameters
mute true to encode mute data, false otherwise

public void setUseSyncMode (boolean useSyncMode)

Set if encoding frames in sync mode.

Parameters
useSyncMode true in sync mode, false in async mode.

public void start ()

Start encoding.
Should be called on ENCODER_STATE_IDLE.

public void startRepeatLastFrame ()

Repeating to send last video frame.

public void stop ()

Stop encoding.
Should be called on ENCODER_STATE_ENCODING.

public void stopRepeatLastFrame ()

Stop repeating last video frame.

Protected Methods

protected abstract void doAdjustBitrate (int bitrate)

protected void doFlush ()

protected void doFormatChanged (Object format)

protected abstract int doFrameAvailable (I frame)

protected void doFrameDropped (I frame)

protected abstract int doStart (Object encodeConfig)

protected abstract void doStop ()

protected void onEncodedFormatChanged (Object encodedFormat)

should be called by child class after output format changed.

Parameters
encodedFormat output format

protected void onEncodedFrame (O encodedFrame)

should be called by child class after a video frame encoded.

Parameters
encodedFrame encoded frame

protected boolean onFrameAvailable (I frame)

Give child class a chance to handle onFrameAvailable

Parameters
frame frame
Returns
  • true if handled by child, and Encoder would ignore this frame, false otherwise.

protected void sendError (int err)

protected void sendInfo (int type, int extra)

protected boolean updateEncodeFormat (Object src, Object dst)

Update encode format with input frame format.

Parameters
src input frame format
dst encode format to be updated
Returns
  • true if success, false otherwise