AVPKit
VideoPicture.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 VIDEOPICTURE_H_
21 #define VIDEOPICTURE_H_
22 
23 #include <com/avpkit/ferry/RefPointer.h>
24 #include <com/avpkit/core/IVideoPicture.h>
25 #include <com/avpkit/core/ICodec.h>
26 #include <com/avpkit/core/FfmpegIncludes.h>
27 #include <com/avpkit/ferry/IBuffer.h>
28 #include <com/avpkit/core/IRational.h>
29 
30 namespace com { namespace avpkit { namespace core
31 {
32 
33  class VideoPicture : public IVideoPicture
34  {
35  VS_JNIUTILS_REFCOUNTED_OBJECT_PRIVATE_MAKE(VideoPicture);
36  public:
37  // IMediaData
38  virtual int64_t getTimeStamp() { return getPts(); }
39  virtual void setTimeStamp(int64_t aTimeStamp) { setPts(aTimeStamp); }
40  virtual bool isKey() { return isKeyFrame(); }
41  virtual IRational* getTimeBase() { return mTimeBase.get(); }
42  virtual void setTimeBase(IRational *aBase) { mTimeBase.reset(aBase, true); }
43 
44  // IVideoPicture Implementation
45  virtual bool isKeyFrame();
46  virtual void setKeyFrame(bool aIsKey);
47  virtual bool isComplete() { return mIsComplete; }
48  virtual int getWidth() { return mFrame->width; }
49  virtual int getHeight() { return mFrame->height; }
50  virtual IPixelFormat::Type getPixelType() { return (IPixelFormat::Type) mFrame->format; }
51  virtual int64_t getPts();
52  virtual void setPts(int64_t);
53 
54  virtual int getQuality();
55  virtual void setQuality(int newQuality);
56  virtual int32_t getSize();
58  virtual int getDataLineSize(int lineNo);
59  virtual void setComplete(bool aIsComplete, IPixelFormat::Type format,
60  int width, int height, int64_t pts);
61  virtual bool copy(IVideoPicture* srcFrame);
62  virtual void setData(com::avpkit::ferry::IBuffer* buffer);
63  virtual void render(bool drop, int64_t timeStamp);
64  virtual void* getOpaqueData();
65 
66  // Not for calling from Java
74  void fillAVFrame(AVFrame *frame);
75 
88  void copyAVFrame(AVFrame *frame, IPixelFormat::Type pixel,
89  int32_t width, int32_t height);
90 
99  VS_API_AVPKIT AVFrame *getAVFrame();
100 
113  static VideoPicture* make(IPixelFormat::Type format, int width, int height);
114 
116  virtual void setPictureType(IVideoPicture::PictType type);
117 
118  virtual void setSideData(IVideoPicture::FrameDataType type, com::avpkit::ferry::IBuffer* buffer);
119 
121  IPixelFormat::Type format, int width, int height);
122 
123  protected:
124  VideoPicture();
125  virtual ~VideoPicture();
126 
127  private:
128  void allocInternalFrameBuffer();
129 
130  // This is where frame information is kept
131  // about a decoded frame.
132  AVFrame * mFrame;
133  bool mIsComplete;
134 
135 #ifdef __APPLE__
136  CMSampleBufferRef mCMSampleBuffer;
137 #endif
138 
141  };
142 
143 }}}
144 
145 #endif /*VIDEOPICTURE_H_*/
This class wraps represents a Rational number for the AVPKit.
Definition: IRational.h:43
Represents one raw (undecoded) picture in a video stream, plus a timestamp for when to display that v...
Definition: IVideoPicture.h:40
PictType
The different types of images that we can set.
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 void setData(com::avpkit::ferry::IBuffer *buffer)
Sets the underlying buffer used by this object.
virtual int64_t getPts()
What is the Presentation Time Stamp (in Microseconds) of this picture.
virtual IPixelFormat::Type getPixelType()
Returns the pixel format of the picture.
Definition: VideoPicture.h:50
virtual int32_t getSize()
Total size in bytes of the decoded picture.
void copyAVFrame(AVFrame *frame, IPixelFormat::Type pixel, int32_t width, int32_t height)
Called by the StreamCoder once it's done decoding.
virtual void setKeyFrame(bool aIsKey)
Reset if this is a key frame or not.
virtual bool isKeyFrame()
Is this a key frame?
virtual void setPictureType(IVideoPicture::PictType type)
Set the picture type.
virtual com::avpkit::ferry::IBuffer * getData()
Get any underlying raw data available for this object.
virtual void setPts(int64_t)
Set the Presentation Time Stamp (in Microseconds) for this picture.
virtual int64_t getTimeStamp()
Get the time stamp of this object in getTimeBase() units.
Definition: VideoPicture.h:38
virtual IVideoPicture::PictType getPictureType()
Get the picture type.
virtual int getDataLineSize(int lineNo)
Return the size of each line in the VideoPicture data.
void fillAVFrame(AVFrame *frame)
Called by the StreamCoder before it encodes a picture.
virtual bool isComplete()
Is this picture completely decoded?
Definition: VideoPicture.h:47
virtual bool copy(IVideoPicture *srcFrame)
Copy the contents of the given picture into this picture.
virtual void setQuality(int newQuality)
Set the Quality to a new value.
virtual void setTimeStamp(int64_t aTimeStamp)
Set the time stamp for this object in getTimeBase() units.
Definition: VideoPicture.h:39
virtual bool isKey()
Is this object a key object? i.e.
Definition: VideoPicture.h:40
virtual int getQuality()
This value is the quality setting this VideoPicture had when it was decoded, or is the value to use w...
virtual int getWidth()
What is the width of the picture.
Definition: VideoPicture.h:48
virtual int getHeight()
What is the height of the picture.
Definition: VideoPicture.h:49
static VideoPicture * make(IPixelFormat::Type format, int width, int height)
The default factory for a frame.
virtual void setTimeBase(IRational *aBase)
Set the time base that time stamps of this object are represented in.
Definition: VideoPicture.h:42
virtual IRational * getTimeBase()
Get the time base that time stamps of this object are represented in.
Definition: VideoPicture.h:41
virtual void render(bool drop, int64_t timeStamp)
Render this picture on configured surface.
VS_API_AVPKIT AVFrame * getAVFrame()
Call to get the raw underlying AVFrame we manage; don't pass this to ffmpeg directly as ffmpeg often ...
Allows Java code to get data from a native buffers, and optionally modify native memory directly.
Definition: IBuffer.h:54
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...