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 
69 {
70 
71  struct scheduled_sound_type
72  {
73  double scheduled_time;
74  yarp::sig::Sound sound_data;
75  };
76 
77 public:
83 
84  ~AudioPlayerWrapper() override;
85 
86  bool open(yarp::os::Searchable &params) override;
87  bool close() override;
88 
92  bool attachAll(const yarp::dev::PolyDriverList &p) override;
93  bool detachAll() override;
94 
95  void attach(yarp::dev::IAudioRender *irend);
96  void detach();
97 
98  bool threadInit() override;
99  void threadRelease() override;
100  void run() override;
101 
102 private:
103  yarp::dev::PolyDriver m_driver;
104 
105  std::string m_rpcPortName;
106  yarp::os::Port m_rpcPort;
107  std::string m_audioInPortName;
109  std::string m_statusPortName;
111 
112  yarp::dev::IAudioRender *m_irender;
113  yarp::os::Stamp m_lastStateStamp;
114  yarp::dev::AudioBufferSize m_current_buffer_size;
115  yarp::dev::AudioBufferSize m_max_buffer_size;
116  std::queue<scheduled_sound_type> m_sound_buffer;
117  double m_period;
118  double m_buffer_delay;
119  bool m_isDeviceOwned;
120  bool m_debug_enabled;
121  bool m_isPlaying = false;
122 
123  bool initialize_YARP(yarp::os::Searchable &config);
124  bool read(yarp::os::ConnectionReader& connection) override;
125 
126 };
127 
128 #endif // YARP_DEV_AUDIOPLAYERWRAPPER_H
AudioPlayerWrapper::attach
void attach(yarp::dev::IAudioRender *irend)
Definition: AudioPlayerWrapper.cpp:97
Network.h
AudioPlayerWrapper::AudioPlayerWrapper
AudioPlayerWrapper(AudioPlayerWrapper &&)=delete
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
AudioPlayerWrapper::detach
void detach()
Definition: AudioPlayerWrapper.cpp:102
Vector.h
contains the definition of a Vector type
AudioPlayerWrapper::run
void run() override
Loop function.
Definition: AudioPlayerWrapper.cpp:276
AudioPlayerWrapper::attachAll
bool attachAll(const yarp::dev::PolyDriverList &p) override
Specify which sensor this thread has to read from.
Definition: AudioPlayerWrapper.cpp:61
Port.h
yarp::dev::AudioBufferSize
Definition: AudioBufferSize.h:26
AudioPlayerWrapper::~AudioPlayerWrapper
~AudioPlayerWrapper() override
Definition: AudioPlayerWrapper.cpp:52
IPreciselyTimed.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
AudioPlayerWrapper::AudioPlayerWrapper
AudioPlayerWrapper()
Definition: AudioPlayerWrapper.cpp:42
AudioGrabberInterfaces.h
AudioPlayerWrapper::threadInit
bool threadInit() override
Initialization method.
Definition: AudioPlayerWrapper.cpp:159
yarp::dev::PolyDriverList
Definition: PolyDriverList.h:22
AudioPlayerWrapper
AudioPlayerWrapper: A Wrapper which receives audio streams from a network port and sends it to device...
Definition: AudioPlayerWrapper.h:69
yarp::dev::IAudioRender
Definition: IAudioRender.h:21
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
yarp::os::BufferedPort< yarp::sig::Sound >
AudioPlayerWrapper::AudioPlayerWrapper
AudioPlayerWrapper(const AudioPlayerWrapper &)=delete
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
Property.h
PolyDriver.h
Stamp.h
AudioPlayerWrapper::close
bool close() override
Close the DeviceDriver.
Definition: AudioPlayerWrapper.cpp:315
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
AudioPlayerWrapper::operator=
AudioPlayerWrapper & operator=(const AudioPlayerWrapper &)=delete
AudioPlayerWrapper::operator=
AudioPlayerWrapper & operator=(AudioPlayerWrapper &&)=delete
AudioPlayerWrapper::open
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
Definition: AudioPlayerWrapper.cpp:164
BufferedPort.h
IMultipleWrapper.h
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
PeriodicThread.h
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
yarp::sig::Sound
Class for storing sounds.
Definition: Sound.h:28
AudioPlayerWrapper::threadRelease
void threadRelease() override
Release method.
Definition: AudioPlayerWrapper.cpp:266
yarp::dev::IMultipleWrapper
Interface for an object that can wrap/attach to to another.
Definition: IMultipleWrapper.h:30
Time.h
AudioPlayerWrapper::detachAll
bool detachAll() override
Detach the object (you must have first called attach).
Definition: AudioPlayerWrapper.cpp:87
api.h
Bottle.h
DeviceDriver.h