AudioSource.h revision 46292fb347d72a314d985e34e5e3743d846cb9b6
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 AUDIO_SOURCE_H_ 18 19#define AUDIO_SOURCE_H_ 20 21#include <media/AudioSystem.h> 22#include <media/stagefright/MediaSource.h> 23 24namespace android { 25 26class AudioRecord; 27struct MediaBufferGroup; 28 29struct AudioSource : public MediaSource { 30 // Note that the "channels" parameter is _not_ the number of channels, 31 // but a bitmask of AudioSystem::audio_channels constants. 32 AudioSource( 33 int inputSource, uint32_t sampleRate, 34 uint32_t channels = AudioSystem::CHANNEL_IN_MONO); 35 36 status_t initCheck() const; 37 38 virtual status_t start(MetaData *params = NULL); 39 virtual status_t stop(); 40 virtual sp<MetaData> getFormat(); 41 42 // Returns the maximum amplitude since last call. 43 int16_t getMaxAmplitude(); 44 45 virtual status_t read( 46 MediaBuffer **buffer, const ReadOptions *options = NULL); 47 48protected: 49 virtual ~AudioSource(); 50 51private: 52 enum { kMaxBufferSize = 2048 }; 53 54 AudioRecord *mRecord; 55 status_t mInitCheck; 56 bool mStarted; 57 58 bool mCollectStats; 59 bool mTrackMaxAmplitude; 60 int64_t mStartTimeUs; 61 int16_t mMaxAmplitude; 62 int64_t mPrevSampleTimeUs; 63 int64_t mNumLostFrames; 64 65 MediaBufferGroup *mGroup; 66 67 void trackMaxAmplitude(int16_t *data, int nSamples); 68 69 AudioSource(const AudioSource &); 70 AudioSource &operator=(const AudioSource &); 71}; 72 73} // namespace android 74 75#endif // AUDIO_SOURCE_H_ 76