SHOW:
|
|
- or go back to the newest paste.
1 | /* | |
2 | * Jitsi, the OpenSource Java VoIP and Instant Messaging client. | |
3 | * | |
4 | * Distributable under LGPL license. | |
5 | * See terms of license at gnu.org. | |
6 | */ | |
7 | package org.jitsi.impl.neomedia.device; | |
8 | ||
9 | import java.io.File; | |
10 | import java.net.MalformedURLException; | |
11 | import java.util.Vector; | |
12 | import java.util.logging.Level; | |
13 | ||
14 | import javax.media.*; | |
15 | import javax.media.control.*; | |
16 | import javax.media.format.*; | |
17 | import javax.media.protocol.ContentDescriptor; | |
18 | import javax.media.protocol.DataSource; | |
19 | import javax.media.protocol.FileTypeDescriptor; | |
20 | ||
21 | import org.jitsi.impl.neomedia.audiolevel.*; | |
22 | import org.jitsi.service.neomedia.event.*; | |
23 | import org.jitsi.util.*; | |
24 | ||
25 | - | import com.sabienzia.libjitsi.FakeFMJManager; |
25 | + | |
26 | * Extends <tt>AudioMediaDeviceSession</tt> to add file-recording functionality. | |
27 | */ | |
28 | public class FileMediaDeviceSession extends AudioMediaDeviceSession { | |
29 | /** | |
30 | * The <tt>Logger</tt> used by the <tt>AudioMediaDeviceSession</tt> class | |
31 | * and its instances for logging output. | |
32 | */ | |
33 | private static final Logger logger = Logger | |
34 | .getLogger(FileMediaDeviceSession.class); | |
35 | ||
36 | /** | |
37 | * Initializes a new <tt>MediaDeviceSession</tt> instance which is to | |
38 | * represent the use of a specific <tt>MediaDevice</tt> by a | |
39 | * <tt>MediaStream</tt>. | |
40 | * | |
41 | * @param device | |
42 | * the <tt>MediaDevice</tt> the use of which by a | |
43 | * <tt>MediaStream</tt> is to be represented by the new instance | |
44 | */ | |
45 | protected FileMediaDeviceSession(AbstractMediaDevice device) { | |
46 | super(device); | |
47 | } | |
48 | ||
49 | DataSink sink; | |
50 | ||
51 | @Override | |
52 | protected void playerControllerUpdate(ControllerEvent event) { | |
53 | if (event instanceof ConfigureCompleteEvent) { | |
54 | Processor player = (Processor) event.getSourceController(); | |
55 | ||
56 | if (player != null) { | |
57 | // playerConfigureComplete(player); | |
58 | ||
59 | // * To use the processor as a Player we must set its | |
60 | // * ContentDescriptor to null. | |
61 | ||
62 | try { | |
63 | // player.setContentDescriptor(null); | |
64 | player.setContentDescriptor( new ContentDescriptor(FileTypeDescriptor.WAVE)); | |
65 | } catch (NotConfiguredError nce) { | |
66 | logger.error("Failed to set ContentDescriptor to Player.", | |
67 | nce); | |
68 | return; | |
69 | } | |
70 | player.realize(); | |
71 | } | |
72 | } else if (event instanceof RealizeCompleteEvent) { | |
73 | Processor player = (Processor) event.getSourceController(); | |
74 | ||
75 | if (player != null) { | |
76 | playerRealizeComplete(player); | |
77 | ||
78 | MediaLocator dest = null; | |
79 | try { | |
80 | dest = new MediaLocator(new File("recording.wav").toURI().toURL()); | |
81 | } catch (MalformedURLException e1) { | |
82 | e1.printStackTrace(); | |
83 | } | |
84 | ||
85 | System.out.println("Trying to record."); | |
86 | ||
87 | try { | |
88 | sink = Manager.createDataSink(player.getDataOutput(), dest); | |
89 | sink.open(); | |
90 | sink.start(); | |
91 | } catch (Exception e) { | |
92 | e.printStackTrace(); | |
93 | } | |
94 | } | |
95 | } | |
96 | } | |
97 | ||
98 | @Override | |
99 | protected void disposePlayer(Player player){ | |
100 | super.disposePlayer(player); | |
101 | System.out.println("disposePlayer"); | |
102 | sink.close(); | |
103 | } | |
104 | } |