blob: a61a7bd555ecf9aae93387a2f33600e9e347e7fe [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
Phil Burk062e67a2015-02-11 13:40:50 -080052 /**
53 * Write audio buffer to driver. Returns number of bytes written, or a
54 * negative status_t. If at least one frame was written successfully prior to the error,
55 * it is suggested that the driver return that successful (short) byte count
56 * and then return an error in the subsequent call.
57 *
58 * If set_callback() has previously been called to enable non-blocking mode
59 * the write() is not allowed to block. It must write only the number of
60 * bytes that currently fit in the driver/hardware buffer and then return
61 * this byte count. If this is less than the requested write size the
62 * callback function must be called when more space is available in the
63 * driver/hardware buffer.
64 */
65 virtual ssize_t write(const void* buffer, size_t bytes);
66
67 virtual size_t getFrameSize();
68
69 virtual status_t flush();
70 virtual status_t standby();
71
72private:
73
74 class MySPDIFEncoder : public SPDIFEncoder
75 {
76 public:
Phil Burk23d89972015-04-06 16:22:23 -070077 MySPDIFEncoder(SpdifStreamOut *spdifStreamOut, audio_format_t format)
78 : SPDIFEncoder(format)
79 , mSpdifStreamOut(spdifStreamOut)
Phil Burk062e67a2015-02-11 13:40:50 -080080 {
81 }
82
83 virtual ssize_t writeOutput(const void* buffer, size_t bytes)
84 {
85 return mSpdifStreamOut->writeDataBurst(buffer, bytes);
86 }
87 protected:
88 SpdifStreamOut * const mSpdifStreamOut;
89 };
90
Phil Burk062e67a2015-02-11 13:40:50 -080091 MySPDIFEncoder mSpdifEncoder;
92
Phil Burk062e67a2015-02-11 13:40:50 -080093 ssize_t writeDataBurst(const void* data, size_t bytes);
94 ssize_t writeInternal(const void* buffer, size_t bytes);
95
96};
97
98} // namespace android
99
100#endif // ANDROID_SPDIF_STREAM_OUT_H