blob: d81c0642e216134b001605fe182d235a726bd150 [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
Phil Burk23d89972015-04-06 16:22:23 -070041 SpdifStreamOut(AudioHwDevice *dev, audio_output_flags_t flags,
42 audio_format_t format);
Phil Burk062e67a2015-02-11 13:40:50 -080043
44 virtual ~SpdifStreamOut() { }
45
46 virtual status_t open(
47 audio_io_handle_t handle,
48 audio_devices_t devices,
49 struct audio_config *config,
50 const char *address);
51
52 virtual status_t getRenderPosition(uint32_t *frames);
53
54 virtual status_t getPresentationPosition(uint64_t *frames, struct timespec *timestamp);
55
56 /**
57 * Write audio buffer to driver. Returns number of bytes written, or a
58 * negative status_t. If at least one frame was written successfully prior to the error,
59 * it is suggested that the driver return that successful (short) byte count
60 * and then return an error in the subsequent call.
61 *
62 * If set_callback() has previously been called to enable non-blocking mode
63 * the write() is not allowed to block. It must write only the number of
64 * bytes that currently fit in the driver/hardware buffer and then return
65 * this byte count. If this is less than the requested write size the
66 * callback function must be called when more space is available in the
67 * driver/hardware buffer.
68 */
69 virtual ssize_t write(const void* buffer, size_t bytes);
70
71 virtual size_t getFrameSize();
72
73 virtual status_t flush();
74 virtual status_t standby();
75
76private:
77
78 class MySPDIFEncoder : public SPDIFEncoder
79 {
80 public:
Phil Burk23d89972015-04-06 16:22:23 -070081 MySPDIFEncoder(SpdifStreamOut *spdifStreamOut, audio_format_t format)
82 : SPDIFEncoder(format)
83 , mSpdifStreamOut(spdifStreamOut)
Phil Burk062e67a2015-02-11 13:40:50 -080084 {
85 }
86
87 virtual ssize_t writeOutput(const void* buffer, size_t bytes)
88 {
89 return mSpdifStreamOut->writeDataBurst(buffer, bytes);
90 }
91 protected:
92 SpdifStreamOut * const mSpdifStreamOut;
93 };
94
95 int mRateMultiplier;
96 MySPDIFEncoder mSpdifEncoder;
97
98 // Used to implement getRenderPosition()
99 int64_t mRenderPositionHal;
100 uint32_t mPreviousHalPosition32;
101
102 ssize_t writeDataBurst(const void* data, size_t bytes);
103 ssize_t writeInternal(const void* buffer, size_t bytes);
104
105};
106
107} // namespace android
108
109#endif // ANDROID_SPDIF_STREAM_OUT_H