1 /* 2 ** 3 ** Copyright 2008, The Android Open Source Project 4 ** 5 ** Licensed under the Apache License, Version 2.0 (the "License"); 6 ** you may not use this file except in compliance with the License. 7 ** You may obtain a copy of the License at 8 ** 9 ** http://www.apache.org/licenses/LICENSE-2.0 10 ** 11 ** Unless required by applicable law or agreed to in writing, software 12 ** distributed under the License is distributed on an "AS IS" BASIS, 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 ** See the License for the specific language governing permissions and 15 ** limitations under the License. 16 */ 17 18 #ifndef ANDROID_MEDIARECORDERCLIENT_H 19 #define ANDROID_MEDIARECORDERCLIENT_H 20 21 #include <media/AudioSystem.h> 22 #include <media/IMediaRecorder.h> 23 24 #include <android/hardware/media/omx/1.0/IOmx.h> 25 26 namespace android { 27 28 struct MediaRecorderBase; 29 class MediaPlayerService; 30 class ICameraRecordingProxy; 31 32 class MediaRecorderClient : public BnMediaRecorder 33 { 34 typedef ::android::hardware::media::omx::V1_0::IOmx IOmx; 35 36 class ServiceDeathNotifier : 37 public IBinder::DeathRecipient, 38 public ::android::hardware::hidl_death_recipient 39 { 40 public: 41 ServiceDeathNotifier( 42 const sp<IBinder>& service, 43 const sp<IMediaRecorderClient>& listener, 44 int which); 45 ServiceDeathNotifier( 46 const sp<IOmx>& omx, 47 const sp<IMediaRecorderClient>& listener, 48 int which); 49 virtual ~ServiceDeathNotifier(); 50 virtual void binderDied(const wp<IBinder>& who); 51 virtual void serviceDied( 52 uint64_t cookie, 53 const wp<::android::hidl::base::V1_0::IBase>& who); 54 void unlinkToDeath(); 55 private: 56 int mWhich; 57 sp<IBinder> mService; 58 sp<IOmx> mOmx; 59 wp<IMediaRecorderClient> mListener; 60 }; 61 62 class AudioDeviceUpdatedNotifier: public AudioSystem::AudioDeviceCallback 63 { 64 public: 65 AudioDeviceUpdatedNotifier(const sp<IMediaRecorderClient>& listener); 66 virtual ~AudioDeviceUpdatedNotifier(); 67 virtual void onAudioDeviceUpdate( 68 audio_io_handle_t audioIo, 69 audio_port_handle_t deviceId); 70 private: 71 wp<IMediaRecorderClient> mListener; 72 }; 73 74 void clearDeathNotifiers_l(); 75 76 public: 77 virtual status_t setCamera(const sp<hardware::ICamera>& camera, 78 const sp<ICameraRecordingProxy>& proxy); 79 virtual status_t setPreviewSurface(const sp<IGraphicBufferProducer>& surface); 80 virtual status_t setVideoSource(int vs); 81 virtual status_t setAudioSource(int as); 82 virtual status_t setOutputFormat(int of); 83 virtual status_t setVideoEncoder(int ve); 84 virtual status_t setAudioEncoder(int ae); 85 virtual status_t setOutputFile(int fd); 86 virtual status_t setNextOutputFile(int fd); 87 virtual status_t setVideoSize(int width, int height); 88 virtual status_t setVideoFrameRate(int frames_per_second); 89 virtual status_t setParameters(const String8& params); 90 virtual status_t setListener( 91 const sp<IMediaRecorderClient>& listener); 92 virtual status_t setClientName(const String16& clientName); 93 virtual status_t prepare(); 94 virtual status_t getMaxAmplitude(int* max); 95 virtual status_t getMetrics(Parcel* reply); 96 virtual status_t start(); 97 virtual status_t stop(); 98 virtual status_t reset(); 99 virtual status_t pause(); 100 virtual status_t resume(); 101 virtual status_t init(); 102 virtual status_t close(); 103 virtual status_t release(); 104 virtual status_t dump(int fd, const Vector<String16>& args); 105 virtual status_t setInputSurface(const sp<PersistentSurface>& surface); 106 virtual sp<IGraphicBufferProducer> querySurfaceMediaSource(); 107 virtual status_t setInputDevice(audio_port_handle_t deviceId); 108 virtual status_t getRoutedDeviceId(audio_port_handle_t* deviceId); 109 virtual status_t enableAudioDeviceCallback(bool enabled); 110 virtual status_t getActiveMicrophones( 111 std::vector<media::MicrophoneInfo>* activeMicrophones); 112 113 private: 114 friend class MediaPlayerService; // for accessing private constructor 115 116 MediaRecorderClient( 117 const sp<MediaPlayerService>& service, 118 pid_t pid, 119 const String16& opPackageName); 120 virtual ~MediaRecorderClient(); 121 122 sp<ServiceDeathNotifier> mCameraDeathListener; 123 sp<ServiceDeathNotifier> mCodecDeathListener; 124 sp<AudioDeviceUpdatedNotifier> mAudioDeviceUpdatedNotifier; 125 126 pid_t mPid; 127 Mutex mLock; 128 MediaRecorderBase *mRecorder; 129 sp<MediaPlayerService> mMediaPlayerService; 130 }; 131 132 }; // namespace android 133 134 #endif // ANDROID_MEDIARECORDERCLIENT_H 135