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_CodecContext_HeaderFile |
16 | #define _Media_CodecContext_HeaderFile |
17 | |
18 | #include <Media_Packet.hxx> |
19 | |
20 | struct AVCodec; |
21 | struct AVCodecContext; |
22 | struct AVStream; |
23 | class Media_Frame; |
24 | |
25 | //! AVCodecContext wrapper - the coder/decoder holder. |
26 | class Media_CodecContext : public Standard_Transient |
27 | { |
28 | DEFINE_STANDARD_RTTIEXT(Media_CodecContext, Standard_Transient) |
29 | public: |
30 | |
31 | //! Constructor. |
32 | Standard_EXPORT Media_CodecContext(); |
33 | |
34 | //! Destructor. |
35 | Standard_EXPORT virtual ~Media_CodecContext(); |
36 | |
37 | //! Return context. |
38 | AVCodecContext* Context() const { return myCodecCtx; } |
39 | |
40 | //! Open codec specified within the stream. |
41 | //! @param theStream stream to open |
42 | //! @param thePtsStartBase PTS start in seconds |
43 | //! @param theNbThreads amount of threads to use for AVMEDIA_TYPE_VIDEO stream; |
44 | //! -1 means OSD_Parallel::NbLogicalProcessors(), |
45 | //! 0 means auto by FFmpeg itself |
46 | //! >0 means specified number of threads (decoder should support multi-threading to take effect) |
47 | Standard_EXPORT bool Init (const AVStream& theStream, |
48 | double thePtsStartBase, |
49 | int theNbThreads = -1); |
50 | |
51 | //! Open codec. |
52 | //! @param theStream stream to open |
53 | //! @param thePtsStartBase PTS start in seconds |
54 | //! @param theNbThreads amount of threads to use for AVMEDIA_TYPE_VIDEO stream; |
55 | //! -1 means OSD_Parallel::NbLogicalProcessors(), |
56 | //! 0 means auto by FFmpeg itself |
57 | //! >0 means specified number of threads (decoder should support multi-threading to take effect) |
58 | //! @param theCodecId codec (AVCodecID) to open |
59 | Standard_EXPORT bool Init (const AVStream& theStream, |
60 | double thePtsStartBase, |
61 | int theNbThreads, |
62 | int theCodecId); |
63 | |
64 | //! Close input. |
65 | Standard_EXPORT void Close(); |
66 | |
67 | //! @return source frame width |
68 | Standard_EXPORT int SizeX() const; |
69 | |
70 | //! @return source frame height |
71 | Standard_EXPORT int SizeY() const; |
72 | |
73 | //! Return stream index. |
74 | int StreamIndex() const { return myStreamIndex; } |
75 | |
76 | //! avcodec_flush_buffers() wrapper. |
77 | Standard_EXPORT void Flush(); |
78 | |
79 | //! Return true if packet belongs to this stream. |
80 | Standard_EXPORT bool CanProcessPacket (const Handle(Media_Packet)& thePacket) const; |
81 | |
82 | //! avcodec_send_packet() wrapper. |
83 | Standard_EXPORT bool SendPacket (const Handle(Media_Packet)& thePacket); |
84 | |
85 | //! avcodec_receive_frame() wrapper. |
86 | Standard_EXPORT bool ReceiveFrame (const Handle(Media_Frame)& theFrame); |
87 | |
88 | protected: |
89 | |
90 | AVCodecContext* myCodecCtx; //!< codec context |
91 | AVCodec* myCodec; //!< opened codec |
92 | double myPtsStartBase; //!< starting PTS in context |
93 | double myPtsStartStream; //!< starting PTS in the stream |
94 | double myTimeBase; //!< stream timebase |
95 | int myStreamIndex; //!< stream index |
96 | float myPixelAspectRatio; //!< pixel aspect ratio |
97 | |
98 | }; |
99 | |
100 | #endif // _Media_CodecContext_HeaderFile |