blob: 94878e06c579e12fd52b0e7b26926394a1cebe0c
1 | //#define LOG_NDEBUG 0 |
2 | #define LOG_TAG "AudioSPDIF-wrap" |
3 | #include <stdint.h> |
4 | #include <utils/Log.h> |
5 | #include <system/audio.h> |
6 | #include <audio_utils/spdif/SPDIFEncoder.h> |
7 | #include <tinyalsa/asoundlib.h> |
8 | #include <cutils/properties.h> |
9 | |
10 | extern "C" |
11 | { |
12 | #include "audio_hw_utils.h" |
13 | } |
14 | |
15 | namespace android |
16 | { |
17 | class MySPDIFEncoder : public SPDIFEncoder |
18 | { |
19 | public: |
20 | MySPDIFEncoder(struct pcm *mypcm, audio_format_t format) |
21 | : SPDIFEncoder(format), |
22 | pcm_handle(mypcm), mTotalBytes(0), eac3_frame(0), mformat(format) |
23 | {}; |
24 | virtual ssize_t writeOutput(const void* buffer, size_t bytes) |
25 | { |
26 | int ret = -1; |
27 | ALOGV("write size %zu \n", bytes); |
28 | #if 1 |
29 | if (getprop_bool("media.spdif.outdump")) { |
30 | FILE *fp1 = fopen("/data/tmp/hdmi_audio_out.spdif", "a+"); |
31 | if (fp1) { |
32 | int flen = fwrite((char *)buffer, 1, bytes, fp1); |
33 | //LOGFUNC("flen = %d---outlen=%d ", flen, out_frames * frame_size); |
34 | fclose(fp1); |
35 | } else { |
36 | //LOGFUNC("could not open file:/data/hdmi_audio_out.pcm"); |
37 | } |
38 | } |
39 | #endif |
40 | mTotalBytes += bytes; |
41 | ret = pcm_write(pcm_handle, buffer, bytes); |
42 | if (ret) |
43 | return ret; |
44 | |
45 | return bytes; |
46 | } |
47 | virtual uint64_t total_bytes() |
48 | { |
49 | return mTotalBytes; |
50 | } |
51 | protected: |
52 | struct pcm *pcm_handle; |
53 | private: |
54 | uint64_t mTotalBytes; |
55 | uint64_t eac3_frame; |
56 | audio_format_t mformat; |
57 | }; |
58 | static MySPDIFEncoder *myencoder = NULL; |
59 | extern "C" int spdifenc_init(struct pcm *mypcm, audio_format_t format) |
60 | { |
61 | if (myencoder) { |
62 | delete myencoder; |
63 | myencoder = NULL; |
64 | } |
65 | myencoder = new MySPDIFEncoder(mypcm, format); |
66 | if (myencoder == NULL) { |
67 | ALOGE("init SPDIFEncoder failed \n"); |
68 | return -1; |
69 | } |
70 | ALOGI("init SPDIFEncoder done\n"); |
71 | return 0; |
72 | } |
73 | extern "C" int spdifenc_write(const void *buffer, size_t numBytes) |
74 | { |
75 | return myencoder->write(buffer, numBytes); |
76 | } |
77 | extern "C" uint64_t spdifenc_get_total() |
78 | { |
79 | return myencoder->total_bytes(); |
80 | } |
81 | } |
82 |