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_Packet.hxx> 21 22 #ifdef HAVE_FFMPEG 23 #include <Standard_WarningsDisable.hxx> 24 extern "C" 25 { 26 #include <libavcodec/avcodec.h> 27 }; 28 #include <Standard_WarningsRestore.hxx> 29 #endif 30 IMPLEMENT_STANDARD_RTTIEXT(Media_Packet,Standard_Transient)31IMPLEMENT_STANDARD_RTTIEXT(Media_Packet, Standard_Transient) 32 33 // ======================================================================= 34 // function : Media_Packet 35 // purpose : 36 // ======================================================================= 37 Media_Packet::Media_Packet() 38 : myPacket (NULL) 39 { 40 #ifdef HAVE_FFMPEG 41 myPacket = av_packet_alloc(); 42 #endif 43 } 44 45 // ======================================================================= 46 // function : ~Media_Packet 47 // purpose : 48 // ======================================================================= ~Media_Packet()49Media_Packet::~Media_Packet() 50 { 51 #ifdef HAVE_FFMPEG 52 av_packet_free (&myPacket); 53 #endif 54 } 55 56 // ======================================================================= 57 // function : Unref 58 // purpose : 59 // ======================================================================= Unref()60void Media_Packet::Unref() 61 { 62 #ifdef HAVE_FFMPEG 63 av_packet_unref (myPacket); 64 #endif 65 } 66 67 // ======================================================================= 68 // function : Data 69 // purpose : 70 // ======================================================================= Data() const71const uint8_t* Media_Packet::Data() const 72 { 73 #ifdef HAVE_FFMPEG 74 return myPacket->data; 75 #else 76 return NULL; 77 #endif 78 } 79 80 // ======================================================================= 81 // function : ChangeData 82 // purpose : 83 // ======================================================================= ChangeData()84uint8_t* Media_Packet::ChangeData() 85 { 86 #ifdef HAVE_FFMPEG 87 return myPacket->data; 88 #else 89 return NULL; 90 #endif 91 } 92 93 // ======================================================================= 94 // function : Size 95 // purpose : 96 // ======================================================================= Size() const97int Media_Packet::Size() const 98 { 99 #ifdef HAVE_FFMPEG 100 return myPacket->size; 101 #else 102 return 0; 103 #endif 104 } 105 106 // ======================================================================= 107 // function : Pts 108 // purpose : 109 // ======================================================================= Pts() const110int64_t Media_Packet::Pts() const 111 { 112 #ifdef HAVE_FFMPEG 113 return myPacket->pts; 114 #else 115 return 0; 116 #endif 117 } 118 119 // ======================================================================= 120 // function : Dts 121 // purpose : 122 // ======================================================================= Dts() const123int64_t Media_Packet::Dts() const 124 { 125 #ifdef HAVE_FFMPEG 126 return myPacket->dts; 127 #else 128 return 0; 129 #endif 130 } 131 132 // ======================================================================= 133 // function : Duration 134 // purpose : 135 // ======================================================================= Duration() const136int64_t Media_Packet::Duration() const 137 { 138 #ifdef HAVE_FFMPEG 139 return myPacket->duration; 140 #else 141 return 0; 142 #endif 143 } 144 145 // ======================================================================= 146 // function : StreamIndex 147 // purpose : 148 // ======================================================================= StreamIndex() const149int Media_Packet::StreamIndex() const 150 { 151 #ifdef HAVE_FFMPEG 152 return myPacket->stream_index; 153 #else 154 return 0; 155 #endif 156 } 157 158 // ======================================================================= 159 // function : IsKeyFrame 160 // purpose : 161 // ======================================================================= IsKeyFrame() const162bool Media_Packet::IsKeyFrame() const 163 { 164 #ifdef HAVE_FFMPEG 165 return (myPacket->flags & AV_PKT_FLAG_KEY) != 0; 166 #else 167 return false; 168 #endif 169 } 170 171 // ======================================================================= 172 // function : SetKeyFrame 173 // purpose : 174 // ======================================================================= SetKeyFrame()175void Media_Packet::SetKeyFrame() 176 { 177 #ifdef HAVE_FFMPEG 178 myPacket->flags |= AV_PKT_FLAG_KEY; 179 #endif 180 } 181