01: /*
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999-2005 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * Initial developer(s): Brice Ruzand
22: *
23: * --------------------------------------------------------------------------
24: * $Id$
25: * --------------------------------------------------------------------------
26: */
27: package emb.sample.servlet;
28:
29: import javax.emb.MediaConverterSpec;
30: import javax.emb.MediaEntityLocal;
31: import javax.servlet.ServletException;
32: import javax.servlet.http.HttpServletRequest;
33: import javax.servlet.http.HttpServletResponse;
34:
35: import org.objectweb.jonas.emb.mfb.formats.video.VideoMediaFormat;
36:
37: import emb.sample.MediaSampleException;
38: import emb.sample.session.MediaSampleSessionLocal;
39:
40: /**
41: * @author Brice Ruzand
42: */
43: public class ConvertSampleVideoTo3GPP extends BaseSampleServlet {
44:
45: /**
46: * serialVersionUID
47: */
48: private static final long serialVersionUID = 3687815080511141944L;
49:
50: /**
51: * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
52: * javax.servlet.http.HttpServletResponse)
53: * @inheritDoc
54: */
55: public void service(HttpServletRequest request,
56: HttpServletResponse response) throws ServletException {
57: try {
58: MediaSampleSessionLocal session = getSession(request);
59:
60: // Query the media entity EJB instance.
61: String identity = request.getParameter("identity");
62: MediaEntityLocal mediaEntity = session
63: .getMediaFromPrimaryKey(identity);
64:
65: if (!(mediaEntity.getFormat() instanceof VideoMediaFormat)) {
66: throw new MediaSampleException(
67: "The selected media must be an Video format.");
68: }
69:
70: // Create a copy
71: MediaEntityLocal media = session
72: .copyMediaEntity(mediaEntity);
73: media
74: .setDescription("Video to 3GPP conversion using ffmpeg of : "
75: + mediaEntity.getName());
76:
77: // Convert the Video to 3GPP with FFMPEG
78: Class converterSpecClass = getClass()
79: .getClassLoader()
80: .loadClass(
81: "org.objectweb.jonas.emb.mfb.plugins.video.ffmpeg.converter.VideoTo3GPPConverterSpec");
82: MediaConverterSpec converterSpec = (MediaConverterSpec) converterSpecClass
83: .newInstance();
84: MediaConverterSpec[] specs = new MediaConverterSpec[] { converterSpec };
85: media.convert(specs);
86:
87: identity = (String) media.getPrimaryKey();
88:
89: // forward onto the retrieve servlet
90: request.setAttribute("identity", media.getPrimaryKey());
91: this .getServletContext().getRequestDispatcher(
92: RETRIEVE_SERVLET).forward(request, response);
93:
94: } catch (Throwable e) {
95: exceptionHandler(e, getClass(), request, response);
96: }
97: }
98:
99: }
|