MediaRecorderClient.cpp revision c048cae0367db6fbb4fe1127be5011910713d4ad
1/*
2 ** Copyright 2008, HTC Inc.
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>
27#include <android_runtime/ActivityManager.h>
28#include <utils/IPCThreadState.h>
29#include <utils/IServiceManager.h>
30#include <utils/MemoryHeapBase.h>
31#include <utils/MemoryBase.h>
32#include <media/PVMediaRecorder.h>
33
34#include "MediaRecorderClient.h"
35
36namespace android {
37
38status_t MediaRecorderClient::setCamera(const sp<ICamera>& camera)
39{
40    LOGV("setCamera");
41    Mutex::Autolock lock(mLock);
42    if (mRecorder == NULL) {
43        LOGE("recorder is not initialized");
44        return NO_INIT;
45    }
46    return mRecorder->setCamera(camera);
47}
48
49status_t MediaRecorderClient::setPreviewSurface(const sp<ISurface>& surface)
50{
51    LOGV("setPreviewSurface");
52    Mutex::Autolock lock(mLock);
53    if (mRecorder == NULL) {
54        LOGE("recorder is not initialized");
55        return NO_INIT;
56    }
57    return mRecorder->setPreviewSurface(surface);
58}
59
60status_t MediaRecorderClient::setVideoSource(int vs)
61{
62    LOGV("setVideoSource(%d)", vs);
63    Mutex::Autolock lock(mLock);
64    if (mRecorder == NULL)	{
65        LOGE("recorder is not initialized");
66    }
67    return mRecorder->setVideoSource((video_source)vs);
68}
69
70status_t MediaRecorderClient::setAudioSource(int as)
71{
72    LOGV("setAudioSource(%d)", as);
73    Mutex::Autolock lock(mLock);
74    if (mRecorder == NULL)  {
75        LOGE("recorder is not initialized");
76    }
77    return mRecorder->setAudioSource((audio_source)as);
78}
79
80status_t MediaRecorderClient::setOutputFormat(int of)
81{
82    LOGV("setOutputFormat(%d)", of);
83    Mutex::Autolock lock(mLock);
84    if (mRecorder == NULL) {
85        LOGE("recorder is not initialized");
86        return NO_INIT;
87    }
88    return mRecorder->setOutputFormat((output_format)of);
89}
90
91status_t MediaRecorderClient::setVideoEncoder(int ve)
92{
93    LOGV("setVideoEncoder(%d)", ve);
94    Mutex::Autolock lock(mLock);
95    if (mRecorder == NULL) {
96        LOGE("recorder is not initialized");
97        return NO_INIT;
98    }
99    return mRecorder->setVideoEncoder((video_encoder)ve);
100}
101
102status_t MediaRecorderClient::setAudioEncoder(int ae)
103{
104    LOGV("setAudioEncoder(%d)", ae);
105    Mutex::Autolock lock(mLock);
106    if (mRecorder == NULL) {
107        LOGE("recorder is not initialized");
108        return NO_INIT;
109    }
110    return mRecorder->setAudioEncoder((audio_encoder)ae);
111}
112
113status_t MediaRecorderClient::setOutputFile(const char* path)
114{
115    LOGV("setOutputFile(%s)", path);
116    Mutex::Autolock lock(mLock);
117    if (mRecorder == NULL) {
118        LOGE("recorder is not initialized");
119        return NO_INIT;
120    }
121    return mRecorder->setOutputFile(path);
122}
123
124status_t MediaRecorderClient::setOutputFile(int fd, int64_t offset, int64_t length)
125{
126    LOGV("setOutputFile(%d, %lld, %lld)", fd, offset, length);
127    Mutex::Autolock lock(mLock);
128    if (mRecorder == NULL) {
129        LOGE("recorder is not initialized");
130        return NO_INIT;
131    }
132    return mRecorder->setOutputFile(fd, offset, length);
133}
134
135status_t MediaRecorderClient::setVideoSize(int width, int height)
136{
137    LOGV("setVideoSize(%dx%d)", width, height);
138    Mutex::Autolock lock(mLock);
139    if (mRecorder == NULL) {
140        LOGE("recorder is not initialized");
141        return NO_INIT;
142    }
143    return mRecorder->setVideoSize(width, height);
144}
145
146status_t MediaRecorderClient::setVideoFrameRate(int frames_per_second)
147{
148    LOGV("setVideoFrameRate(%d)", frames_per_second);
149    Mutex::Autolock lock(mLock);
150    if (mRecorder == NULL) {
151        LOGE("recorder is not initialized");
152        return NO_INIT;
153    }
154    return mRecorder->setVideoFrameRate(frames_per_second);
155}
156
157status_t MediaRecorderClient::setParameters(const String8& params) {
158    LOGV("setParameters(%s)", params.string());
159    Mutex::Autolock lock(mLock);
160    if (mRecorder == NULL) {
161        LOGE("recorder is not initialized");
162        return NO_INIT;
163    }
164    return mRecorder->setParameters(params);
165}
166
167status_t MediaRecorderClient::prepare()
168{
169    LOGV("prepare");
170    Mutex::Autolock lock(mLock);
171    if (mRecorder == NULL) {
172        LOGE("recorder is not initialized");
173        return NO_INIT;
174    }
175    return mRecorder->prepare();
176}
177
178
179status_t MediaRecorderClient::getMaxAmplitude(int* max)
180{
181    LOGV("getMaxAmplitude");
182    Mutex::Autolock lock(mLock);
183    if (mRecorder == NULL) {
184        LOGE("recorder is not initialized");
185        return NO_INIT;
186    }
187    return mRecorder->getMaxAmplitude(max);
188}
189
190status_t MediaRecorderClient::start()
191{
192    LOGV("start");
193    Mutex::Autolock lock(mLock);
194    if (mRecorder == NULL) {
195        LOGE("recorder is not initialized");
196        return NO_INIT;
197    }
198    return mRecorder->start();
199
200}
201
202status_t MediaRecorderClient::stop()
203{
204    LOGV("stop");
205    Mutex::Autolock lock(mLock);
206    if (mRecorder == NULL) {
207        LOGE("recorder is not initialized");
208        return NO_INIT;
209    }
210    return mRecorder->stop();
211}
212
213status_t MediaRecorderClient::init()
214{
215    LOGV("init");
216    Mutex::Autolock lock(mLock);
217    if (mRecorder == NULL) {
218        LOGE("recorder is not initialized");
219        return NO_INIT;
220    }
221    return mRecorder->init();
222}
223
224status_t MediaRecorderClient::close()
225{
226    LOGV("close");
227    Mutex::Autolock lock(mLock);
228    if (mRecorder == NULL) {
229        LOGE("recorder is not initialized");
230        return NO_INIT;
231    }
232    return mRecorder->close();
233}
234
235
236status_t MediaRecorderClient::reset()
237{
238    LOGV("reset");
239    Mutex::Autolock lock(mLock);
240    if (mRecorder == NULL) {
241        LOGE("recorder is not initialized");
242        return NO_INIT;
243    }
244    return mRecorder->reset();
245}
246
247status_t MediaRecorderClient::release()
248{
249    LOGV("release");
250    Mutex::Autolock lock(mLock);
251    if (mRecorder != NULL) {
252        delete mRecorder;
253        mRecorder = NULL;
254    }
255    return NO_ERROR;
256}
257
258MediaRecorderClient::MediaRecorderClient(pid_t pid)
259{
260    LOGV("Client constructor");
261    mPid = pid;
262    mRecorder = new PVMediaRecorder();
263}
264
265MediaRecorderClient::~MediaRecorderClient()
266{
267    LOGV("Client destructor");
268    release();
269}
270
271status_t MediaRecorderClient::setListener(const sp<IMediaPlayerClient>& listener)
272{
273    LOGV("setListener");
274    Mutex::Autolock lock(mLock);
275    if (mRecorder == NULL) {
276        LOGE("recorder is not initialized");
277        return NO_INIT;
278    }
279    return mRecorder->setListener(listener);
280}
281
282}; // namespace android
283
284