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 * The parent class of all media objects than can be gotten from an {IStream}.
013 */
014public class IMediaData extends RefCounted {
015  // JNIHelper.swg: Start generated code
016  // >>>>>>>>>>>>>>>>>>>>>>>>>>>
017  /**
018   * This method is only here to use some references and remove
019   * a Eclipse compiler warning.
020   */
021  @SuppressWarnings("unused")
022  private void noop()
023  {
024    IBuffer.make(null, 1);
025  }
026   
027  private volatile long swigCPtr;
028
029  /**
030   * Internal Only.
031   */
032  protected IMediaData(long cPtr, boolean cMemoryOwn) {
033    super(AVPKitJNI.IMediaData_SWIGUpcast(cPtr), cMemoryOwn);
034    swigCPtr = cPtr;
035  }
036  
037  /**
038   * Internal Only.
039   */
040  protected IMediaData(long cPtr, boolean cMemoryOwn,
041      java.util.concurrent.atomic.AtomicLong ref)
042  {
043    super(AVPKitJNI.IMediaData_SWIGUpcast(cPtr),
044     cMemoryOwn, ref);
045    swigCPtr = cPtr;
046  }
047    
048  /**
049   * Internal Only.  Not part of public API.
050   *
051   * Get the raw value of the native object that obj is proxying for.
052   *   
053   * @param obj The java proxy object for a native object.
054   * @return The raw pointer obj is proxying for.
055   */
056  public static long getCPtr(IMediaData obj) {
057    if (obj == null) return 0;
058    return obj.getMyCPtr();
059  }
060
061  /**
062   * Internal Only.  Not part of public API.
063   *
064   * Get the raw value of the native object that we're proxying for.
065   *   
066   * @return The raw pointer we're proxying for.
067   */  
068  public long getMyCPtr() {
069    if (swigCPtr == 0) throw new IllegalStateException("underlying native object already deleted");
070    return swigCPtr;
071  }
072  
073  /**
074   * Create a new IMediaData object that is actually referring to the
075   * exact same underlying native object.
076   *
077   * @return the new Java object.
078   */
079  @Override
080  public IMediaData copyReference() {
081    if (swigCPtr == 0)
082      return null;
083    else
084      return new IMediaData(swigCPtr, swigCMemOwn, getJavaRefCount());
085  }
086
087  /**
088   * Compares two values, returning true if the underlying objects in native code are the same object.
089   *
090   * That means you can have two different Java objects, but when you do a comparison, you'll find out
091   * they are the EXACT same object.
092   *
093   * @return True if the underlying native object is the same.  False otherwise.
094   */
095  public boolean equals(Object obj) {
096    boolean equal = false;
097    if (obj instanceof IMediaData)
098      equal = (((IMediaData)obj).swigCPtr == this.swigCPtr);
099    return equal;
100  }
101  
102  /**
103   * Get a hashable value for this object.
104   *
105   * @return the hashable value.
106   */
107  public int hashCode() {
108     return (int)swigCPtr;
109  }
110  
111  // <<<<<<<<<<<<<<<<<<<<<<<<<<<
112  // JNIHelper.swg: End generated code
113  
114
115  // used to correct timezone offsets for timestamp format 
116
117  private static final long TIME_OFFSET = -java.util.Calendar.getInstance()
118    .getTimeZone().getRawOffset();
119
120  /** The default time stamp format. */
121  
122  public static final String DEFAULT_TIME_STAMP_FORMAT =
123    "%1$tH:%1$tM:%1$tS.%1$tL";
124/**
125 * Absolute bulk put method.
126 * <p>
127 * This method delegates to the same put method on the
128 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
129 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
130 * configurations.
131 * </p>
132 * @see com.avpkit.ferry.IBuffer#put(byte[], int, int, int)
133 */
134public void put(byte[] src, int srcPos, int destPos, int length)
135{
136  com.avpkit.ferry.IBuffer buffer = getDataCached();
137  if (buffer == null)
138    return;
139  buffer.put(src, srcPos, destPos, length);
140  return;
141}
142
143/**
144 * Absolute bulk get method.
145 * <p>
146 * This method delegates to the same get method on the
147 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
148 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
149 * configurations.
150 * </p>
151 * @see com.avpkit.ferry.IBuffer#get(int, byte[], int, int)
152 */
153public void get(int srcPos, byte[] dest, int destPos, int length)
154{
155   com.avpkit.ferry.IBuffer buffer = getDataCached();
156   if (buffer == null)
157     return;
158   buffer.get(srcPos, dest, destPos, length);
159   return;
160}
161
162/**
163 * Absolute bulk put method.
164 * <p>
165 * This method delegates to the same put method on the
166 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
167 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
168 * configurations.
169 * </p>
170 * @see com.avpkit.ferry.IBuffer#put(char[], int, int, int)
171 */
172public void put(char[] src, int srcPos, int destPos, int length)
173{
174  com.avpkit.ferry.IBuffer buffer = getDataCached();
175  if (buffer == null)
176    return;
177  buffer.put(src, srcPos, destPos, length);
178  return;
179}
180
181/**
182 * Absolute bulk get method.
183 * <p>
184 * This method delegates to the same get method on the
185 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
186 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
187 * configurations.
188 * </p>
189 * @see com.avpkit.ferry.IBuffer#get(int, char[], int, int)
190 */
191public void get(int srcPos, char[] dest, int destPos, int length)
192{
193   com.avpkit.ferry.IBuffer buffer = getDataCached();
194   if (buffer == null)
195     return;
196   buffer.get(srcPos, dest, destPos, length);
197   return;
198}
199
200/**
201 * Absolute bulk put method.
202 * <p>
203 * This method delegates to the same put method on the
204 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
205 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
206 * configurations.
207 * </p>
208 * @see com.avpkit.ferry.IBuffer#put(short[], int, int, int)
209 */
210public void put(short[] src, int srcPos, int destPos, int length)
211{
212  com.avpkit.ferry.IBuffer buffer = getDataCached();
213  if (buffer == null)
214    return;
215  buffer.put(src, srcPos, destPos, length);
216  return;
217}
218
219/**
220 * Absolute bulk get method.
221 * <p>
222 * This method delegates to the same get method on the
223 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
224 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
225 * configurations.
226 * </p>
227 * @see com.avpkit.ferry.IBuffer#get(int, short[], int, int)
228 */
229public void get(int srcPos, short[] dest, int destPos, int length)
230{
231   com.avpkit.ferry.IBuffer buffer = getDataCached();
232   if (buffer == null)
233     return;
234   buffer.get(srcPos, dest, destPos, length);
235   return;
236}
237
238/**
239 * Absolute bulk put method.
240 * <p>
241 * This method delegates to the same put method on the
242 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
243 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
244 * configurations.
245 * </p>
246 * @see com.avpkit.ferry.IBuffer#put(int[], int, int, int)
247 */
248public void put(int[] src, int srcPos, int destPos, int length)
249{
250  com.avpkit.ferry.IBuffer buffer = getDataCached();
251  if (buffer == null)
252    return;
253  buffer.put(src, srcPos, destPos, length);
254  return;
255}
256
257/**
258 * Absolute bulk get method.
259 * <p>
260 * This method delegates to the same get method on the
261 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
262 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
263 * configurations.
264 * </p>
265 * @see com.avpkit.ferry.IBuffer#get(int, int[], int, int)
266 */
267public void get(int srcPos, int[] dest, int destPos, int length)
268{
269   com.avpkit.ferry.IBuffer buffer = getDataCached();
270   if (buffer == null)
271     return;
272   buffer.get(srcPos, dest, destPos, length);
273   return;
274}
275
276/**
277 * Absolute bulk put method.
278 * <p>
279 * This method delegates to the same put method on the
280 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
281 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
282 * configurations.
283 * </p>
284 * @see com.avpkit.ferry.IBuffer#put(long[], int, int, int)
285 */
286public void put(long[] src, int srcPos, int destPos, int length)
287{
288  com.avpkit.ferry.IBuffer buffer = getDataCached();
289  if (buffer == null)
290    return;
291  buffer.put(src, srcPos, destPos, length);
292  return;
293}
294
295/**
296 * Absolute bulk get method.
297 * <p>
298 * This method delegates to the same get method on the
299 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
300 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
301 * configurations.
302 * </p>
303 * @see com.avpkit.ferry.IBuffer#get(int, long[], int, int)
304 */
305public void get(int srcPos, long[] dest, int destPos, int length)
306{
307   com.avpkit.ferry.IBuffer buffer = getDataCached();
308   if (buffer == null)
309     return;
310   buffer.get(srcPos, dest, destPos, length);
311   return;
312}
313
314/**
315 * Absolute bulk put method.
316 * <p>
317 * This method delegates to the same put method on the
318 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
319 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
320 * configurations.
321 * </p>
322 * @see com.avpkit.ferry.IBuffer#put(float[], int, int, int)
323 */
324public void put(float[] src, int srcPos, int destPos, int length)
325{
326  com.avpkit.ferry.IBuffer buffer = getDataCached();
327  if (buffer == null)
328    return;
329  buffer.put(src, srcPos, destPos, length);
330  return;
331}
332
333/**
334 * Absolute bulk get method.
335 * <p>
336 * This method delegates to the same get method on the
337 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
338 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
339 * configurations.
340 * </p>
341 * @see com.avpkit.ferry.IBuffer#get(int, float[], int, int)
342 */
343public void get(int srcPos, float[] dest, int destPos, int length)
344{
345   com.avpkit.ferry.IBuffer buffer = getDataCached();
346   if (buffer == null)
347     return;
348   buffer.get(srcPos, dest, destPos, length);
349   return;
350}
351
352/**
353 * Absolute bulk put method.
354 * <p>
355 * This method delegates to the same put method on the
356 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
357 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
358 * configurations.
359 * </p>
360 * @see com.avpkit.ferry.IBuffer#put(double[], int, int, int)
361 */
362public void put(double[] src, int srcPos, int destPos, int length)
363{
364  com.avpkit.ferry.IBuffer buffer = getDataCached();
365  if (buffer == null)
366    return;
367  buffer.put(src, srcPos, destPos, length);
368  return;
369}
370
371/**
372 * Absolute bulk get method.
373 * <p>
374 * This method delegates to the same get method on the
375 * underlying {@link com.avpkit.ferry.IBuffer} returned from {@link #getData()} ,
376 * but may be more efficient in some {@link com.avpkit.ferry.JNIMemoryManager.MemoryModel}
377 * configurations.
378 * </p>
379 * @see com.avpkit.ferry.IBuffer#get(int, double[], int, int)
380 */
381public void get(int srcPos, double[] dest, int destPos, int length)
382{
383   com.avpkit.ferry.IBuffer buffer = getDataCached();
384   if (buffer == null)
385     return;
386   buffer.get(srcPos, dest, destPos, length);
387   return;
388}
389
390
391  /**
392   * Gets the underlying {@link java.nio.ByteBuffer} for this {@link
393   * IMediaData} object.  Users may modify the contents of the
394   * ByteBuffer and their changes will be reflected in the underlying
395   * memory.  See {@link com.avpkit.ferry.IBuffer} for the warnings
396   * associated with the use of raw memory.  The buffer position and
397   * mark are initialized to zero, and the limit is initialized to the
398   * number of elements in the buffer.
399   *
400   * <p>
401   *
402   * This is a convenience method to allow you to avoid getting the
403   * IBuffer object that has the actual data.
404   *
405   * </p>
406   *
407   * @return The underlying ByteBuffer
408   * 
409   * @see com.avpkit.ferry.IBuffer#getByteBuffer(int, int)
410   */
411
412  public java.nio.ByteBuffer getByteBuffer()
413  {
414    return getByteBuffer(null);
415  }
416
417  /**
418   * Gets the underlying {@link java.nio.ByteBuffer} for this {@link
419   * IMediaData} object.  Users may modify the contents of the
420   * ByteBuffer and their changes will be reflected in the underlying
421   * memory.  See {@link com.avpkit.ferry.IBuffer} for the warnings
422   * associated with the use of raw memory.  The buffer position and
423   * mark are initialized to zero, and the limit is initialized to the
424   * number of elements in the buffer.
425   *
426   * <p>
427   *
428   * This is a convenience method to allow you to avoid getting the
429   * IBuffer object that has the actual data.
430   *
431   * </p>
432   *
433   * @param ref A reference that on return from this method will
434   *   contain a {@link com.avpkit.ferry.JNIReference} object
435   *   that can be used for explicit memory management.
436   * @return The underlying ByteBuffer
437   * 
438   * @see com.avpkit.ferry.IBuffer#getByteBuffer(int, int, java.util.concurrent.atomic.AtomicReference)
439   */
440
441  public java.nio.ByteBuffer getByteBuffer(
442      java.util.concurrent.atomic.AtomicReference<com.avpkit.ferry.JNIReference> ref) {
443    if (ref != null)
444      ref.set(null);
445      
446    com.avpkit.ferry.IBuffer buf = this.getDataCached();
447    if (buf == null)
448      return null;
449    java.nio.ByteBuffer byteBuffer = buf.getByteBuffer(0, this.getSize(), ref);
450    if (byteBuffer != null)
451    {
452      byteBuffer.position(0);
453      byteBuffer.mark();
454      byteBuffer.limit(this.getSize());
455    }
456    return byteBuffer;
457  }
458
459
460  /**
461   * Get a string representation of the time stamp for this {@link
462   * IMediaData}.  The time is formatted as: <b>HH:MM:SS.ms</b>
463   *
464   * @return the printable string form of the time stamp of this media
465   *
466   * @see #getFormattedTimeStamp(String)
467   * @see #DEFAULT_TIME_STAMP_FORMAT
468   */
469
470  public String getFormattedTimeStamp()
471  {
472    return getFormattedTimeStamp(DEFAULT_TIME_STAMP_FORMAT);
473  }
474
475  /**
476   * Get a string representation of the time stamp for this {@link
477   * IMediaData}.  The format of the resulting string is specified by
478   * the format parameter.  See {@link java.util.Formatter} for 
479   * details on how to specify formats, however a good place to start
480   * is with the following format: <b>%1$tH:%1$tM:%1$tS.%1$tL</b>
481   *
482   * @param format the format for the time stamp string
483   *
484   * @return the printable string form of the timestamp
485   * 
486   * @see #getFormattedTimeStamp()
487   * @see #DEFAULT_TIME_STAMP_FORMAT
488   * @see java.util.Formatter
489   */
490
491  public String getFormattedTimeStamp(String format)
492  {
493    java.util.Formatter formatter = new java.util.Formatter();
494    IRational timeBase = getTimeBase();
495    if (timeBase == null)
496      timeBase = IRational.make(1,(int)Global.DEFAULT_PTS_PER_SECOND);
497    String retval = formatter.format(format,
498      (long)(getTimeStamp() * timeBase.getDouble() * 1000) +
499      TIME_OFFSET).toString();
500    timeBase.delete();
501    return retval;
502  }
503  
504  /**
505   * The data used by {@link #getDataCached()}.
506   */
507  private IBuffer mData;
508
509  /**
510   * Get any underlying raw data available for this object.
511   * 
512   * @return The raw data, or null if not accessible.
513   */
514  public IBuffer getData()
515  {
516    IBuffer retval = getData_internal();
517    if (retval == null)
518    {
519       if (mData != null)
520         mData.delete();
521       mData = retval;
522    } else {
523      if (mData == null) {
524        mData = retval.copyReference();
525      } else {
526        if (mData.getMyCPtr() != retval.getMyCPtr())
527        {
528          mData.delete();
529          mData = retval.copyReference();
530        }
531      }
532    }
533    return retval;
534  }
535  
536  /**
537   * Sets the underlying buffer used by this object.
538   * <p>
539   * This is an advanced method and is not recommended for use by those
540   * who don't fully understand how IBuffers work.  Implementations of
541   * {@link IMediaData} may behave in undefined ways if the buffer you
542   * pass in is not big enough for what you ask them to do (e.g. they may
543   * discard your buffer and allocate a larger one if they need more space).
544   * It is up to the caller to ensure the buffer passed in is large enough,
545   * and is not simultaneously in use by another part of the system.
546   * </p>
547   * @param buffer The buffer to set.  If null, this method
548   *   is ignored.
549   * @since 3.2
550   */
551  public void setData(IBuffer buffer)
552  {
553    if (buffer == null)
554    {
555      if (mData != null)
556        mData.delete();
557      mData = buffer;
558    } else {
559      if (mData == null) {
560        mData = buffer.copyReference();
561      } else {
562        if (mData.getMyCPtr() != buffer.getMyCPtr())
563        {
564          mData.delete();
565          mData = buffer.copyReference();
566        }
567      }
568    }
569    setData_internal(buffer);
570  }
571
572  /**
573   * Get any underlying raw data available for this object, but do
574   * not create a new Java wrapping object for it.
575   *
576   * <p>
577   * Do not call {@link com.avpkit.ferry.RefCounted#delete()} on
578   * the returned value. 
579   * </p>
580   * 
581   * @return The raw data, or null if not accessible.
582   * @since 3.2
583   */
584  public IBuffer getDataCached()
585  {
586    if (mData == null)
587      mData = getData_internal(); // Try crossing the boundary anyway
588    return mData;
589  }
590
591  /**
592   * Releases this instance of IMediaData and frees any underlying
593   * native memory.
594   * <p>
595   * {@inheritDoc}
596   * </p> 
597   */
598  @Override
599  public void delete()
600  {
601    if (mData != null) {
602      mData.delete();
603      mData = null;
604    }
605    super.delete();
606  }
607
608
609  
610
611  /**
612   * Get the time stamp of this object in getTimeBase() units.<br>
613   * <br>
614   * @return the time stamp
615   */
616  public long getTimeStamp() {
617    return AVPKitJNI.IMediaData_getTimeStamp(swigCPtr, this);
618  }
619
620  /**
621   * Set the time stamp for this object in getTimeBase() units.<br>
622   * <br>
623   * @param aTimeStamp The time stamp
624   */
625  public void setTimeStamp(long aTimeStamp) {
626    AVPKitJNI.IMediaData_setTimeStamp(swigCPtr, this, aTimeStamp);
627  }
628
629  /**
630   * Get the time base that time stamps of this object are represented in.<br>
631   * <br>
632   * Caller must release the returned value.<br>
633   * <br>
634   * @return the time base.
635   */
636  public IRational getTimeBase() {
637    long cPtr = AVPKitJNI.IMediaData_getTimeBase(swigCPtr, this);
638    return (cPtr == 0) ? null : new IRational(cPtr, false);
639  }
640
641  /**
642   * Set the time base that time stamps of this object are represented in.<br>
643   * <br>
644   * @param aBase the new time base.  If null an exception is thrown.
645   */
646  public void setTimeBase(IRational aBase) {
647    AVPKitJNI.IMediaData_setTimeBase(swigCPtr, this, IRational.getCPtr(aBase), aBase);
648  }
649
650  /**
651   * Get any underlying raw data available for this object.<br>
652   * <br>
653   * @return The raw data, or null if not accessible.
654   */
655  protected IBuffer getData_internal() {
656    long cPtr = AVPKitJNI.IMediaData_getData_internal(swigCPtr, this);
657    return (cPtr == 0) ? null : new IBuffer(cPtr, false);
658  }
659
660  /**
661   * Get the size in bytes of the raw data available for this object.<br>
662   * <br>
663   * @return the size in bytes, or -1 if it cannot be computed.
664   */
665  public int getSize() {
666    return AVPKitJNI.IMediaData_getSize(swigCPtr, this);
667  }
668
669  /**
670   * Is this object a key object?  i.e. it can be interpreted without needing any other media objects<br>
671   * <br>
672   * @return true if it's a key, false if not
673   */
674  public boolean isKey() {
675    return AVPKitJNI.IMediaData_isKey(swigCPtr, this);
676  }
677
678  /**
679   * Sets the underlying buffer used by this object.<br>
680   * <p><br>
681   * This is an advanced method and is not recommended for use by those<br>
682   * who don't fully understand how IBuffers work.  Implementations of<br>
683   * {IMediaData} may behave in undefined ways if the buffer you<br>
684   * pass in is not big enough for what you ask them to do (e.g. they may<br>
685   * discard your buffer and allocate a larger one if they need more space).<br>
686   * It is up to the caller to ensure the buffer passed in is large enough,<br>
687   * and is not simultaneously in use by another part of the system.<br>
688   * </p><br>
689   * @param buffer The buffer to set.  If null, this method<br>
690   *   is ignored.
691   */
692  protected void setData_internal(IBuffer buffer) {
693    AVPKitJNI.IMediaData_setData_internal(swigCPtr, this, IBuffer.getCPtr(buffer), buffer);
694  }
695
696}