RecordingManager.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
17 package com.generalrobotix.ui.view.tdview;
18 
19 import java.io.*;
20 import java.util.*;
21 import java.awt.image.BufferedImage;
22 import javax.media.Format;
23 
24 
25 public class RecordingManager{
26  //--------------------------------------------------------------------
27  // 定数
28  //最適化パラメータ
29  private static int SLEEP_TIME=50; //スリープする時間(ms)
30 
31  //スリープに入るまでの最大許容イメージスタック数
32  private static int MAX_STACK_SIZE=0;
33 
34  //--------------------------------------------------------------------
35  // クラス変数
36  private static RecordingManager this_;
37 
38  //--------------------------------------------------------------------
39  // メンバ変数
40  private int width_,height_;
41  private float frameRate_;
42  private Hashtable<String, Format> htFormat_; //String--Format
43 
45 
46  //--------------------------------------------------------------------
47  // コンストラクタ
48  private RecordingManager() {
49  }
50 
51  //--------------------------------------------------------------------
52  // クラスメソッド
53  public static RecordingManager getInstance() {
54  if (this_ == null) {
55  this_ = new RecordingManager();
56  }
57 
58  return this_;
59  }
60 
61  //--------------------------------------------------------------------
62  // 公開メソッド
63 
64  public void setImageSize(int w, int h) {
65  width_ = w;
66  height_ = h;
67  }
68 
69  public int getWidth(){
70  return width_;
71  }
72 
73  public int getHeight(){
74  return height_;
75  }
76 
77  public void setFrameRate(float rate){
78  frameRate_=rate;
79  }
80 
81  public float getFrameRate(){
82  return frameRate_;
83  }
84 
85  public Object[] getSuportedFormat(){
86  htFormat_=new Hashtable<String, Format>();
87  Vector<String> ret = new Vector<String>();
88  //テンポラリを作ってフォーマットを得る
89  String fileName =
90  "file:" +
91  System.getProperty("user.dir") +
92  System.getProperty("file.separator") +
94  ImageToMovie tempMovie =
95  new ImageToMovie(
96  width_,
97  height_,
98  frameRate_,
99  fileName,
101  );
102  Format[] formats=tempMovie.getSupportedFormats();
103  for(int i=0;i<formats.length;i++){
104  String keyStr = formats[i].toString();
105  if(htFormat_.get(keyStr) != null){
106  continue;
107  }
108  ret.add(keyStr);
109  htFormat_.put(keyStr,formats[i]);
110  }
111  tempMovie.setFormat(formats[0]);
112  //テンポラリを消す
113  File file=new File(fileName);
114  file.delete();
115 
116  return ret.toArray();
117  }
118 
119  private String _getUniqueName() {
120  Calendar cal=new GregorianCalendar();
121  String str="`~$" + cal.getTime().hashCode() +".TMP";
122  return str;
123  }
124  public Object[] preRecord(String fileName, String fileType)
125  {
126  Vector<String> ret = new Vector<String>();
127  movie_=
128  new ImageToMovie(
129  width_,
130  height_,
131  frameRate_,
132  fileName,
133  fileType
134  );
135  htFormat_=new Hashtable<String, Format>();
136 
137  Format[] formats = movie_.getSupportedFormats();
138  for(int i=0;i<formats.length;i++){
139  String keyStr = formats[i].toString();
140  if(htFormat_.get(keyStr) != null){
141  continue;
142  }
143  ret.add(keyStr);
144  htFormat_.put(keyStr,formats[i]);
145  }
146  return ret.toArray();
147  }
148 
149  public boolean startRecord(String formatStr){
150  Format format=(Format)htFormat_.get(formatStr);
151  movie_.setFormat(format);
152 
153  if(movie_.startProcess())
154  return true;
155  else
156  return false;
157  }
158 
159  public void endRecord() {
160  movie_.endProcess();
161  }
162 
163  public void pushImage(BufferedImage image)
164  {
165  movie_.pushImage(image);
166  do {
167  try {
168  Thread.sleep(SLEEP_TIME);
169  } catch (Exception ex) {
170  ex.printStackTrace();
171  }
172  } while (movie_.getImageStackSize() > MAX_STACK_SIZE);
173  }
174 }
#define null
our own NULL pointer
Definition: IceTypes.h:57
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
png_uint_32 i
Definition: png.h:2735
png_bytepp image
Definition: png.h:1772
Object[] preRecord(String fileName, String fileType)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:40