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 _Graphic3d_MediaTextureSet_HeaderFile |
16 | #define _Graphic3d_MediaTextureSet_HeaderFile |
17 | |
18 | #include <Media_IFrameQueue.hxx> |
19 | #include <Graphic3d_MediaTexture.hxx> |
20 | #include <Graphic3d_TextureSet.hxx> |
21 | |
22 | class Graphic3d_ShaderProgram; |
23 | class Media_PlayerContext; |
24 | |
25 | //! Texture adapter for Media_Frame. |
26 | class Graphic3d_MediaTextureSet : public Graphic3d_TextureSet, public Media_IFrameQueue |
27 | { |
28 | DEFINE_STANDARD_RTTIEXT(Graphic3d_MediaTextureSet, Graphic3d_TextureSet) |
29 | public: |
30 | |
31 | //! Callback definition. |
32 | typedef void (*CallbackOnUpdate_t)(void* theUserPtr); |
33 | |
34 | public: |
35 | |
36 | //! Empty constructor. |
37 | Standard_EXPORT Graphic3d_MediaTextureSet(); |
38 | |
39 | //! Setup callback to be called on queue progress (e.g. when new frame should be displayed). |
40 | Standard_EXPORT void SetCallback (CallbackOnUpdate_t theCallbackFunction, void* theCallbackUserPtr); |
41 | |
42 | //! Call callback. |
43 | Standard_EXPORT void Notify(); |
44 | |
45 | //! Return input media. |
46 | const TCollection_AsciiString& Input() const { return myInput; } |
47 | |
48 | //! Open specified file. |
49 | //! Passing an empty path would close current input. |
50 | Standard_EXPORT void OpenInput (const TCollection_AsciiString& thePath, |
51 | Standard_Boolean theToWait); |
52 | |
53 | //! Return player context; it can be NULL until first OpenInput(). |
54 | const Handle(Media_PlayerContext)& PlayerContext() const { return myPlayerCtx; } |
55 | |
56 | //! Swap front/back frames. |
57 | Standard_EXPORT Standard_Boolean SwapFrames(); |
58 | |
59 | //! Return front frame dimensions. |
60 | Graphic3d_Vec2i FrameSize() const { return myFrameSize; } |
61 | |
62 | //! Return shader program for displaying texture set. |
63 | Handle(Graphic3d_ShaderProgram) ShaderProgram() const |
64 | { |
65 | if (myIsPlanarYUV) |
66 | { |
67 | return myIsFullRangeYUV ? myShaderYUVJ : myShaderYUV; |
68 | } |
69 | return Handle(Graphic3d_ShaderProgram)(); |
70 | } |
71 | |
72 | //! Return TRUE if texture set defined 3 YUV planes. |
73 | Standard_Boolean IsPlanarYUV() const { return myIsPlanarYUV; } |
74 | |
75 | //! Return TRUE if YUV range is full. |
76 | Standard_Boolean IsFullRangeYUV() const { return myIsFullRangeYUV; } |
77 | |
78 | //! Return duration in seconds. |
79 | double Duration() const { return myDuration; } |
80 | |
81 | //! Return playback progress in seconds. |
82 | double Progress() const { return myProgress; } |
83 | |
84 | //! @name Media_IFrameQueue interface |
85 | private: |
86 | |
87 | //! Lock the frame for decoding into. |
b31fbc83 |
88 | Standard_EXPORT virtual Handle(Media_Frame) LockFrame() Standard_OVERRIDE; |
98e6c6d1 |
89 | |
90 | //! Release the frame to present decoding results. |
b31fbc83 |
91 | Standard_EXPORT virtual void ReleaseFrame (const Handle(Media_Frame)& theFrame) Standard_OVERRIDE; |
98e6c6d1 |
92 | |
93 | protected: |
94 | |
95 | Handle(Media_PlayerContext) myPlayerCtx; //!< player context |
96 | Handle(Media_Frame) myFramePair[2]; //!< front/back frames pair |
97 | Handle(Graphic3d_ShaderProgram) myShaderYUV; //!< shader program for YUV texture set |
98 | Handle(Graphic3d_ShaderProgram) myShaderYUVJ; //!< shader program for YUVJ texture set |
99 | Handle(Media_HMutex) myMutex; //!< mutex for accessing frames |
100 | TCollection_AsciiString myInput; //!< input media |
101 | CallbackOnUpdate_t myCallbackFunction; //!< callback function |
102 | void* myCallbackUserPtr; //!< callback data |
103 | Graphic3d_Vec2i myFrameSize; //!< front frame size |
104 | Standard_Real myProgress; //!< playback progress in seconds |
105 | Standard_Real myDuration; //!< stream duration |
106 | Standard_Integer myFront; //!< index of front texture |
107 | Standard_Boolean myToPresentFrame; //!< flag |
108 | Standard_Boolean myIsPlanarYUV; //!< front frame contains planar YUV data or native texture format |
109 | Standard_Boolean myIsFullRangeYUV; //!< front frame defines full-range or reduced-range YUV |
110 | |
111 | }; |
112 | |
113 | #endif // _Graphic3d_MediaTextureSet_HeaderFile |