AVPKit
com::avpkit::core::IContainer Class Referenceabstract

A file (or network data source) that contains one or more IStream objects of audio and video data. More...

#include <IContainer.h>

Inheritance diagram for com::avpkit::core::IContainer:
Collaboration diagram for com::avpkit::core::IContainer:

Public Types

enum  Type { READ , WRITE }
 The different types of Containers AVPKit supports. More...
 
enum  Flags {
  FLAG_GENPTS =0x0001 , FLAG_IGNIDX =0x0002 , FLAG_NONBLOCK =0x0004 , FLAG_IGNDTS =0x0008 ,
  FLAG_NOFILLIN =0x0010 , FLAG_NOPARSE =0x0020 , FLAG_NOBUFFER =0x0040 , FLAG_CUSTOM_IO =0x0080 ,
  FLAG_DISCARD_CORRUPT =0x0100 , FLAG_FLUSH_PACKETS =0x0200 , FLAG_BITEXACT =0x0400 , FLAG_MP4A_LATM =0x8000 ,
  FLAG_SORT_DTS =0x10000 , FLAG_PRIV_OPT =0x20000 , FLAG_KEEP_SIDE_DATA =0x40000 , FLAG_FAST_SEEK =0x80000 ,
  FLAG_SHORTEST =0x100000 , FLAG_AUTO_BSF =0x200000
}
 
typedef enum com::avpkit::core::IContainer::Type Type
 The different types of Containers AVPKit supports. More...
 
typedef enum com::avpkit::core::IContainer::Flags Flags
 

Public Member Functions

virtual int32_t setInputBufferLength (int32_t size)=0
 Set the buffer length AVPKit will suggest to FFMPEG for reading inputs. More...
 
virtual int32_t getInputBufferLength ()=0
 Return the input buffer length. More...
 
virtual bool isOpened ()=0
 Is this container opened? More...
 
virtual bool isHeaderWritten ()=0
 Has a header been successfully written? More...
 
virtual int32_t open (const char *url, Type type, IContainerFormat *pContainerFormat)=0
 Open this container and make it ready for reading or writing. More...
 
virtual int32_t open (const char *url, Type type, IContainerFormat *pContainerFormat, bool aStreamsCanBeAddedDynamically, bool aQueryStreamMetaData)=0
 Open this container and make it ready for reading or writing, optionally reading as far into the container as necessary to find all streams. More...
 
virtual IStreamCoder::CodecStandardsCompliance getStandardsCompliance ()=0
 Gets the current level of standards compliance. More...
 
virtual int32_t setStandardsCompliance (IStreamCoder::CodecStandardsCompliance compliance)=0
 Set the level of standards compliance. More...
 
virtual IContainerFormatgetContainerFormat ()=0
 Returns the IContainerFormat object being used for this IContainer, or null if the IContainer doesn't yet know. More...
 
virtual int32_t close (bool dangling=false)=0
 Close the container. More...
 
virtual Type getType ()=0
 Find out the type of this container. More...
 
virtual int32_t getNumStreams ()=0
 The number of streams in this container. More...
 
virtual IStreamgetStream (int32_t streamIndex)=0
 Get the stream at the given position. More...
 
virtual IStreamaddNewStream (int32_t id)=0
 
virtual int32_t writeHeader ()=0
 Adds a header, if needed, for this container. More...
 
virtual int32_t writeTrailer ()=0
 Adds a trailer, if needed, for this container. More...
 
virtual int32_t readNextPacket (IPacket *packet)=0
 Reads the next packet into the IPacket. More...
 
virtual int32_t writePacket (IPacket *packet, bool forceInterleave)=0
 Writes the contents of the packet to the container. More...
 
virtual int32_t writePacket (IPacket *packet)=0
 Writes the contents of the packet to the container, but make sure the packets are interleaved. More...
 
virtual int32_t queryStreamMetaData ()=0
 Attempts to read all the meta data in this stream, potentially by reading ahead and decoding packets. More...
 
virtual int32_t seekKeyFrame (int32_t streamIndex, int64_t timestamp, int32_t flags)=0
 Seeks to the key frame at (or the first one after) the given timestamp. More...
 
virtual int64_t getDuration ()=0
 Gets the duration, if known, of this container. More...
 
virtual int64_t getStartTime ()=0
 Get the starting timestamp in microseconds of the first packet of the earliest stream in this container. More...
 
virtual int64_t getFileSize ()=0
 Get the file size in bytes of this container. More...
 
virtual int32_t getBitRate ()=0
 Get the calculated overall bit rate of this file. More...
 
virtual int32_t getNumProperties ()=0
 Returns the total number of settable properties on this object. More...
 
virtual IPropertygetPropertyMetaData (int32_t propertyNo)=0
 Returns the name of the numbered property. More...
 
virtual IPropertygetPropertyMetaData (const char *name)=0
 Returns the name of the numbered property. More...
 
virtual int32_t setProperty (const char *name, const char *value)=0
 Sets a property on this Object. More...
 
virtual int32_t setProperty (const char *name, double value)=0
 Looks up the property 'name' and sets the value of the property to 'value'. More...
 
virtual int32_t setProperty (const char *name, int64_t value)=0
 Looks up the property 'name' and sets the value of the property to 'value'. More...
 
