Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 335 lines (295 sloc) 8.679 kb
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
1 /*
4506c62 fix inaccurate copyrights
Jean-Baptiste Queru authored
2 ** Copyright 2008, The Android Open Source Project
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16
17 //#define LOG_NDEBUG 0
18 #define LOG_TAG "MediaRecorderService"
19 #include <utils/Log.h>
20
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <dirent.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include <cutils/atomic.h>
ea6a38c Squashed commit of the following:
Andreas Huber authored
27 #include <cutils/properties.h> // for property_get
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
28 #include <android_runtime/ActivityManager.h>
0795272 move libbinder's header files under includes/binder
Mathias Agopian authored
29 #include <binder/IPCThreadState.h>
30 #include <binder/IServiceManager.h>
31 #include <binder/MemoryHeapBase.h>
32 #include <binder/MemoryBase.h>
bfb9fb1 Refactor MediaScanner. Some steps on the way towards being able to build...
Andreas Huber authored
33
17612fc AI 143396: am: CL 143267 am: CL 143127 Media recorder service requires a...
Dave Sparks authored
34 #include <utils/String16.h>
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
35
608a263 Dump media recorder PID in dumpsys media.player, and fix minor bugs.
Gloria Wang authored
36 #include <media/AudioTrack.h>
37
34bb419 update for new audio.h header location
Dima Zavin authored
38 #include <system/audio.h>
24fc2fb audio/media: convert to using the audio HAL and new audio defs
Dima Zavin authored
39
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
40 #include "MediaRecorderClient.h"
608a263 Dump media recorder PID in dumpsys media.player, and fix minor bugs.
Gloria Wang authored
41 #include "MediaPlayerService.h"
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
42
ea6a38c Squashed commit of the following:
Andreas Huber authored
43 #include "StagefrightRecorder.h"
44
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
45 namespace android {
46
17612fc AI 143396: am: CL 143267 am: CL 143127 Media recorder service requires a...
Dave Sparks authored
47 const char* cameraPermission = "android.permission.CAMERA";
6690dc5 Fix permission hole for RECORD_AUDIO created when we moved the MediaReco...
Dave Sparks authored
48 const char* recordAudioPermission = "android.permission.RECORD_AUDIO";
17612fc AI 143396: am: CL 143267 am: CL 143127 Media recorder service requires a...
Dave Sparks authored
49
50 static bool checkPermission(const char* permissionString) {
51 #ifndef HAVE_ANDROID_OS
52 return true;
53 #endif
54 if (getpid() == IPCThreadState::self()->getCallingPid()) return true;
55 bool ok = checkCallingPermission(String16(permissionString));
56 if (!ok) LOGE("Request requires %s", permissionString);
57 return ok;
58 }
59
42419ce Add framework support for camcorder zoom.
Wu-cheng Li authored
60 status_t MediaRecorderClient::setCamera(const sp<ICamera>& camera,
61 const sp<ICameraRecordingProxy>& proxy)
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
62 {
63 LOGV("setCamera");
64 Mutex::Autolock lock(mLock);
65 if (mRecorder == NULL) {
66 LOGE("recorder is not initialized");
67 return NO_INIT;
68 }
42419ce Add framework support for camcorder zoom.
Wu-cheng Li authored
69 return mRecorder->setCamera(camera, proxy);
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
70 }
71
85cfdd0 Change the framework to use the new camera preview path.
Jamie Gennis authored
72 status_t MediaRecorderClient::setPreviewSurface(const sp<Surface>& surface)
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
73 {
74 LOGV("setPreviewSurface");
75 Mutex::Autolock lock(mLock);
76 if (mRecorder == NULL) {
77 LOGE("recorder is not initialized");
78 return NO_INIT;
79 }
80 return mRecorder->setPreviewSurface(surface);
81 }
82
83 status_t MediaRecorderClient::setVideoSource(int vs)
84 {
85 LOGV("setVideoSource(%d)", vs);
17612fc AI 143396: am: CL 143267 am: CL 143127 Media recorder service requires a...
Dave Sparks authored
86 if (!checkPermission(cameraPermission)) {
87 return PERMISSION_DENIED;
88 }
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
89 Mutex::Autolock lock(mLock);
90 if (mRecorder == NULL) {
91 LOGE("recorder is not initialized");
608a263 Dump media recorder PID in dumpsys media.player, and fix minor bugs.
Gloria Wang authored
92 return NO_INIT;
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
93 }
94 return mRecorder->setVideoSource((video_source)vs);
95 }
96
97 status_t MediaRecorderClient::setAudioSource(int as)
98 {
99 LOGV("setAudioSource(%d)", as);
6690dc5 Fix permission hole for RECORD_AUDIO created when we moved the MediaReco...
Dave Sparks authored
100 if (!checkPermission(recordAudioPermission)) {
101 return PERMISSION_DENIED;
102 }
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
103 Mutex::Autolock lock(mLock);
104 if (mRecorder == NULL) {
105 LOGE("recorder is not initialized");
608a263 Dump media recorder PID in dumpsys media.player, and fix minor bugs.
Gloria Wang authored
106 return NO_INIT;
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
107 }
24fc2fb audio/media: convert to using the audio HAL and new audio defs
Dima Zavin authored
108 return mRecorder->setAudioSource((audio_source_t)as);
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
109 }
110
111 status_t MediaRecorderClient::setOutputFormat(int of)
112 {
113 LOGV("setOutputFormat(%d)", of);
114 Mutex::Autolock lock(mLock);
115 if (mRecorder == NULL) {
116 LOGE("recorder is not initialized");
117 return NO_INIT;
118 }
119 return mRecorder->setOutputFormat((output_format)of);
120 }
121
122 status_t MediaRecorderClient::setVideoEncoder(int ve)
123 {
124 LOGV("setVideoEncoder(%d)", ve);
125 Mutex::Autolock lock(mLock);
126 if (mRecorder == NULL) {
127 LOGE("recorder is not initialized");
128 return NO_INIT;
129 }
130 return mRecorder->setVideoEncoder((video_encoder)ve);
131 }
132
133 status_t MediaRecorderClient::setAudioEncoder(int ae)
134 {
135 LOGV("setAudioEncoder(%d)", ae);
136 Mutex::Autolock lock(mLock);
137 if (mRecorder == NULL) {
138 LOGE("recorder is not initialized");
139 return NO_INIT;
140 }
141 return mRecorder->setAudioEncoder((audio_encoder)ae);
142 }
143
144 status_t MediaRecorderClient::setOutputFile(const char* path)
145 {
146 LOGV("setOutputFile(%s)", path);
147 Mutex::Autolock lock(mLock);
148 if (mRecorder == NULL) {
149 LOGE("recorder is not initialized");
150 return NO_INIT;
151 }
152 return mRecorder->setOutputFile(path);
153 }
154
155 status_t MediaRecorderClient::setOutputFile(int fd, int64_t offset, int64_t length)
156 {
157 LOGV("setOutputFile(%d, %lld, %lld)", fd, offset, length);
158 Mutex::Autolock lock(mLock);
159 if (mRecorder == NULL) {
160 LOGE("recorder is not initialized");
161 return NO_INIT;
162 }
163 return mRecorder->setOutputFile(fd, offset, length);
164 }
165
b33a5ae Added setAuxiliaryOutputFile to MediaRecorder and JNI
Nipun Kwatra authored
166 status_t MediaRecorderClient::setOutputFileAuxiliary(int fd)
167 {
168 LOGV("setOutputFileAuxiliary(%d)", fd);
169 Mutex::Autolock lock(mLock);
170 if (mRecorder == NULL) {
171 LOGE("recorder is not initialized");
172 return NO_INIT;
173 }
174 return mRecorder->setOutputFileAuxiliary(fd);
175 }
176
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
177 status_t MediaRecorderClient::setVideoSize(int width, int height)
178 {
179 LOGV("setVideoSize(%dx%d)", width, height);
180 Mutex::Autolock lock(mLock);
181 if (mRecorder == NULL) {
182 LOGE("recorder is not initialized");
183 return NO_INIT;
184 }
185 return mRecorder->setVideoSize(width, height);
186 }
187
188 status_t MediaRecorderClient::setVideoFrameRate(int frames_per_second)
189 {
190 LOGV("setVideoFrameRate(%d)", frames_per_second);
191 Mutex::Autolock lock(mLock);
192 if (mRecorder == NULL) {
193 LOGE("recorder is not initialized");
194 return NO_INIT;
195 }
196 return mRecorder->setVideoFrameRate(frames_per_second);
197 }
198
ba87e3e auto import from //branches/cupcake_rel/...@138607
The Android Open Source Project authored
199 status_t MediaRecorderClient::setParameters(const String8& params) {
200 LOGV("setParameters(%s)", params.string());
201 Mutex::Autolock lock(mLock);
202 if (mRecorder == NULL) {
203 LOGE("recorder is not initialized");
204 return NO_INIT;
205 }
206 return mRecorder->setParameters(params);
207 }
208
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
209 status_t MediaRecorderClient::prepare()
210 {
211 LOGV("prepare");
212 Mutex::Autolock lock(mLock);
213 if (mRecorder == NULL) {
214 LOGE("recorder is not initialized");
215 return NO_INIT;
216 }
217 return mRecorder->prepare();
218 }
219
220
221 status_t MediaRecorderClient::getMaxAmplitude(int* max)
222 {
223 LOGV("getMaxAmplitude");
224 Mutex::Autolock lock(mLock);
225 if (mRecorder == NULL) {
226 LOGE("recorder is not initialized");
227 return NO_INIT;
228 }
229 return mRecorder->getMaxAmplitude(max);
230 }
231
232 status_t MediaRecorderClient::start()
233 {
234 LOGV("start");
235 Mutex::Autolock lock(mLock);
236 if (mRecorder == NULL) {
237 LOGE("recorder is not initialized");
238 return NO_INIT;
239 }
240 return mRecorder->start();
241
242 }
243
244 status_t MediaRecorderClient::stop()
245 {
246 LOGV("stop");
247 Mutex::Autolock lock(mLock);
248 if (mRecorder == NULL) {
249 LOGE("recorder is not initialized");
250 return NO_INIT;
251 }
252 return mRecorder->stop();
253 }
254
255 status_t MediaRecorderClient::init()
256 {
257 LOGV("init");
258 Mutex::Autolock lock(mLock);
259 if (mRecorder == NULL) {
260 LOGE("recorder is not initialized");
261 return NO_INIT;
262 }
263 return mRecorder->init();
264 }
265
266 status_t MediaRecorderClient::close()
267 {
268 LOGV("close");
269 Mutex::Autolock lock(mLock);
270 if (mRecorder == NULL) {
271 LOGE("recorder is not initialized");
272 return NO_INIT;
273 }
274 return mRecorder->close();
275 }
276
277
278 status_t MediaRecorderClient::reset()
279 {
280 LOGV("reset");
281 Mutex::Autolock lock(mLock);
282 if (mRecorder == NULL) {
283 LOGE("recorder is not initialized");
284 return NO_INIT;
285 }
286 return mRecorder->reset();
287 }
288
289 status_t MediaRecorderClient::release()
290 {
291 LOGV("release");
292 Mutex::Autolock lock(mLock);
293 if (mRecorder != NULL) {
294 delete mRecorder;
295 mRecorder = NULL;
608a263 Dump media recorder PID in dumpsys media.player, and fix minor bugs.
Gloria Wang authored
296 wp<MediaRecorderClient> client(this);
297 mMediaPlayerService->removeMediaRecorderClient(client);
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
298 }
299 return NO_ERROR;
300 }
301
608a263 Dump media recorder PID in dumpsys media.player, and fix minor bugs.
Gloria Wang authored
302 MediaRecorderClient::MediaRecorderClient(const sp<MediaPlayerService>& service, pid_t pid)
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
303 {
304 LOGV("Client constructor");
305 mPid = pid;
8ec2d9a Remove legacy PV stuff
James Dong authored
306 mRecorder = new StagefrightRecorder;
608a263 Dump media recorder PID in dumpsys media.player, and fix minor bugs.
Gloria Wang authored
307 mMediaPlayerService = service;
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
308 }
309
310 MediaRecorderClient::~MediaRecorderClient()
311 {
312 LOGV("Client destructor");
313 release();
314 }
315
fe1bafe Separate MediaRecorderClient with MediaPlayerClient
James Dong authored
316 status_t MediaRecorderClient::setListener(const sp<IMediaRecorderClient>& listener)
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
317 {
318 LOGV("setListener");
319 Mutex::Autolock lock(mLock);
320 if (mRecorder == NULL) {
321 LOGE("recorder is not initialized");
322 return NO_INIT;
323 }
324 return mRecorder->setListener(listener);
325 }
326
929642e Add runtime dumpsys support for media recorder client
James Dong authored
327 status_t MediaRecorderClient::dump(int fd, const Vector<String16>& args) const {
328 if (mRecorder != NULL) {
329 return mRecorder->dump(fd, args);
330 }
331 return OK;
332 }
333
9066cfe auto import from //depot/cupcake/@135843
The Android Open Source Project authored
334 }; // namespace android
Something went wrong with that request. Please try again.