001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Thomas Roger <troger@nuxeo.com> 016 */ 017 018package org.nuxeo.ecm.platform.video; 019 020import java.io.Serializable; 021import java.util.HashMap; 022import java.util.Map; 023 024/** 025 * Object representing a Stream of a video. 026 * 027 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 028 * @since 5.5 029 */ 030public class Stream { 031 032 public static final String VIDEO_TYPE = "Video"; 033 034 public static final String AUDIO_TYPE = "Audio"; 035 036 public static final String TYPE_ATTRIBUTE = "type"; 037 038 public static final String CODEC_ATTRIBUTE = "codec"; 039 040 public static final String STREAM_INFO_ATTRIBUTE = "streamInfo"; 041 042 public static final String BIT_RATE_ATTRIBUTE = "bitRate"; 043 044 private final Map<String, Serializable> attributes; 045 046 /** 047 * Build a {@code Stream} from a {@code Map} of attributes. 048 * <p> 049 * Used when creating a {@code Stream} from a {@code DocumentModel} property. 050 */ 051 public static Stream fromMap(Map<String, Serializable> m) { 052 return new Stream(m); 053 } 054 055 private Stream(Map<String, Serializable> m) { 056 attributes = new HashMap<String, Serializable>(m); 057 } 058 059 /** 060 * Returns this {@code Stream}'s type. 061 * <p> 062 * Can be one of the following: 063 * <ul> 064 * <li>Video</li> 065 * <li>Audio</li> 066 * </ul> 067 */ 068 public String getType() { 069 return (String) attributes.get(TYPE_ATTRIBUTE); 070 } 071 072 /** 073 * Returns this {@code Stream}'s codec. 074 */ 075 public String getCodec() { 076 return (String) attributes.get(CODEC_ATTRIBUTE); 077 } 078 079 /** 080 * Returns this {@code Stream} whole info as returned by FFmpeg. 081 */ 082 public String getStreamInfo() { 083 return (String) attributes.get(STREAM_INFO_ATTRIBUTE); 084 } 085 086 /** 087 * Returns this {@code Stream}'s bit rate. 088 */ 089 public double getBitRate() { 090 return (Double) attributes.get(BIT_RATE_ATTRIBUTE); 091 } 092 093 /** 094 * Returns a {@code Map} of attributes for this {@code Stream}. 095 * <p> 096 * Used when saving this {@code Stream} to a {@code DocumentModel} property. 097 */ 098 public Map<String, Serializable> toMap() { 099 return attributes; 100 } 101 102}