virtual int32_t setProperty (const char *name, bool value)=0
 Looks up the property 'name' and sets the value of the property to 'value'. More...
 
virtual int32_t setProperty (const char *name, IRational *value)=0
 Looks up the property 'name' and sets the value of the property to 'value'. More...
 
virtual char * getPropertyAsString (const char *name)=0
 Gets a property on this Object. More...
 
virtual double getPropertyAsDouble (const char *name)=0
 Gets the value of this property, and returns as a double;. More...
 
virtual int64_t getPropertyAsLong (const char *name)=0
 Gets the value of this property, and returns as an long;. More...
 
virtual IRationalgetPropertyAsRational (const char *name)=0
 Gets the value of this property, and returns as an IRational;. More...
 
virtual bool getPropertyAsBoolean (const char *name)=0
 Gets the value of this property, and returns as a boolean. More...
 
virtual int32_t getFlags ()=0
 Get the flags associated with this object. More...
 
virtual void setFlags (int32_t newFlags)=0
 Set the flags to use with this object. More...
 
virtual bool getFlag (Flags flag)=0
 Get the setting for the specified flag. More...
 
virtual void setFlag (Flags flag, bool value)=0
 Set the flag. More...
 
virtual const char * getURL ()=0
 Get the URL the IContainer was opened with. More...
 
virtual int32_t flushPackets ()=0
 Flush all packets to output. More...
 
virtual int32_t getReadRetryCount ()=0
 Get the number of times IContainer#readNextPacket(IPacket) will retry a read if it gets a IError.Type#ERROR_AGAIN value back. More...
 
virtual void setReadRetryCount (int32_t count)=0
 Sets the read retry count. More...
 
virtual bool canStreamsBeAddedDynamically ()=0
 Can streams be added dynamically to this container? More...
 
virtual IMetaDatagetMetaData ()=0
 Get the IMetaData for this object, or null if none. More...
 
virtual void setMetaData (IMetaData *data)=0
 Set the IMetaData on this object, overriding any previous meta data. More...
 
virtual int32_t createSDPData (com::avpkit::ferry::IBuffer *buffer)=0
 Fills the given buffer with a null-terminated ASCII set of bytes representing SDP data that is suitable for use with an RTSP-based system. More...
 
virtual int32_t setForcedAudioCodec (ICodec::ID id)=0
 Forces the IContainer to assume all audio streams are encoded with the given audio codec when demuxing. More...
 
virtual int32_t setForcedVideoCodec (ICodec::ID id)=0
 Forces the IContainer to assume all video streams are encoded with the given video codec when demuxing. More...
 
virtual int32_t setForcedSubtitleCodec (ICodec::ID id)=0
 Forces the IContainer to assume all subtitle streams are encoded with the given subtitle codec when demuxing. More...
 
virtual int32_t seekKeyFrame (int32_t streamIndex, int64_t minTimeStamp, int64_t targetTimeStamp, int64_t maxTimeStamp, int32_t flags)=0
 EXPERIMENTAL - Seeks to timestamp in the container. More...
 
virtual int32_t setPreload (int32_t preload)=0
 @Deprecated use setProperty instead. More...
 
virtual int32_t getPreload ()=0
 @Deprecated use getPropertyAsLong instead. More...
 
virtual int32_t setMaxDelay (int32_t maxdelay)=0
 Sets the max delay for the AVFormatContext.max_delay property. More...
 
virtual int32_t getMaxDelay ()=0
 Gets the AVFormatContext.max_delay property if possible. More...
 
virtual IStreamaddNewStream (ICodec::ID id)=0
 Add a new stream that will use the given codec. More...
 
virtual IStreamaddNewStream (ICodec *codec)=0
 Add a new stream that will use the given codec. More...
 
virtual IStreamaddNewStream (IStreamCoder *coder)=0
 Add a new stream that will use the given StreamCoder. More...
 
virtual int32_t setProperty (IMetaData *valuesToSet, IMetaData *valuesNotFound)=0
 
virtual IContainerFormatgetFormat ()=0
 Get the IContainerFormat that is used by this IContainer. More...
 
virtual int32_t setFormat (IContainerFormat *format)=0
 Set the IContainerFormat to use with this IContainer. More...
 
virtual int32_t open (const char *url, Type type, IContainerFormat *containerFormat, bool streamsCanBeAddedDynamically, bool queryStreamMetaData, IMetaData *options, IMetaData *optionsNotSet)=0
 Open this container and make it ready for reading or writing, optionally reading as far into the container as necessary to find all streams. More...
 
- Public Member Functions inherited from com::avpkit::ferry::RefCounted
virtual int32_t acquire ()
 Internal Only. More...
 
virtual int32_t release ()
 Internal Only. More...
 
virtual RefCountedcopyReference ()
 Create a new Java object that refers to the same native object. More...
 
virtual int32_t getCurrentRefCount ()
 Return the current reference count on this object. More...
 
void setJavaAllocator (void *allocator)
 This method is public but not part of the standard API. More...
 
void * getJavaAllocator ()
 This method is public but not part of the standard API. More...
 

Static Public Member Functions

static IContainermake ()
 Create a new container object. More...
 
static IContainermake (IContainerFormat *format)
 Create a new IContainer and call setFormat(IContainerFormat) on it immediately. More...
 

Static Public Attributes

