AudioSource.h revision f60cafe0e6aad8f9ce54660fa88b651ae4e749e6
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 virtual status_t read( 43 MediaBuffer **buffer, const ReadOptions *options = NULL); 44 45protected: 46 virtual ~AudioSource(); 47 48private: 49 enum { kMaxBufferSize = 2048 }; 50 51 AudioRecord *mRecord; 52 status_t mInitCheck; 53 bool mStarted; 54 55 bool mCollectStats; 56 int64_t mTotalReadTimeUs; 57 int64_t mTotalReadBytes; 58 int64_t mTotalReads; 59 int64_t mStartTimeUs; 60 61 MediaBufferGroup *mGroup; 62 63 AudioSource(const AudioSource &); 64 AudioSource &operator=(const AudioSource &); 65}; 66 67} // namespace android 68 69#endif // AUDIO_SOURCE_H_ 70