130ab66297501757d745b9ae10da61adcd891f497Andreas Huber/* 230ab66297501757d745b9ae10da61adcd891f497Andreas Huber * Copyright (C) 2009 The Android Open Source Project 330ab66297501757d745b9ae10da61adcd891f497Andreas Huber * 430ab66297501757d745b9ae10da61adcd891f497Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License"); 530ab66297501757d745b9ae10da61adcd891f497Andreas Huber * you may not use this file except in compliance with the License. 630ab66297501757d745b9ae10da61adcd891f497Andreas Huber * You may obtain a copy of the License at 730ab66297501757d745b9ae10da61adcd891f497Andreas Huber * 830ab66297501757d745b9ae10da61adcd891f497Andreas Huber * http://www.apache.org/licenses/LICENSE-2.0 930ab66297501757d745b9ae10da61adcd891f497Andreas Huber * 1030ab66297501757d745b9ae10da61adcd891f497Andreas Huber * Unless required by applicable law or agreed to in writing, software 1130ab66297501757d745b9ae10da61adcd891f497Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS, 1230ab66297501757d745b9ae10da61adcd891f497Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1330ab66297501757d745b9ae10da61adcd891f497Andreas Huber * See the License for the specific language governing permissions and 1430ab66297501757d745b9ae10da61adcd891f497Andreas Huber * limitations under the License. 1530ab66297501757d745b9ae10da61adcd891f497Andreas Huber */ 1630ab66297501757d745b9ae10da61adcd891f497Andreas Huber 1730ab66297501757d745b9ae10da61adcd891f497Andreas Huber#ifndef STAGEFRIGHT_RECORDER_H_ 1830ab66297501757d745b9ae10da61adcd891f497Andreas Huber 1930ab66297501757d745b9ae10da61adcd891f497Andreas Huber#define STAGEFRIGHT_RECORDER_H_ 2030ab66297501757d745b9ae10da61adcd891f497Andreas Huber 2130ab66297501757d745b9ae10da61adcd891f497Andreas Huber#include <media/MediaRecorderBase.h> 225f4d93467a03b3a38320416f8cc2c2c2c94bf3fcJames Dong#include <camera/CameraParameters.h> 2330ab66297501757d745b9ae10da61adcd891f497Andreas Huber#include <utils/String8.h> 2430ab66297501757d745b9ae10da61adcd891f497Andreas Huber 2564760240f931714858a59c1579f07264d7182ba2Dima Zavin#include <system/audio.h> 26fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin 2730ab66297501757d745b9ae10da61adcd891f497Andreas Hubernamespace android { 2830ab66297501757d745b9ae10da61adcd891f497Andreas Huber 29c32cd79d9ad4aba7d959b5b3be7361b4715e6f18James Dongclass Camera; 304ca2c7c913f8bd4ada13aca56d36045d42d1e00fWu-cheng Liclass ICameraRecordingProxy; 319c075bca0b75093ca0514a3c8f74d73c8e9e83fdNipun Kwatraclass CameraSource; 3278eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatraclass CameraSourceTimeLapse; 332dce41ad26cb3e9e15c9e456a84bcf5309548ca0Andreas Huberstruct MediaSource; 342dce41ad26cb3e9e15c9e456a84bcf5309548ca0Andreas Huberstruct MediaWriter; 359c075bca0b75093ca0514a3c8f74d73c8e9e83fdNipun Kwatraclass MetaData; 36d3d4e5069e1af0437c4f5a7b4ba344bda5b937afJames Dongstruct AudioSource; 3799c2a076b4a46762a22bbb4dfbd51d107e0532d9James Dongclass MediaProfiles; 388ba01021b573889802e67e029225a96f0dfa471aAndy McFaddenclass IGraphicBufferProducer; 39b33f3407bab0970a7f9241680723a1140b177c50Pannag Sanketiclass SurfaceMediaSource; 4072cecca17d735db6532c45f0a7e10c47ee6f065aChong Zhangclass ALooper; 4130ab66297501757d745b9ae10da61adcd891f497Andreas Huber 4230ab66297501757d745b9ae10da61adcd891f497Andreas Huberstruct StagefrightRecorder : public MediaRecorderBase { 4330ab66297501757d745b9ae10da61adcd891f497Andreas Huber StagefrightRecorder(); 4430ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual ~StagefrightRecorder(); 4530ab66297501757d745b9ae10da61adcd891f497Andreas Huber 4630ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t init(); 47fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin virtual status_t setAudioSource(audio_source_t as); 4830ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t setVideoSource(video_source vs); 4930ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t setOutputFormat(output_format of); 5030ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t setAudioEncoder(audio_encoder ae); 5130ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t setVideoEncoder(video_encoder ve); 5230ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t setVideoSize(int width, int height); 5330ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t setVideoFrameRate(int frames_per_second); 544ca2c7c913f8bd4ada13aca56d36045d42d1e00fWu-cheng Li virtual status_t setCamera(const sp<ICamera>& camera, const sp<ICameraRecordingProxy>& proxy); 5599617adda9bc46c43f511f0940bc735c73de61deMathias Agopian virtual status_t setPreviewSurface(const sp<IGraphicBufferProducer>& surface); 5630ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t setOutputFile(const char *path); 5730ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t setOutputFile(int fd, int64_t offset, int64_t length); 5830ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t setParameters(const String8& params); 5937047fceba836f341d0108beed0991b0f8dfc543James Dong virtual status_t setListener(const sp<IMediaRecorderClient>& listener); 60ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala virtual status_t setClientName(const String16& clientName); 6130ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t prepare(); 6230ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t start(); 63a7d1a2dd776bf356c228785a94ba8e0ff6a2ec7fJames Dong virtual status_t pause(); 6430ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t stop(); 6530ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t close(); 6630ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t reset(); 6730ab66297501757d745b9ae10da61adcd891f497Andreas Huber virtual status_t getMaxAmplitude(int *max); 68b914122eb9cb54bbeae4ec03bfebb194aecdccbdJames Dong virtual status_t dump(int fd, const Vector<String16>& args) const; 69b33f3407bab0970a7f9241680723a1140b177c50Pannag Sanketi // Querying a SurfaceMediaSourcer 708ba01021b573889802e67e029225a96f0dfa471aAndy McFadden virtual sp<IGraphicBufferProducer> querySurfaceMediaSource() const; 7130ab66297501757d745b9ae10da61adcd891f497Andreas Huber 7230ab66297501757d745b9ae10da61adcd891f497Andreas Huberprivate: 7354ff19ac69ace7c05ea90d225e26dab3b133f487James Dong sp<ICamera> mCamera; 744ca2c7c913f8bd4ada13aca56d36045d42d1e00fWu-cheng Li sp<ICameraRecordingProxy> mCameraProxy; 7599617adda9bc46c43f511f0940bc735c73de61deMathias Agopian sp<IGraphicBufferProducer> mPreviewSurface; 7637047fceba836f341d0108beed0991b0f8dfc543James Dong sp<IMediaRecorderClient> mListener; 77ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala String16 mClientName; 78ceb388d6c03c38b96dc41c0ea4804b749aa077c4Eino-Ville Talvala uid_t mClientUid; 793cecf640c4daf2df616b278bd9986018c8182908James Dong sp<MediaWriter> mWriter; 803cecf640c4daf2df616b278bd9986018c8182908James Dong int mOutputFd; 81d3d4e5069e1af0437c4f5a7b4ba344bda5b937afJames Dong sp<AudioSource> mAudioSourceNode; 8230ab66297501757d745b9ae10da61adcd891f497Andreas Huber 83fce7a473248381cc83a01855f92581077d3c9ee2Dima Zavin audio_source_t mAudioSource; 8430ab66297501757d745b9ae10da61adcd891f497Andreas Huber video_source mVideoSource; 8530ab66297501757d745b9ae10da61adcd891f497Andreas Huber output_format mOutputFormat; 8630ab66297501757d745b9ae10da61adcd891f497Andreas Huber audio_encoder mAudioEncoder; 8730ab66297501757d745b9ae10da61adcd891f497Andreas Huber video_encoder mVideoEncoder; 882dec2b5be2056c6d9428897dc672185872d30d17James Dong bool mUse64BitFileOffset; 89050b28a593350047845a45a14cc5026221ac1620James Dong int32_t mVideoWidth, mVideoHeight; 90050b28a593350047845a45a14cc5026221ac1620James Dong int32_t mFrameRate; 913cecf640c4daf2df616b278bd9986018c8182908James Dong int32_t mVideoBitRate; 92cfe88a20345dad981842b2c8092e4c704d3f98b4Nipun Kwatra int32_t mAudioBitRate; 93050b28a593350047845a45a14cc5026221ac1620James Dong int32_t mAudioChannels; 94050b28a593350047845a45a14cc5026221ac1620James Dong int32_t mSampleRate; 9513aec890216948b0c364f8f92792129d0335f506James Dong int32_t mInterleaveDurationUs; 968f5f2fcee5c12d08df71d17017410c50951fc2e3James Dong int32_t mIFramesIntervalSec; 9793d6b102a13afa23bfa80d74c399d93d542e6ad6James Dong int32_t mCameraId; 98145bfe5eb3e08c9689c28f6bf3287a979438b04bJames Dong int32_t mVideoEncoderProfile; 99145bfe5eb3e08c9689c28f6bf3287a979438b04bJames Dong int32_t mVideoEncoderLevel; 1008f5f2fcee5c12d08df71d17017410c50951fc2e3James Dong int32_t mMovieTimeScale; 1018f5f2fcee5c12d08df71d17017410c50951fc2e3James Dong int32_t mVideoTimeScale; 1028f5f2fcee5c12d08df71d17017410c50951fc2e3James Dong int32_t mAudioTimeScale; 103ef9d0cd72e476a4b7556833fb09505a51b626797James Dong int64_t mMaxFileSizeBytes; 104ef9d0cd72e476a4b7556833fb09505a51b626797James Dong int64_t mMaxFileDurationUs; 10593d6b102a13afa23bfa80d74c399d93d542e6ad6James Dong int64_t mTrackEveryTimeDurationUs; 10613f6284305e4b27395a23db7882d670bdb1bcae1James Dong int32_t mRotationDegrees; // Clockwise 10707b1bb529a1ae76c46a71b01338c166f9490629dJames Dong int32_t mLatitudex10000; 10807b1bb529a1ae76c46a71b01338c166f9490629dJames Dong int32_t mLongitudex10000; 10986b7f47aa7482424cf8fd248f1315311919be3b0James Dong int32_t mStartTimeOffsetMs; 11072cecca17d735db6532c45f0a7e10c47ee6f065aChong Zhang int32_t mTotalBitRate; 111050b28a593350047845a45a14cc5026221ac1620James Dong 112fc20aab463f527ab3b0664986f0381a86b375884Nipun Kwatra bool mCaptureTimeLapse; 113e4e0a6994d39c4a7cba09c5fff442b2dca1df8f8Nipun Kwatra int64_t mTimeBetweenTimeLapseFrameCaptureUs; 11478eff720c86eb6d4e3d45a144df60b2ca464d2d4Nipun Kwatra sp<CameraSourceTimeLapse> mCameraSourceTimeLapse; 115fc20aab463f527ab3b0664986f0381a86b375884Nipun Kwatra 116b33f3407bab0970a7f9241680723a1140b177c50Pannag Sanketi 11730ab66297501757d745b9ae10da61adcd891f497Andreas Huber String8 mParams; 11830ab66297501757d745b9ae10da61adcd891f497Andreas Huber 1198480835b4bc1350646376aa7f3ae33742a7adeb1James Dong bool mIsMetaDataStoredInVideoBuffers; 12099c2a076b4a46762a22bbb4dfbd51d107e0532d9James Dong MediaProfiles *mEncoderProfiles; 12199c2a076b4a46762a22bbb4dfbd51d107e0532d9James Dong 12275b0b5473c7b43f8c5972db7e6e8930988ead751Gloria Wang bool mStarted; 123b33f3407bab0970a7f9241680723a1140b177c50Pannag Sanketi // Needed when GLFrames are encoded. 1248ba01021b573889802e67e029225a96f0dfa471aAndy McFadden // An <IGraphicBufferProducer> pointer 125b33f3407bab0970a7f9241680723a1140b177c50Pannag Sanketi // will be sent to the client side using which the 126b33f3407bab0970a7f9241680723a1140b177c50Pannag Sanketi // frame buffers will be queued and dequeued 12772cecca17d735db6532c45f0a7e10c47ee6f065aChong Zhang sp<IGraphicBufferProducer> mGraphicBufferProducer; 12872cecca17d735db6532c45f0a7e10c47ee6f065aChong Zhang sp<ALooper> mLooper; 12972cecca17d735db6532c45f0a7e10c47ee6f065aChong Zhang 1301a5690652f3f6ee40f15c2f9f6c4b6badf4dbcf5Chong Zhang status_t prepareInternal(); 131114819633470ebd5b346c13c2a82a0025d2d39c0Robert Shih status_t setupMPEG4orWEBMRecording(); 132114819633470ebd5b346c13c2a82a0025d2d39c0Robert Shih void setupMPEG4orWEBMMetaData(sp<MetaData> *meta); 13372cecca17d735db6532c45f0a7e10c47ee6f065aChong Zhang status_t setupAMRRecording(); 13472cecca17d735db6532c45f0a7e10c47ee6f065aChong Zhang status_t setupAACRecording(); 13572cecca17d735db6532c45f0a7e10c47ee6f065aChong Zhang status_t setupRawAudioRecording(); 13672cecca17d735db6532c45f0a7e10c47ee6f065aChong Zhang status_t setupRTPRecording(); 13772cecca17d735db6532c45f0a7e10c47ee6f065aChong Zhang status_t setupMPEG2TSRecording(); 138050b28a593350047845a45a14cc5026221ac1620James Dong sp<MediaSource> createAudioSource(); 1399c7f845780d62ea09469a8dac7117cc01adfea5cLajos Molnar status_t checkVideoEncoderCapabilities( 1409c7f845780d62ea09469a8dac7117cc01adfea5cLajos Molnar bool *supportsCameraSourceMetaDataMode); 14142dd1d5f186252a7f09f8fb1a46ea82e3877b2d3James Dong status_t checkAudioEncoderCapabilities(); 142b33f3407bab0970a7f9241680723a1140b177c50Pannag Sanketi // Generic MediaSource set-up. Returns the appropriate 143b33f3407bab0970a7f9241680723a1140b177c50Pannag Sanketi // source (CameraSource or SurfaceMediaSource) 144b33f3407bab0970a7f9241680723a1140b177c50Pannag Sanketi // depending on the videosource type 145b33f3407bab0970a7f9241680723a1140b177c50Pannag Sanketi status_t setupMediaSource(sp<MediaSource> *mediaSource); 1469c075bca0b75093ca0514a3c8f74d73c8e9e83fdNipun Kwatra status_t setupCameraSource(sp<CameraSource> *cameraSource); 147934da11c4cc598d3dd3b53726c362bcdcc0fd37fJames Dong status_t setupAudioEncoder(const sp<MediaWriter>& writer); 1484db37cedd4db8230f3ec6191d8d7ba2b0036886eRobert Shih status_t setupVideoEncoder(sp<MediaSource> cameraSource, sp<MediaSource> *source); 149934da11c4cc598d3dd3b53726c362bcdcc0fd37fJames Dong 150934da11c4cc598d3dd3b53726c362bcdcc0fd37fJames Dong // Encoding parameter handling utilities 151050b28a593350047845a45a14cc5026221ac1620James Dong status_t setParameter(const String8 &key, const String8 &value); 152050b28a593350047845a45a14cc5026221ac1620James Dong status_t setParamAudioEncodingBitRate(int32_t bitRate); 153050b28a593350047845a45a14cc5026221ac1620James Dong status_t setParamAudioNumberOfChannels(int32_t channles); 154050b28a593350047845a45a14cc5026221ac1620James Dong status_t setParamAudioSamplingRate(int32_t sampleRate); 1558f5f2fcee5c12d08df71d17017410c50951fc2e3James Dong status_t setParamAudioTimeScale(int32_t timeScale); 156e4e0a6994d39c4a7cba09c5fff442b2dca1df8f8Nipun Kwatra status_t setParamTimeLapseEnable(int32_t timeLapseEnable); 157e4e0a6994d39c4a7cba09c5fff442b2dca1df8f8Nipun Kwatra status_t setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs); 15893d6b102a13afa23bfa80d74c399d93d542e6ad6James Dong status_t setParamVideoEncodingBitRate(int32_t bitRate); 1598f5f2fcee5c12d08df71d17017410c50951fc2e3James Dong status_t setParamVideoIFramesInterval(int32_t seconds); 160145bfe5eb3e08c9689c28f6bf3287a979438b04bJames Dong status_t setParamVideoEncoderProfile(int32_t profile); 161145bfe5eb3e08c9689c28f6bf3287a979438b04bJames Dong status_t setParamVideoEncoderLevel(int32_t level); 16293d6b102a13afa23bfa80d74c399d93d542e6ad6James Dong status_t setParamVideoCameraId(int32_t cameraId); 1638f5f2fcee5c12d08df71d17017410c50951fc2e3James Dong status_t setParamVideoTimeScale(int32_t timeScale); 16413f6284305e4b27395a23db7882d670bdb1bcae1James Dong status_t setParamVideoRotation(int32_t degrees); 16593d6b102a13afa23bfa80d74c399d93d542e6ad6James Dong status_t setParamTrackTimeStatus(int64_t timeDurationUs); 16613aec890216948b0c364f8f92792129d0335f506James Dong status_t setParamInterleaveDuration(int32_t durationUs); 1672dec2b5be2056c6d9428897dc672185872d30d17James Dong status_t setParam64BitFileOffset(bool use64BitFileOffset); 168934da11c4cc598d3dd3b53726c362bcdcc0fd37fJames Dong status_t setParamMaxFileDurationUs(int64_t timeUs); 169934da11c4cc598d3dd3b53726c362bcdcc0fd37fJames Dong status_t setParamMaxFileSizeBytes(int64_t bytes); 1708f5f2fcee5c12d08df71d17017410c50951fc2e3James Dong status_t setParamMovieTimeScale(int32_t timeScale); 171b832a03d563dd000faa44f2577e92237525edc32James Dong status_t setParamGeoDataLongitude(int64_t longitudex10000); 172b832a03d563dd000faa44f2577e92237525edc32James Dong status_t setParamGeoDataLatitude(int64_t latitudex10000); 17399c2a076b4a46762a22bbb4dfbd51d107e0532d9James Dong void clipVideoBitRate(); 17499c2a076b4a46762a22bbb4dfbd51d107e0532d9James Dong void clipVideoFrameRate(); 17599c2a076b4a46762a22bbb4dfbd51d107e0532d9James Dong void clipVideoFrameWidth(); 17699c2a076b4a46762a22bbb4dfbd51d107e0532d9James Dong void clipVideoFrameHeight(); 17742dd1d5f186252a7f09f8fb1a46ea82e3877b2d3James Dong void clipAudioBitRate(); 17842dd1d5f186252a7f09f8fb1a46ea82e3877b2d3James Dong void clipAudioSampleRate(); 17942dd1d5f186252a7f09f8fb1a46ea82e3877b2d3James Dong void clipNumberOfAudioChannels(); 180d552b88515c6ccd18695e5db5e6032a6425d8c63James Dong void setDefaultProfileIfNecessary(); 18154ef1bae010f12dfe6a40ff4452695b1b11ff449Chong Zhang void setDefaultVideoEncoderIfNecessary(); 1822dce41ad26cb3e9e15c9e456a84bcf5309548ca0Andreas Huber 183b33f3407bab0970a7f9241680723a1140b177c50Pannag Sanketi 18430ab66297501757d745b9ae10da61adcd891f497Andreas Huber StagefrightRecorder(const StagefrightRecorder &); 18530ab66297501757d745b9ae10da61adcd891f497Andreas Huber StagefrightRecorder &operator=(const StagefrightRecorder &); 18630ab66297501757d745b9ae10da61adcd891f497Andreas Huber}; 18730ab66297501757d745b9ae10da61adcd891f497Andreas Huber 18830ab66297501757d745b9ae10da61adcd891f497Andreas Huber} // namespace android 18930ab66297501757d745b9ae10da61adcd891f497Andreas Huber 19030ab66297501757d745b9ae10da61adcd891f497Andreas Huber#endif // STAGEFRIGHT_RECORDER_H_ 191