blob: 216f6bca124002a0f9cd28537488bfa79e3de646 [file] [log] [blame]
Andreas Huberea6a38c2009-11-16 15:43:38 -08001/*
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
24namespace android {
25
James Dongb00e2462010-04-26 17:48:26 -070026class Camera;
Andreas Huber996dddf2010-01-25 15:30:31 -080027struct MediaSource;
28struct MediaWriter;
James Dong57e7f832010-06-24 19:55:31 -070029struct AudioSource;
James Dong42a18c02010-06-16 17:27:46 -070030class MediaProfiles;
Andreas Huberea6a38c2009-11-16 15:43:38 -080031
32struct 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 Dongfe1bafe2010-06-25 17:06:47 -070049 virtual status_t setListener(const sp<IMediaRecorderClient>& listener);
Andreas Huberea6a38c2009-11-16 15:43:38 -080050 virtual status_t prepare();
51 virtual status_t start();
James Dong08c74732010-06-10 12:28:15 -070052 virtual status_t pause();
Andreas Huberea6a38c2009-11-16 15:43:38 -080053 virtual status_t stop();
54 virtual status_t close();
55 virtual status_t reset();
56 virtual status_t getMaxAmplitude(int *max);
James Dong929642e2010-07-08 11:16:11 -070057 virtual status_t dump(int fd, const Vector<String16>& args) const;
Andreas Huberea6a38c2009-11-16 15:43:38 -080058
59private:
James Dongb00e2462010-04-26 17:48:26 -070060 enum CameraFlags {
61 FLAGS_SET_CAMERA = 1L << 0,
62 FLAGS_HOT_CAMERA = 1L << 1,
63 };
64
65 sp<Camera> mCamera;
Andreas Huberea6a38c2009-11-16 15:43:38 -080066 sp<ISurface> mPreviewSurface;
James Dongfe1bafe2010-06-25 17:06:47 -070067 sp<IMediaRecorderClient> mListener;
Andreas Huber996dddf2010-01-25 15:30:31 -080068 sp<MediaWriter> mWriter;
James Dong57e7f832010-06-24 19:55:31 -070069 sp<AudioSource> mAudioSourceNode;
Andreas Huberea6a38c2009-11-16 15:43:38 -080070
71 audio_source mAudioSource;
72 video_source mVideoSource;
73 output_format mOutputFormat;
74 audio_encoder mAudioEncoder;
75 video_encoder mVideoEncoder;
James Dong6feaa462010-06-20 08:20:54 -070076 bool mUse64BitFileOffset;
James Dongabed93a2010-04-22 17:27:04 -070077 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 Dong3300e962010-04-21 16:14:15 -070083 int32_t mInterleaveDurationUs;
James Dong52d13f02010-07-02 11:39:06 -070084 int32_t mIFramesIntervalSec;
James Dong09936ed2010-06-24 19:04:27 -070085 int32_t mCameraId;
James Dong81c929a2010-07-01 15:02:14 -070086 int32_t mVideoEncoderProfile;
87 int32_t mVideoEncoderLevel;
James Dong52d13f02010-07-02 11:39:06 -070088 int32_t mMovieTimeScale;
89 int32_t mVideoTimeScale;
90 int32_t mAudioTimeScale;
James Dong2cd841d2010-05-11 11:46:59 -070091 int64_t mMaxFileSizeBytes;
92 int64_t mMaxFileDurationUs;
James Dong09936ed2010-06-24 19:04:27 -070093 int64_t mTrackEveryTimeDurationUs;
James Dongabed93a2010-04-22 17:27:04 -070094
Andreas Huberea6a38c2009-11-16 15:43:38 -080095 String8 mParams;
96 int mOutputFd;
James Dongb00e2462010-04-26 17:48:26 -070097 int32_t mFlags;
Andreas Huberea6a38c2009-11-16 15:43:38 -080098
James Dong42a18c02010-06-16 17:27:46 -070099 MediaProfiles *mEncoderProfiles;
100
Andreas Huber996dddf2010-01-25 15:30:31 -0800101 status_t startMPEG4Recording();
102 status_t startAMRRecording();
James Dong2cd841d2010-05-11 11:46:59 -0700103 status_t startAACRecording();
Andreas Huber57648e42010-08-04 10:14:30 -0700104 status_t startRTPRecording();
James Dongabed93a2010-04-22 17:27:04 -0700105 sp<MediaSource> createAudioSource();
James Dong7b06de62010-06-30 12:41:16 -0700106 status_t setupCameraSource();
107 status_t setupAudioEncoder(const sp<MediaWriter>& writer);
Andreas Huber57648e42010-08-04 10:14:30 -0700108 status_t setupVideoEncoder(sp<MediaSource> *source);
James Dong7b06de62010-06-30 12:41:16 -0700109
110 // Encoding parameter handling utilities
James Dongabed93a2010-04-22 17:27:04 -0700111 status_t setParameter(const String8 &key, const String8 &value);
James Dongabed93a2010-04-22 17:27:04 -0700112 status_t setParamAudioEncodingBitRate(int32_t bitRate);
113 status_t setParamAudioNumberOfChannels(int32_t channles);
114 status_t setParamAudioSamplingRate(int32_t sampleRate);
James Dong52d13f02010-07-02 11:39:06 -0700115 status_t setParamAudioTimeScale(int32_t timeScale);
James Dong09936ed2010-06-24 19:04:27 -0700116 status_t setParamVideoEncodingBitRate(int32_t bitRate);
James Dong52d13f02010-07-02 11:39:06 -0700117 status_t setParamVideoIFramesInterval(int32_t seconds);
James Dong81c929a2010-07-01 15:02:14 -0700118 status_t setParamVideoEncoderProfile(int32_t profile);
119 status_t setParamVideoEncoderLevel(int32_t level);
James Dong09936ed2010-06-24 19:04:27 -0700120 status_t setParamVideoCameraId(int32_t cameraId);
James Dong52d13f02010-07-02 11:39:06 -0700121 status_t setParamVideoTimeScale(int32_t timeScale);
James Dong09936ed2010-06-24 19:04:27 -0700122 status_t setParamTrackTimeStatus(int64_t timeDurationUs);
James Dong3300e962010-04-21 16:14:15 -0700123 status_t setParamInterleaveDuration(int32_t durationUs);
James Dong6feaa462010-06-20 08:20:54 -0700124 status_t setParam64BitFileOffset(bool use64BitFileOffset);
James Dong7b06de62010-06-30 12:41:16 -0700125 status_t setParamMaxFileDurationUs(int64_t timeUs);
126 status_t setParamMaxFileSizeBytes(int64_t bytes);
James Dong52d13f02010-07-02 11:39:06 -0700127 status_t setParamMovieTimeScale(int32_t timeScale);
James Dong42a18c02010-06-16 17:27:46 -0700128 void clipVideoBitRate();
129 void clipVideoFrameRate();
130 void clipVideoFrameWidth();
131 void clipVideoFrameHeight();
Andreas Huber996dddf2010-01-25 15:30:31 -0800132
Andreas Huberea6a38c2009-11-16 15:43:38 -0800133 StagefrightRecorder(const StagefrightRecorder &);
134 StagefrightRecorder &operator=(const StagefrightRecorder &);
135};
136
137} // namespace android
138
139#endif // STAGEFRIGHT_RECORDER_H_
140