1 /* Copyright 2017 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #include <time.h>
7 #include <unordered_map>
8 
9 extern "C" {
10 #include "cras_iodev.h"
11 }
12 
13 namespace {
14   struct cb_data {
15     int frames_queued_ret;
16     timespec frames_queued_ts;
17   };
18   std::unordered_map<cras_iodev*, cb_data> data_map;
19 } // namespace
20 
iodev_stub_reset()21 void iodev_stub_reset() {
22   data_map.clear();
23 }
24 
iodev_stub_frames_queued(cras_iodev * iodev,int ret,timespec ts)25 void iodev_stub_frames_queued(cras_iodev* iodev, int ret, timespec ts) {
26   cb_data data = { ret, ts };
27   data_map.insert({iodev, data});
28 }
29 
30 extern "C" {
31 
cras_iodev_get_est_rate_ratio(const struct cras_iodev * iodev)32 double cras_iodev_get_est_rate_ratio(const struct cras_iodev *iodev) {
33   return 48000.0;
34 }
35 
cras_iodev_get_dsp_delay(const struct cras_iodev * iodev)36 int cras_iodev_get_dsp_delay(const struct cras_iodev *iodev) {
37   return 0;
38 }
39 
cras_iodev_frames_queued(struct cras_iodev * iodev,struct timespec * tstamp)40 int cras_iodev_frames_queued(struct cras_iodev *iodev,
41                              struct timespec *tstamp) {
42   auto elem = data_map.find(iodev);
43   if (elem != data_map.end()) {
44     *tstamp = elem->second.frames_queued_ts;
45     return elem->second.frames_queued_ret;
46   }
47   clock_gettime(CLOCK_MONOTONIC_RAW, tstamp);
48   return 0;
49 }
50 
cras_iodev_rm_stream(struct cras_iodev * iodev,const struct cras_rstream * stream)51 struct dev_stream *cras_iodev_rm_stream(struct cras_iodev *iodev,
52                                         const struct cras_rstream *stream) {
53   return NULL;
54 }
55 
cras_iodev_update_rate(struct cras_iodev * iodev,unsigned int level,struct timespec * level_tstamp)56 int cras_iodev_update_rate(struct cras_iodev *iodev, unsigned int level,
57                            struct timespec *level_tstamp) {
58   return 0;
59 }
60 
cras_iodev_state(const struct cras_iodev * iodev)61 enum CRAS_IODEV_STATE cras_iodev_state(const struct cras_iodev *iodev) {
62   return CRAS_IODEV_STATE_OPEN;
63 }
64 
cras_iodev_all_streams_written(struct cras_iodev * iodev)65 unsigned int cras_iodev_all_streams_written(struct cras_iodev *iodev) {
66   return 0;
67 }
68 
cras_iodev_put_input_buffer(struct cras_iodev * iodev)69 int cras_iodev_put_input_buffer(struct cras_iodev *iodev) {
70   return 0;
71 }
72 
cras_iodev_put_output_buffer(struct cras_iodev * iodev,uint8_t * frames,unsigned int nframes,int * non_empty,struct cras_fmt_conv * output_converter)73 int cras_iodev_put_output_buffer(struct cras_iodev *iodev, uint8_t *frames,
74                                  unsigned int nframes, int* non_empty,
75                                  struct cras_fmt_conv *output_converter) {
76   return 0;
77 }
78 
cras_iodev_get_input_buffer(struct cras_iodev * iodev,unsigned * frames)79 int cras_iodev_get_input_buffer(struct cras_iodev *iodev,
80                                 unsigned *frames) {
81   return 0;
82 }
83 
cras_iodev_get_output_buffer(struct cras_iodev * iodev,struct cras_audio_area ** area,unsigned * frames)84 int cras_iodev_get_output_buffer(struct cras_iodev *iodev,
85                                  struct cras_audio_area **area,
86                                  unsigned *frames) {
87   return 0;
88 }
89 
cras_iodev_get_software_gain_scaler(const struct cras_iodev * iodev)90 float cras_iodev_get_software_gain_scaler(const struct cras_iodev *iodev) {
91   return 0.0;
92 }
93 
cras_iodev_stream_written(struct cras_iodev * iodev,struct dev_stream * stream,unsigned int nwritten)94 void cras_iodev_stream_written(struct cras_iodev *iodev,
95                                struct dev_stream *stream,
96                                unsigned int nwritten) {
97 }
98 
cras_iodev_prepare_output_before_write_samples(struct cras_iodev * odev)99 int cras_iodev_prepare_output_before_write_samples(struct cras_iodev *odev)
100 { return 0;
101 }
102 
cras_iodev_buffer_avail(struct cras_iodev * iodev,unsigned hw_level)103 int cras_iodev_buffer_avail(struct cras_iodev *iodev, unsigned hw_level) {
104   return 0;
105 }
106 
cras_iodev_max_stream_offset(const struct cras_iodev * iodev)107 unsigned int cras_iodev_max_stream_offset(const struct cras_iodev *iodev) {
108   return 0;
109 }
110 
cras_iodev_odev_should_wake(const struct cras_iodev * odev)111 int cras_iodev_odev_should_wake(const struct cras_iodev *odev)
112 {
113   return 1;
114 }
115 
cras_iodev_output_underrun(struct cras_iodev * odev)116 int cras_iodev_output_underrun(struct cras_iodev *odev) {
117   return 0;
118 }
119 
cras_iodev_reset_request(struct cras_iodev * iodev)120 int cras_iodev_reset_request(struct cras_iodev* iodev) {
121   return 0;
122 }
123 
cras_iodev_stream_offset(struct cras_iodev * iodev,struct dev_stream * stream)124 unsigned int cras_iodev_stream_offset(struct cras_iodev *iodev,
125                                       struct dev_stream *stream) {
126   return 0;
127 }
128 
cras_iodev_get_num_underruns(const struct cras_iodev * iodev)129 unsigned int cras_iodev_get_num_underruns(const struct cras_iodev *iodev)
130 {
131   return 0;
132 }
133 
cras_iodev_frames_to_play_in_sleep(struct cras_iodev * odev,unsigned int * hw_level,struct timespec * hw_tstamp)134 unsigned int cras_iodev_frames_to_play_in_sleep(struct cras_iodev *odev,
135                                                 unsigned int *hw_level,
136                                                 struct timespec *hw_tstamp)
137 {
138   clock_gettime(CLOCK_MONOTONIC_RAW, hw_tstamp);
139   *hw_level = 0;
140   return 0;
141 }
142 
cras_iodev_update_highest_hw_level(struct cras_iodev * iodev,unsigned int hw_level)143 void cras_iodev_update_highest_hw_level(struct cras_iodev *iodev,
144 		unsigned int hw_level)
145 {
146 }
147 
148 } // extern "C"
149