30#include <gst/app/gstappsink.h>
31#include <gst/audio/gstaudiobasesrc.h>
34#define DEBUG_RECORD_PURE_OGG 1
41#define OPUS_CHANNELS 1
46#define MAX_PAYLOAD_SIZE (1024 / OPUS_CHANNELS)
53#define OPUS_FRAME_SIZE 40
58#define PACKET_LOSS_PERCENTAGE 1
64#define INBAND_FEC_MODE 1
70#define BUFFER_TIME 1000
76#define LATENCY_TIME 1000
83#define OGG_MAX_DELAY 0
90#define OGG_MAX_PAGE_DELAY 0
97#ifdef DEBUG_RECORD_PURE_OGG
105 gst_element_set_state (
pipeline, GST_STATE_NULL);
113 switch (GST_MESSAGE_TYPE (
msg))
115 case GST_MESSAGE_EOS:
120 case GST_MESSAGE_ERROR:
125 gst_message_parse_error (
msg, &error, &
debug);
129 g_error_free (error);
147 if (GST_IS_AUDIO_BASE_SRC (
object))
148 g_object_set (
object,
"buffer-time", (gint64)
BUFFER_TIME,
"latency-time",
170 typedef void (*SignalHandlerPointer) (
int);
172 SignalHandlerPointer inthandler, termhandler;
176#ifdef DEBUG_RECORD_PURE_OGG
181 gst_init (&argc, &argv);
189 "Audio source starts\n");
194 pipeline = gst_pipeline_new (
"audio-recorder");
204 ! encoder || ! oggmux || !
sink)
207 "One element could not be created. Exiting.\n");
216 caps = gst_caps_new_simple (
"audio/x-raw",
217 "format", G_TYPE_STRING,
"S16LE",
222 g_object_set (G_OBJECT (
filter),
225 gst_caps_unref (caps);
227 g_object_set (G_OBJECT (encoder),
237 g_object_set (G_OBJECT (oggmux),
243 bus = gst_pipeline_get_bus (GST_PIPELINE (
pipeline));
245 gst_object_unref (bus);
259 gst_element_set_state (
pipeline, GST_STATE_PLAYING);
269 size_t len, msg_size;
274 s = gst_app_sink_pull_sample (GST_APP_SINK (
sink));
282 const GstStructure *si;
286 si = gst_sample_get_info (s);
289 si_str = gst_structure_to_string (si);
298 s_caps = gst_sample_get_caps (s);
301 caps_str = gst_caps_to_string (s_caps);
312 b = gst_sample_get_buffer (s);
313 if ((NULL == b) || ! gst_buffer_map (b, &
m, GST_MAP_READ))
316 "got NULL buffer %p or failed to map the buffer\n", b);
317 gst_sample_unref (s);
331 "Sending %u bytes of audio data\n", (
unsigned int) msg_size);
339#ifdef DEBUG_RECORD_PURE_OGG
348 ptr = (
const char *)
m.data;
352 "Sending %u bytes on phase %d\n", (
unsigned int) to_send,
354 for (offset = 0; offset < to_send; offset +=
ret)
356 ret = write (1, &ptr[offset], to_send - offset);
361 "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n",
362 (
unsigned int) (to_send - offset),
363 (
unsigned int) offset,
364 (
unsigned int) (to_send + offset),
374 gst_buffer_unmap (b, &
m);
375 gst_sample_unref (s);
378 signal (SIGINT, inthandler);
379 signal (SIGINT, termhandler);
385 gst_object_unref (GST_OBJECT (
pipeline));
387 g_source_remove (bus_watch_id);
struct GNUNET_MessageHeader * msg
constants for network protocols
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
static int ret
Final status code.
static unsigned int phase
Processing stage that we are in.
static char * data
The data to insert into the dht.
static GstElement * source
Appsrc instance into which we write data for the pipeline.
static GstElement * resampler
static void signalhandler(int s)
#define LATENCY_TIME
Min number of microseconds to buffer in audiosource.
static GstElement * pipeline
Main pipeline.
int main(int argc, char **argv)
#define MAX_PAYLOAD_SIZE
Maximal size of a single opus packet.
#define OGG_MAX_DELAY
Maximum delay in multiplexing streams, in ns.
#define INBAND_FEC_MODE
Set to 1 to enable forward error correction.
#define OPUS_FRAME_SIZE
Size of a single frame fed to the encoder, in ms.
#define OGG_MAX_PAGE_DELAY
Maximum delay for sending out a page, in ns.
#define OPUS_CHANNELS
Number of channels.
static void source_child_added(GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data)
static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data)
#define PACKET_LOSS_PERCENTAGE
Expected packet loss to prepare for, in percents.
#define BUFFER_TIME
Max number of microseconds to buffer in audiosource.
static struct AudioMessage * audio_message
Audio message skeleton.
static char * name
Name (label) of the records to list.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
#define gst_element_factory_make(element, name)
Constants for network protocols.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
Message to transmit the audio between helper and speaker/microphone library.
Message to transmit the audio (between client and helpers).
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO.