YARP
Yet Another Robot Platform
AudioPlayerWrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef YARP_DEV_AUDIOPLAYERWRAPPER_H
20 #define YARP_DEV_AUDIOPLAYERWRAPPER_H
21 
22  //#include <list>
23 #include <vector>
24 #include <queue>
25 #include <iostream>
26 #include <string>
27 #include <sstream>
28 
29 #include <yarp/os/Network.h>
30 #include <yarp/os/Port.h>
31 #include <yarp/os/BufferedPort.h>
32 #include <yarp/os/Bottle.h>
33 #include <yarp/os/Time.h>
34 #include <yarp/os/Property.h>
35 
36 #include <yarp/os/PeriodicThread.h>
37 #include <yarp/os/BufferedPort.h>
38 #include <yarp/os/Stamp.h>
39 
40 #include <yarp/sig/Vector.h>
41 
43 #include <yarp/dev/PolyDriver.h>
44 #include <yarp/dev/DeviceDriver.h>
46 #include <yarp/dev/api.h>
48 
49 
55 {
56 
57  struct scheduled_sound_type
58  {
59  double scheduled_time;
60  yarp::sig::Sound sound_data;
61  };
62 
63 public:
69 
70  ~AudioPlayerWrapper() override;
71 
72  bool open(yarp::os::Searchable &params) override;
73  bool close() override;
74 
78  bool attachAll(const yarp::dev::PolyDriverList &p) override;
79  bool detachAll() override;
80 
81  void attach(yarp::dev::IAudioRender *irend);
82  void detach();
83 
84  bool threadInit() override;
85  void threadRelease() override;
86  void run() override;
87 
88 private:
89  yarp::dev::PolyDriver m_driver;
90 
91  std::string m_rpcPortName;
92  yarp::os::Port m_rpcPort;
93  std::string m_audioInPortName;
95  std::string m_statusPortName;
97 
98  yarp::dev::IAudioRender *m_irender;
99  yarp::os::Stamp m_lastStateStamp;
100  yarp::dev::AudioBufferSize m_current_buffer_size;
101  yarp::dev::AudioBufferSize m_max_buffer_size;
102  std::queue<scheduled_sound_type> m_sound_buffer;
103  double m_period;
104  double m_buffer_delay;
105  bool m_isDeviceOwned;
106  bool m_debug_enabled;
107 
108  bool initialize_YARP(yarp::os::Searchable &config);
109  bool read(yarp::os::ConnectionReader& connection) override;
110 
111 };
112 
113 #endif // YARP_DEV_AUDIOPLAYERWRAPPER_H
contains the definition of a Vector type
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:38
Interface for an object that can wrap/attach to to another.
A container for a device driver.
Definition: PolyDriver.h:27
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:28
A mini-server for network communication.
Definition: Port.h:50
A base class for nested structures that can be searched.
Definition: Searchable.h:69
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
Class for storing sounds.
Definition: Sound.h:28