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 * Get MetaData about a {IContainer} or {IStream}.<br>
013 * <p><br>
014 * MetaData is a bag of key/value pairs that can be embedded<br>
015 * in some {IContainer} or some {IStream}<br>
016 * in an {IContainer}, and are then written to<br>
017 * or read from a media file.  Keys must be unique, and<br>
018 * any attempt to set a key value replaces any previous values.<br>
019 * </p><br>
020 * <p><br>
021 * An example is the "title" meta-data item in an MP3 file.<br>
022 * </p><br>
023 * <p><br>
024 * Support for IMetaData differs depending upon the {<br>
025 * IContainer} format you're using and the implementation<br>
026 * in <a href="http://www.ffmpeg.org/">FFmpeg</a>.  For example,<br>
027 * MP3 meta-data reading and writing is supported, but<br>
028 * (as of the writing of this comment) FLV meta-data writing<br>
029 * is not supported.<br>
030 * </p>
031 */
032public class IMetaData extends RefCounted {
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 IMetaData(long cPtr, boolean cMemoryOwn) {
051    super(AVPKitJNI.IMetaData_SWIGUpcast(cPtr), cMemoryOwn);
052    swigCPtr = cPtr;
053  }
054  
055  /**
056   * Internal Only.
057   */
058  protected IMetaData(long cPtr, boolean cMemoryOwn,
059      java.util.concurrent.atomic.AtomicLong ref)
060  {
061    super(AVPKitJNI.IMetaData_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(IMetaData 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 IMetaData 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 IMetaData copyReference() {
099    if (swigCPtr == 0)
100      return null;
101    else
102      return new IMetaData(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 IMetaData)
116      equal = (((IMetaData)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   * Return the meta-data, with all values expanded.
134   */
135  @Override
136  public String toString()
137  {
138    StringBuilder result = new StringBuilder();
139    result.append(this.getClass().getName()).append("@").append(hashCode());
140    result.append("[");
141    java.util.Collection<String> keys = getKeys();
142    for(String key: keys)
143    {
144      String value = getValue(key, IMetaData.Flags.METADATA_NONE);
145      result.append(key).append("=").append(value).append(";");
146    }
147    result.append("]");
148    return result.toString();
149  }
150  
151  /**
152   * Get the set of keys currently in this {@link IMediaData} object
153   * as an unordered collection.
154   * @return the keys.
155   */
156  public java.util.Collection<String> getKeys()
157  {
158    int numKeys = getNumKeys();
159    
160    java.util.List<String> retval = new java.util.ArrayList<String>(numKeys);
161    for(int i = 0; i < getNumKeys(); i++)
162    {
163      String key = getKey(i);
164      if (key != null && key.length() > 0)
165        retval.add(key);
166    }
167    return retval;
168  }
169 
170  /**
171   * Return the value for this key, comparing case insensitively.
172   * @param key the key
173   * @return the value.
174   */
175  public String getValue(String key)
176  {
177    return getValue(key, IMetaData.Flags.METADATA_NONE);
178  }
179
180  /**
181   * Get the total number of keys currently in this<br>
182   * {IMetaData} object.<br>
183   * <br>
184   * @return the number of keys.
185   */
186  public int getNumKeys() {
187    return AVPKitJNI.IMetaData_getNumKeys(swigCPtr, this);
188  }
189
190  /**
191   * Get the key at the given position, or null if no such<br>
192   * key at that position.<br>
193   * <br>
194   * <p><br>
195   * Note: positions of keys may change between<br>
196   * calls to {#setValue(String, String)} and <br>
197   * should be requiried.<br>
198   * </p><br>
199   * <br>
200   * @param position The position.  Must be &gt;=0 and &lt; <br>
201   * {#getNumKeys()}.<br>
202   * <br>
203   * @return the key, or null if not found.
204   */
205  private String getKey(int position) {
206    return AVPKitJNI.IMetaData_getKey(swigCPtr, this, position);
207  }
208
209  /**
210   * Get the value for the given key.<br>
211   * <br>
212   * @param key The key<br>
213   * @param flag A flag for how to search<br>
214   * <br>
215   * @return The value, or null if none.
216   */
217  public String getValue(String key, IMetaData.Flags flag) {
218    return AVPKitJNI.IMetaData_getValue(swigCPtr, this, key, flag.swigValue());
219  }
220
221  /**
222   * Sets the value for the given key to value.  This overrides<br>
223   * any prior setting for key, or adds key to the meta-data<br>
224   * if appropriate.<br>
225   * <br>
226   * @param key The key to set.<br>
227   * @param value The value to set.
228   */
229  public int setValue(String key, String value) {
230    return AVPKitJNI.IMetaData_setValue__SWIG_0(swigCPtr, this, key, value);
231  }
232
233  /**
234   * Create a new {IMetaData} bag of properties with<br>
235   * no values set.
236   */
237  public static IMetaData make() {
238    long cPtr = AVPKitJNI.IMetaData_make();
239    return (cPtr == 0) ? null : new IMetaData(cPtr, false);
240  }
241
242  /**
243   * Sets the value for the given key to value.  This overrides<br>
244   * any prior setting for key, or adds key to the meta-data<br>
245   * if appropriate.<br>
246   * <br>
247   * @param key The key to set.<br>
248   * @param value The value to set.<br>
249   * @param flag A flag on how this should be set.<br>
250   * <br>
251   * @since 5.0
252   */
253  public int setValue(String key, String value, IMetaData.Flags flag) {
254    return AVPKitJNI.IMetaData_setValue__SWIG_1(swigCPtr, this, key, value, flag.swigValue());
255  }
256
257  /**
258   * Different types of flags that can be passed to {IMetaData#getValue}
259   */
260  public enum Flags {
261    /**
262     * For {#getValue(String)} case-insensitive match of key.
263     */
264    METADATA_NONE(AVPKitJNI.IMetaData_METADATA_NONE_get()),
265    /**
266     * For {#getValue(String)} case-sensitive match of key.
267     */
268    METADATA_MATCH_CASE(AVPKitJNI.IMetaData_METADATA_MATCH_CASE_get()),
269    /**
270     * For {#setValue(String,String,Flags)} do not overwrite existing value -- append another key/value pair.
271     */
272    METADATA_DONT_OVERWRITE(AVPKitJNI.IMetaData_METADATA_DONT_OVERWRITE_get()),
273    /**
274     * For {#setValue(String,String,Flags)} append to the existing value in a key (string append).
275     */
276    META_DATA_APPEND(AVPKitJNI.IMetaData_META_DATA_APPEND_get());
277
278    public final int swigValue() {
279      return swigValue;
280    }
281
282    public static Flags swigToEnum(int swigValue) {
283      Flags[] swigValues = Flags.class.getEnumConstants();
284      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
285        return swigValues[swigValue];
286      for (Flags swigEnum : swigValues)
287        if (swigEnum.swigValue == swigValue)
288          return swigEnum;
289      throw new IllegalArgumentException("No enum " + Flags.class + " with value " + swigValue);
290    }
291
292    @SuppressWarnings("unused")
293    private Flags() {
294      this.swigValue = SwigNext.next++;
295    }
296
297    @SuppressWarnings("unused")
298    private Flags(int swigValue) {
299      this.swigValue = swigValue;
300      SwigNext.next = swigValue+1;
301    }
302
303    @SuppressWarnings("unused")
304    private Flags(Flags swigEnum) {
305      this.swigValue = swigEnum.swigValue;
306      SwigNext.next = this.swigValue+1;
307    }
308
309    private final int swigValue;
310
311    private static class SwigNext {
312      private static int next = 0;
313    }
314  }
315
316}