24#if defined (YARP_HAS_FFMPEG)
27 #include <libavutil/opt.h>
28 #include <libavcodec/avcodec.h>
29 #include <libavcodec/version.h>
30 #include <libavutil/channel_layout.h>
31 #include <libavutil/common.h>
32 #include <libavutil/imgutils.h>
33 #include <libavutil/mathematics.h>
34 #include <libavutil/samplefmt.h>
48#if defined (YARP_HAS_FFMPEG)
49#define AUDIO_INBUF_SIZE 20480
50#define AUDIO_REFILL_THRESH 4096
54#if defined (YARP_HAS_FFMPEG)
89#if LIBAVCODEC_VERSION_MAJOR >= 61
97 for (i = 0; i < frame->nb_samples; i++)
101 short int val = *((
short int*)frame->data[ch] + i);
129 if (!codec->supported_samplerates) {
133 p = codec->supported_samplerates;
170 os.write((
const char*)(
pkt->data),
pkt->size);
176#if LIBAVCODEC_VERSION_MAJOR >= 61
184 if (!codec->ch_layouts)
190 p = codec->ch_layouts;
191 while (p->nb_channels)
219 if (!codec->channel_layouts) {
223 p = codec->channel_layouts;
243#if !defined (YARP_HAS_FFMPEG)
248 const AVCodec * codec =
nullptr;
256#if LIBAVCODEC_VERSION_MAJOR < 58
290#if LIBAVCODEC_VERSION_MAJOR >= 61
310 fos.
open(filename, std::fstream::out | std::fstream::binary);
311 if (
fos.is_open()==
false)
335 frame->nb_samples =
c->frame_size;
336 frame->format =
c->sample_fmt;
338#if LIBAVCODEC_VERSION_MAJOR >= 61
348 frame->channel_layout =
c->channel_layout;
365 for (
size_t i = 0; i <
nframes; i++)
372#if LIBAVCODEC_VERSION_MAJOR >= 61
380 samples = (
uint16_t*)frame->data[0];
381 for (
int j = 0;
j <
c->frame_size;
j++)
387 if (encode(
c, frame,
pkt,
fos) ==
false)
411#if !defined (YARP_HAS_FFMPEG)
415 const AVCodec* codec =
nullptr;
427#if LIBAVCODEC_VERSION_MAJOR < 58
493 len = istream.gcount();
519 fis.
open(filename, std::fstream::in | std::fstream::binary);
520 if (
fis.is_open() ==
false)
bool read_mp3_istream(Sound &sound_data, std::istream &istream)
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
T * read(bool shouldWait=true) override
Read an available object from the port.
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
void setFrequency(int freq)
Set the frequency of the sound (i.e.
size_t getChannels() const
Get the number of channels of the sound.
void resize(size_t samples, size_t channels=1)
Set the sound size.
audio_sample get(size_t sample, size_t channel=0) const
size_t getSamples() const
Get the number of samples contained in the sound.
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
An interface to the operating system, including Port based communication.
bool write_mp3_file(const Sound &data, const char *filename, size_t bitrate=64000)
Write a sound to a mp3 file.
bool read_mp3_file(Sound &data, const char *filename)
Read a sound from a .mp3 audio file.
bool read_mp3_bytestream(Sound &data, const char *bytestream, size_t streamsize)
Read a sound from a byte array.