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_PlayerContext_HeaderFile
0016 #define _Media_PlayerContext_HeaderFile
0017 
0018 #include <Media_IFrameQueue.hxx>
0019 #include <Media_Timer.hxx>
0020 #include <OSD_Thread.hxx>
0021 #include <Standard_Condition.hxx>
0022 #include <Standard_Mutex.hxx>
0023 #include <Standard_Transient.hxx>
0024 #include <Standard_Type.hxx>
0025 #include <TCollection_AsciiString.hxx>
0026 
0027 class Media_BufferPool;
0028 class Media_CodecContext;
0029 class Media_FormatContext;
0030 class Media_Scaler;
0031 
0032 //! Player context.
0033 class Media_PlayerContext : public Standard_Transient
0034 {
0035   DEFINE_STANDARD_RTTIEXT(Media_PlayerContext, Standard_Transient)
0036 public:
0037 
0038   //! Dump first video frame.
0039   //! @param theSrcVideo [in] path to the video
0040   //! @param theMediaInfo [out] video description
0041   Standard_EXPORT static Handle(Media_Frame) DumpFirstFrame (const TCollection_AsciiString& theSrcVideo,
0042                                                              TCollection_AsciiString& theMediaInfo);
0043 
0044   //! Dump first video frame.
0045   //! @param theSrcVideo [in] path to the video
0046   //! @param theOutImage [in] path to make a screenshot
0047   //! @param theMediaInfo [out] video description
0048   //! @param theMaxSize [in] when positive - downscales image to specified size
0049   Standard_EXPORT static bool DumpFirstFrame (const TCollection_AsciiString& theSrcVideo,
0050                                               const TCollection_AsciiString& theOutImage,
0051                                               TCollection_AsciiString& theMediaInfo,
0052                                               int theMaxSize = 0);
0053 
0054 public:
0055 
0056   //! Main constructor.
0057   //! Note that Frame Queue is stored as pointer,
0058   //! and it is expected that this context is stored as a class field of Frame Queue.
0059   Standard_EXPORT Media_PlayerContext (Media_IFrameQueue* theFrameQueue);
0060 
0061   //! Destructor.
0062   Standard_EXPORT virtual ~Media_PlayerContext();
0063 
0064 public:
0065 
0066   //! Set new input for playback.
0067   Standard_EXPORT void SetInput (const TCollection_AsciiString& theInputPath,
0068                                  Standard_Boolean theToWait);
0069 
0070   //! Return playback state.
0071   Standard_EXPORT void PlaybackState (Standard_Boolean& theIsPaused,
0072                                       Standard_Real& theProgress,
0073                                       Standard_Real& theDuration);
0074 
0075   //! Pause/Pause playback depending on the current state.
0076   Standard_EXPORT void PlayPause (Standard_Boolean& theIsPaused,
0077                                   Standard_Real& theProgress,
0078                                   Standard_Real& theDuration);
0079 
0080   //! Seek to specified position.
0081   Standard_EXPORT void Seek (Standard_Real thePosSec);
0082 
0083   //! Pause playback.
0084   void Pause() { pushPlayEvent (Media_PlayerEvent_PAUSE); }
0085 
0086   //! Resume playback.
0087   void Resume() { pushPlayEvent (Media_PlayerEvent_RESUME); }
0088 
0089   //! Return TRUE if queue requires RGB pixel format or can handle also YUV pixel format; TRUE by default.
0090   bool ToForceRgb() const { return myToForceRgb; }
0091 
0092   //! Set if queue requires RGB pixel format or can handle also YUV pixel format.
0093   void SetForceRgb (bool theToForce) { myToForceRgb = theToForce; }
0094 
0095 private:
0096 
0097   //! Internal enumeration for events.
0098   enum Media_PlayerEvent
0099   {
0100     Media_PlayerEvent_NONE = 0,
0101     Media_PlayerEvent_PAUSE,
0102     Media_PlayerEvent_RESUME,
0103     Media_PlayerEvent_SEEK,
0104     Media_PlayerEvent_NEXT,
0105   };
0106 
0107 private:
0108 
0109   //! Thread loop.
0110   Standard_EXPORT void doThreadLoop();
0111 
0112   //! Push new playback event.
0113   Standard_EXPORT void pushPlayEvent (Media_PlayerEvent thePlayEvent);
0114 
0115   //! Fetch new playback event.
0116   Standard_EXPORT bool popPlayEvent (Media_PlayerEvent& thePlayEvent,
0117                                      const Handle(Media_FormatContext)& theFormatCtx,
0118                                      const Handle(Media_CodecContext)& theVideoCtx,
0119                                      const Handle(Media_Frame)& theFrame);
0120 
0121   //! Decode new frame.
0122   bool receiveFrame (const Handle(Media_Frame)& theFrame,
0123                      const Handle(Media_CodecContext)& theVideoCtx);
0124 
0125   //! Thread creation callback.
0126   static Standard_Address doThreadWrapper (Standard_Address theData)
0127   {
0128     Media_PlayerContext* aThis = (Media_PlayerContext* )theData;
0129     aThis->doThreadLoop();
0130     return 0;
0131   }
0132 
0133 private:
0134 
0135   Media_IFrameQueue*          myFrameQueue;     //!< frame queue
0136   OSD_Thread                  myThread;         //!< working thread
0137   Standard_Mutex              myMutex;          //!< mutex for events
0138   Standard_Condition          myWakeEvent;      //!< event to wake up working thread and proceed new playback event
0139   Standard_Condition          myNextEvent;      //!< event to check if working thread processed next file event (e.g. released file handles of previous input)
0140   Media_Timer                 myTimer;          //!< playback timer       
0141   Standard_Real               myDuration;       //!< playback duration
0142 
0143   Handle(Media_BufferPool)    myBufferPools[4]; //!< per-plane pools
0144   Handle(Media_Frame)         myFrameTmp;       //!< temporary object holding decoded frame
0145   Handle(Media_Scaler)        myScaler;         //!< pixel format conversion tool
0146   bool                        myToForceRgb;     //!< flag indicating if queue requires RGB pixel format or can handle also YUV pixel format
0147 
0148   volatile bool               myToShutDown;     //!< flag to terminate working thread
0149   TCollection_AsciiString     myInputPath;      //!< new input to open
0150   volatile Standard_Real      mySeekTo;         //!< new seeking position
0151   volatile Media_PlayerEvent  myPlayEvent;      //!< playback event
0152 
0153 };
0154 
0155 #endif // _Media_PlayerContext_HeaderFile