UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
mixer.cpp File Reference
#include "audio/audio_capture.h"
#include "audio/audio_playback.h"
#include "audio/codec.h"
#include "audio/types.h"
#include "debug.h"
#include "lib_common.h"
#include "module.h"
#include "rtp/rtp.h"
#include "transmit.h"
#include "utils/audio_buffer.h"
#include "utils/thread.h"
#include <chrono>
#include <iostream>
#include <map>
#include <mutex>
#include <thread>
#include <vector>
Include dependency graph for mixer.cpp:

Go to the source code of this file.

Classes

struct  am_participant
 
class  generic_mix_algo< source_t, intermediate_t >
 
class  linear_mix_algo< source_t, intermediate_t >
 
class  logarithmic_mix_algo< source_t, intermediate_t >
 
class  sockaddr_storage_less
 
struct  state_audio_mixer
 

Macros

#define BPS   2
 
#define CHANNELS   1
 
#define FRAMES_PER_SEC   25
 
#define PARTICIPANT_TIMEOUT_S   60
 
#define SAMPLE_RATE   48000
 
#define SAMPLES_PER_FRAME   (SAMPLE_RATE / FRAMES_PER_SEC)
 

Typedefs

typedef int32_t sample_type_mixed
 
typedef int16_t sample_type_source
 

Functions

static bool audio_play_mixer_ctl (void *state, int request, void *data, size_t *len)
 
static void audio_play_mixer_done (void *state)
 
static void audio_play_mixer_help ()
 
static void * audio_play_mixer_init (const char *cfg)
 
static void audio_play_mixer_probe (struct device_info **available_devices, int *count, void(**deleter)(void *))
 
static void audio_play_mixer_put_frame (void *state, const struct audio_frame *frame)
 
static bool audio_play_mixer_reconfigure (void *state, struct audio_desc desc)
 
static void mixer_dummy_rtp_callback (struct rtp *session, rtp_event *e)
 
 REGISTER_MODULE (mixer, &aplay_mixer_info, LIBRARY_CLASS_AUDIO_PLAYBACK, AUDIO_PLAYBACK_ABI_VERSION)
 

Variables

static const struct audio_playback_info aplay_mixer_info
 

Detailed Description

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file mixer.cpp.

Macro Definition Documentation

◆ BPS

◆ CHANNELS

◆ FRAMES_PER_SEC

#define FRAMES_PER_SEC   25

Definition at line 66 of file mixer.cpp.

◆ PARTICIPANT_TIMEOUT_S

#define PARTICIPANT_TIMEOUT_S   60

Definition at line 70 of file mixer.cpp.

Referenced by state_audio_mixer::worker().

◆ SAMPLE_RATE

◆ SAMPLES_PER_FRAME

#define SAMPLES_PER_FRAME   (SAMPLE_RATE / FRAMES_PER_SEC)

Definition at line 68 of file mixer.cpp.

Referenced by state_audio_mixer::worker().

Typedef Documentation

◆ sample_type_mixed

typedef int32_t sample_type_mixed

Definition at line 72 of file mixer.cpp.

◆ sample_type_source

typedef int16_t sample_type_source

Definition at line 71 of file mixer.cpp.

Function Documentation

◆ audio_play_mixer_ctl()

static bool audio_play_mixer_ctl ( void * state,
int request,
void * data,
size_t * len )
static

Definition at line 433 of file mixer.cpp.

434{
435 struct state_audio_mixer *s = (struct state_audio_mixer *) state;
436
437 switch (request) {
439 if (*len >= sizeof(struct audio_desc)) {
441 memcpy(data, &desc, sizeof desc);
442 *len = sizeof desc;
443 return true;
444 } else {
445 return false;
446 }
448 if (*len >= sizeof(bool)) {
449 *(bool *) data = true;
450 *len = sizeof(bool);
451 return true;
452 } else {
453 return false;
454 }
456 if (*len != sizeof(struct rtp *)) {
457 return false;
458 } else {
459 s->recv_socket = rtp_get_udp_local_socket(*(struct rtp **) data);
460 assert(s->recv_socket != NULL);
461 return true;
462 }
463 default:
464 return false;
465 }
466}
void ** state
struct video_desc desc
int void size_t * len
@ AC_PCM
Definition types.h:53
#define AUDIO_PLAYBACK_CTL_QUERY_FORMAT
#define AUDIO_PLAYBACK_CTL_MULTIPLE_STREAMS
#define AUDIO_PLAYBACK_PUT_NETWORK_DEVICE
#define CHANNELS
Definition mixer.cpp:65
#define SAMPLE_RATE
Definition mixer.cpp:63
#define BPS
Definition mixer.cpp:64
struct socket_udp_local * rtp_get_udp_local_socket(struct rtp *session)
Definition rtp.c:4037
Definition rtp.c:274
struct socket_udp_local * recv_socket
Definition mixer.cpp:277

References AC_PCM, AUDIO_PLAYBACK_CTL_MULTIPLE_STREAMS, AUDIO_PLAYBACK_CTL_QUERY_FORMAT, AUDIO_PLAYBACK_PUT_NETWORK_DEVICE, BPS, CHANNELS, desc, len, state_audio_mixer::recv_socket, rtp_get_udp_local_socket(), SAMPLE_RATE, and state.

Here is the call graph for this function:

◆ audio_play_mixer_done()

static void audio_play_mixer_done ( void * state)
static

Definition at line 425 of file mixer.cpp.

