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_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,
0045                                                 int64_t theTimeUnits);
0046 
0047   //! Convert time units into seconds using stream base.
0048   //! @param theStream    the stream;
0049   //! @param theTimeUnits value to convert;
0050   //! @return converted time units in seconds.
0051   Standard_EXPORT static double StreamUnitsToSeconds (const AVStream& theStream,
0052                                                       int64_t theTimeUnits);
0053 
0054   //! Convert seconds into time units for context.
0055   //! @param theTimeSeconds value to convert
0056   //! @return time units
0057   Standard_EXPORT static int64_t SecondsToUnits (double theTimeSeconds);
0058 
0059   //! Convert seconds into time units.
0060   //! @param theTimeBase    the timebase
0061   //! @param theTimeSeconds value to convert
0062   //! @return time units
0063   Standard_EXPORT static int64_t SecondsToUnits (const AVRational& theTimeBase,
0064                                                  double theTimeSeconds);
0065 
0066   //! Convert seconds into time units for stream.
0067   //! @param theStream      the stream
0068   //! @param theTimeSeconds value to convert
0069   //! @return time units
0070   Standard_EXPORT static int64_t StreamSecondsToUnits (const AVStream& theStream,
0071                                                        double theTimeSeconds);
0072 
0073   //! Time formatter.
0074   Standard_EXPORT static TCollection_AsciiString FormatTime (double theSeconds);
0075 
0076   //! Time progress / duration formatter.
0077   Standard_EXPORT static TCollection_AsciiString FormatTimeProgress (double theProgress,
0078                                                                      double theDuration);
0079 
0080 public:
0081 
0082   //! Constructor.
0083   Standard_EXPORT Media_FormatContext();
0084 
0085   //! Destructor.
0086   Standard_EXPORT virtual ~Media_FormatContext();
0087 
0088   //! Return context.
0089   AVFormatContext* Context() const { return myFormatCtx; }
0090 
0091   //! Open input.
0092   Standard_EXPORT bool OpenInput (const TCollection_AsciiString& theInput);
0093 
0094   //! Close input.
0095   Standard_EXPORT void Close();
0096 
0097   //! Return amount of streams.
0098   Standard_EXPORT unsigned int NbSteams() const;
0099 
0100   //! Return stream.
0101   Standard_EXPORT const AVStream& Stream (unsigned int theIndex) const;
0102 
0103   //! Format stream info.
0104   Standard_EXPORT TCollection_AsciiString StreamInfo (unsigned int theIndex,
0105                                                       AVCodecContext* theCodecCtx = NULL) const;
0106 
0107   //! Return PTS start base in seconds.
0108   double PtsStartBase() const { return myPtsStartBase; }
0109 
0110   //! Return duration in seconds.
0111   double Duration() const { return myDuration; }
0112 
0113   //! av_read_frame() wrapper.
0114   Standard_EXPORT bool ReadPacket (const Handle(Media_Packet)& thePacket);
0115 
0116   //! Seek stream to specified position.
0117   Standard_EXPORT bool SeekStream (unsigned int theStreamId,
0118                                    double theSeekPts,
0119                                    bool toSeekBack);
0120 
0121   //! Seek context to specified position.
0122   Standard_EXPORT bool Seek (double theSeekPts,
0123                              bool   toSeekBack);
0124 
0125 protected:
0126 
0127   AVFormatContext* myFormatCtx;    //!< format context
0128   double           myPtsStartBase; //!< start time
0129   double           myDuration;     //!< duration
0130 
0131 };
0132 
0133 #endif // _Media_FormatContext_HeaderFile