static const int32_t SEEK_FLAG_BACKWARDS =1
 Flag; Seek backwards.
 
static const int32_t SEEK_FLAG_BYTE =2
 Flag; Use bytes instead of time stamps for seeking.
 
static const int32_t SEEK_FLAG_ANY =4
 Flag; Seek to any frame, even non-keyframes.
 
static const int32_t SEEK_FLAG_FRAME =8
 Flag; Seek based on frame number instead of time stamps.
 

Additional Inherited Members

- Protected Member Functions inherited from com::avpkit::ferry::RefCounted
virtual void destroy ()
 This method is called by RefCounted objects when their Ref Count reaches zero and they are about to be destroyed.
 
- Protected Attributes inherited from com::avpkit::ferry::RefCounted
AtomicIntegermRefCount
 This is the internal reference count, represented as an AtomicInteger to make sure it is thread safe.
 
void * mAllocator
 Not part of public API.
 

Detailed Description

A file (or network data source) that contains one or more IStream objects of audio and video data.

Typical usage for reading looks like this:

IContainer container = IContainer.make();

if (container.open("myfile.flv", IContainer.Type.READ, null) <0)
  throw new RuntimeException("failed to open");

int numStreams = container.getNumStreams();
for(i = 0; i < numStreams; i++) {
  IStream stream = container.getStream(i);
  ...query IStream for stream information...
}

IPacket packet = IPacket.make();
while(container.readNextPacket(packet) >= 0)
{
    ... Do something with the packet...
}
container.close();

<p<blockquote>

Typical usage for writing looks like this (makes an FLV file with one audio track encoded as mp3 data):

IContainer container = IContainer.make();

if (container.open("myfile.flv", IContainer.Type.WRITE, null) <0)
  throw new RuntimeException("failed to open");

IStream stream = container.addNewStream(0);

IStreamCoder coder = stream.getStreamCoder();

coder.setCodec(ICodec.ID.AV_CODEC_ID_MP3);
coder.setSampleRate(22050);
coder.setChannels(2);
coder.setBitRate(64000);

if (coder.open()<0) throw new RuntimeException("could not open coder");

if (container.writeHeader() < 0) throw new RuntimeException();

IPacket packet = IPacket.make();

while( ... have more data to process ... ) {
  ... Use the coder to encode audio data into packets
  then assuming it generated an IPacket for you...
  if (container.writePacket(packet)<0)
    throw new RuntimeException("could not write packet");
}

if (container.writeTrailer() <0) throw new RuntimeException();

container.close();

Definition at line 99 of file IContainer.h.

Member Typedef Documentation

◆ Type

The different types of Containers AVPKit supports.

A container may only be opened in a uni-directional mode.

Member Enumeration Documentation

◆ Type

The different types of Containers AVPKit supports.

A container may only be opened in a uni-directional mode.

Definition at line 106 of file IContainer.h.

106  {
107  READ,
108  WRITE,
109  } Type;
Type
The different types of Containers AVPKit supports.
Definition: IContainer.h:106

Member Function Documentation

◆ addNewStream() [1/4]

virtual IStream* com::avpkit::core::IContainer::addNewStream ( ICodec codec)
pure virtual

Add a new stream that will use the given codec.

Parameters
codecThe codec that will be used to insert packets.
Returns
An IStream for the new stream on success, or null on failure.
Since
5.0

Implemented in com::avpkit::core::Container.

◆ addNewStream() [2/4]

virtual IStream* com::avpkit::core::IContainer::addNewStream ( ICodec::ID  id)
pure virtual

Add a new stream that will use the given codec.

Parameters
idThe id for the codec used to insert packets. If you are adding an arbitrary data stream, use ICodec.ID#AV_CODEC_ID_NONE, otherwise use the ID of the code type you plan to use.
Returns
An IStream for the new stream on success, or null on failure.
Since
5.0

Implemented in com::avpkit::core::Container.

◆ addNewStream() [3/4]

virtual IStream* com::avpkit::core::IContainer::addNewStream ( int32_t  id)
pure virtual
Deprecated:
Use addNewStream(ICodec.ID) instead.

Creates a new stream in this container and returns it.

Parameters
idA format-dependent id for this stream.
Returns
A new stream.

Implemented in com::avpkit::core::Container.

◆ addNewStream() [4/4]

virtual IStream* com::avpkit::core::IContainer::addNewStream ( IStreamCoder coder)
pure virtual

Add a new stream that will use the given StreamCoder.

The StreamCoder passed in MUST contain the IStreamCoder#getExtraData that was used to encode the packet.

Parameters
coderThe IStreamCoder that contains the meta-information needed for decoding the packets that will be muexed into this stream.
Returns
An IStream for the new stream on success, or null on failure.
Since
5.0

Implemented in com::avpkit::core::Container.

◆ canStreamsBeAddedDynamically()

virtual bool com::avpkit::core::IContainer::canStreamsBeAddedDynamically ( )
pure virtual

Can streams be added dynamically to this container?

Returns
true if streams can be added dynamically

Implemented in com::avpkit::core::Container.

◆ close()

virtual int32_t com::avpkit::core::IContainer::close ( bool  dangling = false)
pure virtual

Close the container.

open() must have been called first, or else an error is returned.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

If this method exits because of an interruption, all resources will be closed anyway.

