001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Thomas Roger <troger@nuxeo.com>
018 */
019
020package org.nuxeo.ecm.platform.video;
021
022import java.io.Serializable;
023import java.util.HashMap;
024import java.util.Map;
025
026/**
027 * Object representing a Stream of a video.
028 *
029 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
030 * @since 5.5
031 */
032public class Stream {
033
034    public static final String VIDEO_TYPE = "Video";
035
036    public static final String AUDIO_TYPE = "Audio";
037
038    public static final String TYPE_ATTRIBUTE = "type";
039
040    public static final String CODEC_ATTRIBUTE = "codec";
041
042    public static final String STREAM_INFO_ATTRIBUTE = "streamInfo";
043
044    public static final String BIT_RATE_ATTRIBUTE = "bitRate";
045
046    private final Map<String, Serializable> attributes;
047
048    /**
049     * Build a {@code Stream} from a {@code Map} of attributes.
050     * <p>
051     * Used when creating a {@code Stream} from a {@code DocumentModel} property.
052     */
053    public static Stream fromMap(Map<String, Serializable> m) {
054        return new Stream(m);
055    }
056
057    private Stream(Map<String, Serializable> m) {
058        attributes = new HashMap<String, Serializable>(m);
059    }
060
061    /**
062     * Returns this {@code Stream}'s type.
063     * <p>
064     * Can be one of the following:
065     * <ul>
066     * <li>Video</li>
067     * <li>Audio</li>
068     * </ul>
069     */
070    public String getType() {
071        return (String) attributes.get(TYPE_ATTRIBUTE);
072    }
073
074    /**
075     * Returns this {@code Stream}'s codec.
076     */
077    public String getCodec() {
078        return (String) attributes.get(CODEC_ATTRIBUTE);
079    }
080
081    /**
082     * Returns this {@code Stream} whole info as returned by FFmpeg.
083     */
084    public String getStreamInfo() {
085        return (String) attributes.get(STREAM_INFO_ATTRIBUTE);
086    }
087
088    /**
089     * Returns this {@code Stream}'s bit rate.
090     */
091    public double getBitRate() {
092        return (Double) attributes.get(BIT_RATE_ATTRIBUTE);
093    }
094
095    /**
096     * Returns a {@code Map} of attributes for this {@code Stream}.
097     * <p>
098     * Used when saving this {@code Stream} to a {@code DocumentModel} property.
099     */
100    public Map<String, Serializable> toMap() {
101        return attributes;
102    }
103
104}