blob: cb82ac7a6c92768a9db6d7a63193218e9f9f932f [file] [log] [blame]
Phil Burk062e67a2015-02-11 13:40:50 -08001/*
2**
3** Copyright 2015, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef ANDROID_SPDIF_STREAM_OUT_H
19#define ANDROID_SPDIF_STREAM_OUT_H
20
21#include <stdint.h>
22#include <sys/types.h>
23
24#include <system/audio.h>
25
26#include "AudioHwDevice.h"
27#include "AudioStreamOut.h"
28#include "SpdifStreamOut.h"
29
30#include <audio_utils/spdif/SPDIFEncoder.h>
31
32namespace android {
33
34/**
35 * Stream that is a PCM data burst in the HAL but looks like an encoded stream
36 * to the AudioFlinger. Wraps encoded data in an SPDIF wrapper per IEC61973-3.
37 */
38class SpdifStreamOut : public AudioStreamOut {
39public:
40
41 SpdifStreamOut(AudioHwDevice *dev, audio_output_flags_t flags);
42
43 virtual ~SpdifStreamOut() { }
44
45 virtual status_t open(
46 audio_io_handle_t handle,
47 audio_devices_t devices,
48 struct audio_config *config,
49 const char *address);
50
51 virtual status_t getRenderPosition(uint32_t *frames);
52
53 virtual status_t getPresentationPosition(uint64_t *frames, struct timespec *timestamp);
54
55 /**
56 * Write audio buffer to driver. Returns number of bytes written, or a
57 * negative status_t. If at least one frame was written successfully prior to the error,
58 * it is suggested that the driver return that successful (short) byte count
59 * and then return an error in the subsequent call.
60 *
61 * If set_callback() has previously been called to enable non-blocking mode
62 * the write() is not allowed to block. It must write only the number of
63 * bytes that currently fit in the driver/hardware buffer and then return
64 * this byte count. If this is less than the requested write size the
65 * callback function must be called when more space is available in the
66 * driver/hardware buffer.
67 */
68 virtual ssize_t write(const void* buffer, size_t bytes);
69
70 virtual size_t getFrameSize();
71
72 virtual status_t flush();
73 virtual status_t standby();
74
75private:
76
77 class MySPDIFEncoder : public SPDIFEncoder
78 {
79 public:
80 MySPDIFEncoder(SpdifStreamOut *spdifStreamOut)
81 : mSpdifStreamOut(spdifStreamOut)
82 {
83 }
84
85 virtual ssize_t writeOutput(const void* buffer, size_t bytes)
86 {
87 return mSpdifStreamOut->writeDataBurst(buffer, bytes);
88 }
89 protected:
90 SpdifStreamOut * const mSpdifStreamOut;
91 };
92
93 int mRateMultiplier;
94 MySPDIFEncoder mSpdifEncoder;
95
96 // Used to implement getRenderPosition()
97 int64_t mRenderPositionHal;
98 uint32_t mPreviousHalPosition32;
99
100 ssize_t writeDataBurst(const void* data, size_t bytes);
101 ssize_t writeInternal(const void* buffer, size_t bytes);
102
103};
104
105} // namespace android
106
107#endif // ANDROID_SPDIF_STREAM_OUT_H