• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <stdint.h>
6 #include <stdio.h>
7 #include <time.h>
8 
9 #include <memory>
10 
11 extern "C" {
12 #include "cras_iodev.h"
13 #include "cras_rstream.h"
14 #include "cras_shm.h"
15 #include "cras_types.h"
16 #include "dev_io.h"
17 #include "dev_stream.h"
18 #include "utlist.h"
19 }
20 
21 #include "iodev_stub.h"
22 #include "rstream_stub.h"
23 
24 #define RSTREAM_FAKE_POLL_FD 33
25 
26 using DevStreamPtr = std::unique_ptr<dev_stream, decltype(free)*>;
27 using IodevPtr = std::unique_ptr<cras_iodev, decltype(free)*>;
28 using IonodePtr = std::unique_ptr<cras_ionode, decltype(free)*>;
29 using OpendevPtr = std::unique_ptr<open_dev, decltype(free)*>;
30 using RstreamPtr = std::unique_ptr<cras_rstream, decltype(free)*>;
31 
32 void destroy_shm(struct cras_audio_shm* shm);
33 using ShmPtr = std::unique_ptr<cras_audio_shm, decltype(destroy_shm)*>;
34 ShmPtr create_shm(size_t cb_threshold);
35 
36 // Holds the rstream and devstream pointers for an attached stream.
37 struct Stream {
StreamStream38   Stream(ShmPtr shm, RstreamPtr rstream, DevStreamPtr dstream)
39       : shm(std::move(shm)),
40         rstream(std::move(rstream)),
41         dstream(std::move(dstream)) {}
42   ShmPtr shm;
43   RstreamPtr rstream;
44   DevStreamPtr dstream;
45 };
46 using StreamPtr = std::unique_ptr<Stream>;
47 
48 // Holds the iodev and ionode pointers for an attached device.
49 struct Device {
DeviceDevice50   Device(IodevPtr dev, IonodePtr node, OpendevPtr odev)
51       : dev(std::move(dev)), node(std::move(node)), odev(std::move(odev)) {}
52   IodevPtr dev;
53   IonodePtr node;
54   OpendevPtr odev;
55 };
56 using DevicePtr = std::unique_ptr<Device>;
57 
58 RstreamPtr create_rstream(cras_stream_id_t id,
59                           CRAS_STREAM_DIRECTION direction,
60                           size_t cb_threshold,
61                           const cras_audio_format* format,
62                           cras_audio_shm* shm);
63 DevStreamPtr create_dev_stream(unsigned int dev_id, cras_rstream* rstream);
64 StreamPtr create_stream(cras_stream_id_t id,
65                         unsigned int dev_id,
66                         CRAS_STREAM_DIRECTION direction,
67                         size_t cb_threshold,
68                         const cras_audio_format* format);
69 void AddFakeDataToStream(Stream* stream, unsigned int frames);
70 int delay_frames_stub(const struct cras_iodev* iodev);
71 IonodePtr create_ionode(CRAS_NODE_TYPE type);
72 IodevPtr create_open_iodev(CRAS_STREAM_DIRECTION direction,
73                            size_t cb_threshold,
74                            cras_audio_format* format,
75                            cras_ionode* active_node);
76 DevicePtr create_device(CRAS_STREAM_DIRECTION direction,
77                         size_t cb_threshold,
78                         cras_audio_format* format,
79                         CRAS_NODE_TYPE active_node_type);
80 void add_stream_to_dev(IodevPtr& dev, const StreamPtr& stream);
81 void fill_audio_format(cras_audio_format* format, unsigned int rate);
82