summaryrefslogtreecommitdiff
path: root/spdifenc_wrap.cpp (plain)
blob: 9eb9a8ae8da985b393e6971698ac728c2f060dce
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
10extern "C"
11{
12#include "audio_hw_utils.h"
13}
14#if 0
15static int
16getprop_bool(const char *path)
17{
18 char buf[PROPERTY_VALUE_MAX];
19 int ret = -1;
20 ret = property_get(path, buf, NULL);
21 if (ret > 0) {
22 if (strcasecmp(buf, "true") == 0 || strcmp(buf, "1") == 0) {
23 return 1;
24 }
25 }
26 return 0;
27}
28#endif
29extern "C" int getprop_boll(const char *path);
30namespace android
31{
32class MySPDIFEncoder : public SPDIFEncoder
33{
34public:
35 MySPDIFEncoder(struct pcm *mypcm, audio_format_t format)
36 : SPDIFEncoder(format),
37 pcm_handle(mypcm), mTotalBytes(0), eac3_frame(0), mformat(format)
38 {};
39 virtual ssize_t writeOutput(const void* buffer, size_t bytes)
40 {
41 ALOGV("write size %d \n", bytes);
42#if 1
43 if (getprop_bool("media.spdif.outdump")) {
44 FILE *fp1 = fopen("/data/tmp/hdmi_audio_out.spdif", "a+");
45 if (fp1) {
46 int flen = fwrite((char *)buffer, 1, bytes, fp1);
47 //LOGFUNC("flen = %d---outlen=%d ", flen, out_frames * frame_size);
48 fclose(fp1);
49 } else {
50 //LOGFUNC("could not open file:/data/hdmi_audio_out.pcm");
51 }
52 }
53#endif
54 mTotalBytes += bytes;
55 return pcm_write(pcm_handle, buffer, bytes);
56 }
57 virtual uint64_t total_bytes()
58 {
59 return mTotalBytes;
60 }
61protected:
62 struct pcm *pcm_handle;
63private:
64 uint64_t mTotalBytes;
65 uint64_t eac3_frame;
66 audio_format_t mformat;
67};
68static MySPDIFEncoder *myencoder = NULL;
69extern "C" int spdifenc_init(struct pcm *mypcm, audio_format_t format)
70{
71 if (myencoder) {
72 delete myencoder;
73 myencoder = NULL;
74 }
75 myencoder = new MySPDIFEncoder(mypcm, format);
76 if (myencoder == NULL) {
77 ALOGE("init SPDIFEncoder failed \n");
78 return -1;
79 }
80 ALOGI("init SPDIFEncoder done\n");
81 return 0;
82}
83extern "C" int spdifenc_write(const void *buffer, size_t numBytes)
84{
85 return myencoder->write(buffer, numBytes);
86}
87extern "C" uint64_t spdifenc_get_total()
88{
89 return myencoder->total_bytes();
90}
91}
92