001/* 002 * (C) Copyright 2015 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 016 */ 017 018package org.nuxeo.ecm.platform.video.rendition; 019 020import java.util.Collections; 021import java.util.List; 022 023import org.nuxeo.ecm.core.api.Blob; 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.platform.rendition.extension.RenditionProvider; 026import org.nuxeo.ecm.platform.rendition.service.RenditionDefinition; 027import org.nuxeo.ecm.platform.video.TranscodedVideo; 028import org.nuxeo.ecm.platform.video.VideoDocument; 029 030/** 031 * Provides a rendition based on a transcoded video 032 * (referenced through the rendition definition name). 033 * 034 * @since 7.2 035 */ 036public class VideoRenditionProvider implements RenditionProvider { 037 038 @Override 039 public boolean isAvailable(DocumentModel doc, RenditionDefinition definition) { 040 VideoDocument videoDocument = doc.getAdapter(VideoDocument.class); 041 if (videoDocument == null) { 042 return false; 043 } 044 045 TranscodedVideo transcodedVideo = videoDocument.getTranscodedVideo(definition.getName()); 046 return transcodedVideo != null && transcodedVideo.getBlob() != null; 047 } 048 049 @Override 050 public List<Blob> render(DocumentModel doc, RenditionDefinition definition) { 051 VideoDocument videoDocument = doc.getAdapter(VideoDocument.class); 052 if (videoDocument == null) { 053 return Collections.emptyList(); 054 } 055 056 TranscodedVideo transcodedVideo = videoDocument.getTranscodedVideo(definition.getName()); 057 if (transcodedVideo != null) { 058 return Collections.singletonList(transcodedVideo.getBlob()); 059 } 060 return Collections.emptyList(); 061 } 062}