AVPKit
com::avpkit::core::Stream Class Reference
Inheritance diagram for com::avpkit::core::Stream:
Collaboration diagram for com::avpkit::core::Stream:

Public Member Functions

virtual Direction getDirection ()
 Get the Direction this stream is pointing in. More...
 
virtual int getIndex ()
 Get the relative position this stream has in the hosting IContainer object. More...
 
virtual int getId ()
 Return a container format specific id for this stream. More...
 
virtual IStreamCodergetStreamCoder ()
 Get the StreamCoder than can manipulate this stream. More...
 
virtual IRationalgetFrameRate ()
 Get the (sometimes estimated) frame rate of this container. More...
 
virtual IRationalgetTimeBase ()
 The time base in which all timestamps (e.g. More...
 
virtual int64_t getStartTime ()
 Return the start time, in getTimeBase() units, when this stream started. More...
 
virtual int64_t getDuration ()
 Return the duration, in getTimeBase() units, of this stream, or Global#NO_PTS if unknown. More...
 
virtual int64_t getCurrentDts ()
 The current Decompression Time Stamp that will be used on this stream, in getTimeBase() units. More...
 
virtual int getNumIndexEntries ()
 Get the number of index entries in this stream. More...
 
virtual int64_t getNumFrames ()
 Returns the number of encoded frames if known. More...
 
virtual void setTimeBase (IRational *)
 
virtual void setFrameRate (IRational *)
 
virtual int containerClosed (Container *container)
 
virtual int32_t acquire ()
 Internal Only. More...
 
virtual int32_t release ()
 Internal Only. More...
 
virtual IRationalgetSampleAspectRatio ()
 Added in 1.17. More...
 
virtual void setSampleAspectRatio (IRational *newRatio)
 Sets the sample aspect ratio. More...
 
virtual const char * getLanguage ()
 Get the 4-character language setting for this stream. More...
 
virtual void setLanguage (const char *language)
 Set the 4-character language setting for this stream. More...
 
virtual IContainergetContainer ()
 Get the underlying container for this stream, or null if AVPKit doesn't know. More...
 
virtual IStream::ParseType getParseType ()
 Get how the decoding codec should parse data from this stream. More...
 
virtual void setParseType (ParseType type)
 Set the parse type the decoding codec should use. More...
 
virtual int setBitstreamFilter (const char *name)
 Set a bitstream filter on this stream. More...
 
virtual int32_t setStreamCoder (IStreamCoder *coder)
 Sets the stream coder to use for this stream. More...
 
virtual AVStream * getAVStream ()
 
virtual AVBSFContext * getAVBsfContext ()
 
virtual IMetaDatagetMetaData ()
 Get the IMetaData for this object, or null if none. More...
 
virtual void setMetaData (IMetaData *metaData)
 Set the IMetaData on this object, overriding any previous meta data. More...
 
virtual int32_t stampOutputPacket (IPacket *packet)
 Takes a packet destined for this stream, and stamps the stream index, and converts the time stamp to the correct units (adjusting for rounding errors between stream conversions). More...
 
virtual int32_t setStreamCoder (IStreamCoder *newCoder, bool assumeOnlyStream)
 Sets the stream coder to use for this stream. More...
 
virtual IIndexEntryfindTimeStampEntryInIndex (int64_t wantedTimeStamp, int32_t flags)
 Search for the given time stamp in the key-frame index for this IStream. More...
 
virtual int32_t findTimeStampPositionInIndex (int64_t wantedTimeStamp, int32_t flags)
 Search for the given time stamp in the key-frame index for this IStream. More...
 
virtual IIndexEntrygetIndexEntry (int32_t position)
 Get the IIndexEntry at the given position in this IStream object's index. More...
 
virtual int32_t addIndexEntry (IIndexEntry *entry)
 Adds an index entry into the stream's sorted index list. More...
 
void setId (int32_t id)
 Set the format-specific stream id. More...
 
- Public Member Functions inherited from com::avpkit::ferry::RefCounted
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 Streammake (Container *container, AVStream *, Direction direction, const AVCodec *)
 

Additional Inherited Members

- Public Types inherited from com::avpkit::core::IStream
enum  Direction { INBOUND , OUTBOUND }
 The direction this stream is going (based on the container). More...
 
enum  ParseType {
  PARSE_NONE , PARSE_FULL , PARSE_HEADERS , PARSE_TIMESTAMPS ,
  PARSE_FULL_ONCE , PARSE_FULL_RAW
}
 What types of parsing can we do on a call to IContainer#readNextPacket(IPacket). More...
 
typedef enum com::avpkit::core::IStream::Direction Direction
 The direction this stream is going (based on the container). More...
 
typedef enum com::avpkit::core::IStream::ParseType ParseType
 What types of parsing can we do on a call to IContainer#readNextPacket(IPacket).
 
- 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

Definition at line 36 of file Stream.h.

Member Function Documentation

◆ acquire()

int32_t com::avpkit::core::Stream::acquire ( )
virtual

Internal Only.

DO NOT USE FROM JAVA.

Acquire a reference to this object. This increments the native internal ref count in native code by +1.

This method is called internally by Ferry in Java, and you should not call it without knowing what you are doing. But if you do call it, make sure you call release() once for each call you make to this method.

Returns
The refcount after the acquire. Note due to multi-threaded issues, you should not rely on this value, as it may change before the method returns to you.

Reimplemented from com::avpkit::ferry::RefCounted.

Definition at line 204 of file Stream.cpp.

205  {
206  int retval = 0;
207  retval = RefCounted::acquire();
208  VS_LOG_TRACE("Acquired %p: %d", this, retval);
209  return retval;
210  }
virtual int32_t acquire()
Internal Only.
Definition: RefCounted.cpp:63

References com::avpkit::ferry::RefCounted::acquire().

◆ addIndexEntry()

int32_t com::avpkit::core::Stream::addIndexEntry ( IIndexEntry entry)
virtual

Adds an index entry into the stream's sorted index list.

Updates the entry if the list already contains it.

Parameters
entryThe entry to add.
Returns
>=0 on success; <0 on error.
Since
3.4

Implements com::avpkit::core::IStream.

Definition at line 507 of file Stream.cpp.

508  {
509  if (!entry)
510  return -1;
511  if (!mStream)
512  return -1;
513  return av_add_index_entry(mStream,
514  entry->getPosition(),
515  entry->getTimeStamp(),
516  entry->getSize(),
517  entry->getMinDistance(),
518  entry->getFlags());
519  }

References com::avpkit::core::IIndexEntry::getFlags(), com::avpkit::core::IIndexEntry::getMinDistance(), com::avpkit::core::IIndexEntry::getPosition(), com::avpkit::core::IIndexEntry::getSize(), and com::avpkit::core::IIndexEntry::getTimeStamp().

◆ findTimeStampEntryInIndex()

IIndexEntry * com::avpkit::core::Stream::findTimeStampEntryInIndex ( int64_t  wantedTimeStamp,
int32_t  flags 
)
virtual

Search for the given time stamp in the key-frame index for this IStream.

Not all IContainerFormat implementations maintain key frame indexes, but if they have one, then this method searches in the IStream index to quickly find the byte-offset of the nearest key-frame to the given time stamp.

Parameters
wantedTimeStampthe time stamp wanted, in the stream's time base units.
flagsA bitmask of the SEEK_FLAG_* flags, or 0 to turn all flags off. If IContainer#SEEK_FLAG_BACKWARDS then the returned index will correspond to the time stamp which is <= the requested one (not supported by all demuxers). If IContainer#SEEK_FLAG_BACKWARDS is not set then it will be >=. if IContainer#SEEK_FLAG_ANY seek to any frame, only keyframes otherwise (not supported by all demuxers).
Returns
The IIndexEntry for the nearest appropriate timestamp in the index, or null if it can't be found.
Since
3.4

Implements com::avpkit::core::IStream.

Definition at line 465 of file Stream.cpp.

466  {
467  int32_t index = findTimeStampPositionInIndex(wantedTimeStamp, flags);
468  // getIndexEntry will check for a negative index and return null if so
469  return getIndexEntry(index);
470  }
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 IIndexEntry * getIndexEntry(int32_t position)
Get the IIndexEntry at the given position in this IStream object's index.
Definition: Stream.cpp:486

References findTimeStampPositionInIndex(), and getIndexEntry().

◆ findTimeStampPositionInIndex()

int32_t com::avpkit::core::Stream::findTimeStampPositionInIndex ( int64_t  wantedTimeStamp,
int32_t  flags 
)
virtual

Search for the given time stamp in the key-frame index for this IStream.

Not all IContainerFormat implementations maintain key frame indexes, but if they have one, then this method searches in the IStream index to quickly find the index entry position of the nearest key-frame to the given time stamp.

Parameters
wantedTimeStampthe time stamp wanted, in the stream's time base units.
flagsA bitmask of the SEEK_FLAG_* flags, or 0 to turn all flags off. If IContainer#SEEK_FLAG_BACKWARDS then the returned index will correspond to the time stamp which is <= the requested one (not supported by all demuxers). If IContainer#SEEK_FLAG_BACKWARDS is not set then it will be >=. if IContainer#SEEK_FLAG_ANY seek to any frame, only keyframes otherwise (not supported by all demuxers).
Returns
The position in this IStream index, or -1 if it cannot be found or an index is not maintained.
See also
#getIndexEntry(int)
Since
3.4

Implements com::avpkit::core::IStream.

Definition at line 472 of file Stream.cpp.

474  {
475  int retval = -1;
476  if (mStream) {
477  retval = av_index_search_timestamp(
478  mStream,
479  wantedTimeStamp,
480  flags);
481  }
482  return retval;
483  }

Referenced by findTimeStampEntryInIndex().

◆ getContainer()

IContainer * com::avpkit::core::Stream::getContainer ( )
virtual

Get the underlying container for this stream, or null if AVPKit doesn't know.

Returns
the container, or null if we don't know.

Implements com::avpkit::core::IStream.

Definition at line 269 of file Stream.cpp.

270  {
271  // add ref for caller
272  VS_REF_ACQUIRE(mContainer);
273  return mContainer;
274  }

◆ getCurrentDts()

int64_t com::avpkit::core::Stream::getCurrentDts ( )
virtual

The current Decompression Time Stamp that will be used on this stream, in getTimeBase() units.

Returns
The current Decompression Time Stamp that will be used on this stream.

Implements com::avpkit::core::IStream.

Definition at line 178 of file Stream.cpp.

179  {
180  return (mStream ? mStream->cur_dts : Global::NO_PTS);
181  }
static const int64_t NO_PTS
A value that means no time stamp is set for a given object.
Definition: Global.h:50

References com::avpkit::core::Global::NO_PTS.

◆ getDirection()

virtual Direction com::avpkit::core::Stream::getDirection ( )
inlinevirtual

Get the Direction this stream is pointing in.

Returns
The direction of this stream.

Implements com::avpkit::core::IStream.

Definition at line 42 of file Stream.h.

42 { return mDirection; }

◆ getDuration()

int64_t com::avpkit::core::Stream::getDuration ( )
virtual

Return the duration, in getTimeBase() units, of this stream, or Global#NO_PTS if unknown.

Returns
The duration (in getTimeBase units) of this stream, if known.

Implements com::avpkit::core::IStream.

Definition at line 172 of file Stream.cpp.

173  {
174  return (mStream ? mStream->duration : Global::NO_PTS);
175  }

References com::avpkit::core::Global::NO_PTS.

◆ getFrameRate()

IRational * com::avpkit::core::Stream::getFrameRate ( )
virtual

Get the (sometimes estimated) frame rate of this container.

For variable frame-rate containers (they do exist) this is just an approimation. Better to use getTimeBase().

For contant frame-rate containers, this will be 1 / ( getTimeBase() )

Returns
The frame-rate of this container.

Implements com::avpkit::core::IStream.

Definition at line 125 of file Stream.cpp.

126  {
127  IRational * result = 0;
128  if (mStream)
129  {
130  AVRational f = av_guess_frame_rate(NULL, mStream, NULL);
131  result = Rational::make(&f);
132  }
133  return result;
134  }
static IRational * make()
Get a new rational that will be set to 0/0.
Definition: IRational.cpp:79

References com::avpkit::core::IRational::make().

◆ getId()

int com::avpkit::core::Stream::getId ( )
virtual

Return a container format specific id for this stream.

Returns
The (container format specific) id of this stream.

Implements com::avpkit::core::IStream.

Definition at line 107 of file Stream.cpp.

108  {
109  return (mStream ? mStream->id : -1);
110  }

◆ getIndex()

int com::avpkit::core::Stream::getIndex ( )
virtual

Get the relative position this stream has in the hosting IContainer object.

Returns
The Index within the Container of this stream.

Implements com::avpkit::core::IStream.

Definition at line 101 of file Stream.cpp.

102  {
103  return (mStream ? mStream->index : -1);
104  }

Referenced by stampOutputPacket().

◆ getIndexEntry()

IIndexEntry * com::avpkit::core::Stream::getIndexEntry ( int32_t  position)
virtual

Get the IIndexEntry at the given position in this IStream object's index.

Not all IContainerFormat types maintain IStream indexes, but if they do, this method can return those entries.

Do not modify the IContainer this stream is from between calls to this method and getNumIndexEntries() as indexes may be compacted while processing.

Parameters
positionThe position in the index table.
Since
3.4

Implements com::avpkit::core::IStream.

Definition at line 486 of file Stream.cpp.

487  {
488  IIndexEntry* retval = 0;
489  if (mStream->index_entries
490  && index >= 0
491  && index < mStream->nb_index_entries)
492  {
493  AVIndexEntry* entry = &(mStream->index_entries[index]);
494  if (entry) {
495  retval = IIndexEntry::make(
496  entry->pos,
497  entry->timestamp,
498  entry->flags,
499  entry->size,
500  entry->min_distance
501  );
502  }
503  }
504  return retval;
505  }
static IIndexEntry * make(int64_t position, int64_t timeStamp, int32_t flags, int32_t size, int32_t minDistance)
Create a new IIndexEntry with the specified values.
Definition: IIndexEntry.cpp:44

References com::avpkit::core::IIndexEntry::make().

Referenced by findTimeStampEntryInIndex().

◆ getLanguage()

const char * com::avpkit::core::Stream::getLanguage ( )
virtual

Get the 4-character language setting for this stream.

This will return null if no setting. When calling from C++, callers must ensure that the IStream outlives the value returned.

Implements com::avpkit::core::IStream.

Definition at line 248 of file Stream.cpp.

249  {
250  const char*retval = 0;
252  if (metaData) {
253  retval = metaData->getValue("language", IMetaData::METADATA_NONE);
254  }
255  return retval;
256  }
@ METADATA_NONE
For getValue(String) case-insensitive match of key.
Definition: IMetaData.h:60
virtual IMetaData * getMetaData()
Get the IMetaData for this object, or null if none.
Definition: Stream.cpp:368
This class is only useful from C++.
Definition: RefPointer.h:47

References getMetaData(), and com::avpkit::core::IMetaData::METADATA_NONE.

◆ getMetaData()

IMetaData * com::avpkit::core::Stream::getMetaData ( )
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.
Since
3.1

Implements com::avpkit::core::IStream.

Definition at line 368 of file Stream.cpp.

369  {
370  if (!mMetaData && mStream)
371  {
372  if (mDirection == IStream::OUTBOUND)
373  mMetaData = MetaData::make(&mStream->metadata);
374  else
375  // make a read-only copy so when libav deletes the
376  // input version we don't delete our copy
377  mMetaData = MetaData::make(mStream->metadata);
378  }
379  return mMetaData.get();
380  }
static IMetaData * make()
Create a new IMetaData bag of properties with no values set.
Definition: IMetaData.cpp:36

References com::avpkit::core::IMetaData::make().

Referenced by getLanguage(), setLanguage(), and setMetaData().

◆ getNumFrames()

int64_t com::avpkit::core::Stream::getNumFrames ( )
virtual

Returns the number of encoded frames if known.

Note that frames here means encoded frames, which can consist of many encoded audio samples, or an encoded video frame.

Returns
The number of frames (encoded) in this stream.

Implements com::avpkit::core::IStream.

Definition at line 184 of file Stream.cpp.

185  {
186  return (mStream ? mStream->nb_frames : 0);
187  }

◆ getNumIndexEntries()

int com::avpkit::core::Stream::getNumIndexEntries ( )
virtual

Get the number of index entries in this stream.

Returns
The number of index entries in this stream.
See also
#getIndexEntry(int)

Implements com::avpkit::core::IStream.

Definition at line 189 of file Stream.cpp.

190  {
191  return (mStream ? mStream->nb_index_entries : 0);
192  }

◆ getParseType()

IStream::ParseType com::avpkit::core::Stream::getParseType ( )
virtual

Get how the decoding codec should parse data from this stream.

Returns
the parse type.
Since
3.0

Implements com::avpkit::core::IStream.

Definition at line 320 of file Stream.cpp.

321  {
322  if (mStream) {
323  return (IStream::ParseType)mStream->need_parsing;
324  } else {
325  return IStream::PARSE_NONE;
326  }
327  }
ParseType
What types of parsing can we do on a call to IContainer#readNextPacket(IPacket).
Definition: IStream.h:222

◆ getSampleAspectRatio()

IRational * com::avpkit::core::Stream::getSampleAspectRatio ( )
virtual

Added in 1.17.

Gets the sample aspect ratio.

Returns
The sample aspect ratio.

Implements com::avpkit::core::IStream.

Definition at line 222 of file Stream.cpp.

223  {
224  IRational* retval = 0;
225  if (mStream)
226  {
227  retval = IRational::make(
228  mStream->sample_aspect_ratio.num,
229  mStream->sample_aspect_ratio.den);
230  }
231  return retval;
232  }

References com::avpkit::core::IRational::make().

◆ getStartTime()

int64_t com::avpkit::core::Stream::getStartTime ( )
virtual

Return the start time, in getTimeBase() units, when this stream started.

Returns
The start time.

Implements com::avpkit::core::IStream.

Definition at line 166 of file Stream.cpp.

167  {
168  return (mStream ? mStream->start_time : Global::NO_PTS);
169  }

References com::avpkit::core::Global::NO_PTS.

◆ getStreamCoder()

IStreamCoder * com::avpkit::core::Stream::getStreamCoder ( )
virtual

Get the StreamCoder than can manipulate this stream.

If the stream is an INBOUND stream, then the StreamCoder can do a IStreamCoder::DECODE. IF this stream is an OUTBOUND stream, then the StreamCoder can do all IStreamCoder::ENCODE methods.

Returns
The StreamCoder assigned to this object.

Implements com::avpkit::core::IStream.

Definition at line 113 of file Stream.cpp.

114  {
115  StreamCoder *retval = 0;
116 
117  // acquire a reference for the caller
118  retval = mCoder;
119  VS_REF_ACQUIRE(retval);
120 
121  return retval;
122  }

◆ getTimeBase()

IRational * com::avpkit::core::Stream::getTimeBase ( )
virtual

The time base in which all timestamps (e.g.

Presentation Time Stamp (PTS) and Decompression Time Stamp (DTS)) are represented. For example if the time base is 1/1000, then the difference between a PTS of 1 and a PTS of 2 is 1 millisecond. If the timebase is 1/1, then the difference between a PTS of 1 and a PTS of 2 is 1 second.

Returns
The time base of this stream.

Implements com::avpkit::core::IStream.

Definition at line 137 of file Stream.cpp.

138  {
139  IRational * result = 0;
140  if (mStream)
141  {
142  result = Rational::make(&mStream->time_base);
143  }
144  return result;
145  }

References com::avpkit::core::IRational::make().

Referenced by stampOutputPacket().

◆ release()

int32_t com::avpkit::core::Stream::release ( )
virtual

Internal Only.

DO NOT USE FROM JAVA.

This decrements the native internal ref count by -1; the object is destroyed if its ref count reaches zero.

This method is called internally by Ferry in Java, and you should not call it without knowing what you are doing. But if you do call it, make sure you had previously called acquire() once for each call to release() you make.

Returns
The ref count after the release. Note due to multi-threaded issues, you should not rely on this value, as it may change before the method returns to you.

Reimplemented from com::avpkit::ferry::RefCounted.

Definition at line 213 of file Stream.cpp.

214  {
215  int retval = 0;
216  retval = RefCounted::release();
217  VS_LOG_TRACE("Released %p: %d", this, retval);
218  return retval;
219  }
virtual int32_t release()
Internal Only.
Definition: RefCounted.cpp:70

References com::avpkit::ferry::RefCounted::release().

◆ setBitstreamFilter()

int com::avpkit::core::Stream::setBitstreamFilter ( const char *  name)
virtual

Set a bitstream filter on this stream.

Parameters
nameThe name of bitstream filter
Since
6.0

Implements com::avpkit::core::IStream.

Definition at line 338 of file Stream.cpp.

339  {
340 
341  int ret = -1;
342  if (mStream) {
343  if (!mBsfContext) {
344  const AVBitStreamFilter* filter = av_bsf_get_by_name(name);
345  if (filter) {
346  if (ret = av_bsf_alloc(filter, &mBsfContext) == 0) {
347  if (ret = avcodec_parameters_copy(mBsfContext->par_in, mStream->codecpar) >= 0) {
348  mBsfContext->time_base_in = mStream->time_base;
349  if (ret = av_bsf_init(mBsfContext) < 0) {
350  VS_LOG_ERROR("BSF INIT FAIL");
351  av_bsf_free(&mBsfContext);
352  return ret;
353  }
354  VS_LOG_ERROR("BSF OK");
355  }
356  }
357  }
358 
359  } else {
360  VS_LOG_ERROR("Bistream filter already set on this stream");
361  }
362  }
363 
364  return ret;
365  }

◆ setId()

void com::avpkit::core::Stream::setId ( int32_t  id)
virtual

Set the format-specific stream id.

Parameters
idThe id to set.
See also
getId()
Since
5.0

Implements com::avpkit::core::IStream.

Definition at line 522 of file Stream.cpp.

523  {
524  if (!mStream)
525  return;
526  mStream->id = aId;
527  }

Referenced by com::avpkit::core::Container::addNewStream().

◆ setLanguage()

void com::avpkit::core::Stream::setLanguage ( const char *  language)
virtual

Set the 4-character language setting for this stream.

If a string longer than 4 characters is passed in, only the first 4 characters is copied.

Parameters
languageThe new language setting. null is equivalent to the empty string. strings longer than 4 characters will be truncated to first 4 characters.

Implements com::avpkit::core::IStream.

Definition at line 259 of file Stream.cpp.

260  {
262  if (metaData) {
263  metaData->setValue("language", aNewValue);
264  }
265  return;
266  }

References getMetaData().

◆ setMetaData()

void com::avpkit::core::Stream::setMetaData ( IMetaData data)
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()
Since
3.1

Implements com::avpkit::core::IStream.

Definition at line 383 of file Stream.cpp.

384  {
385  MetaData* data = dynamic_cast<MetaData*>(getMetaData());
386  if (data) {
387  data->copy(copy);
388  // release for the get above
389  data->release();
390  }
391  return;
392  }

References com::avpkit::core::MetaData::copy(), getMetaData(), and com::avpkit::ferry::RefCounted::release().

◆ setParseType()

void com::avpkit::core::Stream::setParseType ( ParseType  type)
virtual

Set the parse type the decoding codec should use.

Set to ParseType#PARSE_NONE if you don't want any parsing to be done.

Warning: do not set this flag unless you know what you're doing, and do not set after you've started decoding.

Parameters
typeThe type to set.
Since
3.0

Implements com::avpkit::core::IStream.

Definition at line 330 of file Stream.cpp.

331  {
332  if (mStream) {
333  mStream->need_parsing = (enum AVStreamParseType)type;
334  }
335  }

◆ setSampleAspectRatio()

void com::avpkit::core::Stream::setSampleAspectRatio ( IRational newRatio)
virtual

Sets the sample aspect ratio.

Parameters
newRatioThe new ratio.

Implements com::avpkit::core::IStream.

Definition at line 235 of file Stream.cpp.

236  {
237  if (aNewValue && mStream)
238  {
239  mStream->sample_aspect_ratio.num =
240  aNewValue->getNumerator();
241  mStream->sample_aspect_ratio.den =
242  aNewValue->getDenominator();
243  }
244  return;
245  }

References com::avpkit::core::IRational::getDenominator(), and com::avpkit::core::IRational::getNumerator().

◆ setStreamCoder() [1/2]

int32_t com::avpkit::core::Stream::setStreamCoder ( IStreamCoder newCoder)
virtual

Sets the stream coder to use for this stream.

This method will only cause a change if the IStreamCoder currently set on this IStream is not open. Otherwise the call is ignore and an error is returned.

Parameters
newCoderThe new stream coder to use.
Returns
>= 0 on success; < 0 on error.

Implements com::avpkit::core::IStream.

Definition at line 277 of file Stream.cpp.

278  {
279  return setStreamCoder(coder, true);
280  }
virtual int32_t setStreamCoder(IStreamCoder *coder)
Sets the stream coder to use for this stream.
Definition: Stream.cpp:277

Referenced by com::avpkit::core::Container::addNewStream().

◆ setStreamCoder() [2/2]

int32_t com::avpkit::core::Stream::setStreamCoder ( IStreamCoder newCoder,
bool  assumeOnlyStream 
)
virtual

Sets the stream coder to use for this stream.

This method will only cause a change if the IStreamCoder currently set on this IStream is not open. Otherwise the call is ignored and an error is returned.

Parameters
newCoderThe new stream coder to use.
assumeOnlyStreamIf true then this IStream will notify the IStreamCoder that it is the only stream and the IStreamCoder may use it to determine time stamps to output packets with. If false then the IStreamCoder does not support automatic stamping of packets with stream index IDs and users must call stampOutputPacket(IPacket) themselves.
Returns
>= 0 on success; < 0 on error.
Since
3.2

Implements com::avpkit::core::IStream.

Definition at line 282 of file Stream.cpp.

283  {
284  int32_t retval = -1;
285  try
286  {
287  if (mCoder && mCoder->isOpen())
288  throw std::runtime_error("cannot call setStreamCoder when current coder is open");
289 
290  if (!aCoder)
291  throw std::runtime_error("cannot set to a null stream coder");
292 
293  StreamCoder *coder = dynamic_cast<StreamCoder*>(aCoder);
294  if (!coder)
295  throw std::runtime_error("IStreamCoder is not of expected underlying C++ type");
296 
297  // Close the old stream coder
298  if (mCoder)
299  {
300  mCoder->streamClosed(this);
301  }
302 
303  if (coder->setStream(this, assumeOnlyStream) < 0)
304  throw std::runtime_error("IStreamCoder doesn't like this stream");
305 
306  VS_REF_RELEASE(mCoder);
307  mCoder = coder;
308  VS_REF_ACQUIRE(mCoder);
309  retval = 0;
310  }
311  catch (std::exception & e)
312  {
313  VS_LOG_ERROR("Error: %s", e.what());
314  retval = -1;
315  }
316  return retval;
317  }
virtual bool isOpen()
Returns true if this IStreamCoder is currently open.

References com::avpkit::core::StreamCoder::isOpen().

◆ stampOutputPacket()

int32_t com::avpkit::core::Stream::stampOutputPacket ( IPacket packet)
virtual

Takes a packet destined for this stream, and stamps the stream index, and converts the time stamp to the correct units (adjusting for rounding errors between stream conversions).

Parameters
packetto stamp
Returns
>= 0 on success; <0 on failure.
Since
3.2

Implements com::avpkit::core::IStream.

Definition at line 395 of file Stream.cpp.

396  {
397  if (!packet)
398  return -1;
399 
400 // VS_LOG_DEBUG("input: duration: %lld; dts: %lld; pts: %lld;",
401 // packet->getDuration(), packet->getDts(), packet->getPts());
402 
403  // Always just reset this; cheaper than checking if it's
404  // already set
405  packet->setStreamIndex(this->getIndex());
406 
408  com::avpkit::ferry::RefPointer<IRational> packetBase = packet->getTimeBase();
409  if (!thisBase || !packetBase)
410  return -1;
411  if (thisBase->compareTo(packetBase.value()) == 0) {
412 // VS_LOG_DEBUG("Same timebase: %d/%d vs %d/%d",
413 // thisBase->getNumerator(), thisBase->getDenominator(),
414 // packetBase->getNumerator(), packetBase->getDenominator());
415  // it's already got the right time values
416  return 0;
417  }
418 
419  int64_t duration = packet->getDuration();
420  int64_t dts = packet->getDts();
421  int64_t pts = packet->getPts();
422 
423  if (duration >= 0)
424  duration = thisBase->rescale(duration, packetBase.value(),
425  IRational::ROUND_DOWN);
426 
427  if (pts != Global::NO_PTS)
428  {
429  pts = thisBase->rescale(pts, packetBase.value(), IRational::ROUND_DOWN);
430  }
431  if (dts != Global::NO_PTS)
432  {
433  dts = thisBase->rescale(dts, packetBase.value(), IRational::ROUND_DOWN);
434  if (mLastDts != Global::NO_PTS && dts == mLastDts)
435  {
436  // adjust for rounding; we never want to insert a frame that
437  // is not monotonically increasing. Note we only do this if
438  // we're off by one; that's because we ROUND_DOWN and then assume
439  // that can be off by at most one. If we're off by more than one
440  // then it's really an error on the person muxing to this stream.
441  dts = mLastDts+1;
442  // and round up pts
443  if (pts != Global::NO_PTS)
444  ++pts;
445  // and if after all that adjusting, pts is less than dts
446  // let dts win.
447  if (pts == Global::NO_PTS || pts < dts)
448  pts = dts;
449  }
450  mLastDts = dts;
451  }
452 
453 // VS_LOG_DEBUG("output: duration: %lld; dts: %lld; pts: %lld;",
454 // duration, dts, pts);
455  packet->setDuration(duration);
456  packet->setPts(pts);
457  packet->setDts(dts);
458  packet->setTimeBase(thisBase.value());
459 // VS_LOG_DEBUG("Reset timebase: %d/%d",
460 // thisBase->getNumerator(), thisBase->getDenominator());
461  return 0;
462  }
virtual IRational * getTimeBase()
The time base in which all timestamps (e.g.
Definition: Stream.cpp:137
virtual int getIndex()
Get the relative position this stream has in the hosting IContainer object.
Definition: Stream.cpp:101
T * value()
Return the managed pointer without calling RefCounted::acquire() on it.
Definition: RefPointer.h:226

References com::avpkit::core::IPacket::getDts(), com::avpkit::core::IPacket::getDuration(), getIndex(), com::avpkit::core::IPacket::getPts(), getTimeBase(), com::avpkit::core::IMediaData::getTimeBase(), com::avpkit::core::Global::NO_PTS, com::avpkit::core::IPacket::setDts(), com::avpkit::core::IPacket::setDuration(), com::avpkit::core::IPacket::setPts(), com::avpkit::core::IPacket::setStreamIndex(), com::avpkit::core::IMediaData::setTimeBase(), and com::avpkit::ferry::RefPointer< T >::value().

Referenced by com::avpkit::core::Container::writePacket().


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