001/* ---------------------------------------------------------------------------- 002 * This file was automatically generated by SWIG (http://www.swig.org). 003 * Version 4.0.2 004 * 005 * Do not make changes to this file unless you know what you are doing--modify 006 * the SWIG interface file instead. 007 * ----------------------------------------------------------------------------- */ 008 009package com.avpkit.core; 010import com.avpkit.ferry.*; 011/** 012 * Represents an encoded piece of data that can be placed in an {IContainer}<br> 013 * for a given {IStream} of data.<br> 014 * <p><br> 015 * You read this object out of {IContainer} objects when decoding, and<br> 016 * pass to an {IStreamCoder} object to decode.<br> 017 * </p><p><br> 018 * You pass this object to a {IStreamCoder} to encode data, and then<br> 019 * pass to an {IContainer} object to write to a data source.<br> 020 * </p><p><br> 021 * Lastly, the units of timestamps in an {IPacket} are determined by the<br> 022 * {IContainer} it came from (or is going to). For example, FLV {IPacket}s<br> 023 * are always in milliseconds (1/1000 of a second). You cannot assume these<br> 024 * timestamps are in any given timeunit without getting an {IStream} object<br> 025 * and finding out what Time Base that stream operates in.<br> 026 * </p><p><br> 027 * For convenience, the AVPKit API always uses Microseconds for raw data<br> 028 * ({IVideoPicture} and {IAudioSamples} objects), and will convert to<br> 029 * the right time stamp unit when decoding or encoding data (with an {IStreamCoder})<br> 030 * from or to an {IContainer}. 031 */ 032public class IPacket extends IMediaData { 033 // JNIHelper.swg: Start generated code 034 // >>>>>>>>>>>>>>>>>>>>>>>>>>> 035 /** 036 * This method is only here to use some references and remove 037 * a Eclipse compiler warning. 038 */ 039 @SuppressWarnings("unused") 040 private void noop() 041 { 042 IBuffer.make(null, 1); 043 } 044 045 private volatile long swigCPtr; 046 047 /** 048 * Internal Only. 049 */ 050 protected IPacket(long cPtr, boolean cMemoryOwn) { 051 super(AVPKitJNI.IPacket_SWIGUpcast(cPtr), cMemoryOwn); 052 swigCPtr = cPtr; 053 } 054 055 /** 056 * Internal Only. 057 */ 058 protected IPacket(long cPtr, boolean cMemoryOwn, 059 java.util.concurrent.atomic.AtomicLong ref) 060 { 061 super(AVPKitJNI.IPacket_SWIGUpcast(cPtr), 062 cMemoryOwn, ref); 063 swigCPtr = cPtr; 064 } 065 066 /** 067 * Internal Only. Not part of public API. 068 * 069 * Get the raw value of the native object that obj is proxying for. 070 * 071 * @param obj The java proxy object for a native object. 072 * @return The raw pointer obj is proxying for. 073 */ 074 public static long getCPtr(IPacket obj) { 075 if (obj == null) return 0; 076 return obj.getMyCPtr(); 077 } 078 079 /** 080 * Internal Only. Not part of public API. 081 * 082 * Get the raw value of the native object that we're proxying for. 083 * 084 * @return The raw pointer we're proxying for. 085 */ 086 public long getMyCPtr() { 087 if (swigCPtr == 0) throw new IllegalStateException("underlying native object already deleted"); 088 return swigCPtr; 089 } 090 091 /** 092 * Create a new IPacket object that is actually referring to the 093 * exact same underlying native object. 094 * 095 * @return the new Java object. 096 */ 097 @Override 098 public IPacket copyReference() { 099 if (swigCPtr == 0) 100 return null; 101 else 102 return new IPacket(swigCPtr, swigCMemOwn, getJavaRefCount()); 103 } 104 105 /** 106 * Compares two values, returning true if the underlying objects in native code are the same object. 107 * 108 * That means you can have two different Java objects, but when you do a comparison, you'll find out 109 * they are the EXACT same object. 110 * 111 * @return True if the underlying native object is the same. False otherwise. 112 */ 113 public boolean equals(Object obj) { 114 boolean equal = false; 115 if (obj instanceof IPacket) 116 equal = (((IPacket)obj).swigCPtr == this.swigCPtr); 117 return equal; 118 } 119 120 /** 121 * Get a hashable value for this object. 122 * 123 * @return the hashable value. 124 */ 125 public int hashCode() { 126 return (int)swigCPtr; 127 } 128 129 // <<<<<<<<<<<<<<<<<<<<<<<<<<< 130 // JNIHelper.swg: End generated code 131 132 133 /** 134 * info about this packet 135 * @return information about this packet 136 */ 137 138 @Override 139 public String toString() 140 { 141 StringBuilder result = new StringBuilder(); 142 143 result.append(this.getClass().getName()+"@"+hashCode()+"["); 144 result.append("complete:"+isComplete()+";"); 145 result.append("dts:"+getDts()+";"); 146 result.append("pts:"+getPts()+";"); 147 result.append("size:"+getSize()+";"); 148 result.append("key:"+isKey()+";"); 149 result.append("flags:"+getFlags()+";"); 150 result.append("stream index:"+getStreamIndex()+";"); 151 result.append("duration:"+getDuration()+";"); 152 result.append("position:"+getPosition()+";"); 153 IRational timeBase = getTimeBase(); 154 result.append("time base:"+timeBase+";"); 155 if (timeBase != null) timeBase.delete(); 156 result.append("]"); 157 return result.toString(); 158 } 159 160 161 /** 162 * Clear out any data in this packet, but leaves<br> 163 * the buffer available for reuse. 164 */ 165 public void reset() { 166 AVPKitJNI.IPacket_reset(swigCPtr, this); 167 } 168 169 /** 170 * Is this packet complete.<br> 171 * @return Is this packet full and therefore has valid information. 172 */ 173 public boolean isComplete() { 174 return AVPKitJNI.IPacket_isComplete(swigCPtr, this); 175 } 176 177 /** 178 * Get the Presentation Time Stamp (PTS) for this packet.<br> 179 * <br> 180 * This is the time at which the payload for this packet should<br> 181 * be <strong>presented</strong> to the user, in units of<br> 182 * {#getTimeBase()}, relative to the start of stream.<br> 183 * <br> 184 * @return Get the Presentation Timestamp for this packet. 185 */ 186 public long getPts() { 187 return AVPKitJNI.IPacket_getPts(swigCPtr, this); 188 } 189 190 /** 191 * Set a new Presentation Time Stamp (PTS) for this packet.<br> 192 * <br> 193 * @param aPts a new PTS for this packet.<br> 194 * <br> 195 * @see #getPts() 196 */ 197 public void setPts(long aPts) { 198 AVPKitJNI.IPacket_setPts(swigCPtr, this, aPts); 199 } 200 201 /** 202 * Get the Decompression Time Stamp (DTS) for this packet.<br> 203 * <p><br> 204 * This is the time at which the payload for this packet should<br> 205 * be <strong>decompressed</strong>, in units of<br> 206 * {#getTimeBase()}, relative to the start of stream.<br> 207 * </p><br> 208 * <p><br> 209 * Some media codecs can require packets from the "future" to<br> 210 * be decompressed before earliest packets as an additional way to compress<br> 211 * data. In general you don't need to worry about this, but if you're<br> 212 * curious start reading about the difference between I-Frames, P-Frames<br> 213 * and B-Frames (or Bi-Directional Frames). B-Frames can use information<br> 214 * from future frames when compressed.<br> 215 * </p><br> 216 * @return Get the Decompression Timestamp (i.e. when this was read relative<br> 217 * to the start of reading packets). 218 */ 219 public long getDts() { 220 return AVPKitJNI.IPacket_getDts(swigCPtr, this); 221 } 222 223 /** 224 * Set a new Decompression Time Stamp (DTS) for this packet.<br> 225 * @param aDts a new DTS for this packet.<br> 226 * @see #getDts() 227 */ 228 public void setDts(long aDts) { 229 AVPKitJNI.IPacket_setDts(swigCPtr, this, aDts); 230 } 231 232 /** 233 * Get the size in bytes of the payload currently in this packet.<br> 234 * @return Size (in bytes) of payload currently in packet. 235 */ 236 public int getSize() { 237 return AVPKitJNI.IPacket_getSize(swigCPtr, this); 238 } 239 240 /** 241 * Get the maximum size (in bytes) of payload this packet can hold.<br> 242 * @return Get maximum size (in bytes) of payload this packet can hold. 243 */ 244 public int getMaxSize() { 245 return AVPKitJNI.IPacket_getMaxSize(swigCPtr, this); 246 } 247 248 /** 249 * Get the container-specific index for the stream this packet is<br> 250 * part of.<br> 251 * @return Stream in container that this packet has data for. 252 */ 253 public int getStreamIndex() { 254 return AVPKitJNI.IPacket_getStreamIndex(swigCPtr, this); 255 } 256 257 /** 258 * Get any flags set on this packet, as a 4-byte binary-ORed bit-mask.<br> 259 * This is access to raw FFMPEG<br> 260 * flags, but it is easier to use the is* methods below.<br> 261 * @return Any flags on the packet. 262 */ 263 public int getFlags() { 264 return AVPKitJNI.IPacket_getFlags(swigCPtr, this); 265 } 266 267 /** 268 * Does this packet contain Key data? i.e. data that needs no other<br> 269 * frames or samples to decode.<br> 270 * @return true if key; false otherwise. 271 */ 272 public boolean isKeyPacket() { 273 return AVPKitJNI.IPacket_isKeyPacket(swigCPtr, this); 274 } 275 276 /** 277 * Return the duration of this packet, in units of {#getTimeBase()}<br> 278 * @return Duration of this packet, in same time-base as the PTS. 279 */ 280 public long getDuration() { 281 return AVPKitJNI.IPacket_getDuration(swigCPtr, this); 282 } 283 284 /** 285 * Return the position (in bytes) of this packet in the stream.<br> 286 * @return The position of this packet in the stream, or -1 if<br> 287 * unknown. 288 */ 289 public long getPosition() { 290 return AVPKitJNI.IPacket_getPosition(swigCPtr, this); 291 } 292 293 /** 294 * Discard the current payload and allocate a new payload.<br> 295 * <p><br> 296 * Note that if any people have access to the old payload using<br> 297 * getData(), the memory will continue to be available to them<br> 298 * until they release their hold of the IBuffer.<br> 299 * </p><br> 300 * <p><br> 301 * When requesting a packet size, the system<br> 302 * may allocate a larger payloadSize.<br> 303 * </p><br> 304 * @param payloadSize The (minimum) payloadSize of this packet in bytes.<br> 305 * <br> 306 * @return >= 0 if successful. < 0 if error. 307 */ 308 public int allocateNewPayload(int payloadSize) { 309 return AVPKitJNI.IPacket_allocateNewPayload(swigCPtr, this, payloadSize); 310 } 311 312 /** 313 * Allocate a new packet.<br> 314 * <p><br> 315 * Note that any buffers this packet needs will be<br> 316 * lazily allocated (i.e. we won't actually grab all<br> 317 * the memory until we need it).<br> 318 * </p><br> 319 * <br> 320 * @return a new packet, or null on error. 321 */ 322 public static IPacket make() { 323 long cPtr = AVPKitJNI.IPacket_make__SWIG_0(); 324 return (cPtr == 0) ? null : new IPacket(cPtr, false); 325 } 326 327 /** 328 * Allocate a new packet that wraps an existing IBuffer.<br> 329 * <br> 330 * @param buffer The IBuffer to wrap.<br> 331 * @return a new packet or null on error. 332 */ 333 public static IPacket make(IBuffer buffer) { 334 long cPtr = AVPKitJNI.IPacket_make__SWIG_1(IBuffer.getCPtr(buffer), buffer); 335 return (cPtr == 0) ? null : new IPacket(cPtr, false); 336 } 337 338 /** 339 * Set if this is a key packet.<br> 340 * <br> 341 * @param keyPacket true for yes, false for no. 342 */ 343 public void setKeyPacket(boolean keyPacket) { 344 AVPKitJNI.IPacket_setKeyPacket(swigCPtr, this, keyPacket); 345 } 346 347 /** 348 * Set any internal flags.<br> 349 * <br> 350 * @param flags Flags to set 351 */ 352 public void setFlags(int flags) { 353 AVPKitJNI.IPacket_setFlags(swigCPtr, this, flags); 354 } 355 356 /** 357 * Set if this packet is complete, and what the total size of the data should be assumed to be.<br> 358 * <br> 359 * @param complete True for complete, false for not.<br> 360 * @param size Size of data in packet. 361 */ 362 public void setComplete(boolean complete, int size) { 363 AVPKitJNI.IPacket_setComplete(swigCPtr, this, complete, size); 364 } 365 366 /** 367 * Set the stream index for this packet.<br> 368 * <br> 369 * @param streamIndex The stream index, as determined from the {IContainer} this packet will be written to. 370 */ 371 public void setStreamIndex(int streamIndex) { 372 AVPKitJNI.IPacket_setStreamIndex(swigCPtr, this, streamIndex); 373 } 374 375 /** 376 * Set the duration.<br> 377 * @param duration new duration<br> 378 * @see #getDuration() 379 */ 380 public void setDuration(long duration) { 381 AVPKitJNI.IPacket_setDuration(swigCPtr, this, duration); 382 } 383 384 /** 385 * Set the position.<br> 386 * @param position new position<br> 387 * @see #getPosition() 388 */ 389 public void setPosition(long position) { 390 AVPKitJNI.IPacket_setPosition(swigCPtr, this, position); 391 } 392 393 /** 394 * Allocate a new packet wrapping the existing contents of<br> 395 * a passed in packet. Callers can then modify<br> 396 * {#getPts()},<br> 397 * {#getDts()} and other get/set methods without<br> 398 * modifying the original packet.<br> 399 * <br> 400 * @param packet Packet to reuse buffer from and to<br> 401 * copy settings from.<br> 402 * @param copyData if true copy data from packet<br> 403 * into our own buffer. If false, share the same<br> 404 * data buffer that packet uses <br> 405 * <br> 406 * @return a new packet or null on error. 407 */ 408 public static IPacket make(IPacket packet, boolean copyData) { 409 long cPtr = AVPKitJNI.IPacket_make__SWIG_2(IPacket.getCPtr(packet), packet, copyData); 410 return (cPtr == 0) ? null : new IPacket(cPtr, false); 411 } 412 413 /** 414 * Allocate a new packet.<br> 415 * <p><br> 416 * Note that any buffers this packet needs will be<br> 417 * lazily allocated (i.e. we won't actually grab all<br> 418 * the memory until we need it).<br> 419 * </p><br> 420 * @param size The maximum size, in bytes, of data you<br> 421 * want to put in this packet.<br> 422 * <br> 423 * @return a new packet, or null on error. 424 */ 425 public static IPacket make(int size) { 426 long cPtr = AVPKitJNI.IPacket_make__SWIG_3(size); 427 return (cPtr == 0) ? null : new IPacket(cPtr, false); 428 } 429 430}