AVPKit
IContainer.h
1 /*******************************************************************************
2  * Copyright (c) 2024, 2026, Olivier Ayache. All rights reserved.
3  *
4  * This file is part of AVPKit.
5  *
6  * AVPKit is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * AVPKit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with AVPKit. If not, see <http://www.gnu.org/licenses/>.
18  *******************************************************************************/
19 
20 #ifndef ICONTAINER_H_
21 #define ICONTAINER_H_
22 
23 #include <com/avpkit/ferry/RefCounted.h>
24 #include <com/avpkit/ferry/IBuffer.h>
25 #include <com/avpkit/core/AVPKit.h>
26 #include <com/avpkit/core/ICodec.h>
27 #include <com/avpkit/core/IContainerFormat.h>
28 #include <com/avpkit/core/IStream.h>
29 #include <com/avpkit/core/IStreamCoder.h>
30 #include <com/avpkit/core/IPacket.h>
31 #include <com/avpkit/core/IProperty.h>
32 
33 namespace com { namespace avpkit { namespace core
34 {
35  class IMetaData;
36 
99  class VS_API_AVPKIT IContainer : public com::avpkit::ferry::RefCounted
100  {
101  public:
106  typedef enum Type {
107  READ,
108  WRITE,
109  } Type;
110 
119  virtual int32_t setInputBufferLength(int32_t size)=0;
120 
128  virtual int32_t getInputBufferLength()=0;
129 
134  virtual bool isOpened()=0;
135 
140  virtual bool isHeaderWritten()=0;
141 
169  virtual int32_t open(const char *url, Type type,
170  IContainerFormat* pContainerFormat)=0;
171 
201  virtual int32_t open(const char *url, Type type,
202  IContainerFormat* pContainerFormat,
203  bool aStreamsCanBeAddedDynamically,
204  bool aQueryStreamMetaData)=0;
205 
213 
224 
232 
249  virtual int32_t close(bool dangling=false)=0;
250 
257  virtual Type getType()=0;
258 
274  virtual int32_t getNumStreams()=0;
275 
282  virtual IStream* getStream(int32_t streamIndex)=0;
283 
293  virtual IStream* addNewStream(int32_t id)=0;
294 
315  virtual int32_t writeHeader()=0;
316 
345  virtual int32_t writeTrailer()=0;
346 
363  virtual int32_t readNextPacket(IPacket *packet)=0;
364 
385  virtual int32_t writePacket(IPacket *packet, bool forceInterleave)=0;
386 
405  virtual int32_t writePacket(IPacket *packet)=0;
406 
413  static IContainer* make();
414  protected:
415  virtual ~IContainer()=0;
416 
417  /*
418  * Added as of 1.17
419  */
420  public:
421 
440  virtual int32_t queryStreamMetaData()=0;
441 
467  virtual int32_t seekKeyFrame(int32_t streamIndex, int64_t timestamp, int32_t flags)=0;
468 
477  virtual int64_t getDuration()=0;
478 
490  virtual int64_t getStartTime()=0;
491 
499  virtual int64_t getFileSize()=0;
500 
508  virtual int32_t getBitRate()=0;
509 
510  /*
511  * Added for 1.19
512  */
513 
519  virtual int32_t getNumProperties()=0;
520 
528  virtual IProperty *getPropertyMetaData(int32_t propertyNo)=0;
529 
537  virtual IProperty *getPropertyMetaData(const char *name)=0;
538 
549  virtual int32_t setProperty(const char *name, const char* value)=0;
550 
551 
561  virtual int32_t setProperty(const char* name, double value)=0;
562 
572  virtual int32_t setProperty(const char* name, int64_t value)=0;
573 
583  virtual int32_t setProperty(const char* name, bool value)=0;
584 
594  virtual int32_t setProperty(const char* name, IRational *value)=0;
595 
596 #ifdef SWIG
597  %newobject getPropertyAsString(const char*);
598  %typemap(newfree) char * "free($1);";
599 #endif
614  virtual char * getPropertyAsString(const char* name)=0;
615 
623  virtual double getPropertyAsDouble(const char* name)=0;
624 
632  virtual int64_t getPropertyAsLong(const char* name)=0;
633 
641  virtual IRational *getPropertyAsRational(const char* name)=0;
642 
650  virtual bool getPropertyAsBoolean(const char* name)=0;
651 
652  typedef enum Flags {
653  FLAG_GENPTS=0x0001,
654  FLAG_IGNIDX=0x0002,
655  FLAG_NONBLOCK=0x0004,
656  FLAG_IGNDTS=0x0008,
657  FLAG_NOFILLIN=0x0010,
658  FLAG_NOPARSE=0x0020,
659  FLAG_NOBUFFER=0x0040,
660  FLAG_CUSTOM_IO=0x0080,
661  FLAG_DISCARD_CORRUPT=0x0100,
662  FLAG_FLUSH_PACKETS=0x0200,
663  FLAG_BITEXACT=0x0400,
664  FLAG_MP4A_LATM=0x8000,
665  FLAG_SORT_DTS=0x10000,
666  FLAG_PRIV_OPT=0x20000,
667  FLAG_KEEP_SIDE_DATA=0x40000,
668  FLAG_FAST_SEEK=0x80000,
669  FLAG_SHORTEST=0x100000,
670  FLAG_AUTO_BSF=0x200000
671  } Flags;
672 
678  virtual int32_t getFlags()=0;
679 
688  virtual void setFlags(int32_t newFlags) = 0;
689 
697  virtual bool getFlag(Flags flag) = 0;
698 
706  virtual void setFlag(Flags flag, bool value) = 0;
707 
708 
714  virtual const char* getURL()=0;
715 
730  virtual int32_t flushPackets()=0;
731 
732  /*
733  * Added for 1.23
734  */
735 
745  virtual int32_t getReadRetryCount()=0;
746 
754  virtual void setReadRetryCount(int32_t count)=0;
755 
756 
757  /*
758  * Added for 3.0
759  */
760 
767 
768  /*
769  * Added for 3.1
770  */
771 
790  virtual IMetaData* getMetaData()=0;
791 
801  virtual void setMetaData(IMetaData* data)=0;
802 
816  virtual int32_t createSDPData(com::avpkit::ferry::IBuffer* buffer)=0;
817 
818  /*
819  * For 3.3
820  */
821 
829  virtual int32_t setForcedAudioCodec(ICodec::ID id)=0;
830 
838  virtual int32_t setForcedVideoCodec(ICodec::ID id)=0;
839 
847  virtual int32_t setForcedSubtitleCodec(ICodec::ID id)=0;
848 
849  /*
850  * Added for 3.4
851  */
852 
854  static const int32_t SEEK_FLAG_BACKWARDS=1;
856  static const int32_t SEEK_FLAG_BYTE=2;
858  static const int32_t SEEK_FLAG_ANY=4;
860  static const int32_t SEEK_FLAG_FRAME=8;
861 
896  virtual int32_t seekKeyFrame(int32_t streamIndex, int64_t minTimeStamp,
897  int64_t targetTimeStamp, int64_t maxTimeStamp, int32_t flags)=0;
898 
909  virtual int32_t setPreload(int32_t preload)=0;
910 
917  virtual int32_t getPreload()=0;
918 
926  virtual int32_t setMaxDelay(int32_t maxdelay)=0;
927 
933  virtual int32_t getMaxDelay()=0;
934 
935  /*
936  * Added for 5.0
937  */
938 
957  virtual IStream* addNewStream(ICodec* codec)=0;
958 
967  virtual IStream* addNewStream(IStreamCoder* coder)=0;
968 
972  virtual int32_t setProperty(IMetaData* valuesToSet, IMetaData* valuesNotFound)=0;
973 
981 
990  virtual int32_t setFormat(IContainerFormat* format)=0;
991 
998  static IContainer* make(IContainerFormat* format);
999 
1036  virtual int32_t open(const char *url, Type type,
1037  IContainerFormat* containerFormat,
1038  bool streamsCanBeAddedDynamically,
1039  bool queryStreamMetaData,
1040  IMetaData* options,
1041  IMetaData* optionsNotSet)=0;
1042  };
1043 }}}
1044 #endif /*ICONTAINER_H_*/
A "key" to an IStreamCoder that tells it how to encode or decode data.
Definition: ICodec.h:53
ID
These are the codecs this library currently supports.
Definition: ICodec.h:61
Specifies format information than can be used to configure an IContainer for input or output.
A file (or network data source) that contains one or more IStream objects of audio and video data.
Definition: IContainer.h:100
virtual int32_t setInputBufferLength(int32_t size)=0
Set the buffer length AVPKit will suggest to FFMPEG for reading inputs.
virtual int32_t getReadRetryCount()=0
Get the number of times IContainer#readNextPacket(IPacket) will retry a read if it gets a IError....
virtual double getPropertyAsDouble(const char *name)=0
Gets the value of this property, and returns as a double;.
virtual IStream * getStream(int32_t streamIndex)=0
Get the stream at the given position.
virtual IStreamCoder::CodecStandardsCompliance getStandardsCompliance()=0
Gets the current level of standards compliance.
virtual void setMetaData(IMetaData *data)=0
Set the IMetaData on this object, overriding any previous meta data.
virtual void setReadRetryCount(int32_t count)=0
Sets the read retry count.
virtual int32_t setMaxDelay(int32_t maxdelay)=0
Sets the max delay for the AVFormatContext.max_delay property.
virtual int32_t setForcedVideoCodec(ICodec::ID id)=0
Forces the IContainer to assume all video streams are encoded with the given video codec when demuxin...
virtual int32_t getNumStreams()=0
The number of streams in this container.
virtual int64_t getDuration()=0
Gets the duration, if known, of this container.
virtual int32_t writeHeader()=0
Adds a header, if needed, for this container.
virtual int32_t setForcedAudioCodec(ICodec::ID id)=0
Forces the IContainer to assume all audio streams are encoded with the given audio codec when demuxin...
virtual int64_t getPropertyAsLong(const char *name)=0
Gets the value of this property, and returns as an long;.
virtual int64_t getFileSize()=0
Get the file size in bytes of this container.
virtual IProperty * getPropertyMetaData(const char *name)=0
Returns the name of the numbered property.
virtual int32_t getPreload()=0
@Deprecated use getPropertyAsLong instead.
virtual IStream * addNewStream(int32_t id)=0
virtual IStream * addNewStream(ICodec::ID id)=0
Add a new stream that will use the given codec.
virtual int32_t setFormat(IContainerFormat *format)=0
Set the IContainerFormat to use with this IContainer.
virtual int32_t setProperty(const char *name, bool value)=0
Looks up the property 'name' and sets the value of the property to 'value'.
virtual int32_t getBitRate()=0
Get the calculated overall bit rate of this file.
virtual IStream * addNewStream(ICodec *codec)=0
Add a new stream that will use the given codec.
virtual int32_t open(const char *url, Type type, IContainerFormat *pContainerFormat)=0
Open this container and make it ready for reading or writing.
virtual int32_t setProperty(const char *name, const char *value)=0
Sets a property on this Object.
virtual void setFlags(int32_t newFlags)=0
Set the flags to use with this object.
virtual bool canStreamsBeAddedDynamically()=0
Can streams be added dynamically to this container?
virtual int32_t setProperty(const char *name, double value)=0
Looks up the property 'name' and sets the value of the property to 'value'.
virtual int32_t setPreload(int32_t preload)=0
@Deprecated use setProperty instead.
virtual Type getType()=0
Find out the type of this container.
virtual bool isOpened()=0
Is this container opened?
virtual int32_t writePacket(IPacket *packet, bool forceInterleave)=0
Writes the contents of the packet to the container.
virtual int32_t writeTrailer()=0
Adds a trailer, if needed, for this container.
virtual void setFlag(Flags flag, bool value)=0
Set the flag.
virtual IContainerFormat * getFormat()=0
Get the IContainerFormat that is used by this IContainer.
Type
The different types of Containers AVPKit supports.
Definition: IContainer.h:106
virtual int32_t getNumProperties()=0
Returns the total number of settable properties on this object.
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 cont...
virtual int32_t flushPackets()=0
Flush all packets to output.
virtual const char * getURL()=0
Get the URL the IContainer was opened with.
virtual IRational * getPropertyAsRational(const char *name)=0
Gets the value of this property, and returns as an IRational;.
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.
virtual int32_t getMaxDelay()=0
Gets the AVFormatContext.max_delay property if possible.
virtual int32_t setForcedSubtitleCodec(ICodec::ID id)=0
Forces the IContainer to assume all subtitle streams are encoded with the given subtitle codec when d...
virtual IStream * addNewStream(IStreamCoder *coder)=0
Add a new stream that will use the given StreamCoder.
virtual int32_t setProperty(const char *name, IRational *value)=0
Looks up the property 'name' and sets the value of the property to 'value'.
virtual int32_t writePacket(IPacket *packet)=0
Writes the contents of the packet to the container, but make sure the packets are interleaved.
virtual IContainerFormat * getContainerFormat()=0
Returns the IContainerFormat object being used for this IContainer, or null if the IContainer doesn't...
virtual int32_t getFlags()=0
Get the flags associated with this object.
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.
virtual int32_t queryStreamMetaData()=0
Attempts to read all the meta data in this stream, potentially by reading ahead and decoding packets.
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 cont...
virtual bool isHeaderWritten()=0
Has a header been successfully written?
virtual bool getPropertyAsBoolean(const char *name)=0
Gets the value of this property, and returns as a boolean.
virtual int32_t close(bool dangling=false)=0
Close the container.
virtual int32_t setProperty(IMetaData *valuesToSet, IMetaData *valuesNotFound)=0
virtual int32_t getInputBufferLength()=0
Return the input buffer length.
virtual int32_t setStandardsCompliance(IStreamCoder::CodecStandardsCompliance compliance)=0
Set the level of standards compliance.
virtual IMetaData * getMetaData()=0
Get the IMetaData for this object, or null if none.
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'.
virtual char * getPropertyAsString(const char *name)=0
Gets a property on this Object.
virtual int32_t readNextPacket(IPacket *packet)=0
Reads the next packet into the IPacket.
virtual bool getFlag(Flags flag)=0
Get the setting for the specified flag.
virtual int64_t getStartTime()=0
Get the starting timestamp in microseconds of the first packet of the earliest stream in this contain...
virtual IProperty * getPropertyMetaData(int32_t propertyNo)=0
Returns the name of the numbered property.
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 suitab...
Get MetaData about a IContainer or IStream.
Definition: IMetaData.h:51
Represents an encoded piece of data that can be placed in an IContainer for a given IStream of data.
Definition: IPacket.h:50
Represents settable properties that effect how AVPKit objects operate.
Definition: IProperty.h:37
This class wraps represents a Rational number for the AVPKit.
Definition: IRational.h:43
The work horse of the AVPKit: Takes IPacket data from an IContainer (representing an IStream) and an ...
Definition: IStreamCoder.h:45
CodecStandardsCompliance
An enumeration of how strictly Codecs may follow the spec.
Definition: IStreamCoder.h:959
Represents a stream of similar data (eg video) in a IContainer.
Definition: IStream.h:50
Allows Java code to get data from a native buffers, and optionally modify native memory directly.
Definition: IBuffer.h:54
Parent of all Ferry objects – it mains reference counts in native code.
Definition: RefCounted.h:85
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...