Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 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 | #ifndef STAGEFRIGHT_RECORDER_H_ |
| 18 | |
| 19 | #define STAGEFRIGHT_RECORDER_H_ |
| 20 | |
| 21 | #include <media/MediaRecorderBase.h> |
| 22 | #include <utils/String8.h> |
| 23 | |
| 24 | namespace android { |
| 25 | |
James Dong | b00e246 | 2010-04-26 17:48:26 -0700 | [diff] [blame] | 26 | class Camera; |
Andreas Huber | 996dddf | 2010-01-25 15:30:31 -0800 | [diff] [blame] | 27 | struct MediaSource; |
| 28 | struct MediaWriter; |
James Dong | 57e7f83 | 2010-06-24 19:55:31 -0700 | [diff] [blame] | 29 | struct AudioSource; |
James Dong | 42a18c0 | 2010-06-16 17:27:46 -0700 | [diff] [blame] | 30 | class MediaProfiles; |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 31 | |
| 32 | struct StagefrightRecorder : public MediaRecorderBase { |
| 33 | StagefrightRecorder(); |
| 34 | virtual ~StagefrightRecorder(); |
| 35 | |
| 36 | virtual status_t init(); |
| 37 | virtual status_t setAudioSource(audio_source as); |
| 38 | virtual status_t setVideoSource(video_source vs); |
| 39 | virtual status_t setOutputFormat(output_format of); |
| 40 | virtual status_t setAudioEncoder(audio_encoder ae); |
| 41 | virtual status_t setVideoEncoder(video_encoder ve); |
| 42 | virtual status_t setVideoSize(int width, int height); |
| 43 | virtual status_t setVideoFrameRate(int frames_per_second); |
| 44 | virtual status_t setCamera(const sp<ICamera>& camera); |
| 45 | virtual status_t setPreviewSurface(const sp<ISurface>& surface); |
| 46 | virtual status_t setOutputFile(const char *path); |
| 47 | virtual status_t setOutputFile(int fd, int64_t offset, int64_t length); |
| 48 | virtual status_t setParameters(const String8& params); |
James Dong | fe1bafe | 2010-06-25 17:06:47 -0700 | [diff] [blame] | 49 | virtual status_t setListener(const sp<IMediaRecorderClient>& listener); |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 50 | virtual status_t prepare(); |
| 51 | virtual status_t start(); |
James Dong | 08c7473 | 2010-06-10 12:28:15 -0700 | [diff] [blame] | 52 | virtual status_t pause(); |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 53 | virtual status_t stop(); |
| 54 | virtual status_t close(); |
| 55 | virtual status_t reset(); |
| 56 | virtual status_t getMaxAmplitude(int *max); |
James Dong | 929642e | 2010-07-08 11:16:11 -0700 | [diff] [blame] | 57 | virtual status_t dump(int fd, const Vector<String16>& args) const; |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 58 | |
| 59 | private: |
James Dong | b00e246 | 2010-04-26 17:48:26 -0700 | [diff] [blame] | 60 | enum CameraFlags { |
| 61 | FLAGS_SET_CAMERA = 1L << 0, |
| 62 | FLAGS_HOT_CAMERA = 1L << 1, |
| 63 | }; |
| 64 | |
| 65 | sp<Camera> mCamera; |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 66 | sp<ISurface> mPreviewSurface; |
James Dong | fe1bafe | 2010-06-25 17:06:47 -0700 | [diff] [blame] | 67 | sp<IMediaRecorderClient> mListener; |
Andreas Huber | 996dddf | 2010-01-25 15:30:31 -0800 | [diff] [blame] | 68 | sp<MediaWriter> mWriter; |
James Dong | 57e7f83 | 2010-06-24 19:55:31 -0700 | [diff] [blame] | 69 | sp<AudioSource> mAudioSourceNode; |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 70 | |
| 71 | audio_source mAudioSource; |
| 72 | video_source mVideoSource; |
| 73 | output_format mOutputFormat; |
| 74 | audio_encoder mAudioEncoder; |
| 75 | video_encoder mVideoEncoder; |
James Dong | 6feaa46 | 2010-06-20 08:20:54 -0700 | [diff] [blame] | 76 | bool mUse64BitFileOffset; |
James Dong | abed93a | 2010-04-22 17:27:04 -0700 | [diff] [blame] | 77 | int32_t mVideoWidth, mVideoHeight; |
| 78 | int32_t mFrameRate; |
| 79 | int32_t mVideoBitRate; |
| 80 | int32_t mAudioBitRate; |
| 81 | int32_t mAudioChannels; |
| 82 | int32_t mSampleRate; |
James Dong | 3300e96 | 2010-04-21 16:14:15 -0700 | [diff] [blame] | 83 | int32_t mInterleaveDurationUs; |
James Dong | 52d13f0 | 2010-07-02 11:39:06 -0700 | [diff] [blame] | 84 | int32_t mIFramesIntervalSec; |
James Dong | 09936ed | 2010-06-24 19:04:27 -0700 | [diff] [blame] | 85 | int32_t mCameraId; |
James Dong | 81c929a | 2010-07-01 15:02:14 -0700 | [diff] [blame] | 86 | int32_t mVideoEncoderProfile; |
| 87 | int32_t mVideoEncoderLevel; |
James Dong | 52d13f0 | 2010-07-02 11:39:06 -0700 | [diff] [blame] | 88 | int32_t mMovieTimeScale; |
| 89 | int32_t mVideoTimeScale; |
| 90 | int32_t mAudioTimeScale; |
James Dong | 2cd841d | 2010-05-11 11:46:59 -0700 | [diff] [blame] | 91 | int64_t mMaxFileSizeBytes; |
| 92 | int64_t mMaxFileDurationUs; |
James Dong | 09936ed | 2010-06-24 19:04:27 -0700 | [diff] [blame] | 93 | int64_t mTrackEveryTimeDurationUs; |
James Dong | abed93a | 2010-04-22 17:27:04 -0700 | [diff] [blame] | 94 | |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 95 | String8 mParams; |
| 96 | int mOutputFd; |
James Dong | b00e246 | 2010-04-26 17:48:26 -0700 | [diff] [blame] | 97 | int32_t mFlags; |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 98 | |
James Dong | 42a18c0 | 2010-06-16 17:27:46 -0700 | [diff] [blame] | 99 | MediaProfiles *mEncoderProfiles; |
| 100 | |
Andreas Huber | 996dddf | 2010-01-25 15:30:31 -0800 | [diff] [blame] | 101 | status_t startMPEG4Recording(); |
| 102 | status_t startAMRRecording(); |
James Dong | 2cd841d | 2010-05-11 11:46:59 -0700 | [diff] [blame] | 103 | status_t startAACRecording(); |
Andreas Huber | 57648e4 | 2010-08-04 10:14:30 -0700 | [diff] [blame] | 104 | status_t startRTPRecording(); |
James Dong | abed93a | 2010-04-22 17:27:04 -0700 | [diff] [blame] | 105 | sp<MediaSource> createAudioSource(); |
James Dong | 7b06de6 | 2010-06-30 12:41:16 -0700 | [diff] [blame] | 106 | status_t setupCameraSource(); |
| 107 | status_t setupAudioEncoder(const sp<MediaWriter>& writer); |
Andreas Huber | 57648e4 | 2010-08-04 10:14:30 -0700 | [diff] [blame] | 108 | status_t setupVideoEncoder(sp<MediaSource> *source); |
James Dong | 7b06de6 | 2010-06-30 12:41:16 -0700 | [diff] [blame] | 109 | |
| 110 | // Encoding parameter handling utilities |
James Dong | abed93a | 2010-04-22 17:27:04 -0700 | [diff] [blame] | 111 | status_t setParameter(const String8 &key, const String8 &value); |
James Dong | abed93a | 2010-04-22 17:27:04 -0700 | [diff] [blame] | 112 | status_t setParamAudioEncodingBitRate(int32_t bitRate); |
| 113 | status_t setParamAudioNumberOfChannels(int32_t channles); |
| 114 | status_t setParamAudioSamplingRate(int32_t sampleRate); |
James Dong | 52d13f0 | 2010-07-02 11:39:06 -0700 | [diff] [blame] | 115 | status_t setParamAudioTimeScale(int32_t timeScale); |
James Dong | 09936ed | 2010-06-24 19:04:27 -0700 | [diff] [blame] | 116 | status_t setParamVideoEncodingBitRate(int32_t bitRate); |
James Dong | 52d13f0 | 2010-07-02 11:39:06 -0700 | [diff] [blame] | 117 | status_t setParamVideoIFramesInterval(int32_t seconds); |
James Dong | 81c929a | 2010-07-01 15:02:14 -0700 | [diff] [blame] | 118 | status_t setParamVideoEncoderProfile(int32_t profile); |
| 119 | status_t setParamVideoEncoderLevel(int32_t level); |
James Dong | 09936ed | 2010-06-24 19:04:27 -0700 | [diff] [blame] | 120 | status_t setParamVideoCameraId(int32_t cameraId); |
James Dong | 52d13f0 | 2010-07-02 11:39:06 -0700 | [diff] [blame] | 121 | status_t setParamVideoTimeScale(int32_t timeScale); |
James Dong | 09936ed | 2010-06-24 19:04:27 -0700 | [diff] [blame] | 122 | status_t setParamTrackTimeStatus(int64_t timeDurationUs); |
James Dong | 3300e96 | 2010-04-21 16:14:15 -0700 | [diff] [blame] | 123 | status_t setParamInterleaveDuration(int32_t durationUs); |
James Dong | 6feaa46 | 2010-06-20 08:20:54 -0700 | [diff] [blame] | 124 | status_t setParam64BitFileOffset(bool use64BitFileOffset); |
James Dong | 7b06de6 | 2010-06-30 12:41:16 -0700 | [diff] [blame] | 125 | status_t setParamMaxFileDurationUs(int64_t timeUs); |
| 126 | status_t setParamMaxFileSizeBytes(int64_t bytes); |
James Dong | 52d13f0 | 2010-07-02 11:39:06 -0700 | [diff] [blame] | 127 | status_t setParamMovieTimeScale(int32_t timeScale); |
James Dong | 42a18c0 | 2010-06-16 17:27:46 -0700 | [diff] [blame] | 128 | void clipVideoBitRate(); |
| 129 | void clipVideoFrameRate(); |
| 130 | void clipVideoFrameWidth(); |
| 131 | void clipVideoFrameHeight(); |
Andreas Huber | 996dddf | 2010-01-25 15:30:31 -0800 | [diff] [blame] | 132 | |
Andreas Huber | ea6a38c | 2009-11-16 15:43:38 -0800 | [diff] [blame] | 133 | StagefrightRecorder(const StagefrightRecorder &); |
| 134 | StagefrightRecorder &operator=(const StagefrightRecorder &); |
| 135 | }; |
| 136 | |
| 137 | } // namespace android |
| 138 | |
| 139 | #endif // STAGEFRIGHT_RECORDER_H_ |
| 140 | |