MediaRecorderClient.cpp revision 7b5eb023f8d87cca6d830ae6c11c6aadbe02aca8
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::setVideoSize(int width, int height)
125{
126    LOGV("setVideoSize(%dx%d)", width, height);
127    Mutex::Autolock lock(mLock);
128    if (mRecorder == NULL) {
129        LOGE("recorder is not initialized");
130        return NO_INIT;
131    }
132    return mRecorder->setVideoSize(width, height);
133}
134
135status_t MediaRecorderClient::setVideoFrameRate(int frames_per_second)
136{
137    LOGV("setVideoFrameRate(%d)", frames_per_second);
138    Mutex::Autolock lock(mLock);
139    if (mRecorder == NULL) {
140        LOGE("recorder is not initialized");
141        return NO_INIT;
142    }
143    return mRecorder->setVideoFrameRate(frames_per_second);
144}
145
146status_t MediaRecorderClient::prepare()
147{
148    LOGV("prepare");
149    Mutex::Autolock lock(mLock);
150    if (mRecorder == NULL) {
151        LOGE("recorder is not initialized");
152        return NO_INIT;
153    }
154    return mRecorder->prepare();
155}
156
157
158status_t MediaRecorderClient::getMaxAmplitude(int* max)
159{
160    LOGV("getMaxAmplitude");
161    Mutex::Autolock lock(mLock);
162    if (mRecorder == NULL) {
163        LOGE("recorder is not initialized");
164        return NO_INIT;
165    }
166    return mRecorder->getMaxAmplitude(max);
167}
168
169status_t MediaRecorderClient::start()
170{
171    LOGV("start");
172    Mutex::Autolock lock(mLock);
173    if (mRecorder == NULL) {
174        LOGE("recorder is not initialized");
175        return NO_INIT;
176    }
177    return mRecorder->start();
178
179}
180
181status_t MediaRecorderClient::stop()
182{
183    LOGV("stop");
184    Mutex::Autolock lock(mLock);
185    if (mRecorder == NULL) {
186        LOGE("recorder is not initialized");
187        return NO_INIT;
188    }
189    return mRecorder->stop();
190}
191
192status_t MediaRecorderClient::init()
193{
194    LOGV("init");
195    Mutex::Autolock lock(mLock);
196    if (mRecorder == NULL) {
197        LOGE("recorder is not initialized");
198        return NO_INIT;
199    }
200    return mRecorder->init();
201}
202
203status_t MediaRecorderClient::close()
204{
205    LOGV("close");
206    Mutex::Autolock lock(mLock);
207    if (mRecorder == NULL) {
208        LOGE("recorder is not initialized");
209        return NO_INIT;
210    }
211    return mRecorder->close();
212}
213
214
215status_t MediaRecorderClient::reset()
216{
217    LOGV("reset");
218    Mutex::Autolock lock(mLock);
219    if (mRecorder == NULL) {
220        LOGE("recorder is not initialized");
221        return NO_INIT;
222    }
223    return mRecorder->reset();
224}
225
226status_t MediaRecorderClient::release()
227{
228    LOGV("release");
229    Mutex::Autolock lock(mLock);
230    if (mRecorder != NULL) {
231        delete mRecorder;
232        mRecorder = NULL;
233    }
234    return NO_ERROR;
235}
236
237MediaRecorderClient::MediaRecorderClient(pid_t pid)
238{
239    LOGV("Client constructor");
240    mPid = pid;
241    mRecorder = new PVMediaRecorder();
242}
243
244MediaRecorderClient::~MediaRecorderClient()
245{
246    LOGV("Client destructor");
247    release();
248}
249
250}; // namespace android
251
252