View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  
23  package org.opencastproject.composer.api;
24  
25  import java.util.List;
26  import java.util.Map;
27  
28  import javax.xml.bind.annotation.XmlType;
29  
30  /**
31   * An encoding format encapsulates all the relevant configuration data for
32   * encoding a media file to a certain encoding formats.
33   */
34  public interface EncodingProfile {
35  
36    /**
37     * Input and output formats.
38     */
39    @XmlType(name = "media-type", namespace = "http://composer.opencastproject.org")
40    enum MediaType {
41      // Nothing is a special type that indicates that the encoding process does not produce any media
42      Audio, Visual, AudioVisual, Stream, EnhancedAudio, Image, ImageSequence, Cover, Nothing, Manifest;
43  
44      /**
45       * Try to parse the argument <code>type</code> and produce a
46       * {@link MediaType} out of it.
47       *
48       * @param type
49       *          the type string representation
50       * @return a track type
51       */
52      public static MediaType parseString(String type) {
53        if (type == null || type.length() == 0)
54          throw new IllegalArgumentException(type
55                  + " is not a valid track type definition");
56        if ("audiovisual".equalsIgnoreCase(type))
57          return AudioVisual;
58        else if ("enhancedaudio".equalsIgnoreCase(type))
59          return EnhancedAudio;
60        else if ("imagesequence".equalsIgnoreCase(type))
61          return ImageSequence;
62        else {
63          type = type.substring(0, 1).toUpperCase()
64                  + type.substring(1).toLowerCase();
65        }
66        return MediaType.valueOf(type.trim());
67      }
68  
69    }
70  
71    /**
72     * Returns the unique format identifier.
73     *
74     * @return the format identifier
75     */
76    String getIdentifier();
77  
78    /**
79     * Returns the encoding format's name.
80     *
81     * @return the format name
82     */
83    String getName();
84  
85  
86    /**
87     * Returns the source object that provided this encoding profile
88     *
89     * @return the source object that provided this profile
90     */
91    Object getSource();
92  
93    /**
94     * Returns the encoding format's media type, which is either video (plus
95     * audio) or audio only.
96     *
97     * @return the format type
98     */
99    MediaType getOutputType();
100 
101   /**
102    * Returns a suffix of the files. First tag found used if tags are used but not provided in the request
103    *
104    * @return the suffix
105    */
106   String getSuffix();
107 
108   /**
109    * Returns a suffix of the files for a certain tag.
110    *
111    * @param tag a tag that describes the aoutput file
112    * @return the suffix
113    */
114   String getSuffix(String tag);
115 
116   /**
117    * Returns a list of the tags for output files used in this request
118    * @return a list of the used tags
119    */
120   List<String> getTags();
121 
122   /**
123    * {@inheritDoc}
124    *
125    * @see org.opencastproject.composer.api.EncodingProfile#getMimeType()
126    */
127   String getMimeType();
128 
129   /**
130    * Sets the Mimetype.
131    *
132    * @param mimeType
133    *          the Mimetype
134    */
135   void setMimeType(String mimeType);
136 
137   /**
138    * Returns the media format that can be used with this encoding profile.
139    *
140    * @return the applicable input format
141    */
142   MediaType getApplicableMediaType();
143 
144   /**
145    * Returns <code>true</code> if the profile is applicable for the given track
146    * type.
147    *
148    * @param type
149    *          the track type
150    * @return <code>true</code> if the profile is applicable
151    */
152   boolean isApplicableTo(MediaType type);
153 
154   /**
155    * Returns <code>true</code> if additional properties have been specified.
156    *
157    * @return <code>true</code> if there are additional properties
158    */
159   boolean hasExtensions();
160 
161   /**
162    * Returns the extension specified by <code>key</code> or <code>null</code> if
163    * no such key was defined.
164    * <p>
165    * Note that <code>key</code> must not contain the media format prefix, so if
166    * the configured entry was <code>mediaformat.format.xyz.test</code>, then the key
167    * to access the value must simply be <code>test</code>.
168    * </p>
169    *
170    * @param key
171    *          the extension key
172    * @return the value or <code>null</code>
173    */
174   String getExtension(String key);
175 
176   /**
177    * Returns a map containing the additional properties or an empty map if no
178    * additional properties were found.
179    *
180    * @return the additional properties
181    */
182   Map<String, String> getExtensions();
183 
184   /**
185    * Returns an estimate of the load a single job with this profile causes.
186    * This should be roughly equal to the number of processor cores used at runtime.
187    *
188    * @return the load a single job with this profile causes
189    */
190   float getJobLoad();
191 }