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 | // activate some C99 macros like UINT64_C in "stdint.h" which used by FFmpeg |
16 | #ifndef __STDC_CONSTANT_MACROS |
17 | #define __STDC_CONSTANT_MACROS |
18 | #endif |
19 | |
20 | #include <Media_BufferPool.hxx> |
21 | |
22 | #include <Media_Frame.hxx> |
23 | |
24 | #ifdef HAVE_FFMPEG |
25 | #include <Standard_WarningsDisable.hxx> |
26 | extern "C" |
27 | { |
28 | #include <libavcodec/avcodec.h> |
29 | #include <libavutil/imgutils.h> |
30 | }; |
31 | #include <Standard_WarningsRestore.hxx> |
32 | #endif |
33 | |
34 | IMPLEMENT_STANDARD_RTTIEXT(Media_BufferPool, Standard_Transient) |
35 | |
36 | // ======================================================================= |
37 | // function : Media_BufferPool |
38 | // purpose : |
39 | // ======================================================================= |
40 | Media_BufferPool::Media_BufferPool() |
41 | : myPool (NULL), |
42 | myBufferSize (0) |
43 | { |
44 | // |
45 | } |
46 | |
47 | // ======================================================================= |
48 | // function : ~Media_BufferPool |
49 | // purpose : |
50 | // ======================================================================= |
51 | Media_BufferPool::~Media_BufferPool() |
52 | { |
53 | Release(); |
54 | } |
55 | |
56 | // ======================================================================= |
57 | // function : Release |
58 | // purpose : |
59 | // ======================================================================= |
60 | void Media_BufferPool::Release() |
61 | { |
62 | if (myPool != NULL) |
63 | { |
64 | #ifdef HAVE_FFMPEG |
65 | av_buffer_pool_uninit (&myPool); |
66 | #endif |
67 | myPool = NULL; |
68 | myBufferSize = 0; |
69 | } |
70 | } |
71 | |
72 | // ======================================================================= |
73 | // function : Init |
74 | // purpose : |
75 | // ======================================================================= |
76 | bool Media_BufferPool::Init (int theBufferSize) |
77 | { |
78 | if (myBufferSize == theBufferSize) |
79 | { |
80 | return true; |
81 | } |
82 | |
83 | Release(); |
84 | if (theBufferSize == 0) |
85 | { |
86 | return true; |
87 | } |
88 | |
89 | #ifdef HAVE_FFMPEG |
90 | myPool = av_buffer_pool_init (theBufferSize, NULL); |
91 | #endif |
92 | myBufferSize = theBufferSize; |
93 | return myPool != NULL; |
94 | } |
95 | |
96 | // ======================================================================= |
97 | // function : GetBuffer |
98 | // purpose : |
99 | // ======================================================================= |
100 | AVBufferRef* Media_BufferPool::GetBuffer() |
101 | { |
102 | #ifdef HAVE_FFMPEG |
103 | return av_buffer_pool_get (myPool); |
104 | #else |
105 | return NULL; |
106 | #endif |
107 | } |