0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / Media / Media_Frame.hxx
CommitLineData
98e6c6d1 1// Created by: Kirill GAVRILOV
2// Copyright (c) 2019 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
15#ifndef _Media_Frame_HeaderFile
16#define _Media_Frame_HeaderFile
17
18#include <Graphic3d_Vec2.hxx>
19#include <Image_PixMap.hxx>
20#include <Standard_Transient.hxx>
21#include <Standard_Type.hxx>
22
23struct AVFrame;
24
25//! AVFrame wrapper - the frame (decoded image/audio sample data) holder.
26class Media_Frame : public Standard_Transient
27{
28 DEFINE_STANDARD_RTTIEXT(Media_Frame, Standard_Transient)
29public:
30
31 //! Convert pixel format from FFmpeg (AVPixelFormat) to OCCT.
32 Standard_EXPORT static Image_Format FormatFFmpeg2Occt (int theFormat);
33
34 //! Convert pixel format from OCCT to FFmpeg (AVPixelFormat).
35 //! Returns -1 (AV_PIX_FMT_NONE) if undefined.
36 Standard_EXPORT static int FormatOcct2FFmpeg (Image_Format theFormat);
37
38 //! Swap AVFrame* within two frames.
39 Standard_EXPORT static void Swap (const Handle(Media_Frame)& theFrame1,
40 const Handle(Media_Frame)& theFrame2);
41
42public:
43
44 //! Empty constructor
45 Standard_EXPORT Media_Frame();
46
47 //! Destructor
48 Standard_EXPORT virtual ~Media_Frame();
49
50 //! Return true if frame does not contain any data.
51 Standard_EXPORT bool IsEmpty() const;
52
53 //! av_frame_unref() wrapper.
54 Standard_EXPORT void Unref();
55
56 //! Return image dimensions.
57 Graphic3d_Vec2i Size() const { return Graphic3d_Vec2i (SizeX(), SizeY()); }
58
59 //! Return image width.
60 Standard_EXPORT int SizeX() const;
61
62 //! Return image height.
63 Standard_EXPORT int SizeY() const;
64
65 //! Return pixel format (AVPixelFormat).
66 Standard_EXPORT int Format() const;
67
68 //! Return TRUE if YUV range is full.
69 Standard_EXPORT bool IsFullRangeYUV() const;
70
71 //! Access data plane for specified Id.
72 Standard_EXPORT uint8_t* Plane (int thePlaneId) const;
73
74 //! @return linesize in bytes for specified data plane
75 Standard_EXPORT int LineSize (int thePlaneId) const;
76
77 //! @return frame timestamp estimated using various heuristics, in stream time base
78 Standard_EXPORT int64_t BestEffortTimestamp() const;
79
80 //! Return frame.
81 const AVFrame* Frame() const { return myFrame; }
82
83 //! Return frame.
84 AVFrame* ChangeFrame() { return myFrame; }
85
86 //! Return presentation timestamp (PTS).
87 double Pts() const { return myFramePts; }
88
89 //! Set presentation timestamp (PTS).
90 void SetPts (double thePts) { myFramePts = thePts; }
91
92 //! Return PAR.
93 float PixelAspectRatio() const { return myPixelRatio; }
94
95 //! Set PAR.
96 void SetPixelAspectRatio (float theRatio) { myPixelRatio = theRatio; }
97
98 //! Return locked state.
99 bool IsLocked() const { return myIsLocked; }
100
101 //! Lock/free frame for edition.
102 void SetLocked (bool theToLock) { myIsLocked = theToLock; }
103
104public:
105
106 //! Wrap allocated image pixmap.
107 Standard_EXPORT bool InitWrapper (const Handle(Image_PixMap)& thePixMap);
108
109protected:
110
111 AVFrame* myFrame; //!< frame
112 double myFramePts; //!< presentation timestamp
113 float myPixelRatio; //!< pixel aspect ratio
114 bool myIsLocked; //!< locked state
115
116};
117
118#endif // _Media_Frame_HeaderFile