• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.robolectric.shadows;
2 
3 import android.hardware.Camera;
4 import android.media.MediaRecorder;
5 import android.view.Surface;
6 import org.robolectric.annotation.Implementation;
7 import org.robolectric.annotation.Implements;
8 
9 @Implements(MediaRecorder.class)
10 public class ShadowMediaRecorder {
11   @SuppressWarnings("UnusedDeclaration")
12   @Implementation
__staticInitializer__()13   protected static void __staticInitializer__() {
14     // don't bind the JNI library
15   }
16 
17   // Recording machine state, as per:
18   // http://developer.android.com/reference/android/media/MediaRecorder.html
19   public static final int STATE_ERROR = -1;
20   public static final int STATE_INITIAL = 1;
21   public static final int STATE_INITIALIZED = 2;
22   public static final int STATE_DATA_SOURCE_CONFIGURED = 3;
23   public static final int STATE_PREPARED = 4;
24   public static final int STATE_RECORDING = 5;
25   public static final int STATE_RELEASED = 6;
26 
27   private int state;
28 
29   private Camera camera;
30   private int audioChannels;
31   private int audioEncoder;
32   private int audioBitRate;
33   private int audioSamplingRate;
34   private int audioSource;
35   private int maxDuration;
36   private long maxFileSize;
37   private String outputPath;
38   private int outputFormat;
39   private int videoEncoder;
40   private int videoBitRate;
41   private int videoFrameRate;
42   private int videoWidth;
43   private int videoHeight;
44   private int videoSource;
45 
46   private Surface previewDisplay;
47   private MediaRecorder.OnErrorListener errorListener;
48   private MediaRecorder.OnInfoListener infoListener;
49 
50   @Implementation
__constructor__()51   protected void __constructor__() {
52     state = STATE_INITIAL;
53   }
54 
55   @Implementation
setAudioChannels(int numChannels)56   protected void setAudioChannels(int numChannels) {
57     audioChannels = numChannels;
58   }
59 
60   @Implementation
setAudioEncoder(int audio_encoder)61   protected void setAudioEncoder(int audio_encoder) {
62     audioEncoder = audio_encoder;
63     state = STATE_DATA_SOURCE_CONFIGURED;
64   }
65 
66   @Implementation
setAudioEncodingBitRate(int bitRate)67   protected void setAudioEncodingBitRate(int bitRate) {
68     audioBitRate = bitRate;
69   }
70 
71   @Implementation
setAudioSamplingRate(int samplingRate)72   protected void setAudioSamplingRate(int samplingRate) {
73     audioSamplingRate = samplingRate;
74   }
75 
76   @Implementation
setAudioSource(int audio_source)77   protected void setAudioSource(int audio_source) {
78     audioSource = audio_source;
79     state = STATE_INITIALIZED;
80   }
81 
82   @Implementation
setCamera(Camera c)83   protected void setCamera(Camera c) {
84     camera = c;
85   }
86 
87   @Implementation
setMaxDuration(int max_duration_ms)88   protected void setMaxDuration(int max_duration_ms) {
89     maxDuration = max_duration_ms;
90   }
91 
92   @Implementation
setMaxFileSize(long max_filesize_bytes)93   protected void setMaxFileSize(long max_filesize_bytes) {
94     maxFileSize = max_filesize_bytes;
95   }
96 
97   @Implementation
setOnErrorListener(MediaRecorder.OnErrorListener l)98   protected void setOnErrorListener(MediaRecorder.OnErrorListener l) {
99     errorListener = l;
100   }
101 
102   @Implementation
setOnInfoListener(MediaRecorder.OnInfoListener listener)103   protected void setOnInfoListener(MediaRecorder.OnInfoListener listener) {
104     infoListener = listener;
105   }
106 
107   @Implementation
setOutputFile(String path)108   protected void setOutputFile(String path) {
109     outputPath = path;
110     state = STATE_DATA_SOURCE_CONFIGURED;
111   }
112 
113   @Implementation
setOutputFormat(int output_format)114   protected void setOutputFormat(int output_format) {
115     outputFormat = output_format;
116     state = STATE_DATA_SOURCE_CONFIGURED;
117   }
118 
119   @Implementation
setPreviewDisplay(Surface sv)120   protected void setPreviewDisplay(Surface sv) {
121     previewDisplay = sv;
122     state = STATE_DATA_SOURCE_CONFIGURED;
123   }
124 
125   @Implementation
setVideoEncoder(int video_encoder)126   protected void setVideoEncoder(int video_encoder) {
127     videoEncoder = video_encoder;
128     state = STATE_DATA_SOURCE_CONFIGURED;
129   }
130 
131   @Implementation
setVideoEncodingBitRate(int bitRate)132   protected void setVideoEncodingBitRate(int bitRate) {
133     videoBitRate = bitRate;
134   }
135 
136   @Implementation
setVideoFrameRate(int rate)137   protected void setVideoFrameRate(int rate) {
138     videoFrameRate = rate;
139     state = STATE_DATA_SOURCE_CONFIGURED;
140   }
141 
142   @Implementation
setVideoSize(int width, int height)143   protected void setVideoSize(int width, int height) {
144     videoWidth = width;
145     videoHeight = height;
146     state = STATE_DATA_SOURCE_CONFIGURED;
147   }
148 
149   @Implementation
setVideoSource(int video_source)150   protected void setVideoSource(int video_source) {
151     videoSource = video_source;
152     state = STATE_INITIALIZED;
153   }
154 
155   @Implementation
prepare()156   protected void prepare() {
157     state = STATE_PREPARED;
158   }
159 
160   @Implementation
start()161   protected void start() {
162     state = STATE_RECORDING;
163   }
164 
165   @Implementation
stop()166   protected void stop() {
167     state = STATE_INITIAL;
168   }
169 
170   @Implementation
reset()171   protected void reset() {
172     state = STATE_INITIAL;
173   }
174 
175   @Implementation
release()176   protected void release() {
177     state = STATE_RELEASED;
178   }
179 
getCamera()180   public Camera getCamera() {
181     return camera;
182   }
183 
getAudioChannels()184   public int getAudioChannels() {
185     return audioChannels;
186   }
187 
getAudioEncoder()188   public int getAudioEncoder() {
189     return audioEncoder;
190   }
191 
getAudioEncodingBitRate()192   public int getAudioEncodingBitRate() {
193     return audioBitRate;
194   }
195 
getAudioSamplingRate()196   public int getAudioSamplingRate() {
197     return audioSamplingRate;
198   }
199 
getAudioSource()200   public int getAudioSource() {
201     return audioSource;
202   }
203 
getMaxDuration()204   public int getMaxDuration() {
205     return maxDuration;
206   }
207 
getMaxFileSize()208   public long getMaxFileSize() {
209     return maxFileSize;
210   }
211 
getOutputPath()212   public String getOutputPath() {
213     return outputPath;
214   }
215 
getOutputFormat()216   public int getOutputFormat() {
217     return outputFormat;
218   }
219 
getVideoEncoder()220   public int getVideoEncoder() {
221     return videoEncoder;
222   }
223 
getVideoEncodingBitRate()224   public int getVideoEncodingBitRate() {
225     return videoBitRate;
226   }
227 
getVideoFrameRate()228   public int getVideoFrameRate() {
229     return videoFrameRate;
230   }
231 
getVideoWidth()232   public int getVideoWidth() {
233     return videoWidth;
234   }
235 
getVideoHeight()236   public int getVideoHeight() {
237     return videoHeight;
238   }
239 
getVideoSource()240   public int getVideoSource() {
241     return videoSource;
242   }
243 
getPreviewDisplay()244   public Surface getPreviewDisplay() {
245     return previewDisplay;
246   }
247 
getErrorListener()248   public MediaRecorder.OnErrorListener getErrorListener() {
249     return errorListener;
250   }
251 
getInfoListener()252   public MediaRecorder.OnInfoListener getInfoListener() {
253     return infoListener;
254   }
255 
getState()256   public int getState() {
257     return state;
258   }
259 }
260