YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Mp3Sound.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "Mp3Sound.h"
7
8#include <algorithm>
9#include <cmath>
10
12#include <yarp/sig/SoundFile.h>
13
14using namespace yarp::os;
15using namespace yarp::sig;
16
17namespace {
19 "yarp.carrier.portmonitor.sound_compression_mp3",
23 nullptr)
24}
25
27{
28 senderSide = (options.find("sender_side").asBool());
29 return true;
30}
31
35
37{
38 return false;
39}
40
42{
43 return false;
44}
45
47{
48 if (senderSide)
49 {
50 yCError(MP3TOSOUND, "accept(): Sender side not yet supported!");
51 return false;
52 }
53 else
54 {
55 auto* bot = thing.cast_as<Bottle>();
56 if(bot == nullptr || bot->size()!=1)
57 {
58 yCError(MP3TOSOUND, "Data cannot be accepted!");
59 return false;
60 }
61 }
62 return true;
63}
64
66{
67 if (senderSide)
68 {
69 yCError(MP3TOSOUND, "update(): Sender side not yet supported!");
70 }
71 else
72 {
73 yarp::os::Bottle* bot = thing.cast_as<Bottle>();
74 if (bot)
75 {
76 const char* binary_data = bot->get(0).asBlob();
77 size_t length = bot->get(0).asBlobLength();
78
80 }
81 else
82 {
83 yCError(MP3TOSOUND, "Conversion failed!");
84 }
85 }
86
87 th.setPortWriter(&snd);
88 return th;
89}
bool accept(yarp::os::Things &thing) override
This will be called when the data reach the portmonitor object.
Definition Mp3Sound.cpp:46
bool create(const yarp::os::Property &options) override
This will be called when the dll is properly loaded by the portmonitor carrier.
Definition Mp3Sound.cpp:26
yarp::os::Things & update(yarp::os::Things &thing) override
After data get accpeted in the accept() callback, an instance of that is given to the update function...
Definition Mp3Sound.cpp:65
bool getparam(yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are requested via YARP admin port.
Definition Mp3Sound.cpp:41
void destroy() override
This will be called when the portmonitor object destroyes.
Definition Mp3Sound.cpp:32
bool setparam(const yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are set via YARP admin port.
Definition Mp3Sound.cpp:36
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:246
A mini-server for performing network communication in the background.
static LogCallback printCallback()
Get current print callback.
Definition Log.cpp:873
static LogType minimumPrintLevel()
Get current minimum print level.
Definition Log.cpp:833
@ LogTypeReserved
Definition Log.h:98
A class for storing options and configuration information.
Definition Property.h:33
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Base class for generic things.
Definition Things.h:18
T * cast_as()
Definition Things.h:53
void setPortWriter(yarp::os::PortWriter *writer)
Set the reference to a PortWriter object.
Definition Things.cpp:26
virtual bool asBool() const
Get boolean value.
Definition Value.cpp:186
virtual size_t asBlobLength() const
Get binary data length.
Definition Value.cpp:267
virtual const char * asBlob() const
Get binary data value.
Definition Value.cpp:261
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface to the operating system, including Port based communication.
bool read_bytestream(Sound &data, const char *filename, size_t streamsize, std::string format)
Read a sound from a byte array.
Definition SoundFile.cpp:56