program to playback audio data to the speaker More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "conversation.h"
#include "gnunet_constants.h"
#include "gnunet_core_service.h"
#include <pulse/simple.h>
#include <pulse/error.h>
#include <pulse/rtclock.h>
#include <pulse/pulseaudio.h>
#include <opus/opus.h>
#include <opus/opus_types.h>
#include <ogg/ogg.h>
Go to the source code of this file.
Data Structures | |
struct | OpusHeadPacket |
Macros | |
#define | DEBUG_READ_PURE_OGG 1 |
#define | DEBUG_DUMP_DECODED_OGG 1 |
#define | MAXLINE 4096 |
#define | SAMPLING_RATE 48000 |
#define | CHANNELS 1 |
#define | MAX_FRAME_SIZE (960 * 6) |
#define | fminf(_x, _y) ((_x) < (_y) ? (_x) : (_y)) |
#define | fmaxf(_x, _y) ((_x) > (_y) ? (_x) : (_y)) |
#define | float2int(flt) ((int) (floor (.5 + flt))) |
Functions | |
static GNUNET_NETWORK_STRUCT_END OpusDecoder * | process_header (ogg_packet *op) |
Process an Opus header and setup the opus decoder based on it. More... | |
static size_t | fwrite_le32 (opus_int32 i32, FILE *file) |
static size_t | fwrite_le16 (int i16, FILE *file) |
static int | write_wav_header () |
static int64_t | audio_write (int64_t maxout) |
static void | quit (int ret) |
Pulseaudio shutdown task. More... | |
static void | ogg_demux_and_decode () |
static int | stdin_receiver (void *cls, const struct GNUNET_MessageHeader *msg) |
Message callback. More... | |
static void | stream_write_callback (pa_stream *s, size_t length, void *userdata) |
Callback when data is there for playback. More... | |
static void | exit_signal_callback (pa_mainloop_api *m, pa_signal_event *e, int sig, void *userdata) |
Exit callback for SIGTERM and SIGINT. More... | |
static void | context_state_callback (pa_context *c, void *userdata) |
Pulseaudio stream state callback. More... | |
static void | pa_init () |
Pulseaudio initialization. More... | |
static void | ogg_init () |
static void | drain_callback (pa_stream *s, int success, void *userdata) |
int | main (int argc, char *argv[]) |
The main function for the playback helper. More... | |
Variables | |
static pa_sample_spec | sample_spec |
Pulseaudio specification. More... | |
static int | dump_to_stdout |
static pa_mainloop_api * | mainloop_api |
Pulseaudio mainloop api. More... | |
static pa_threaded_mainloop * | m |
Pulseaudio threaded mainloop. More... | |
static pa_context * | context |
Pulseaudio context. More... | |
static pa_stream * | stream_out |
Pulseaudio output stream. More... | |
static OpusDecoder * | dec |
OPUS decoder. More... | |
static float * | pcm_buffer |
PCM data buffer. More... | |
static int | frame_size |
Number of samples for one frame. More... | |
static int | ready_pipe [2] |
Pipe we use to signal the main loop that we are ready to receive. More... | |
static ogg_sync_state | oy |
Ogg I/O state. More... | |
static ogg_stream_state | os |
Ogg stream state. More... | |
static int | channels |
static int | preskip |
static float | gain |
program to playback audio data to the speaker
Definition in file gnunet-helper-audio-playback.c.
#define DEBUG_READ_PURE_OGG 1 |
Definition at line 43 of file gnunet-helper-audio-playback.c.
#define DEBUG_DUMP_DECODED_OGG 1 |
Definition at line 44 of file gnunet-helper-audio-playback.c.
#define MAXLINE 4096 |
Definition at line 46 of file gnunet-helper-audio-playback.c.
#define SAMPLING_RATE 48000 |
Definition at line 48 of file gnunet-helper-audio-playback.c.
#define CHANNELS 1 |
Definition at line 50 of file gnunet-helper-audio-playback.c.
#define MAX_FRAME_SIZE (960 * 6) |
Definition at line 53 of file gnunet-helper-audio-playback.c.
#define fminf | ( | _x, | |
_y | |||
) | ((_x) < (_y) ? (_x) : (_y)) |
#define fmaxf | ( | _x, | |
_y | |||
) | ((_x) > (_y) ? (_x) : (_y)) |
#define float2int | ( | flt | ) | ((int) (floor (.5 + flt))) |
|
static |
Process an Opus header and setup the opus decoder based on it.
It takes several pointers for header values which are needed elsewhere in the code.
Definition at line 146 of file gnunet-helper-audio-playback.c.
References OpusHeadPacket::channel_mapping, channels, OpusHeadPacket::channels, dec, gain, OpusHeadPacket::gain, GNUNET_ERROR_TYPE_DEBUG, GNUNET_le16toh, GNUNET_le32toh, GNUNET_log, GNUNET_memcpy, consensus-simulation::int, op, preskip, OpusHeadPacket::preskip, SAMPLING_RATE, OpusHeadPacket::sampling_rate, and OpusHeadPacket::version.
Referenced by ogg_demux_and_decode().
|
static |
Definition at line 218 of file gnunet-helper-audio-playback.c.
Referenced by write_wav_header().
|
static |
Definition at line 231 of file gnunet-helper-audio-playback.c.
Referenced by write_wav_header().
|
static |
Definition at line 242 of file gnunet-helper-audio-playback.c.
References channels, fwrite_le16(), fwrite_le32(), ret, and SAMPLING_RATE.
Referenced by audio_write().
|
static |
Definition at line 270 of file gnunet-helper-audio-playback.c.
References _, channels, context, dump_to_stdout, float2int, fmaxf, fminf, frame_size, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, consensus-simulation::int, MAX_FRAME_SIZE, pcm_buffer, preskip, stream_out, and write_wav_header().
Referenced by ogg_demux_and_decode().
|
static |
Pulseaudio shutdown task.
Definition at line 350 of file gnunet-helper-audio-playback.c.
References mainloop_api, and ret.
Referenced by context_state_callback(), exit_signal_callback(), and ogg_demux_and_decode().
|
static |
Definition at line 359 of file gnunet-helper-audio-playback.c.
References audio_write(), channels, dec, frame_size, gain, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, MAX_FRAME_SIZE, op, os, oy, pcm_buffer, preskip, process_header(), quit(), ret, and SAMPLING_RATE.
Referenced by main(), and stdin_receiver().
|
static |
Message callback.
msg | message we received. |
Definition at line 584 of file gnunet-helper-audio-playback.c.
References data, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO, GNUNET_OK, AudioMessage::header, msg, ogg_demux_and_decode(), oy, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.
Referenced by main().
|
static |
Callback when data is there for playback.
Definition at line 618 of file gnunet-helper-audio-playback.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and ready_pipe.
Referenced by context_state_callback().
|
static |
Exit callback for SIGTERM and SIGINT.
Definition at line 639 of file gnunet-helper-audio-playback.c.
References _, GNUNET_ERROR_TYPE_INFO, GNUNET_log, m, and quit().
Referenced by pa_init().
|
static |
Pulseaudio stream state callback.
Definition at line 658 of file gnunet-helper-audio-playback.c.
References _, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, p, quit(), sample_spec, stream_out, and stream_write_callback().
Referenced by pa_init().
|
static |
Pulseaudio initialization.
Definition at line 725 of file gnunet-helper-audio-playback.c.
References _, context, context_state_callback(), exit_signal_callback(), GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, m, mainloop_api, and sample_spec.
Referenced by main().
|
static |
Definition at line 771 of file gnunet-helper-audio-playback.c.
References oy.
Referenced by main().
|
static |
int main | ( | int | argc, |
char * | argv[] | ||
) |
The main function for the playback helper.
argc | number of arguments from the command line |
argv | command line arguments |
Definition at line 796 of file gnunet-helper-audio-playback.c.
References _, data, drain_callback(), dump_to_stdout, getenv(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_log_setup(), GNUNET_log_strerror, GNUNET_memcpy, GNUNET_MST_create(), GNUNET_MST_destroy(), GNUNET_MST_from_buffer(), GNUNET_NO, GNUNET_OK, m, MAXLINE, ogg_demux_and_decode(), ogg_init(), oy, pa_init(), ready_pipe, ret, stdin_mst, stdin_receiver(), and stream_out.
|
static |
Pulseaudio specification.
May change in the future.
Definition at line 58 of file gnunet-helper-audio-playback.c.
Referenced by context_state_callback(), and pa_init().
|
static |
Definition at line 65 of file gnunet-helper-audio-playback.c.
Referenced by audio_write(), and main().
|
static |
Pulseaudio mainloop api.
Definition at line 71 of file gnunet-helper-audio-playback.c.
|
static |
Pulseaudio threaded mainloop.
Definition at line 76 of file gnunet-helper-audio-playback.c.
Referenced by drain_callback(), exit_signal_callback(), main(), and pa_init().
|
static |
Pulseaudio context.
Definition at line 81 of file gnunet-helper-audio-playback.c.
Referenced by audio_write(), derive_h(), enqueue_message_control(), get_context_from_member(), get_handle_contact(), get_store_contact(), get_store_contact_raw(), GNUNET_CRYPTO_ecdsa_private_key_derive(), GNUNET_CRYPTO_ecdsa_public_key_derive(), GNUNET_CRYPTO_ecdsa_sign_derived(), GNUNET_CRYPTO_eddsa_private_key_derive(), GNUNET_CRYPTO_eddsa_public_key_derive(), GNUNET_CRYPTO_eddsa_sign_derived(), GNUNET_SCHEDULER_run(), handle_client_evaluate(), handle_id_message(), handle_join_message(), handle_key_message(), handle_recv_message(), notify_srv_handle_message(), pa_init(), process_message_control(), remove_store_contact(), select_add(), select_del(), select_loop(), select_set_wakeup(), select_store_contact_map(), and update_store_contact().
|
static |
Pulseaudio output stream.
Definition at line 86 of file gnunet-helper-audio-playback.c.
Referenced by audio_write(), context_state_callback(), and main().
|
static |
OPUS decoder.
Definition at line 91 of file gnunet-helper-audio-playback.c.
Referenced by getValue__(), ogg_demux_and_decode(), and process_header().
|
static |
PCM data buffer.
Definition at line 96 of file gnunet-helper-audio-playback.c.
Referenced by audio_write(), and ogg_demux_and_decode().
|
static |
Number of samples for one frame.
Definition at line 101 of file gnunet-helper-audio-playback.c.
Referenced by audio_write(), and ogg_demux_and_decode().
|
static |
Pipe we use to signal the main loop that we are ready to receive.
Definition at line 106 of file gnunet-helper-audio-playback.c.
Referenced by main(), and stream_write_callback().
|
static |
Ogg I/O state.
Definition at line 111 of file gnunet-helper-audio-playback.c.
Referenced by main(), ogg_demux_and_decode(), ogg_init(), and stdin_receiver().
|
static |
Ogg stream state.
Definition at line 116 of file gnunet-helper-audio-playback.c.
Referenced by handle_flow_control(), handle_p2p_estimate(), and ogg_demux_and_decode().
|
static |
Definition at line 118 of file gnunet-helper-audio-playback.c.
Referenced by audio_write(), ogg_demux_and_decode(), process_header(), and write_wav_header().
|
static |
Definition at line 120 of file gnunet-helper-audio-playback.c.
Referenced by audio_write(), ogg_demux_and_decode(), and process_header().
|
static |
Definition at line 122 of file gnunet-helper-audio-playback.c.
Referenced by ogg_demux_and_decode(), and process_header().