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