Returns
>= 0 on success; < 0 on error.

Implemented in com::avpkit::core::Container.

◆ createSDPData()

virtual int32_t com::avpkit::core::IContainer::createSDPData ( com::avpkit::ferry::IBuffer buffer)
pure virtual

Fills the given buffer with a null-terminated ASCII set of bytes representing SDP data that is suitable for use with an RTSP-based system.

This method only works if AVPKit is linking against a version of FFmpeg that supports RTSP.

Parameters
bufferthe com.avpkit.ferry.IBuffer object to fill with data.
Returns
the number of bytes written, including the terminating 0 byte, or < 0 on error.

Implemented in com::avpkit::core::Container.

◆ flushPackets()

virtual int32_t com::avpkit::core::IContainer::flushPackets ( )
pure virtual

Flush all packets to output.

Will only work on IContainer.Type#WRITE containers.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

Returns
>= 0 on success; <0 on error

Implemented in com::avpkit::core::Container.

◆ getBitRate()

virtual int32_t com::avpkit::core::IContainer::getBitRate ( )
pure virtual

Get the calculated overall bit rate of this file.

This will only return a valid value if the container is non-streamed and supports seek.

Returns
The overall bit rate in bytes per second, or <0 on error.

Implemented in com::avpkit::core::Container.

◆ getContainerFormat()

virtual IContainerFormat* com::avpkit::core::IContainer::getContainerFormat ( )
pure virtual

Returns the IContainerFormat object being used for this IContainer, or null if the IContainer doesn't yet know.

Returns
the IContainerFormat object, or null.

Implemented in com::avpkit::core::Container.

◆ getDuration()

virtual int64_t com::avpkit::core::IContainer::getDuration ( )
pure virtual

Gets the duration, if known, of this container.

This will only work for non-streamable containers where IContainer can calculate the container size.

Returns
The duration, or Global#NO_PTS if not known.

Implemented in com::avpkit::core::Container.

◆ getFileSize()

virtual int64_t com::avpkit::core::IContainer::getFileSize ( )
pure virtual

Get the file size in bytes of this container.

This will only return a valid value if the container is non-streamed and supports seek.

Returns
The file size in bytes, or <0 on error.

Implemented in com::avpkit::core::Container.

◆ getFlag()

virtual bool com::avpkit::core::IContainer::getFlag ( Flags  flag)
pure virtual

Get the setting for the specified flag.

Parameters
flagThe flag you want to find the setting for
Returns
0 for false; non-zero for true

Implemented in com::avpkit::core::Container.

◆ getFlags()

virtual int32_t com::avpkit::core::IContainer::getFlags ( )
pure virtual

Get the flags associated with this object.

Returns
The (compacted) value of all flags set.

Implemented in com::avpkit::core::Container.

◆ getFormat()

virtual IContainerFormat* com::avpkit::core::IContainer::getFormat ( )
pure virtual

Get the IContainerFormat that is used by this IContainer.

Returns
The format, or null if none is set yet.
Since
5.0

Implemented in com::avpkit::core::Container.

◆ getInputBufferLength()

virtual int32_t com::avpkit::core::IContainer::getInputBufferLength ( )
pure virtual

Return the input buffer length.

