20 #ifndef STREAMCODER_H_
21 #define STREAMCODER_H_
23 #include <com/avpkit/ferry/RefPointer.h>
24 #include <com/avpkit/core/IStreamCoder.h>
25 #include <com/avpkit/core/FfmpegIncludes.h>
26 #include <com/avpkit/core/Stream.h>
27 #include <com/avpkit/ferry/IBuffer.h>
28 #include <com/avpkit/core/Codec.h>
30 namespace com {
namespace avpkit {
namespace core
36 VS_JNIUTILS_REFCOUNTED_OBJECT_PRIVATE_MAKE(
StreamCoder)
95 virtual void setFlags(int32_t newFlags);
104 virtual int32_t
open();
105 virtual int32_t
close();
107 IPacket *packet, int32_t byteOffset);
109 IPacket *packet, int32_t byteOffset);
124 virtual int32_t
setProperty(
const char* name,
const char* value);
125 virtual int32_t
setProperty(
const char* name,
double value);
126 virtual int32_t
setProperty(
const char* name, int64_t value);
127 virtual int32_t
setProperty(
const char* name,
bool value);
155 AVCodecContext *context,
const AVCodec*,
Stream* stream);
157 AVCodecParameters *codecpar,
const AVCodec*,
Stream* stream);
162 int32_t setStream(
Stream*,
bool assumeOnlyStream);
163 int32_t streamClosed(
Stream*);
180 virtual void* getHardwareSurface();
189 AVCodecContext* mCodecContext;
190 SwrContext* swrContext;
197 int64_t mLastPtsEncoded;
198 int64_t mFakeNextPts;
199 int64_t mFakeCurrPts;
200 int64_t mSamplesForEncoding;
201 int64_t mSamplesCoded;
202 int64_t mLastExternallySetTimeStamp;
205 int32_t mBytesInFrameBuffer;
206 int64_t mPtsOfFrameBuffer;
207 int64_t mStartingTimestampOfBytesInFrameBuffer;
208 int32_t mDefaultAudioFrameSize;
209 int64_t mNumDroppedFrames;
210 bool mAutomaticallyStampPacketsForStream;
211 int64_t mPtsBuffer[MAX_REORDER_DELAY+1];
214 void setPacketParameters(
Packet *packet, int32_t size,
224 static int32_t readyAVContexts(
229 AVCodecContext *avContext,
230 const AVCodec *avCodec);
231 static void resetOptions(AVCodecContext*);
A set of raw (decoded) samples, plus a timestamp for when to play those samples relative to other ite...
Format
The format we use to represent audio.
A "key" to an IStreamCoder that tells it how to encode or decode data.
ID
These are the codecs this library currently supports.
Type
The different types of Codecs that can exist in the system.
Represents an encoded piece of data that can be placed in an IContainer for a given IStream of data.
Represents settable properties that effect how AVPKit objects operate.
This class wraps represents a Rational number for the AVPKit.
The work horse of the AVPKit: Takes IPacket data from an IContainer (representing an IStream) and an ...
CodecStandardsCompliance
An enumeration of how strictly Codecs may follow the spec.
Flags
AVPKIT Flags that can be passed to the setFlag(Flags, bool) method.
Direction
The Direction in which this StreamCoder will work.
Represents a stream of similar data (eg video) in a IContainer.
Represents one raw (undecoded) picture in a video stream, plus a timestamp for when to display that v...
virtual void setTimeBase(IRational *newTimeBase)
Set the time base we'll use to ENCODE with.
virtual int32_t setExtraData(com::avpkit::ferry::IBuffer *src, int32_t offset, int32_t length, bool allocNew)
Copies data from the given buffer into the extra-data area maintained by encoders.
virtual IProperty * getPropertyMetaData(int32_t propertyNo)
Returns the name of the numbered property.
virtual double getPropertyAsDouble(const char *name)
Gets the value of this property, and returns as a double;.
virtual IStream * getStream()
The associated Stream we're working on.
virtual int64_t getPropertyAsLong(const char *name)
Gets the value of this property, and returns as an long;.
virtual bool getPropertyAsBoolean(const char *name)
Gets the value of this property, and returns as a boolean.
virtual void setAutomaticallyStampPacketsForStream(bool value)
Should the IStreamCoder automatically adjust time stamps on output packets for the IStream it is ulti...
virtual int64_t getNextPredictedPts()
For this stream, get the next Pts that we expect to decode.
virtual void setFlag(Flags flag, bool value)
Set the flag.
virtual void setCodec(ICodec *)
Set the Codec to the passed in Codec, discarding the old Codec if set.
virtual void setSampleFormat(IAudioSamples::Format aFormat)
Set the sample format when ENCODING.
virtual void setCodecTag(int32_t)
Set the 4-byte FOURCC tag for this coder.
virtual void setNumPicturesInGroupOfPictures(int32_t gops)
Set the GOPS on this stream.
virtual bool getAutomaticallyStampPacketsForStream()
Does this IStreamCoder automatically adjust time stamps on output packets for the IStream it is ultim...
virtual void setPixelType(IPixelFormat::Type pixelFmt)
Set the pixel format to ENCODE with.
virtual void setSampleRate(int32_t sampleRate)
Set the sample rate to use when ENCODING.
virtual void setCodecID(ICodec::ID id)
Look up a Codec based on the passed in ID, and then set it.
virtual bool getFlag(Flags flag)
Get the setting for the specified flag.
virtual int32_t release()
Internal Only.
virtual IRational * getTimeBase()
Get the time base this stream will ENCODE in, or the time base we detect while DECODING.
virtual CodecStandardsCompliance getStandardsCompliance()
Gets the current level of standards compliance.
virtual int32_t getAudioFrameSize()
For this stream, get the number of audio samples that are represented in a packet of information.
virtual void setBitRate(int32_t rate)
When ENCODING, sets the bit rate to use.
virtual int32_t getCodecTag()
Returns the 4-byte FOURCC tag (Least Significant Byte first).
virtual void setChannels(int32_t channels)
Set the number of channels to use when ENCODING.
virtual IRational * getFrameRate()
Get the frame-rate the attached stream claims to be using when DECODING, or the frame-rate we'll clai...
virtual int32_t decodeVideo(IVideoPicture *pOutFrame, IPacket *packet, int32_t byteOffset)
Decode this packet into pOutFrame.
virtual void setDefaultAudioFrameSize(int32_t)
Set the default audio frame size.
virtual int32_t getNumPicturesInGroupOfPictures()
The the number of pictures in this Group of Pictures (GOP).
virtual int32_t getChannels()
Get the number of channels in this audio stream.
virtual int32_t setStandardsCompliance(CodecStandardsCompliance compliance)
Set the level of standards compliance.
virtual Direction getDirection()
Get the direction.
virtual IRational * getPropertyAsRational(const char *name)
Gets the value of this property, and returns as an IRational;.
virtual void setFlags(int32_t newFlags)
Set the FFMPEG flags to use with this codec.
virtual Codec * getCodec()
The Codec this StreamCoder will use.
virtual int32_t getExtraData(com::avpkit::ferry::IBuffer *dest, int32_t offset, int32_t maxBytesToCopy)
Copies the current content of the extra-data buffer maintained by this codec (e.g.
virtual int32_t decodeAudio(IAudioSamples *pOutSamples, IPacket *packet, int32_t byteOffset)
Decode this packet into pOutSamples.
virtual int32_t getBitRate()
The bit rate.
virtual IAudioSamples::Format getSampleFormat()
Get the audio sample format.
virtual char * getPropertyAsString(const char *name)
Gets a property on this Object.
virtual void setWidth(int32_t)
Set the width, in pixels.
virtual int32_t close()
Close a Codec that was opened on this StreamCoder.
virtual int32_t encodeVideo(IPacket *pOutPacket, IVideoPicture *pFrame, int32_t suggestedBufferSize)
Encode the given frame using this StreamCoder.
virtual ICodec::ID getCodecID()
A short hand for getCodec().getID().
virtual int32_t getExtraDataSize()
Gets the current number of bytes of data maintained in the coder extra-data area.
virtual int32_t encodeAudio(IPacket *pOutPacket, IAudioSamples *pSamples, int32_t sampleToStartFrom)
Encode the given samples using this StreamCoder.
virtual int32_t getFlags()
Get the flags associated with this codec.
virtual int32_t getHeight()
The height, in pixels.
virtual int32_t getSampleRate()
Get the sample rate we use for this stream.
virtual int32_t getNumProperties()
Returns the total number of settable properties on this object.
virtual void setHeight(int32_t)
Set the height, in pixels.
virtual void setGlobalQuality(int32_t newQuality)
Set the Global Quality to a new value.
virtual void setBitRateTolerance(int32_t tolerance)
When ENCODING set the bit rate tolerance.
virtual int32_t acquire()
Internal Only.
virtual int32_t setProperty(const char *name, const char *value)
Sets a property on this Object.
virtual int32_t getDefaultAudioFrameSize()
Get the default audio frame size (in samples).
static StreamCoder * make(Direction direction)
This method creates a StreamCoder that is not tied to any container or stream.
virtual int32_t getGlobalQuality()
Get the Global Quality setting this codec uses for video if a VideoPicture doesn't have a quality set...
virtual void setFrameRate(IRational *newFrameRate)
Set the frame rate we'll set in the headers of this stream while ENCODING.
virtual IPixelFormat::Type getPixelType()
For Video streams, get the Pixel Format in use by the stream.
virtual int32_t getBitRateTolerance()
The bit rate tolerance.
virtual bool isOpen()
Returns true if this IStreamCoder is currently open.
virtual int32_t getWidth()
The width, in pixels.
virtual ICodec::Type getCodecType()
A short hand for getCodec().getType().
virtual int32_t setHardwareDecoding(IPixelFormat::Type type, void *surface=NULL)
Try to change current decoder to an HW decoder compatible with pixel format.
virtual int64_t getNumDroppedFrames()
Get the number of frames this StreamCoder had to drop to encode at the specified getTimeBase().
Allows Java code to get data from a native buffers, and optionally modify native memory directly.
This class is only useful from C++.
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...