Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00017 package com.generalrobotix.ui.view.tdview;
00018
00019 import java.io.*;
00020 import java.util.*;
00021 import java.awt.image.BufferedImage;
00022 import javax.media.Format;
00023
00024
00025 public class RecordingManager{
00026
00027
00028
00029 private static int SLEEP_TIME=50;
00030
00031
00032 private static int MAX_STACK_SIZE=0;
00033
00034
00035
00036 private static RecordingManager this_;
00037
00038
00039
00040 private int width_,height_;
00041 private float frameRate_;
00042 private Hashtable<String, Format> htFormat_;
00043
00044 private ImageToMovie movie_;
00045
00046
00047
00048 private RecordingManager() {
00049 }
00050
00051
00052
00053 public static RecordingManager getInstance() {
00054 if (this_ == null) {
00055 this_ = new RecordingManager();
00056 }
00057
00058 return this_;
00059 }
00060
00061
00062
00063
00064 public void setImageSize(int w, int h) {
00065 width_ = w;
00066 height_ = h;
00067 }
00068
00069 public int getWidth(){
00070 return width_;
00071 }
00072
00073 public int getHeight(){
00074 return height_;
00075 }
00076
00077 public void setFrameRate(float rate){
00078 frameRate_=rate;
00079 }
00080
00081 public float getFrameRate(){
00082 return frameRate_;
00083 }
00084
00085 public Object[] getSuportedFormat(){
00086 htFormat_=new Hashtable<String, Format>();
00087 Vector<String> ret = new Vector<String>();
00088
00089 String fileName =
00090 "file:" +
00091 System.getProperty("user.dir") +
00092 System.getProperty("file.separator") +
00093 _getUniqueName();
00094 ImageToMovie tempMovie =
00095 new ImageToMovie(
00096 width_,
00097 height_,
00098 frameRate_,
00099 fileName,
00100 ImageToMovie.QUICKTIME
00101 );
00102 Format[] formats=tempMovie.getSupportedFormats();
00103 for(int i=0;i<formats.length;i++){
00104 String keyStr = formats[i].toString();
00105 if(htFormat_.get(keyStr) != null){
00106 continue;
00107 }
00108 ret.add(keyStr);
00109 htFormat_.put(keyStr,formats[i]);
00110 }
00111 tempMovie.setFormat(formats[0]);
00112
00113 File file=new File(fileName);
00114 file.delete();
00115
00116 return ret.toArray();
00117 }
00118
00119 private String _getUniqueName() {
00120 Calendar cal=new GregorianCalendar();
00121 String str="`~$" + cal.getTime().hashCode() +".TMP";
00122 return str;
00123 }
00124 public Object[] preRecord(String fileName, String fileType)
00125 {
00126 Vector<String> ret = new Vector<String>();
00127 movie_=
00128 new ImageToMovie(
00129 width_,
00130 height_,
00131 frameRate_,
00132 fileName,
00133 fileType
00134 );
00135 htFormat_=new Hashtable<String, Format>();
00136
00137 Format[] formats = movie_.getSupportedFormats();
00138 for(int i=0;i<formats.length;i++){
00139 String keyStr = formats[i].toString();
00140 if(htFormat_.get(keyStr) != null){
00141 continue;
00142 }
00143 ret.add(keyStr);
00144 htFormat_.put(keyStr,formats[i]);
00145 }
00146 return ret.toArray();
00147 }
00148
00149 public boolean startRecord(String formatStr){
00150 Format format=(Format)htFormat_.get(formatStr);
00151 movie_.setFormat(format);
00152
00153 if(movie_.startProcess())
00154 return true;
00155 else
00156 return false;
00157 }
00158
00159 public void endRecord() {
00160 movie_.endProcess();
00161 }
00162
00163 public void pushImage(BufferedImage image)
00164 {
00165 movie_.pushImage(image);
00166 do {
00167 try {
00168 Thread.sleep(SLEEP_TIME);
00169 } catch (Exception ex) {
00170 ex.printStackTrace();
00171 }
00172 } while (movie_.getImageStackSize() > MAX_STACK_SIZE);
00173 }
00174 }