Returns
The input buffer length AVPKit's told FFMPEG to assume. 0 means FFMPEG should choose it's own size (and it'll probably be 32768).

Implemented in com::avpkit::core::Container.

◆ getMaxDelay()

virtual int32_t com::avpkit::core::IContainer::getMaxDelay ( )
pure virtual

Gets the AVFormatContext.max_delay property if possible.

Returns
The max delay, error code otherwise.
Since
4.0

Implemented in com::avpkit::core::Container.

◆ getMetaData()

virtual IMetaData* com::avpkit::core::IContainer::getMetaData ( )
pure virtual

Get the IMetaData for this object, or null if none.

If the IContainer or IStream object that this IMetaData came from was opened for reading, then changes via IMetaData#setValue(String, String) will have no effect on the underlying media.

If the IContainer or IStream object that this IMetaData came from was opened for writing, then changes via IMetaData#setValue(String, String) will have no effect after IContainer#writeHeader() is called.

Returns
the IMetaData.

Implemented in com::avpkit::core::Container.

◆ getNumProperties()

virtual int32_t com::avpkit::core::IContainer::getNumProperties ( )
pure virtual

Returns the total number of settable properties on this object.

Returns
total number of options (not including constant definitions)

Implemented in com::avpkit::core::Container.

◆ getNumStreams()

virtual int32_t com::avpkit::core::IContainer::getNumStreams ( )
pure virtual

The number of streams in this container.

If opened in IContainer.Type#READ mode, this will query the stream and find out how many streams are in it.

If opened in IContainer.Type#WRITE mode, this will return the number of streams the caller has added to date.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

Returns
The number of streams in this container.

Implemented in com::avpkit::core::Container.

◆ getPreload()

virtual int32_t com::avpkit::core::IContainer::getPreload ( )
pure virtual

@Deprecated use getPropertyAsLong instead.

The amount container will attemtp to preload.

Returns
The amount to preload, error code otherwise.

Implemented in com::avpkit::core::Container.

◆ getPropertyAsBoolean()

virtual bool com::avpkit::core::IContainer::getPropertyAsBoolean ( const char *  name)
pure virtual

Gets the value of this property, and returns as a boolean.

Parameters
namename of option
Returns
boolean value of property, or false on error.

Implemented in com::avpkit::core::Container.

◆ getPropertyAsDouble()

virtual double com::avpkit::core::IContainer::getPropertyAsDouble ( const char *  name)
pure virtual

Gets the value of this property, and returns as a double;.

Parameters
namename of option
Returns
double value of property, or 0 on error.

Implemented in com::avpkit::core::Container.

◆ getPropertyAsLong()

virtual int64_t com::avpkit::core::IContainer::getPropertyAsLong ( const char *  name)
pure virtual

Gets the value of this property, and returns as an long;.

Parameters
namename of option
Returns
long value of property, or 0 on error.

Implemented in com::avpkit::core::Container.

◆ getPropertyAsRational()

virtual IRational* com::avpkit::core::IContainer::getPropertyAsRational ( const char *  name)
pure virtual

Gets the value of this property, and returns as an IRational;.

Parameters
namename of option
Returns
long value of property, or 0 on error.

Implemented in com::avpkit::core::Container.

◆ getPropertyAsString()

virtual char* com::avpkit::core::IContainer::getPropertyAsString ( const char *  name)
pure virtual

Gets a property on this Object.

Note for C++ callers; you must free the returned array with delete[] in order to avoid a memory leak. If you call from Java or any other language, you don't need to worry about this.

Parameters
nameproperty name
Returns
an string copy of the option value, or null if the option doesn't exist.

Implemented in com::avpkit::core::Container.

◆ getPropertyMetaData() [1/2]

virtual IProperty* com::avpkit::core::IContainer::getPropertyMetaData ( const char *  name)
pure virtual

Returns the name of the numbered property.

Parameters
nameThe property name.
Returns
an IProperty value for this properties meta-data

Implemented in com::avpkit::core::Container.

◆ getPropertyMetaData() [2/2]

virtual IProperty* com::avpkit::core::IContainer::getPropertyMetaData ( int32_t  propertyNo)
pure virtual

Returns the name of the numbered property.

Parameters
propertyNoThe property number in the options list.
Returns
an IProperty value for this properties meta-data

Implemented in com::avpkit::core::Container.

◆ getReadRetryCount()

virtual int32_t com::avpkit::core::IContainer::getReadRetryCount ( )
pure virtual

Get the number of times IContainer#readNextPacket(IPacket) will retry a read if it gets a IError.Type#ERROR_AGAIN value back.

Defaults to 1 times. <0 means it will keep retrying indefinitely.

Returns
the read retry count

Implemented in com::avpkit::core::Container.

◆ getStandardsCompliance()

virtual IStreamCoder::CodecStandardsCompliance com::avpkit::core::IContainer::getStandardsCompliance ( )
pure virtual

Gets the current level of standards compliance.

Returns
The level of standards compliance.
See also
CodecStandardsCompliance
Since
5.7

Implemented in com::avpkit::core::Container.

◆ getStartTime()

virtual int64_t com::avpkit::core::IContainer::getStartTime ( )
pure virtual

Get the starting timestamp in microseconds of the first packet of the earliest stream in this container.

This will only return value values either either (a) for non-streamable containers where IContainer can calculate the container size or (b) after IContainer has actually read the first packet from a streamable source.

Returns
The starting timestamp in microseconds, or Global#NO_PTS if not known.

Implemented in com::avpkit::core::Container.

◆ getStream()

virtual IStream* com::avpkit::core::IContainer::getStream ( int32_t  streamIndex)
pure virtual

Get the stream at the given position.

Parameters
streamIndexthe index of this stream in the container
Returns
The stream at that position in the container, or null if none there.

Implemented in com::avpkit::core::Container.

◆ getType()

virtual Type com::avpkit::core::IContainer::getType ( )
pure virtual

Find out the type of this container.

Returns
The Type of this container.
IContainer.Type#READ if not yet opened.

Implemented in com::avpkit::core::Container.

◆ getURL()

virtual const char* com::avpkit::core::IContainer::getURL ( )
pure virtual

Get the URL the IContainer was opened with.

May return null if unknown.

Returns
the URL opened, or null.

Implemented in com::avpkit::core::Container.

◆ isHeaderWritten()

virtual bool com::avpkit::core::IContainer::isHeaderWritten ( )
pure virtual

Has a header been successfully written?

Returns
true if yes, false if no.

Implemented in com::avpkit::core::Container.

◆ isOpened()

virtual bool com::avpkit::core::IContainer::isOpened ( )
pure virtual

Is this container opened?

Returns
true if opened; false if not.

Implemented in com::avpkit::core::Container.

◆ make() [1/2]

IContainer * com::avpkit::core::IContainer::make ( )
static

Create a new container object.

Returns
a new container, or null on error.

Definition at line 31 of file IContainer.cpp.

32  {
33  Global::init();
34  return Container::make();
35  }
static void init()
Internal Only.
Definition: Global.cpp:157
static IContainer * make()
Create a new container object.
Definition: IContainer.cpp:31

References com::avpkit::core::Global::init().

Referenced by make().

◆ make() [2/2]

IContainer * com::avpkit::core::IContainer::make ( IContainerFormat format)
static

Create a new IContainer and call setFormat(IContainerFormat) on it immediately.

Parameters
formatThe format to pass to setFormat(IContainerFormat)
Returns
An IContainer on success, or null on failure.
Since
5.0

Definition at line 38 of file IContainer.cpp.

39  {
40  Global::init();
41  return Container::make(format);
42  }

References com::avpkit::core::Global::init(), and make().

◆ open() [1/3]

virtual int32_t com::avpkit::core::IContainer::open ( const char *  url,
Type  type,
IContainerFormat containerFormat,
bool  streamsCanBeAddedDynamically,
bool  queryStreamMetaData,
IMetaData options,
IMetaData optionsNotSet 
)
pure virtual

Open this container and make it ready for reading or writing, optionally reading as far into the container as necessary to find all streams.

The caller must call close() when done, but if not, the IContainer will eventually close them later but warn to the logging system.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

Parameters
urlThe resource to open; The format of this string is any url that FFMPEG supports (including additional protocols if added through the core.io library).
typeThe type of this container.
containerFormatA pointer to a ContainerFormat object specifying the format of this container, or 0 (NULL) if you want us to guess.
streamsCanBeAddedDynamicallyIf true, open() will expect that new streams can be added at any time, even after the format header has been read.
queryStreamMetaDataIf true, open() will call queryStreamMetaData() on this container, which will potentially block until it has ready enough data to find all streams in a container. If false, it will only block to read a minimal header for this container format.
optionsIf not null, a set of key-value pairs that will be set on the container immediately the format is determined. Some options cannot be set (especially for input containers) until the system has a chance to parse what data is in the file.
optionsNotSetIf not null, on return this IMetaData object will be cleared out, and replace with any key/value pairs that were in options but could not be set on this IContainer.
Returns
>= 0 on success; < 0 on error.
Since
5.0

Implemented in com::avpkit::core::Container.

◆ open() [2/3]

virtual int32_t com::avpkit::core::IContainer::open ( const char *  url,
Type  type,
IContainerFormat pContainerFormat 
)
pure virtual

Open this container and make it ready for reading or writing.

The caller must call close() when done, but if not, the IContainer will eventually close them later but warn to the logging system.

This just forwards to open(String, Type, IContainerFormat, boolean, boolean) passing false for aStreamsCanBeAddedDynamically, and true for aLookForAllStreams.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

Parameters
urlThe resource to open; The format of this string is any url that FFMPEG supports (including additional protocols if added through the core.io library).
typeThe type of this container.
pContainerFormatA pointer to a ContainerFormat object specifying the format of this container, or 0 (NULL) if you want us to guess.
Returns
>= 0 on success; < 0 on error.

Implemented in com::avpkit::core::Container.

◆ open() [3/3]

virtual int32_t com::avpkit::core::IContainer::open ( const char *  url,
Type  type,
IContainerFormat pContainerFormat,
bool  aStreamsCanBeAddedDynamically,
bool  aQueryStreamMetaData 
)
pure virtual

Open this container and make it ready for reading or writing, optionally reading as far into the container as necessary to find all streams.

The caller must call close() when done, but if not, the IContainer will eventually close them later but warn to the logging system.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

Parameters
urlThe resource to open; The format of this string is any url that FFMPEG supports (including additional protocols if added through the core.io library).
typeThe type of this container.
pContainerFormatA pointer to a ContainerFormat object specifying the format of this container, or 0 (NULL) if you want us to guess.
aStreamsCanBeAddedDynamicallyIf true, open() will expect that new streams can be added at any time, even after the format header has been read.
aQueryStreamMetaDataIf true, open() will call queryStreamMetaData() on this container, which will potentially block until it has ready enough data to find all streams in a container. If false, it will only block to read a minimal header for this container format.
Returns
>= 0 on success; < 0 on error.

Implemented in com::avpkit::core::Container.

◆ queryStreamMetaData()

virtual int32_t com::avpkit::core::IContainer::queryStreamMetaData ( )
pure virtual

Attempts to read all the meta data in this stream, potentially by reading ahead and decoding packets.

Any packets this method reads ahead will be cached and correctly returned when you read packets, but this method can be non-blocking potentially until end of container to get all meta data. Take care when you call it.

After this method is called, other meta data methods like getDuration() should work.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

Returns
>= 0 on success; <0 on failure.

Implemented in com::avpkit::core::Container.

◆ readNextPacket()

virtual int32_t com::avpkit::core::IContainer::readNextPacket ( IPacket packet)
pure virtual

Reads the next packet into the IPacket.

This method will release any buffers currently held by this packet and allocate new ones.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

Parameters
packet[In/Out] The packet the IContainer will read into.
Returns
0 if successful, or <0 if not.

Implemented in com::avpkit::core::Container.

◆ seekKeyFrame() [1/2]

virtual int32_t com::avpkit::core::IContainer::seekKeyFrame ( int32_t  streamIndex,
int64_t  minTimeStamp,
int64_t  targetTimeStamp,
int64_t  maxTimeStamp,
int32_t  flags 
)
pure virtual

EXPERIMENTAL - Seeks to timestamp in the container.

Seeking will be done so that the point from which all active streams can be presented successfully will be closest to targetTimeStamp and within minTimeStamp/maxTimeStamp.

If flags contain SEEK_FLAG_BYTE, then all time stamps are in bytes and are the file position (this may not be supported by all demuxers). If flags contain SEEK_FLAG_FRAME, then all time stamps are in frames in the stream with streamIndex (this may not be supported by all demuxers). Otherwise all time stamps are in units of the stream selected by stream_index or if stream_index is -1, in microseconds. If flags contain SEEK_FLAG_ANY, then non-keyframes are treated as keyframes (this may not be supported by all demuxers). If flags contain SEEK_FLAG_BACKWARDS, then we will attempt to search backwards in the container (this may not be supported by all demuxers and file protocols).

This is part of the new seek API which is still under construction. It may change in future AVPKit versions.

Parameters
streamIndexindex of the stream which is used as time base reference
minTimeStampsmallest acceptable time stamp.
targetTimeStamptarget time stamp.
maxTimeStamplargest acceptable time stamp.
flagsA bitmask of the SEEK_FLAG_* flags, or 0 to turn all flags off.
Returns
>=0 on success, error code otherwise
Since
3.4

Implemented in com::avpkit::core::Container.

◆ seekKeyFrame() [2/2]

virtual int32_t com::avpkit::core::IContainer::seekKeyFrame ( int32_t  streamIndex,
int64_t  timestamp,
int32_t  flags 
)
pure virtual

Seeks to the key frame at (or the first one after) the given timestamp.

This method will always fail for any IContainer that is not seekable (e.g. is streamed). When successful the next call to readNextPacket(IPacket) will get the next keyframe from the sought for stream.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

WARNING:: This method will be deprecated in a future AVPKit release and replaced with the new API seekKeyFrame(int, long, long, long, int).

Parameters
streamIndexThe stream to search for the keyframe in; must be a stream the IContainer has either queried meta-data about or already ready a packet for.
timestampThe timestamp, in the timebase of the stream you're looking in (not necessarily Microseconds).
flagsFlags to pass to com.avpkit.core.io.IURLProtocolHandler's seek method.
Returns
>= 0 on success; <0 on failure.

◆ setFlag()

virtual void com::avpkit::core::IContainer::setFlag ( Flags  flag,
bool  value 
)
pure virtual

Set the flag.

Parameters
flagThe flag to set
valueThe value to set it to (true or false)

Implemented in com::avpkit::core::Container.

◆ setFlags()

virtual void com::avpkit::core::IContainer::setFlags ( int32_t  newFlags)
pure virtual

Set the flags to use with this object.

All values must be ORed (|) together.

See also
Flags
Parameters
newFlagsThe new set flags for this codec.

Implemented in com::avpkit::core::Container.

◆ setForcedAudioCodec()

virtual int32_t com::avpkit::core::IContainer::setForcedAudioCodec ( ICodec::ID  id)
pure virtual

Forces the IContainer to assume all audio streams are encoded with the given audio codec when demuxing.

Parameters
idThe codec id
Returns
< 0 on error (e.g. not an audio codec); >= 0 on success.
Since
3.3

Implemented in com::avpkit::core::Container.

◆ setForcedSubtitleCodec()

virtual int32_t com::avpkit::core::IContainer::setForcedSubtitleCodec ( ICodec::ID  id)
pure virtual

Forces the IContainer to assume all subtitle streams are encoded with the given subtitle codec when demuxing.

Parameters
idThe codec id
Returns
< 0 on error (e.g. not an subtitle codec); >= 0 on success.
Since
3.3

Implemented in com::avpkit::core::Container.

◆ setForcedVideoCodec()

virtual int32_t com::avpkit::core::IContainer::setForcedVideoCodec ( ICodec::ID  id)
pure virtual

Forces the IContainer to assume all video streams are encoded with the given video codec when demuxing.

Parameters
idThe codec id
Returns
< 0 on error (e.g. not an video codec); >= 0 on success.
Since
3.3

Implemented in com::avpkit::core::Container.

◆ setFormat()

virtual int32_t com::avpkit::core::IContainer::setFormat ( IContainerFormat format)
pure virtual

Set the IContainerFormat to use with this IContainer.

If called when the IContainer is opened, or if previously called with a non-null value, an error is returned and no action is taken.

Parameters
formatThe format to use return 0 on success; <0 on failure
Since
5.0

Implemented in com::avpkit::core::Container.

◆ setInputBufferLength()

virtual int32_t com::avpkit::core::IContainer::setInputBufferLength ( int32_t  size)
pure virtual

Set the buffer length AVPKit will suggest to FFMPEG for reading inputs.

If called when a IContainer is open, the call is ignored and -1 is returned.

Parameters
sizeThe suggested buffer size.
Returns
size on success; <0 on error.

Implemented in com::avpkit::core::Container.

◆ setMaxDelay()

virtual int32_t com::avpkit::core::IContainer::setMaxDelay ( int32_t  maxdelay)
pure virtual

Sets the max delay for the AVFormatContext.max_delay property.

Parameters
maxdelaymaximum delay for container
Returns
>= 0 on success, error code otherwise
Since
4.0

Implemented in com::avpkit::core::Container.

◆ setMetaData()

virtual void com::avpkit::core::IContainer::setMetaData ( IMetaData data)
pure virtual

Set the IMetaData on this object, overriding any previous meta data.

You should call this method on writable containers and before you call IContainer#writeHeader, as it probably won't do anything after that.

See also
getMetaData()

Implemented in com::avpkit::core::Container.

◆ setPreload()

virtual int32_t com::avpkit::core::IContainer::setPreload ( int32_t  preload)
pure virtual

@Deprecated use setProperty instead.

If the container has not already been opened, sets the AVFormatContext.preload property which can be useful in some circumstances such as when dealing with mpeg formats.

Parameters
preloadamount to preload
Returns
>= 0 on success, error code otherwise
Since
4.0

Implemented in com::avpkit::core::Container.

◆ setProperty() [1/5]

virtual int32_t com::avpkit::core::IContainer::setProperty ( const char *  name,
bool  value 
)
pure virtual

Looks up the property 'name' and sets the value of the property to 'value'.

Parameters
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Implemented in com::avpkit::core::Container.

◆ setProperty() [2/5]

virtual int32_t com::avpkit::core::IContainer::setProperty ( const char *  name,
const char *  value 
)
pure virtual

Sets a property on this Object.

All AVOptions supported by the underlying AVClass are supported.

Parameters
nameThe property name. For example "b" for bit-rate.
valueThe value of the property.
Returns
>= 0 if the property was successfully set; <0 on error

Implemented in com::avpkit::core::Container.

◆ setProperty() [3/5]

virtual int32_t com::avpkit::core::IContainer::setProperty ( const char *  name,
double  value 
)
pure virtual

Looks up the property 'name' and sets the value of the property to 'value'.

Parameters
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Implemented in com::avpkit::core::Container.

◆ setProperty() [4/5]

virtual int32_t com::avpkit::core::IContainer::setProperty ( const char *  name,
int64_t  value 
)
pure virtual

Looks up the property 'name' and sets the value of the property to 'value'.

Parameters
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Implemented in com::avpkit::core::Container.

◆ setProperty() [5/5]

virtual int32_t com::avpkit::core::IContainer::setProperty ( const char *  name,
IRational value 
)
pure virtual

Looks up the property 'name' and sets the value of the property to 'value'.

Parameters
namename of option
valueValue of option
Returns
>= 0 on success; <0 on error.

Implemented in com::avpkit::core::Container.

◆ setReadRetryCount()

virtual void com::avpkit::core::IContainer::setReadRetryCount ( int32_t  count)
pure virtual

Sets the read retry count.

See also
getReadRetryCount()
Parameters
countThe read retry count. <0 means keep trying.

Implemented in com::avpkit::core::Container.

◆ setStandardsCompliance()

virtual int32_t com::avpkit::core::IContainer::setStandardsCompliance ( IStreamCoder::CodecStandardsCompliance  compliance)
pure virtual

Set the level of standards compliance.

Only paid attention to before the code is opened.

Parameters
complianceThe desired compliance level to set
Returns
0 on success; non-zero on failure
See also
CodecStandardsCompliance
Since
5.7

Implemented in com::avpkit::core::Container.

◆ writeHeader()

virtual int32_t com::avpkit::core::IContainer::writeHeader ( )
pure virtual

Adds a header, if needed, for this container.

Call this AFTER you've added all streams you want to add, opened all IStreamCoders for those streams (with proper configuration) and before you write the first frame. If you attempt to write a header but haven't opened all codecs, this method will log a warning, and your output file will likely be corrupt.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

Returns
0 if successful. < 0 if not. Always -1 if this is a READ container.

Implemented in com::avpkit::core::Container.

◆ writePacket() [1/2]

virtual int32_t com::avpkit::core::IContainer::writePacket ( IPacket packet)
pure virtual

Writes the contents of the packet to the container, but make sure the packets are interleaved.

This means the IContainer may have to queue up packets from one stream while waiting for packets from another.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

Parameters
packet[In] The packet to write out.
Returns
# of bytes written if successful, or <0 if not.

Implemented in com::avpkit::core::Container.

◆ writePacket() [2/2]

virtual int32_t com::avpkit::core::IContainer::writePacket ( IPacket packet,
bool  forceInterleave 
)
pure virtual

Writes the contents of the packet to the container.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

Parameters
packet[In] The packet to write out.
forceInterleave[In] If true, then this IContainer will make sure all packets are interleaved by DTS (even across streams in a container). If false, the IContainer won't, and it's up to the caller to interleave if necessary.
Returns
# of bytes written if successful, or <0 if not.

Implemented in com::avpkit::core::Container.

◆ writeTrailer()

virtual int32_t com::avpkit::core::IContainer::writeTrailer ( )
pure virtual

Adds a trailer, if needed, for this container.

Call this AFTER you've written all data you're going to write to this container but BEFORE you call IStreamCoder#close() on your IStreamCoder objects.

You must call writeHeader() before you call this (and if you don't, the IContainer will warn loudly and not actually write the trailer).

If you have closed any of the IStreamCoder objects that were open when you called writeHeader(), then this method will fail.

If the current thread is interrupted while this blocking method is running the method will return with a negative value. To check if the method exited because of an interruption pass the return value to IError#make(int) and then check IError#getType() to see if it is IError.Type#ERROR_INTERRUPTED.

Returns
0 if successful. < 0 if not. Always <0 if this is a READ container.

Implemented in com::avpkit::core::Container.


The documentation for this class was generated from the following files: