michael@0: /* michael@0: * Copyright (C) 2009 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef GONK_RECORDER_H_ michael@0: #define GONK_RECORDER_H_ michael@0: michael@0: #include "nsISupportsImpl.h" michael@0: #include "GonkCameraHwMgr.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "mozilla/RefPtr.h" michael@0: #include "GonkCameraHwMgr.h" michael@0: michael@0: namespace android { michael@0: michael@0: class GonkCameraSource; michael@0: struct MediaSource; michael@0: struct MediaWriter; michael@0: class MetaData; michael@0: struct AudioSource; michael@0: class MediaProfiles; michael@0: class GonkCameraHardware; michael@0: michael@0: struct GonkRecorder { michael@0: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GonkRecorder) michael@0: michael@0: GonkRecorder(); michael@0: michael@0: virtual status_t init(); michael@0: virtual status_t setAudioSource(audio_source_t as); michael@0: virtual status_t setVideoSource(video_source vs); michael@0: virtual status_t setOutputFormat(output_format of); michael@0: virtual status_t setAudioEncoder(audio_encoder ae); michael@0: virtual status_t setVideoEncoder(video_encoder ve); michael@0: virtual status_t setVideoSize(int width, int height); michael@0: virtual status_t setVideoFrameRate(int frames_per_second); michael@0: virtual status_t setOutputFile(const char *path); michael@0: virtual status_t setOutputFile(int fd, int64_t offset, int64_t length); michael@0: virtual status_t setParameters(const String8& params); michael@0: virtual status_t setCamera(const sp& aCameraHw); michael@0: virtual status_t setListener(const sp& listener); michael@0: virtual status_t setClientName(const String16& clientName); michael@0: virtual status_t prepare(); michael@0: virtual status_t start(); michael@0: virtual status_t pause(); michael@0: virtual status_t stop(); michael@0: virtual status_t close(); michael@0: virtual status_t reset(); michael@0: virtual status_t getMaxAmplitude(int *max); michael@0: virtual status_t dump(int fd, const Vector& args) const; michael@0: // Querying a SurfaceMediaSourcer michael@0: michael@0: protected: michael@0: virtual ~GonkRecorder(); michael@0: michael@0: private: michael@0: sp mListener; michael@0: String16 mClientName; michael@0: uid_t mClientUid; michael@0: sp mWriter; michael@0: int mOutputFd; michael@0: sp mAudioSourceNode; michael@0: michael@0: audio_source_t mAudioSource; michael@0: video_source mVideoSource; michael@0: output_format mOutputFormat; michael@0: audio_encoder mAudioEncoder; michael@0: video_encoder mVideoEncoder; michael@0: bool mUse64BitFileOffset; michael@0: int32_t mVideoWidth, mVideoHeight; michael@0: int32_t mFrameRate; michael@0: int32_t mVideoBitRate; michael@0: int32_t mAudioBitRate; michael@0: int32_t mAudioChannels; michael@0: int32_t mSampleRate; michael@0: int32_t mInterleaveDurationUs; michael@0: int32_t mIFramesIntervalSec; michael@0: int32_t mCameraId; michael@0: int32_t mVideoEncoderProfile; michael@0: int32_t mVideoEncoderLevel; michael@0: int32_t mMovieTimeScale; michael@0: int32_t mVideoTimeScale; michael@0: int32_t mAudioTimeScale; michael@0: int64_t mMaxFileSizeBytes; michael@0: int64_t mMaxFileDurationUs; michael@0: int64_t mTrackEveryTimeDurationUs; michael@0: int32_t mRotationDegrees; // Clockwise michael@0: int32_t mLatitudex10000; michael@0: int32_t mLongitudex10000; michael@0: int32_t mStartTimeOffsetMs; michael@0: michael@0: String8 mParams; michael@0: michael@0: bool mIsMetaDataStoredInVideoBuffers; michael@0: MediaProfiles *mEncoderProfiles; michael@0: michael@0: bool mStarted; michael@0: // Needed when GLFrames are encoded. michael@0: // An pointer michael@0: // will be sent to the client side using which the michael@0: // frame buffers will be queued and dequeued michael@0: michael@0: sp mCameraHw; michael@0: michael@0: status_t setupMPEG4Recording( michael@0: int outputFd, michael@0: int32_t videoWidth, int32_t videoHeight, michael@0: int32_t videoBitRate, michael@0: int32_t *totalBitRate, michael@0: sp *mediaWriter); michael@0: void setupMPEG4MetaData(int64_t startTimeUs, int32_t totalBitRate, michael@0: sp *meta); michael@0: status_t startMPEG4Recording(); michael@0: status_t startAMRRecording(); michael@0: #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 michael@0: status_t startAACRecording(); michael@0: #endif michael@0: status_t startRawAudioRecording(); michael@0: status_t startRTPRecording(); michael@0: status_t startMPEG2TSRecording(); michael@0: sp createAudioSource(); michael@0: status_t checkVideoEncoderCapabilities(); michael@0: status_t checkAudioEncoderCapabilities(); michael@0: // Generic MediaSource set-up. Returns the appropriate michael@0: // source (CameraSource or SurfaceMediaSource) michael@0: // depending on the videosource type michael@0: status_t setupMediaSource(sp *mediaSource); michael@0: status_t setupCameraSource(sp *cameraSource); michael@0: // setup the surfacemediasource for the encoder michael@0: michael@0: status_t setupAudioEncoder(const sp& writer); michael@0: status_t setupVideoEncoder( michael@0: sp cameraSource, michael@0: int32_t videoBitRate, michael@0: sp *source); michael@0: michael@0: // Encoding parameter handling utilities michael@0: status_t setParameter(const String8 &key, const String8 &value); michael@0: status_t setParamAudioEncodingBitRate(int32_t bitRate); michael@0: status_t setParamAudioNumberOfChannels(int32_t channles); michael@0: status_t setParamAudioSamplingRate(int32_t sampleRate); michael@0: status_t setParamAudioTimeScale(int32_t timeScale); michael@0: status_t setParamVideoEncodingBitRate(int32_t bitRate); michael@0: status_t setParamVideoIFramesInterval(int32_t seconds); michael@0: status_t setParamVideoEncoderProfile(int32_t profile); michael@0: status_t setParamVideoEncoderLevel(int32_t level); michael@0: status_t setParamVideoCameraId(int32_t cameraId); michael@0: status_t setParamVideoTimeScale(int32_t timeScale); michael@0: status_t setParamVideoRotation(int32_t degrees); michael@0: status_t setParamTrackTimeStatus(int64_t timeDurationUs); michael@0: status_t setParamInterleaveDuration(int32_t durationUs); michael@0: status_t setParam64BitFileOffset(bool use64BitFileOffset); michael@0: status_t setParamMaxFileDurationUs(int64_t timeUs); michael@0: status_t setParamMaxFileSizeBytes(int64_t bytes); michael@0: status_t setParamMovieTimeScale(int32_t timeScale); michael@0: status_t setParamGeoDataLongitude(int64_t longitudex10000); michael@0: status_t setParamGeoDataLatitude(int64_t latitudex10000); michael@0: void clipVideoBitRate(); michael@0: void clipVideoFrameRate(); michael@0: void clipVideoFrameWidth(); michael@0: void clipVideoFrameHeight(); michael@0: void clipAudioBitRate(); michael@0: void clipAudioSampleRate(); michael@0: void clipNumberOfAudioChannels(); michael@0: void setDefaultProfileIfNecessary(); michael@0: michael@0: GonkRecorder(const GonkRecorder &); michael@0: GonkRecorder &operator=(const GonkRecorder &); michael@0: }; michael@0: michael@0: } // namespace android michael@0: michael@0: #endif // GONK_RECORDER_H_