AVPKit
Stream.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 STREAM_H_
21 #define STREAM_H_
22 
23 #include <com/avpkit/ferry/RefPointer.h>
24 #include <com/avpkit/core/IStream.h>
25 #include <com/avpkit/core/FfmpegIncludes.h>
26 #include <com/avpkit/core/IRational.h>
27 #include <com/avpkit/core/IMetaData.h>
28 
29 namespace com { namespace avpkit { namespace core
30 {
31 
32  class StreamCoder;
33  class Container;
34  class IPacket;
35 
36  class Stream : public IStream
37  {
38  VS_JNIUTILS_REFCOUNTED_OBJECT_PRIVATE_MAKE(Stream)
39  public:
40 
41  // IStream
42  virtual Direction getDirection() { return mDirection; }
43  virtual int getIndex();
44  virtual int getId();
45  virtual IStreamCoder * getStreamCoder();
46  virtual IRational * getFrameRate();
47  virtual IRational * getTimeBase();
48  virtual int64_t getStartTime();
49  virtual int64_t getDuration();
50  virtual int64_t getCurrentDts();
51  virtual int getNumIndexEntries();
52  virtual int64_t getNumFrames();
53 
54  // Not for calling from Java
55  static Stream * make(Container* container, AVStream *, Direction direction, const AVCodec*);
56 
57  // The StreamCoder will call this if it needs to
58  virtual void setTimeBase(IRational *);
59  virtual void setFrameRate(IRational *);
60 
61  // Called by the managing container when it is closed
62  // at this point this stream is no longer valid.
63  virtual int containerClosed(Container* container);
64 
65  virtual int32_t acquire();
66  virtual int32_t release();
67 
69  virtual void setSampleAspectRatio(IRational* newRatio);
70  virtual const char* getLanguage();
71  virtual void setLanguage(const char* language);
72 
73  virtual IContainer* getContainer();
75  virtual void setParseType(ParseType type);
76 
77  virtual int setBitstreamFilter(const char* name);
78 
79  virtual int32_t setStreamCoder(IStreamCoder *coder);
80 
81  virtual AVStream* getAVStream() { return mStream; }
82 
83  virtual AVBSFContext* getAVBsfContext() { return mBsfContext; }
84 
85  virtual IMetaData* getMetaData();
86  virtual void setMetaData(IMetaData* metaData);
87 
88  virtual int32_t stampOutputPacket(IPacket* packet);
89  virtual int32_t setStreamCoder(IStreamCoder *newCoder, bool assumeOnlyStream);
90  virtual IIndexEntry* findTimeStampEntryInIndex(
91  int64_t wantedTimeStamp, int32_t flags);
92  virtual int32_t findTimeStampPositionInIndex(
93  int64_t wantedTimeStamp, int32_t flags);
94  virtual IIndexEntry* getIndexEntry(int32_t position);
95  virtual int32_t addIndexEntry(IIndexEntry* entry);
96  void setId(int32_t id);
97 
98  protected:
99  Stream();
100  virtual ~Stream();
101 
102  private:
103  void reset();
104  AVBSFContext *mBsfContext;
105  AVStream *mStream;
106  Direction mDirection;
107  StreamCoder* mCoder;
108  Container* mContainer;
110 
111  int64_t mLastDts;
112  };
113 
114 }}}
115 
116 #endif /*STREAM_H_*/
A file (or network data source) that contains one or more IStream objects of audio and video data.
Definition: IContainer.h:100
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
Represents a stream of similar data (eg video) in a IContainer.
Definition: IStream.h:50
Direction
The direction this stream is going (based on the container).
Definition: IStream.h:59
ParseType
What types of parsing can we do on a call to IContainer#readNextPacket(IPacket).
Definition: IStream.h:222
virtual int32_t acquire()
Internal Only.
Definition: Stream.cpp:204
virtual IContainer * getContainer()
Get the underlying container for this stream, or null if AVPKit doesn't know.
Definition: Stream.cpp:269
virtual int64_t getDuration()
Return the duration, in getTimeBase() units, of this stream, or Global#NO_PTS if unknown.
Definition: Stream.cpp:172
virtual IRational * getTimeBase()
The time base in which all timestamps (e.g.
Definition: Stream.cpp:137
virtual int getNumIndexEntries()
Get the number of index entries in this stream.
Definition: Stream.cpp:189
virtual int getId()
Return a container format specific id for this stream.
Definition: Stream.cpp:107
virtual IRational * getFrameRate()
Get the (sometimes estimated) frame rate of this container.
Definition: Stream.cpp:125
virtual IMetaData * getMetaData()
Get the IMetaData for this object, or null if none.
Definition: Stream.cpp:368
virtual IStream::ParseType getParseType()
Get how the decoding codec should parse data from this stream.
Definition: Stream.cpp:320
virtual int64_t getCurrentDts()
The current Decompression Time Stamp that will be used on this stream, in getTimeBase() units.
Definition: Stream.cpp:178
virtual IIndexEntry * findTimeStampEntryInIndex(int64_t wantedTimeStamp, int32_t flags)
Search for the given time stamp in the key-frame index for this IStream.
Definition: Stream.cpp:465
virtual int32_t stampOutputPacket(IPacket *packet)
Takes a packet destined for this stream, and stamps the stream index, and converts the time stamp to ...
Definition: Stream.cpp:395
virtual void setLanguage(const char *language)
Set the 4-character language setting for this stream.
Definition: Stream.cpp:259
virtual int getIndex()
Get the relative position this stream has in the hosting IContainer object.
Definition: Stream.cpp:101
virtual int64_t getStartTime()
Return the start time, in getTimeBase() units, when this stream started.
Definition: Stream.cpp:166
virtual int setBitstreamFilter(const char *name)
Set a bitstream filter on this stream.
Definition: Stream.cpp:338
virtual void setMetaData(IMetaData *metaData)
Set the IMetaData on this object, overriding any previous meta data.
Definition: Stream.cpp:383
virtual Direction getDirection()
Get the Direction this stream is pointing in.
Definition: Stream.h:42
virtual IStreamCoder * getStreamCoder()
Get the StreamCoder than can manipulate this stream.
Definition: Stream.cpp:113
virtual int32_t setStreamCoder(IStreamCoder *coder)
Sets the stream coder to use for this stream.
Definition: Stream.cpp:277
virtual const char * getLanguage()
Get the 4-character language setting for this stream.
Definition: Stream.cpp:248
virtual int32_t findTimeStampPositionInIndex(int64_t wantedTimeStamp, int32_t flags)
Search for the given time stamp in the key-frame index for this IStream.
Definition: Stream.cpp:472
virtual int32_t addIndexEntry(IIndexEntry *entry)
Adds an index entry into the stream's sorted index list.
Definition: Stream.cpp:507
void setId(int32_t id)
Set the format-specific stream id.
Definition: Stream.cpp:522
virtual IRational * getSampleAspectRatio()
Added in 1.17.
Definition: Stream.cpp:222
virtual int64_t getNumFrames()
Returns the number of encoded frames if known.
Definition: Stream.cpp:184
virtual void setParseType(ParseType type)
Set the parse type the decoding codec should use.
Definition: Stream.cpp:330
virtual int32_t release()
Internal Only.
Definition: Stream.cpp:213
virtual IIndexEntry * getIndexEntry(int32_t position)
Get the IIndexEntry at the given position in this IStream object's index.
Definition: Stream.cpp:486
virtual void setSampleAspectRatio(IRational *newRatio)
Sets the sample aspect ratio.
Definition: Stream.cpp:235
This class is only useful from C++.
Definition: RefPointer.h:47
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...