Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-20 09:18:21

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_FormatContext_HeaderFile
0016 #define _Media_FormatContext_HeaderFile
0017 
0018 #include <Media_Packet.hxx>
0019 
0020 #include <TCollection_AsciiString.hxx>
0021 
0022 struct AVCodecContext;
0023 struct AVFormatContext;
0024 struct AVStream;
0025 struct AVRational;
0026 
0027 //! AVFormatContext wrapper - the media input/output stream holder.
0028 class Media_FormatContext : public Standard_Transient
0029 {
0030   DEFINE_STANDARD_RTTIEXT(Media_FormatContext, Standard_Transient)
0031 public:
0032   //! Returns string description for AVError code.
0033   Standard_EXPORT static TCollection_AsciiString FormatAVErrorDescription(int theErrCodeAV);
0034 
0035   //! Convert time units into seconds for context.
0036   //! @param theTimeUnits value to convert
0037   //! @return converted time units in seconds
0038   Standard_EXPORT static double FormatUnitsToSeconds(int64_t theTimeUnits);
0039 
0040   //! Convert time units into seconds. Returns zero for invalid value.
0041   //! @param theTimeBase  the timebase
0042   //! @param theTimeUnits value to convert
0043   //! @return converted time units in seconds
0044   Standard_EXPORT static double UnitsToSeconds(const AVRational& theTimeBase, int64_t theTimeUnits);
0045 
0046   //! Convert time units into seconds using stream base.
0047   //! @param theStream    the stream;
0048   //! @param theTimeUnits value to convert;
0049   //! @return converted time units in seconds.
0050   Standard_EXPORT static double StreamUnitsToSeconds(const AVStream& theStream,
0051                                                      int64_t         theTimeUnits);
0052 
0053   //! Convert seconds into time units for context.
0054   //! @param theTimeSeconds value to convert
0055   //! @return time units
0056   Standard_EXPORT static int64_t SecondsToUnits(double theTimeSeconds);
0057 
0058   //! Convert seconds into time units.
0059   //! @param theTimeBase    the timebase
0060   //! @param theTimeSeconds value to convert
0061   //! @return time units
0062   Standard_EXPORT static int64_t SecondsToUnits(const AVRational& theTimeBase,
0063                                                 double            theTimeSeconds);
0064 
0065   //! Convert seconds into time units for stream.
0066   //! @param theStream      the stream
0067   //! @param theTimeSeconds value to convert
0068   //! @return time units
0069   Standard_EXPORT static int64_t StreamSecondsToUnits(const AVStream& theStream,
0070                                                       double          theTimeSeconds);
0071 
0072   //! Time formatter.
0073   Standard_EXPORT static TCollection_AsciiString FormatTime(double theSeconds);
0074 
0075   //! Time progress / duration formatter.
0076   Standard_EXPORT static TCollection_AsciiString FormatTimeProgress(double theProgress,
0077                                                                     double theDuration);
0078 
0079 public:
0080   //! Constructor.
0081   Standard_EXPORT Media_FormatContext();
0082 
0083   //! Destructor.
0084   Standard_EXPORT ~Media_FormatContext() override;
0085 
0086   //! Return context.
0087   AVFormatContext* Context() const { return myFormatCtx; }
0088 
0089   //! Open input.
0090   Standard_EXPORT bool OpenInput(const TCollection_AsciiString& theInput);
0091 
0092   //! Close input.
0093   Standard_EXPORT void Close();
0094 
0095   //! Return amount of streams.
0096   Standard_EXPORT unsigned int NbSteams() const;
0097 
0098   //! Return stream.
0099   Standard_EXPORT const AVStream& Stream(unsigned int theIndex) const;
0100 
0101   //! Format stream info.
0102   Standard_EXPORT TCollection_AsciiString StreamInfo(unsigned int    theIndex,
0103                                                      AVCodecContext* theCodecCtx = nullptr) const;
0104 
0105   //! Return PTS start base in seconds.
0106   double PtsStartBase() const { return myPtsStartBase; }
0107 
0108   //! Return duration in seconds.
0109   double Duration() const { return myDuration; }
0110 
0111   //! av_read_frame() wrapper.
0112   Standard_EXPORT bool ReadPacket(const occ::handle<Media_Packet>& thePacket);
0113 
0114   //! Seek stream to specified position.
0115   Standard_EXPORT bool SeekStream(unsigned int theStreamId, double theSeekPts, bool toSeekBack);
0116 
0117   //! Seek context to specified position.
0118   Standard_EXPORT bool Seek(double theSeekPts, bool toSeekBack);
0119 
0120 protected:
0121   AVFormatContext* myFormatCtx;    //!< format context
0122   double           myPtsStartBase; //!< start time
0123   double           myDuration;     //!< duration
0124 };
0125 
0126 #endif // _Media_FormatContext_HeaderFile