33 #include <gst/app/gstappsink.h>
34 #include <gst/audio/gstaudiobasesrc.h>
37 #define DEBUG_RECORD_PURE_OGG 1
44 #define OPUS_CHANNELS 1
49 #define MAX_PAYLOAD_SIZE (1024 / OPUS_CHANNELS)
56 #define OPUS_FRAME_SIZE 40
61 #define PACKET_LOSS_PERCENTAGE 1
67 #define INBAND_FEC_MODE 1
73 #define BUFFER_TIME 1000
79 #define LATENCY_TIME 1000
86 #define OGG_MAX_DELAY 0
93 #define OGG_MAX_PAGE_DELAY 0
100 #ifdef DEBUG_RECORD_PURE_OGG
108 gst_element_set_state (
pipeline, GST_STATE_NULL);
116 switch (GST_MESSAGE_TYPE (
msg))
118 case GST_MESSAGE_EOS:
123 case GST_MESSAGE_ERROR:
128 gst_message_parse_error (
msg, &error, &
debug);
132 g_error_free (error);
150 if (GST_IS_AUDIO_BASE_SRC (
object))
151 g_object_set (
object,
"buffer-time", (gint64)
BUFFER_TIME,
"latency-time",
173 typedef void (*SignalHandlerPointer) (
int);
175 SignalHandlerPointer inthandler, termhandler;
179 #ifdef DEBUG_RECORD_PURE_OGG
184 gst_init (&argc, &argv);
192 "Audio source starts\n");
197 pipeline = gst_pipeline_new (
"audio-recorder");
207 ! encoder || ! oggmux || !
sink)
210 "One element could not be created. Exiting.\n");
219 caps = gst_caps_new_simple (
"audio/x-raw",
220 "format", G_TYPE_STRING,
"S16LE",
225 g_object_set (G_OBJECT (
filter),
228 gst_caps_unref (caps);
230 g_object_set (G_OBJECT (encoder),
240 g_object_set (G_OBJECT (oggmux),
246 bus = gst_pipeline_get_bus (GST_PIPELINE (
pipeline));
248 gst_object_unref (bus);
262 gst_element_set_state (
pipeline, GST_STATE_PLAYING);
272 size_t len, msg_size;
277 s = gst_app_sink_pull_sample (GST_APP_SINK (
sink));
285 const GstStructure *si;
289 si = gst_sample_get_info (s);
292 si_str = gst_structure_to_string (si);
301 s_caps = gst_sample_get_caps (s);
304 caps_str = gst_caps_to_string (s_caps);
315 b = gst_sample_get_buffer (s);
316 if ((NULL == b) || ! gst_buffer_map (b, &
m, GST_MAP_READ))
319 "got NULL buffer %p or failed to map the buffer\n", b);
320 gst_sample_unref (s);
334 "Sending %u bytes of audio data\n", (
unsigned int) msg_size);
342 #ifdef DEBUG_RECORD_PURE_OGG
351 ptr = (
const char *)
m.data;
355 "Sending %u bytes on phase %d\n", (
unsigned int) to_send,
357 for (offset = 0; offset < to_send; offset +=
ret)
359 ret = write (1, &ptr[offset], to_send - offset);
364 "Failed to write %u bytes at offset %u (total %u) in phase %d: %s\n",
365 (
unsigned int) (to_send - offset),
366 (
unsigned int) offset,
367 (
unsigned int) (to_send + offset),
377 gst_buffer_unmap (b, &
m);
378 gst_sample_unref (s);
381 signal (SIGINT, inthandler);
382 signal (SIGINT, termhandler);
388 gst_object_unref (GST_OBJECT (
pipeline));
390 g_source_remove (bus_watch_id);
struct GNUNET_MessageHeader * msg
constants for network protocols
static int ret
Return value of the commandline.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
static unsigned int phase
Processing stage that we are in.
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)
void source_child_added(GstChildProxy *child_proxy, GObject *object, gchar *name, gpointer user_data)
#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 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.
uint32_t data
The data value.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
Core service; the main API for encrypted P2P communications.
#define gst_element_factory_make(element, name)
Constants for network protocols.
#define GNUNET_log(kind,...)
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#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.
@ 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.