Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:15

0001 // Created by: Kirill GAVRILOV
0002 // Copyright (c) 2019 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014 
0015 #ifndef _Media_Frame_HeaderFile
0016 #define _Media_Frame_HeaderFile
0017 
0018 #include <Graphic3d_Vec2.hxx>
0019 #include <Image_PixMap.hxx>
0020 #include <Standard_Transient.hxx>
0021 #include <Standard_Type.hxx>
0022 
0023 struct AVFrame;
0024 
0025 //! AVFrame wrapper - the frame (decoded image/audio sample data) holder.
0026 class Media_Frame : public Standard_Transient
0027 {
0028   DEFINE_STANDARD_RTTIEXT(Media_Frame, Standard_Transient)
0029 public:
0030 
0031   //! Convert pixel format from FFmpeg (AVPixelFormat) to OCCT.
0032   Standard_EXPORT static Image_Format FormatFFmpeg2Occt (int theFormat);
0033 
0034   //! Convert pixel format from OCCT to FFmpeg (AVPixelFormat).
0035   //! Returns -1 (AV_PIX_FMT_NONE) if undefined.
0036   Standard_EXPORT static int FormatOcct2FFmpeg (Image_Format theFormat);
0037 
0038   //! Swap AVFrame* within two frames.
0039   Standard_EXPORT static void Swap (const Handle(Media_Frame)& theFrame1,
0040                                     const Handle(Media_Frame)& theFrame2);
0041 
0042 public:
0043 
0044   //! Empty constructor
0045   Standard_EXPORT Media_Frame();
0046 
0047   //! Destructor
0048   Standard_EXPORT virtual ~Media_Frame();
0049 
0050   //! Return true if frame does not contain any data.
0051   Standard_EXPORT bool IsEmpty() const;
0052 
0053   //! av_frame_unref() wrapper.
0054   Standard_EXPORT void Unref();
0055 
0056   //! Return image dimensions.
0057   Graphic3d_Vec2i Size() const { return Graphic3d_Vec2i (SizeX(), SizeY()); }
0058 
0059   //! Return image width.
0060   Standard_EXPORT int SizeX() const;
0061 
0062   //! Return image height.
0063   Standard_EXPORT int SizeY() const;
0064 
0065   //! Return pixel format (AVPixelFormat).
0066   Standard_EXPORT int Format() const;
0067 
0068   //! Return TRUE if YUV range is full.
0069   Standard_EXPORT bool IsFullRangeYUV() const;
0070 
0071   //! Access data plane for specified Id.
0072   Standard_EXPORT uint8_t* Plane (int thePlaneId) const;
0073 
0074   //! @return linesize in bytes for specified data plane
0075   Standard_EXPORT int LineSize (int thePlaneId) const;
0076 
0077   //! @return frame timestamp estimated using various heuristics, in stream time base
0078   Standard_EXPORT int64_t BestEffortTimestamp() const;
0079 
0080   //! Return frame.
0081   const AVFrame* Frame() const { return myFrame; }
0082 
0083   //! Return frame.
0084   AVFrame* ChangeFrame() { return myFrame; }
0085 
0086   //! Return presentation timestamp (PTS).
0087   double Pts() const { return myFramePts; }
0088 
0089   //! Set presentation timestamp (PTS).
0090   void SetPts (double thePts) { myFramePts = thePts; }
0091 
0092   //! Return PAR.
0093   float PixelAspectRatio() const { return myPixelRatio; }
0094 
0095   //! Set PAR.
0096   void SetPixelAspectRatio (float theRatio) { myPixelRatio = theRatio; }
0097 
0098   //! Return locked state.
0099   bool IsLocked() const { return myIsLocked; }
0100 
0101   //! Lock/free frame for edition.
0102   void SetLocked (bool theToLock) { myIsLocked = theToLock; }
0103 
0104 public:
0105 
0106   //! Wrap allocated image pixmap.
0107   Standard_EXPORT bool InitWrapper (const Handle(Image_PixMap)& thePixMap);
0108 
0109 protected:
0110 
0111   AVFrame* myFrame;      //!< frame
0112   double   myFramePts;   //!< presentation timestamp
0113   float    myPixelRatio; //!< pixel aspect ratio
0114   bool     myIsLocked;   //!< locked state
0115 
0116 };
0117 
0118 #endif // _Media_Frame_HeaderFile