Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/opencascade/Media_PlayerContext.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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