Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:58:09

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 _Graphic3d_MediaTextureSet_HeaderFile
0016 #define _Graphic3d_MediaTextureSet_HeaderFile
0017 
0018 #include <Media_IFrameQueue.hxx>
0019 #include <Graphic3d_MediaTexture.hxx>
0020 #include <Graphic3d_TextureSet.hxx>
0021 
0022 #include <mutex>
0023 
0024 class Graphic3d_ShaderProgram;
0025 class Media_PlayerContext;
0026 
0027 //! Texture adapter for Media_Frame.
0028 class Graphic3d_MediaTextureSet : public Graphic3d_TextureSet, public Media_IFrameQueue
0029 {
0030   DEFINE_STANDARD_RTTIEXT(Graphic3d_MediaTextureSet, Graphic3d_TextureSet)
0031 public:
0032   //! Callback definition.
0033   typedef void (*CallbackOnUpdate_t)(void* theUserPtr);
0034 
0035 public:
0036   //! Empty constructor.
0037   Standard_EXPORT Graphic3d_MediaTextureSet();
0038 
0039   //! Setup callback to be called on queue progress (e.g. when new frame should be displayed).
0040   Standard_EXPORT void SetCallback(CallbackOnUpdate_t theCallbackFunction,
0041                                    void*              theCallbackUserPtr);
0042 
0043   //! Call callback.
0044   Standard_EXPORT void Notify();
0045 
0046   //! Return input media.
0047   const TCollection_AsciiString& Input() const { return myInput; }
0048 
0049   //! Open specified file.
0050   //! Passing an empty path would close current input.
0051   Standard_EXPORT void OpenInput(const TCollection_AsciiString& thePath, bool theToWait);
0052 
0053   //! Return player context; it can be NULL until first OpenInput().
0054   const occ::handle<Media_PlayerContext>& PlayerContext() const { return myPlayerCtx; }
0055 
0056   //! Swap front/back frames.
0057   Standard_EXPORT bool SwapFrames();
0058 
0059   //! Return front frame dimensions.
0060   NCollection_Vec2<int> FrameSize() const { return myFrameSize; }
0061 
0062   //! Return shader program for displaying texture set.
0063   occ::handle<Graphic3d_ShaderProgram> ShaderProgram() const
0064   {
0065     if (myIsPlanarYUV)
0066     {
0067       return myIsFullRangeYUV ? myShaderYUVJ : myShaderYUV;
0068     }
0069     return occ::handle<Graphic3d_ShaderProgram>();
0070   }
0071 
0072   //! Return TRUE if texture set defined 3 YUV planes.
0073   bool IsPlanarYUV() const { return myIsPlanarYUV; }
0074 
0075   //! Return TRUE if YUV range is full.
0076   bool IsFullRangeYUV() const { return myIsFullRangeYUV; }
0077 
0078   //! Return duration in seconds.
0079   double Duration() const { return myDuration; }
0080 
0081   //! Return playback progress in seconds.
0082   double Progress() const { return myProgress; }
0083 
0084   //! @name Media_IFrameQueue interface
0085 private:
0086   //! Lock the frame for decoding into.
0087   Standard_EXPORT occ::handle<Media_Frame> LockFrame() override;
0088 
0089   //! Release the frame to present decoding results.
0090   Standard_EXPORT void ReleaseFrame(const occ::handle<Media_Frame>& theFrame) override;
0091 
0092 protected:
0093   occ::handle<Media_PlayerContext>     myPlayerCtx;        //!< player context
0094   occ::handle<Media_Frame>             myFramePair[2];     //!< front/back frames pair
0095   occ::handle<Graphic3d_ShaderProgram> myShaderYUV;        //!< shader program for YUV  texture set
0096   occ::handle<Graphic3d_ShaderProgram> myShaderYUVJ;       //!< shader program for YUVJ texture set
0097   std::mutex                           myMutex;            //!< mutex for accessing frames
0098   TCollection_AsciiString              myInput;            //!< input media
0099   CallbackOnUpdate_t                   myCallbackFunction; //!< callback function
0100   void*                                myCallbackUserPtr;  //!< callback data
0101   NCollection_Vec2<int>                myFrameSize;        //!< front frame size
0102   double                               myProgress;         //!< playback progress in seconds
0103   double                               myDuration;         //!< stream duration
0104   int                                  myFront;            //!< index of front texture
0105   bool                                 myToPresentFrame;   //!< flag
0106   // clang-format off
0107   bool                myIsPlanarYUV;       //!< front frame contains planar YUV data or native texture format
0108   bool                myIsFullRangeYUV;    //!< front frame defines full-range or reduced-range YUV
0109   // clang-format on
0110 };
0111 
0112 #endif // _Graphic3d_MediaTextureSet_HeaderFile