YARP
Yet Another Robot Platform
AudioPlayerWrapper.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: LGPL-2.1-or-later
4  */
5 
6 #ifndef YARP_DEV_AUDIOPLAYERWRAPPER_H
7 #define YARP_DEV_AUDIOPLAYERWRAPPER_H
8 
9  //#include <list>
10 #include <vector>
11 #include <queue>
12 #include <iostream>
13 #include <string>
14 #include <sstream>
15 
16 #include <yarp/os/Network.h>
17 #include <yarp/os/Port.h>
18 #include <yarp/os/BufferedPort.h>
19 #include <yarp/os/Bottle.h>
20 #include <yarp/os/Time.h>
21 #include <yarp/os/Property.h>
22 
23 #include <yarp/os/PeriodicThread.h>
24 #include <yarp/os/BufferedPort.h>
25 #include <yarp/os/Stamp.h>
26 
27 #include <yarp/sig/Vector.h>
28 
30 #include <yarp/dev/PolyDriver.h>
31 #include <yarp/dev/DeviceDriver.h>
33 #include <yarp/dev/api.h>
35 
58 {
59 
60  struct scheduled_sound_type
61  {
62  double scheduled_time=0;
63  yarp::sig::Sound sound_data;
64  };
65 
66 public:
72 
73  ~AudioPlayerWrapper() override;
74 
75  bool open(yarp::os::Searchable &params) override;
76  bool close() override;
77 
81  bool attachAll(const yarp::dev::PolyDriverList &p) override;
82  bool detachAll() override;
83 
84  void attach(yarp::dev::IAudioRender *irend);
85  void detach();
86 
87  bool threadInit() override;
88  void threadRelease() override;
89  void run() override;
90 
91 private:
92  yarp::dev::PolyDriver m_driver;
93 
94  std::string m_rpcPortName;
95  yarp::os::Port m_rpcPort;
96  std::string m_audioInPortName;
98  std::string m_statusPortName;
99  yarp::os::Port m_statusPort;
100 
101  yarp::dev::IAudioRender *m_irender = nullptr;
102  yarp::os::Stamp m_lastStateStamp;
103  yarp::dev::AudioBufferSize m_current_buffer_size;
104  yarp::dev::AudioBufferSize m_max_buffer_size;
105  std::queue<scheduled_sound_type> m_sound_buffer;
106  double m_period;
107  double m_buffer_delay;
108  bool m_isDeviceOwned = false;
109  bool m_debug_enabled = false;
110  bool m_isPlaying = false;
111 
112  bool initialize_YARP(yarp::os::Searchable &config);
113  bool read(yarp::os::ConnectionReader& connection) override;
114 
115 };
116 
117 #endif // YARP_DEV_AUDIOPLAYERWRAPPER_H
contains the definition of a Vector type
AudioPlayerWrapper: A Wrapper which receives audio streams from a network port and sends it to device...
bool close() override
Close the DeviceDriver.
void attach(yarp::dev::IAudioRender *irend)
bool threadInit() override
Initialization method.
void run() override
Loop function.
bool attachAll(const yarp::dev::PolyDriverList &p) override
Specify which sensor this thread has to read from.
void threadRelease() override
Release method.
AudioPlayerWrapper(const AudioPlayerWrapper &)=delete
bool detachAll() override
Detach the object (you must have first called attach).
AudioPlayerWrapper & operator=(AudioPlayerWrapper &&)=delete
AudioPlayerWrapper & operator=(const AudioPlayerWrapper &)=delete
AudioPlayerWrapper(AudioPlayerWrapper &&)=delete
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
Interface implemented by all device drivers.
Definition: DeviceDriver.h:35
Interface for an object that can wrap/attach to to another.
A container for a device driver.
Definition: PolyDriver.h:24
An interface for reading from a network connection.
An abstraction for a periodic thread.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
A mini-server for network communication.
Definition: Port.h:47
A base class for nested structures that can be searched.
Definition: Searchable.h:66
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:22
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
Definition: Sound.h:26