AudioStreamRecord.h revision 3316d5e6d375a4f09c681205e9094d30a0bfc4a2
1/* 2 * Copyright 2016 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 LEGACY_AUDIO_STREAM_RECORD_H 18#define LEGACY_AUDIO_STREAM_RECORD_H 19 20#include <media/AudioRecord.h> 21#include <aaudio/AAudio.h> 22 23#include "AudioStreamBuilder.h" 24#include "AudioStream.h" 25#include "AAudioLegacy.h" 26 27namespace aaudio { 28 29/** 30 * Internal stream that uses the legacy AudioTrack path. 31 */ 32class AudioStreamRecord : public AudioStream { 33public: 34 AudioStreamRecord(); 35 36 virtual ~AudioStreamRecord(); 37 38 virtual aaudio_result_t open(const AudioStreamBuilder & builder) override; 39 virtual aaudio_result_t close() override; 40 41 virtual aaudio_result_t requestStart() override; 42 virtual aaudio_result_t requestPause() override; 43 virtual aaudio_result_t requestFlush() override; 44 virtual aaudio_result_t requestStop() override; 45 46 virtual aaudio_result_t getTimestamp(clockid_t clockId, 47 int64_t *framePosition, 48 int64_t *timeNanoseconds) override { 49 return AAUDIO_ERROR_UNIMPLEMENTED; // TODO 50 } 51 52 virtual aaudio_result_t read(void *buffer, 53 int32_t numFrames, 54 int64_t timeoutNanoseconds) override; 55 56 virtual aaudio_result_t setBufferSize(int32_t requestedFrames) override; 57 58 virtual int32_t getBufferSize() const override; 59 60 virtual int32_t getBufferCapacity() const override; 61 62 virtual int32_t getXRunCount() const override; 63 64 virtual int32_t getFramesPerBurst() const override; 65 66 virtual aaudio_result_t updateState() override; 67 68private: 69 android::sp<android::AudioRecord> mAudioRecord; 70 // TODO add 64-bit position reporting to AudioRecord and use it. 71 aaudio_wrapping_frames_t mPositionWhenStarting = 0; 72 android::String16 mOpPackageName; 73}; 74 75} /* namespace aaudio */ 76 77#endif /* LEGACY_AUDIO_STREAM_RECORD_H */ 78