blob: 38f1a566a2d1a7557c5c7a828af326a9e7768b85 [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
Phil Burk5204d312017-05-04 17:16:13 -070020#include <media/AudioTimestamp.h>
Phil Burke4d7bb42017-03-28 11:32:39 -070021
22#include <aaudio/AAudio.h>
23
24#include "AudioStream.h"
25#include "AAudioLegacy.h"
26#include "utility/FixedBlockAdapter.h"
27
28namespace aaudio {
29
30
31typedef void (*aaudio_legacy_callback_t)(int event, void* user, void *info);
32
33enum {
34 /**
35 * Request that the callback function should fill the data buffer of an output stream,
36 * or process the data of an input stream.
37 * The address parameter passed to the callback function will point to a data buffer.
38 * For an input stream, the data is read-only.
39 * The value1 parameter will be the number of frames.
40 * The value2 parameter is reserved and will be set to zero.
41 * The callback should return AAUDIO_CALLBACK_RESULT_CONTINUE or AAUDIO_CALLBACK_RESULT_STOP.
42 */
43 AAUDIO_CALLBACK_OPERATION_PROCESS_DATA,
44
45 /**
46 * Inform the callback function that the stream was disconnected.
47 * The address parameter passed to the callback function will be NULL.
48 * The value1 will be an error code or AAUDIO_OK.
49 * The value2 parameter is reserved and will be set to zero.
50 * The callback return value will be ignored.
51 */
52 AAUDIO_CALLBACK_OPERATION_DISCONNECTED,
53};
54typedef int32_t aaudio_callback_operation_t;
55
56
57class AudioStreamLegacy : public AudioStream, public FixedBlockProcessor {
58public:
59 AudioStreamLegacy();
60
61 virtual ~AudioStreamLegacy();
62
63 aaudio_legacy_callback_t getLegacyCallback();
64
65 // This is public so it can be called from the C callback function.
66 // This is called from the AudioTrack/AudioRecord client.
67 virtual void processCallback(int event, void *info) = 0;
68
69 void processCallbackCommon(aaudio_callback_operation_t opcode, void *info);
70
71 // Implement FixedBlockProcessor
72 int32_t onProcessFixedBlock(uint8_t *buffer, int32_t numBytes) override;
73
Phil Burk4c5129b2017-04-28 15:17:32 -070074 virtual int64_t incrementClientFrameCounter(int32_t frames) = 0;
75
Phil Burke4d7bb42017-03-28 11:32:39 -070076protected:
Phil Burk5204d312017-05-04 17:16:13 -070077
78 aaudio_result_t getBestTimestamp(clockid_t clockId,
79 int64_t *framePosition,
80 int64_t *timeNanoseconds,
81 android::ExtendedTimestamp *extendedTimestamp);
82
Phil Burke4d7bb42017-03-28 11:32:39 -070083 FixedBlockAdapter *mBlockAdapter = nullptr;
84 aaudio_wrapping_frames_t mPositionWhenStarting = 0;
85 int32_t mCallbackBufferSize = 0;
86};
87
88} /* namespace aaudio */
89
90#endif //LEGACY_AUDIO_STREAM_LEGACY_H