blob: d5a3ede22b082f591be128446cb93f64ee5a5b20 [file] [log] [blame]
Phil Burke4d7bb42017-03-28 11:32:39 -07001/*
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_LEGACY_H
18#define LEGACY_AUDIO_STREAM_LEGACY_H
19
20
21#include <aaudio/AAudio.h>
22
23#include "AudioStream.h"
24#include "AAudioLegacy.h"
25#include "utility/FixedBlockAdapter.h"
26
27namespace aaudio {
28
29
30typedef void (*aaudio_legacy_callback_t)(int event, void* user, void *info);
31
32enum {
33 /**
34 * Request that the callback function should fill the data buffer of an output stream,
35 * or process the data of an input stream.
36 * The address parameter passed to the callback function will point to a data buffer.
37 * For an input stream, the data is read-only.
38 * The value1 parameter will be the number of frames.
39 * The value2 parameter is reserved and will be set to zero.
40 * The callback should return AAUDIO_CALLBACK_RESULT_CONTINUE or AAUDIO_CALLBACK_RESULT_STOP.
41 */
42 AAUDIO_CALLBACK_OPERATION_PROCESS_DATA,
43
44 /**
45 * Inform the callback function that the stream was disconnected.
46 * The address parameter passed to the callback function will be NULL.
47 * The value1 will be an error code or AAUDIO_OK.
48 * The value2 parameter is reserved and will be set to zero.
49 * The callback return value will be ignored.
50 */
51 AAUDIO_CALLBACK_OPERATION_DISCONNECTED,
52};
53typedef int32_t aaudio_callback_operation_t;
54
55
56class AudioStreamLegacy : public AudioStream, public FixedBlockProcessor {
57public:
58 AudioStreamLegacy();
59
60 virtual ~AudioStreamLegacy();
61
62 aaudio_legacy_callback_t getLegacyCallback();
63
64 // This is public so it can be called from the C callback function.
65 // This is called from the AudioTrack/AudioRecord client.
66 virtual void processCallback(int event, void *info) = 0;
67
68 void processCallbackCommon(aaudio_callback_operation_t opcode, void *info);
69
70 // Implement FixedBlockProcessor
71 int32_t onProcessFixedBlock(uint8_t *buffer, int32_t numBytes) override;
72
Phil Burk4c5129b2017-04-28 15:17:32 -070073 virtual int64_t incrementClientFrameCounter(int32_t frames) = 0;
74
Phil Burke4d7bb42017-03-28 11:32:39 -070075protected:
76 FixedBlockAdapter *mBlockAdapter = nullptr;
77 aaudio_wrapping_frames_t mPositionWhenStarting = 0;
78 int32_t mCallbackBufferSize = 0;
79};
80
81} /* namespace aaudio */
82
83#endif //LEGACY_AUDIO_STREAM_LEGACY_H