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