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

Public Member Functions

virtual int64_t getTimeStamp ()
 Get the time stamp of this object in getTimeBase() units. More...
 
virtual void setTimeStamp (int64_t aTimeStamp)
 Set the time stamp for this object in getTimeBase() units. More...
 
virtual bool isKey ()
 Is this object a key object? i.e. More...
 
virtual IRationalgetTimeBase ()
 Get the time base that time stamps of this object are represented in. More...
 
virtual void setTimeBase (IRational *aBase)
 Set the time base that time stamps of this object are represented in. More...
 
virtual bool isKeyFrame ()
 Is this a key frame? More...
 
virtual void setKeyFrame (bool aIsKey)
 Reset if this is a key frame or not. More...
 
virtual bool isComplete ()
 Is this picture completely decoded? More...
 
virtual int getWidth ()
 What is the width of the picture. More...
 
virtual int getHeight ()
 What is the height of the picture. More...
 
virtual IPixelFormat::Type getPixelType ()
 Returns the pixel format of the picture. More...
 
virtual int64_t getPts ()
 What is the Presentation Time Stamp (in Microseconds) of this picture. More...
 
virtual void setPts (int64_t)
 Set the Presentation Time Stamp (in Microseconds) for this picture. More...
 
virtual int getQuality ()
 This value is the quality setting this VideoPicture had when it was decoded, or is the value to use when this picture is next encoded (if reset with setQuality() More...
 
virtual void setQuality (int newQuality)
 Set the Quality to a new value. More...
 
virtual int32_t getSize ()
 Total size in bytes of the decoded picture. More...
 
virtual com::avpkit::ferry::IBuffergetData ()
 Get any underlying raw data available for this object. More...
 
virtual int getDataLineSize (int lineNo)
 Return the size of each line in the VideoPicture data. More...
 
virtual void setComplete (bool aIsComplete, IPixelFormat::Type format, int width, int height, int64_t pts)
 After modifying the raw data in this buffer, call this function to let the object know it is now complete. More...
 
virtual bool copy (IVideoPicture *srcFrame)
 Copy the contents of the given picture into this picture. More...
 
virtual void setData (com::avpkit::ferry::IBuffer *buffer)
 Sets the underlying buffer used by this object. More...
 
virtual void render (bool drop, int64_t timeStamp)
 Render this picture on configured surface. More...
 
virtual void * getOpaqueData ()
 
void fillAVFrame (AVFrame *frame)
 Called by the StreamCoder before it encodes a picture. More...
 
void copyAVFrame (AVFrame *frame, IPixelFormat::Type pixel, int32_t width, int32_t height)
 Called by the StreamCoder once it's done decoding. More...
 
VS_API_AVPKIT AVFrame * getAVFrame ()
 Call to get the raw underlying AVFrame we manage; don't pass this to ffmpeg directly as ffmpeg often does weird stuff to these guys. More...
 
virtual IVideoPicture::PictType getPictureType ()
 Get the picture type. More...
 
virtual void setPictureType (IVideoPicture::PictType type)
 Set the picture type. More...
 
virtual void setSideData (IVideoPicture::FrameDataType type, com::avpkit::ferry::IBuffer *buffer)
 
- 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 VideoPicturemake (IPixelFormat::Type format, int width, int height)
 The default factory for a frame. More...
 
static VideoPicturemake (com::avpkit::ferry::IBuffer *buffer, IPixelFormat::Type format, int width, int height)
 
- Static Public Member Functions inherited from com::avpkit::core::IVideoPicture
static IVideoPicturemake (IPixelFormat::Type format, int width, int height)
 Get a new picture object. More...
 
static IVideoPicturemake (IVideoPicture *src)
 Get a new picture by copying the data in an existing frame. More...
 
static IVideoPicturemake (com::avpkit::ferry::IBuffer *buffer, IPixelFormat::Type format, int width, int height)
 Get a new picture object, by wrapping an existing com.avpkit.ferry.IBuffer. More...
 

Additional Inherited Members

- Public Types inherited from com::avpkit::core::IVideoPicture
enum  PictType {
  DEFAULT_TYPE =0 , I_TYPE = 1 , P_TYPE = 2 , B_TYPE = 3 ,
  S_TYPE = 4 , SI_TYPE = 5 , SP_TYPE = 6 , BI_TYPE = 7
}
 The different types of images that we can set. More...
 
enum  FrameDataType {
  AV_FRAME_DATA_PANSCAN , AV_FRAME_DATA_A53_CC , AV_FRAME_DATA_STEREO3D , AV_FRAME_DATA_MATRIXENCODING ,
  AV_FRAME_DATA_DOWNMIX_INFO , AV_FRAME_DATA_REPLAYGAIN , AV_FRAME_DATA_DISPLAYMATRIX , AV_FRAME_DATA_AFD ,
  AV_FRAME_DATA_MOTION_VECTORS , AV_FRAME_DATA_SKIP_SAMPLES , AV_FRAME_DATA_AUDIO_SERVICE_TYPE , AV_FRAME_DATA_MASTERING_DISPLAY_METADATA ,
  AV_FRAME_DATA_GOP_TIMECODE , AV_FRAME_DATA_SPHERICAL , AV_FRAME_DATA_CONTENT_LIGHT_LEVEL , AV_FRAME_DATA_ICC_PROFILE
}
 
- 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 33 of file VideoPicture.h.

Member Function Documentation

◆ copy()

bool com::avpkit::core::VideoPicture::copy ( IVideoPicture srcPicture)
virtual

Copy the contents of the given picture into this picture.

All buffers are copied by value, not be reference.

Parameters
srcPictureThe picture you want to copy.
Returns
true if a successful copy; false if not.

Implements com::avpkit::core::IVideoPicture.

Definition at line 155 of file VideoPicture.cpp.

156  {
157  bool result = false;
158  try
159  {
160  if (!srcFrame)
161  throw std::runtime_error("empty source frame to copy");
162 
163  if (!srcFrame->isComplete())
164  throw std::runtime_error("source frame is not complete");
165 
166  VideoPicture* src = static_cast<VideoPicture*>(srcFrame);
167  if (!src)
168  throw std::runtime_error("src frame is not of right subtype");
169 
170  // now copy the data
171  allocInternalFrameBuffer();
172 
173  // get the raw buffers
174  unsigned char* srcBuffer = (unsigned char*)src->mBuffer->getBytes(0, src->getSize());
175  unsigned char* dstBuffer = (unsigned char*)mBuffer->getBytes(0, getSize());
176  if (!srcBuffer || !dstBuffer)
177  throw std::runtime_error("could not get buffer to copy");
178  memcpy(dstBuffer, srcBuffer, getSize());
179 
180  this->setComplete(true,
181  srcFrame->getPixelType(),
182  srcFrame->getWidth(),
183  srcFrame->getHeight(),
184  srcFrame->getPts());
185  result = true;
186  }
187  catch (std::exception & e)
188  {
189  VS_LOG_DEBUG("error: %s", e.what());
190  result = false;
191  }
192  return result;
193  }
virtual void setComplete(bool aIsComplete, IPixelFormat::Type format, int width, int height, int64_t pts)
After modifying the raw data in this buffer, call this function to let the object know it is now comp...
virtual int32_t getSize()
Total size in bytes of the decoded picture.
virtual void * getBytes(int32_t offset, int32_t length)=0
Returns up to length bytes, starting at offset in the underlying buffer we're managing.

References com::avpkit::ferry::IBuffer::getBytes(), com::avpkit::core::IVideoPicture::getHeight(), com::avpkit::core::IVideoPicture::getPixelType(), com::avpkit::core::IVideoPicture::getPts(), getSize(), com::avpkit::core::IVideoPicture::getWidth(), com::avpkit::core::IVideoPicture::isComplete(), and setComplete().

◆ copyAVFrame()

void com::avpkit::core::VideoPicture::copyAVFrame ( AVFrame *  frame,
IPixelFormat::Type  pixel,
int32_t  width,
int32_t  height 
)

Called by the StreamCoder once it's done decoding.

We copy data from the buffers that ffmpeg allocated into our own buffers.

Parameters
frameThe AVFrame that ffmpeg filled in.
pixelThe pixel type
widthThe width of the AVFrame
heightThe height of the AVFrame

Definition at line 279 of file VideoPicture.cpp.

281  {
282  try
283  {
284  // Need to copy the contents of frame->data to our
285  // internal buffer.
286  VS_ASSERT(frame, "no frame?");
287  if (!(av_pix_fmt_desc_get((AVPixelFormat) pixel)->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
288  VS_ASSERT(frame->data[0], "no data in frame");
289  // resize the frame to the AVFrame
290  mFrame->width = width;
291  mFrame->height = height;
292  mFrame->format = (int)pixel;
293 
294  int bufSize = getSize();
295  if (bufSize <= 0)
296  throw std::runtime_error("invalid size for frame");
297 
298  if (!mBuffer || mBuffer->getBufferSize() < bufSize)
299  // reuse buffers if we can.
300  allocInternalFrameBuffer();
301 
302  uint8_t* buffer = (uint8_t*)mBuffer->getBytes(0, bufSize);
303  if (!buffer)
304  throw std::runtime_error("really? no buffer");
305 
306  if (frame->data[0])
307  {
308  // Make sure the frame isn't already using our buffer
309  if(buffer != frame->data[0])
310  {
311  av_image_fill_arrays(mFrame->data, mFrame->linesize, buffer,
312  (AVPixelFormat) frame->format, width, height, 1);
313  av_image_copy(mFrame->data, mFrame->linesize, (const uint8_t **)frame->data,
314  frame->linesize, (AVPixelFormat)frame->format, frame->width, frame->height);
315  }
316  mFrame->key_frame = frame->key_frame;
317  }
318  else
319  {
320  throw std::runtime_error("no data in frame to copy");
321  }
322  }
323  else
324  {
325  mFrame->width = width;
326  mFrame->height = height;
327 // mFrame->format = (int) pixel;
328  if (pixel != IPixelFormat::MEDIACODEC)
329  {
330  //mFrame->hw_frames_ctx = frame->hw_frames_ctx;
331  av_hwframe_transfer_data(mFrame, frame, 0);
332  }
333  else
334  {
335  //av_frame_copy_props(mFrame, frame);
336  mFrame->data[3] = frame->data[3];
337  }
338  }
339  }
340  catch (std::exception & e)
341  {
342  VS_LOG_DEBUG("error: %s", e.what());
343  }
344  }
@ MEDIACODEC
HW decoding through Android MediaCodec
Definition: IPixelFormat.h:288
virtual int32_t getBufferSize()=0
Get the current maximum number of bytes that can be safely placed in this buffer.

References com::avpkit::ferry::IBuffer::getBufferSize(), com::avpkit::ferry::IBuffer::getBytes(), getSize(), and com::avpkit::core::IPixelFormat::MEDIACODEC.

Referenced by com::avpkit::core::StreamCoder::decodeVideo(), and com::avpkit::core::BufferSink::fillVideoPicture().

◆ fillAVFrame()

void com::avpkit::core::VideoPicture::fillAVFrame ( AVFrame *  frame)

Called by the StreamCoder before it encodes a picture.

The VideoPicture fills in Ffmpeg's AVFrame structure with the underlying data for the frame we're managing, but we maintain memory management.

Definition at line 257 of file VideoPicture.cpp.

258  {
259  if (!mBuffer || mBuffer->getBufferSize() < getSize())
260  allocInternalFrameBuffer();
261  unsigned char* buffer = (unsigned char*)mBuffer->getBytes(0, getSize());
262  // This is an inherently unsafe operation; it copies over all the bits in the AVFrame
263  memcpy(frame, mFrame, sizeof(AVFrame));
264  //*frame = *mFrame;
265  // and then relies on avpicture_fill to overwrite any areas in frame that
266  // are pointed to the wrong place.
267  av_image_fill_arrays(frame->data,
268  frame->linesize,
269  buffer,
270  (AVPixelFormat) frame->format,
271  frame->width,
272  frame->height,
273  1);
274  frame->quality = getQuality();
275 // frame->type = FF_BUFFER_TYPE_USER;
276  }
virtual int getQuality()
This value is the quality setting this VideoPicture had when it was decoded, or is the value to use w...

References com::avpkit::ferry::IBuffer::getBufferSize(), com::avpkit::ferry::IBuffer::getBytes(), getQuality(), and getSize().

Referenced by com::avpkit::core::StreamCoder::encodeVideo().

◆ getAVFrame()

AVFrame * com::avpkit::core::VideoPicture::getAVFrame ( )

Call to get the raw underlying AVFrame we manage; don't pass this to ffmpeg directly as ffmpeg often does weird stuff to these guys.

Note: This method is exported out of the DLL because the extras library uses it.

Definition at line 347 of file VideoPicture.cpp.

348  {
349  if (!mBuffer || mBuffer->getBufferSize() < getSize())
350  {
351  // reuse buffers if we can.
352  allocInternalFrameBuffer();
353  }
354  return mFrame;
355  }

References com::avpkit::ferry::IBuffer::getBufferSize(), and getSize().

Referenced by com::avpkit::core::BufferSource::addVideoPicture(), getDataLineSize(), and com::avpkit::core::VideoResampler::resample().

◆ getData()

com::avpkit::ferry::IBuffer * com::avpkit::core::VideoPicture::getData ( )
virtual

Get any underlying raw data available for this object.

Returns
The raw data, or null if not accessible.

Implements com::avpkit::core::IMediaData.

Definition at line 196 of file VideoPicture.cpp.

197  {
198  com::avpkit::ferry::IBuffer *retval = 0;
199  try {
200  if (getSize() > 0) {
201  if (!mBuffer || mBuffer->getBufferSize() < getSize())
202  {
203  allocInternalFrameBuffer();
204  }
205  retval = mBuffer.get();
206  if (!retval) {
207  throw std::bad_alloc();
208  }
209  }
210  } catch (std::bad_alloc &e) {
211  VS_REF_RELEASE(retval);
212  throw e;
213  } catch (std::exception & e)
214  {
215  VS_LOG_DEBUG("Error: %s", e.what());
216  VS_REF_RELEASE(retval);
217  }
218  return retval;
219  }
Allows Java code to get data from a native buffers, and optionally modify native memory directly.
Definition: IBuffer.h:54
T * get()
Call RefCounted::acquire() on the managed pointer and return it.
Definition: RefPointer.h:206

References com::avpkit::ferry::RefPointer< T >::get(), com::avpkit::ferry::IBuffer::getBufferSize(), and getSize().

◆ getDataLineSize()

int com::avpkit::core::VideoPicture::getDataLineSize ( int  lineNo)
virtual

Return the size of each line in the VideoPicture data.

Usually there are no more than 4 lines, but the first line no that returns 0 is the end of the road.

Parameters
lineNoThe line you want to know the (byte) size of.
Returns
The size (in bytes) of that line in data.

Implements com::avpkit::core::IVideoPicture.

Definition at line 358 of file VideoPicture.cpp.

359  {
360  int retval = -1;
361  if (getAVFrame()
362  && lineNo >= 0
363  && (unsigned int) lineNo < (sizeof(mFrame->linesize)/sizeof(mFrame->linesize[0])))
364  retval = mFrame->linesize[lineNo];
365  return retval;
366  }
VS_API_AVPKIT AVFrame * getAVFrame()
Call to get the raw underlying AVFrame we manage; don't pass this to ffmpeg directly as ffmpeg often ...

References getAVFrame().

◆ getHeight()

virtual int com::avpkit::core::VideoPicture::getHeight ( )
inlinevirtual

What is the height of the picture.

Returns
the height of the picture

Implements com::avpkit::core::IVideoPicture.

Definition at line 49 of file VideoPicture.h.

49 { return mFrame->height; }

Referenced by com::avpkit::core::StreamCoder::encodeVideo(), com::avpkit::core::BufferSink::fillVideoPicture(), and com::avpkit::core::VideoResampler::resample().

◆ getPictureType()

IVideoPicture::PictType com::avpkit::core::VideoPicture::getPictureType ( )
virtual

Get the picture type.

This will be set on decoding to tell you what type of packet this was decoded from, and when encoding is a request to the encoder for how to encode the picture.

The request may be ignored by your codec.

Returns
the picture type.

Implements com::avpkit::core::IVideoPicture.

Definition at line 507 of file VideoPicture.cpp.

508  {
509  IVideoPicture::PictType retval = IVideoPicture::DEFAULT_TYPE;
510  if (mFrame)
511  retval = (PictType) mFrame->pict_type;
512  return retval;
513  }
PictType
The different types of images that we can set.

◆ getPixelType()

virtual IPixelFormat::Type com::avpkit::core::VideoPicture::getPixelType ( )
inlinevirtual

Returns the pixel format of the picture.

Returns
the pixel format of the picture.

Implements com::avpkit::core::IVideoPicture.

Definition at line 50 of file VideoPicture.h.

50 { return (IPixelFormat::Type) mFrame->format; }

Referenced by com::avpkit::core::StreamCoder::encodeVideo(), and com::avpkit::core::VideoResampler::resample().

◆ getPts()

int64_t com::avpkit::core::VideoPicture::getPts ( )
virtual

What is the Presentation Time Stamp (in Microseconds) of this picture.

The PTS is is scaled so that 1 PTS = 1/1,000,000 of a second.

Returns
the presentation time stamp (pts)

Implements com::avpkit::core::IVideoPicture.

Definition at line 382 of file VideoPicture.cpp.

383  {
384  return (mFrame ? mFrame->pts : -1);
385  }

Referenced by com::avpkit::core::BufferSource::addVideoPicture(), com::avpkit::core::StreamCoder::encodeVideo(), getTimeStamp(), and com::avpkit::core::VideoResampler::resample().

◆ getQuality()

int com::avpkit::core::VideoPicture::getQuality ( )
virtual

This value is the quality setting this VideoPicture had when it was decoded, or is the value to use when this picture is next encoded (if reset with setQuality()

Returns
The quality.

Implements com::avpkit::core::IVideoPicture.

Definition at line 395 of file VideoPicture.cpp.

396  {
397  return (mFrame ? mFrame->quality : FF_LAMBDA_MAX);
398  }

Referenced by fillAVFrame(), and com::avpkit::core::VideoResampler::resample().

◆ getSize()

int32_t com::avpkit::core::VideoPicture::getSize ( )
virtual

Total size in bytes of the decoded picture.

Returns
number of bytes of decoded picture

Implements com::avpkit::core::IVideoPicture.

Definition at line 442 of file VideoPicture.cpp.

443  {
444  int retval = -1;
445  if (mFrame->width > 0 && mFrame->height > 0)
446  retval = av_image_get_buffer_size((AVPixelFormat)mFrame->format, mFrame->width, mFrame->height, 1);
447  return retval;
448  }

Referenced by copy(), copyAVFrame(), com::avpkit::core::StreamCoder::encodeVideo(), fillAVFrame(), getAVFrame(), getData(), and make().

◆ getTimeBase()

virtual IRational* com::avpkit::core::VideoPicture::getTimeBase ( )
inlinevirtual

Get the time base that time stamps of this object are represented in.

Caller must release the returned value.

Returns
the time base.

Implements com::avpkit::core::IMediaData.

Definition at line 41 of file VideoPicture.h.

41 { return mTimeBase.get(); }

Referenced by com::avpkit::core::BufferSource::addVideoPicture(), and com::avpkit::core::BufferSink::fillVideoPicture().

◆ getTimeStamp()

virtual int64_t com::avpkit::core::VideoPicture::getTimeStamp ( )
inlinevirtual

Get the time stamp of this object in getTimeBase() units.

Returns
the time stamp

Implements com::avpkit::core::IMediaData.

Definition at line 38 of file VideoPicture.h.

38 { return getPts(); }
virtual int64_t getPts()
What is the Presentation Time Stamp (in Microseconds) of this picture.

References getPts().

◆ getWidth()

virtual int com::avpkit::core::VideoPicture::getWidth ( )
inlinevirtual

What is the width of the picture.

Returns
the width of the picture

Implements com::avpkit::core::IVideoPicture.

Definition at line 48 of file VideoPicture.h.

48 { return mFrame->width; }

Referenced by com::avpkit::core::StreamCoder::encodeVideo(), com::avpkit::core::BufferSink::fillVideoPicture(), and com::avpkit::core::VideoResampler::resample().

◆ isComplete()

virtual bool com::avpkit::core::VideoPicture::isComplete ( )
inlinevirtual

Is this picture completely decoded?

Returns
is this picture completely decoded?

Implements com::avpkit::core::IVideoPicture.

Definition at line 47 of file VideoPicture.h.

47 { return mIsComplete; }

Referenced by com::avpkit::core::VideoResampler::resample().

◆ isKey()

virtual bool com::avpkit::core::VideoPicture::isKey ( )
inlinevirtual

Is this object a key object? i.e.

it can be interpreted without needing any other media objects

Returns
true if it's a key, false if not

Implements com::avpkit::core::IMediaData.

Definition at line 40 of file VideoPicture.h.

40 { return isKeyFrame(); }
virtual bool isKeyFrame()
Is this a key frame?

References isKeyFrame().

◆ isKeyFrame()

bool com::avpkit::core::VideoPicture::isKeyFrame ( )
virtual

Is this a key frame?

Returns
is this a key frame

Implements com::avpkit::core::IVideoPicture.

Definition at line 369 of file VideoPicture.cpp.

370  {
371  return (mFrame ? mFrame->key_frame : false);
372  }

Referenced by isKey().

◆ make() [1/2]

VideoPicture * com::avpkit::core::VideoPicture::make ( com::avpkit::ferry::IBuffer buffer,
IPixelFormat::Type  format,
int  width,
int  height 
)
static

Use the buffer

Set the internal flags

Definition at line 101 of file VideoPicture.cpp.

104  {
105  if (!buffer)
106  return 0;
107  VideoPicture *retval = 0;
108  try {
109  retval = make(format, width,height);
110  if (!retval)
111  throw std::bad_alloc();
112 
113  int32_t size = retval->getSize();
114  if (size > 0 && size > buffer->getBufferSize())
115  throw std::runtime_error("input buffer is not large enough for given picture");
116 
118  retval->mBuffer.reset(buffer, true);
120  unsigned char* bytes = (unsigned char*)buffer->getBytes(0, size);
121  if (!bytes)
122  throw std::runtime_error("could not access raw memory in buffer");
123 
124  (void) av_image_fill_arrays(retval->mFrame->data,
125  retval->mFrame->linesize,
126  bytes,
127  (AVPixelFormat) format,
128  width,
129  height,
130  1);
131 
132  }
133  catch (std::bad_alloc &e)
134  {
135  VS_REF_RELEASE(retval);
136  throw e;
137  }
138  catch (std::exception& e)
139  {
140  VS_LOG_DEBUG("error: %s", e.what());
141  VS_REF_RELEASE(retval);
142  }
143  return retval;
144  }
static VideoPicture * make(IPixelFormat::Type format, int width, int height)
The default factory for a frame.

References com::avpkit::ferry::IBuffer::getBufferSize(), com::avpkit::ferry::IBuffer::getBytes(), getSize(), make(), and com::avpkit::ferry::RefPointer< T >::reset().

◆ make() [2/2]

VideoPicture * com::avpkit::core::VideoPicture::make ( IPixelFormat::Type  format,
int  width,
int  height 
)
static

The default factory for a frame.

We require callers to always tell us the format, width and height of the image they want to store in this VideoPicture.

Parameters
formatThe pixel format
widthThe expected width of this image.
heightThe expected height of this image.
Returns
A new frame that can store an image and associated decoding information.

Definition at line 75 of file VideoPicture.cpp.

76  {
77  VideoPicture * retval=0;
78  try {
79  retval = VideoPicture::make();
80  retval->mFrame->format = format;
81  retval->mFrame->width = width;
82  retval->mFrame->height = height;
83  // default new frames to be key frames
84  retval->setKeyFrame(true);
85  }
86  catch (std::bad_alloc &e)
87  {
88  VS_REF_RELEASE(retval);
89  throw e;
90  }
91  catch (std::exception& e)
92  {
93  VS_LOG_DEBUG("error: %s", e.what());
94  VS_REF_RELEASE(retval);
95  }
96 
97  return retval;
98  }

References setKeyFrame().

Referenced by make(), and com::avpkit::core::IVideoPicture::make().

◆ render()

void com::avpkit::core::VideoPicture::render ( bool  drop,
int64_t  timeStamp 
)
virtual

Render this picture on configured surface.

Works only with HW accelerated com.avpkit.core.IPixelFormat. com.avpkit.core.IStreamCoder#setHardwareDecoding(IPixelFormat.Type, Object) must be called before opening decoder.

Implements com::avpkit::core::IVideoPicture.

Definition at line 222 of file VideoPicture.cpp.

222  {
223  if (mFrame && (av_pix_fmt_desc_get((AVPixelFormat) mFrame->format)->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
224  #ifdef __ANDROID__
225  mediacodec_render_frame(mFrame, timeStamp, drop);
226  #elif __APPLE__
227  CVImageBufferRef image = (CVImageBufferRef) mFrame->data[3];
228  CMVideoFormatDescriptionRef formatDescription;
229  if (mCMSampleBuffer){
230  CFRelease(mCMSampleBuffer);
231  }
232  CMTime duration = kCMTimeIndefinite;
233  CMTime pts = CMTimeMake(timeStamp , 1000000000);
234  const CMSampleTimingInfo timingInfo = {
235  .decodeTimeStamp = kCMTimeInvalid,
236  .duration = duration,
237  .presentationTimeStamp = pts
238  };
239  CMVideoFormatDescriptionCreateForImageBuffer(NULL, image, &formatDescription);
240  CMSampleBufferCreateReadyWithImageBuffer(NULL, image, formatDescription, &timingInfo, &mCMSampleBuffer);
241  return sampleBuffer;
242  #endif
243  }
244  }

◆ setComplete()

void com::avpkit::core::VideoPicture::setComplete ( bool  aIsComplete,
IPixelFormat::Type  format,
int  width,
int  height,
int64_t  pts 
)
virtual

After modifying the raw data in this buffer, call this function to let the object know it is now complete.

Parameters
aIsCompleteIs this VideoPicture complete
formatThe pixel format of the data in this picture. Must match what the picture was originally constructed with.
widthThe width of the data in this picture. Must match what the picture was originally constructed with.
heightThe height of the data in this picture. Must match what the picture was originally constructed with.
ptsThe presentation timestamp of the picture that is now complete. The caller must ensure this PTS is in units of 1/1,000,000 seconds.

Implements com::avpkit::core::IVideoPicture.

Definition at line 410 of file VideoPicture.cpp.

417  {
418  try {
419  mIsComplete = aIsComplete;
420 
421  if (mIsComplete)
422  {
423  setPts(pts);
424  }
425 
426  if (!mFrame)
427  throw std::runtime_error("no AVFrame allocated");
428  if (format != IPixelFormat::NONE && mFrame->format != (int)IPixelFormat::NONE && (int)format != mFrame->format)
429  throw std::runtime_error("pixel formats don't match");
430  if (width > 0 && mFrame->width >0 && width != mFrame->width)
431  throw std::runtime_error("width does not match");
432  if (height > 0 && mFrame->height > 0 && height != mFrame->height)
433  throw std::runtime_error("height does not match");
434  }
435  catch (std::exception& e)
436  {
437  VS_LOG_DEBUG("error: %s", e.what());
438  }
439  }
virtual void setPts(int64_t)
Set the Presentation Time Stamp (in Microseconds) for this picture.

References setPts().

Referenced by copy(), com::avpkit::core::StreamCoder::decodeVideo(), com::avpkit::core::BufferSink::fillVideoPicture(), and com::avpkit::core::VideoResampler::resample().

◆ setData()

void com::avpkit::core::VideoPicture::setData ( com::avpkit::ferry::IBuffer buffer)
virtual

Sets the underlying buffer used by this object.

This is an advanced method and is not recommended for use by those who don't fully understand how IBuffers work. Implementations of IMediaData may behave in undefined ways if the buffer you pass in is not big enough for what you ask them to do (e.g. they may discard your buffer and allocate a larger one if they need more space). It is up to the caller to ensure the buffer passed in is large enough, and is not simultaneously in use by another part of the system.

Parameters
bufferThe buffer to set. If null, this method is ignored.

Use the buffer

Implements com::avpkit::core::IMediaData.

Definition at line 147 of file VideoPicture.cpp.

148  {
149  if (!buffer) return;
151  mBuffer.reset(buffer, true);
152  }
void reset(T *ptr=0, bool acquire=false)
Reset the managed pointer, calling RefCounted::release() on the previously managed pointer first.
Definition: RefPointer.h:237

References com::avpkit::ferry::RefPointer< T >::reset().

◆ setKeyFrame()

void com::avpkit::core::VideoPicture::setKeyFrame ( bool  aIsKey)
virtual

Reset if this is a key frame or not.

Note that regardless of how this flag is set, an IVideoPicture always contains raw video data (hence the key setting isn't really that important).

Parameters
aIsKeyTrue if a key frame; false if not.

Implements com::avpkit::core::IVideoPicture.

Definition at line 375 of file VideoPicture.cpp.

376  {
377  if (mFrame)
378  mFrame->key_frame = aIsKey;
379  }

Referenced by make().

◆ setPictureType()

void com::avpkit::core::VideoPicture::setPictureType ( IVideoPicture::PictType  type)
virtual

Set the picture type.

Parameters
typeThe type.
See also
getPictureType()

Implements com::avpkit::core::IVideoPicture.

Definition at line 516 of file VideoPicture.cpp.

517  {
518  if (mFrame)
519  mFrame->pict_type = (enum AVPictureType) type;
520  }

◆ setPts()

void com::avpkit::core::VideoPicture::setPts ( int64_t  value)
virtual

Set the Presentation Time Stamp (in Microseconds) for this picture.

See also
getPts()
Parameters
valuethe new timestamp

Implements com::avpkit::core::IVideoPicture.

Definition at line 388 of file VideoPicture.cpp.

389  {
390  if (mFrame)
391  mFrame->pts = value;
392  }

Referenced by setComplete(), and setTimeStamp().

◆ setQuality()

void com::avpkit::core::VideoPicture::setQuality ( int  newQuality)
virtual

Set the Quality to a new value.

This will be used the next time this VideoPicture is encoded by a StreamCoder

Parameters
newQualityThe new quality.

Implements com::avpkit::core::IVideoPicture.

Definition at line 401 of file VideoPicture.cpp.

402  {
403  if (newQuality < 0 || newQuality > FF_LAMBDA_MAX)
404  newQuality = FF_LAMBDA_MAX;
405  if (mFrame)
406  mFrame->quality = newQuality;
407  }

Referenced by com::avpkit::core::VideoResampler::resample().

◆ setTimeBase()

virtual void com::avpkit::core::VideoPicture::setTimeBase ( IRational aBase)
inlinevirtual

Set the time base that time stamps of this object are represented in.

Parameters
aBasethe new time base. If null an exception is thrown.

Implements com::avpkit::core::IMediaData.

Definition at line 42 of file VideoPicture.h.

42 { mTimeBase.reset(aBase, true); }

◆ setTimeStamp()

virtual void com::avpkit::core::VideoPicture::setTimeStamp ( int64_t  aTimeStamp)
inlinevirtual

Set the time stamp for this object in getTimeBase() units.

Parameters
aTimeStampThe time stamp

Implements com::avpkit::core::IMediaData.

Definition at line 39 of file VideoPicture.h.

39 { setPts(aTimeStamp); }

References setPts().


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