426{
427 struct state_audio_mixer *s = (struct state_audio_mixer *) state;
428 s->should_exit = true;
429
430 delete s;
431}

References state_audio_mixer::should_exit, and state.

◆ audio_play_mixer_help()

static void audio_play_mixer_help ( )
static

Definition at line 364 of file mixer.cpp.

365{
366 printf("Usage:\n"
367 "\t%s -r mixer[:codec=<codec>][:algo={linear|logarithmic}]\n"
368 "\n"
369 "<codec>\n"
370 "\taudio codec to use\n"
371 "linear\n"
372 "\tlinear sum of signals (with clamping)\n"
373 "logarithmic\n"
374 "\tlinear sum of signals to threshold, above threshold logarithmic dynamic range compression is used\n"
375 "\n"
376 "Notes:\n"
377 "1)\tYou do not need to specify audio participants explicitly,\n"
378 "\t" PACKAGE_NAME " simply sends the the stream back to the host\n"
379 "\tthat is sending to mixer. Therefore it is necessary that the\n"
380 "\tparticipant uses single " PACKAGE_NAME " for both sending and\n"
381 "\treceiving audio.\n"
382 "2)\tUses default port for receiving, therefore if you want to use it\n"
383 "\ton machine that is a part of the conference, you should use something like:\n"
384 "\t\t%s -s <your_capture> -P 5004:5004:5010:5006\n"
385 "\tfor the " PACKAGE_NAME " instance that is part of the conference (not mixer!)\n",
386 uv_argv[0], uv_argv[0]);
387}
char ** uv_argv
Definition host.cpp:174

References uv_argv.

Referenced by audio_play_mixer_init().

◆ audio_play_mixer_init()

static void * audio_play_mixer_init ( const char * cfg)
static

Definition at line 396 of file mixer.cpp.

397{
398 if (strcmp(cfg, "help") == 0) {
400 return INIT_NOERR;
401 }
402 try {
403 return new state_audio_mixer{cfg};
404 } catch (...) {
405 return nullptr;
406 }
407}
#define INIT_NOERR
Definition host.h:73
static void audio_play_mixer_help()
Definition mixer.cpp:364

References audio_play_mixer_help(), and INIT_NOERR.

Here is the call graph for this function:

◆ audio_play_mixer_probe()

static void audio_play_mixer_probe ( struct device_info ** available_devices,
int * count,
void(** deleter )(void *) )
static

Definition at line 389 of file mixer.cpp.

390{
391 *deleter = free;
392 *available_devices = NULL;
393 *count = 0;
394}
int void(** deleter)(void *))
int count
Definition hd-rum.c:44

References count, and deleter.

◆ audio_play_mixer_put_frame()

static void audio_play_mixer_put_frame ( void * state,
const struct audio_frame * frame )
static

Definition at line 409 of file mixer.cpp.

410{
411 struct state_audio_mixer *s = (struct state_audio_mixer *) state;
412
413 unique_lock<mutex> lk(s->participants_lock);
414
415 auto ss = *(struct sockaddr_storage *) frame->network_source;
416
417 if (s->participants.find(ss) == s->participants.end()) {
418 s->participants.emplace(ss, am_participant{s->recv_socket, &ss, s->audio_codec});
419 }
420
421 audio_buffer_write(s->participants.at(ss).m_buffer, frame->data, frame->data_len);
422 s->participants.at(ss).last_seen = chrono::steady_clock::now();
423}
struct video_frame * frame
void audio_buffer_write(struct audio_buffer *buf, const char *in, int len)
mutex participants_lock
Definition mixer.cpp:275

References audio_buffer_write(), state_audio_mixer::audio_codec, frame, state_audio_mixer::participants, state_audio_mixer::participants_lock, state_audio_mixer::recv_socket, and state.

Here is the call graph for this function:

◆ audio_play_mixer_reconfigure()

static bool audio_play_mixer_reconfigure ( void * state,
struct audio_desc desc )
static

Definition at line 468 of file mixer.cpp.

469{
471 assert(desc == requested);
472 return true;
473}

References AC_PCM, BPS, CHANNELS, desc, and SAMPLE_RATE.

◆ mixer_dummy_rtp_callback()

static void mixer_dummy_rtp_callback ( struct rtp * session,
rtp_event * e )
static

Definition at line 114 of file mixer.cpp.

114 {
115}

◆ REGISTER_MODULE()

REGISTER_MODULE ( mixer ,
& aplay_mixer_info,
LIBRARY_CLASS_AUDIO_PLAYBACK ,
AUDIO_PLAYBACK_ABI_VERSION  )

Variable Documentation

◆ aplay_mixer_info

const struct audio_playback_info aplay_mixer_info
static
Initial value:
= {
}
static void audio_play_mixer_done(void *state)
Definition mixer.cpp:425
static void audio_play_mixer_put_frame(void *state, const struct audio_frame *frame)
Definition mixer.cpp:409
static bool audio_play_mixer_reconfigure(void *state, struct audio_desc desc)
Definition mixer.cpp:468
static void * audio_play_mixer_init(const char *cfg)
Definition mixer.cpp:396
static bool audio_play_mixer_ctl(void *state, int request, void *data, size_t *len)
Definition mixer.cpp:433
static void audio_play_mixer_probe(struct device_info **available_devices, int *count, void(**deleter)(void *))
Definition mixer.cpp:389

Definition at line 475 of file mixer.cpp.