Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
[voicestreams] added mp3 encoding and saving to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
nonoo committed Sep 15, 2015
1 parent bbf5430 commit bbbfb3a
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 35 deletions.
6 changes: 4 additions & 2 deletions Makefile.defconfig.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
SRCTOPDIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))

# If you don't want to use libmbe then set DECODEVOICE to zero in Makefile.config.inc
DECODEVOICE := 1
# If you don't want to use libmbe then set AMBEDECODEVOICE to 0 in Makefile.config.inc
AMBEDECODEVOICE := 1
# If you don't want to use libmp3lame then set MP3ENCODEVOICE to 0 in Makefile.config.inc
MP3ENCODEVOICE := 1

# If Makefile.config.inc exists, we include it.
ifeq ($(wildcard $(SRCTOPDIR)/Makefile.config.inc),$(SRCTOPDIR)/Makefile.config.inc)
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ You'll need to have the following libs installed on your system to compile dmrsh
- libsnmp-dev / net-snmp-devel
- libmysqlclient-dev / mariadb-devel
- [mbelib](https://github.com/szechyjs/mbelib) (optional)
- libmp3lame-dev (optional)

Instructions on compiling and installing:

Expand All @@ -45,7 +46,15 @@ Now you will have dmrshark installed to **/opt/dmrshark**.
If you don't want to use libmbe, create **Makefile.config.inc** in the dmrshark source root directory, and add the following:

```
DECODEVOICE := 0
AMBEDECODEVOICE := 0
```

### libmp3lame

If you don't want to use libmp3lame, create **Makefile.config.inc** in the dmrshark source root directory, and add the following:

```
MP3ENCODEVOICE := 0
```

## Configuration
Expand Down Expand Up @@ -97,6 +106,7 @@ repeaterhosts=1.2.3.4,repeater123.nonoo.hu
savefiledir=
savetorawfile=1
savedecodedtorawfile=1
savedecodedtomp3file=1
timeslot=1
decodequality=3
Expand All @@ -106,6 +116,7 @@ repeaterhosts=*
savefiledir=
savetorawfile=1
savedecodedtorawfile=1
savedecodedtomp3file=1
timeslot=2
decodequality=64
```
Expand All @@ -119,6 +130,7 @@ Voice stream configure variables:
- **savefiledir**: Captured voice files will be saved to this directory. If empty, files will be saved to the current directory.
- **savetorawfile**: Set this to 1 if you want to save raw AMBE2+ voice data.
- **savedecodedtorawfile**: Set this to 1 if you want to save raw, but decoded voice data. Samples are saved as 8kHz IEEE 32bit floats.
- **savedecodedtomp3file**: Set this to 1 if you want to save decoded voice data in MP3 files.
- **decodequality**: Quality of AMBE2+ decoding, valid values are between 1 and 64, 1 is the worst and 64 is the best quality. Default value is 3. Note that increasing decoding quality increases used CPU time.

## Running
Expand Down
5 changes: 4 additions & 1 deletion build/dmrshark/Makefile.goals
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ include ../../make/Makefile.target.inc
LIBS := $(LIBS) base config daemon comm remotedb dmrpacket coding voicestreams
PREBUILTLIBS := pcap snmp mysqlclient pthread

ifeq ($(DECODEVOICE),1)
ifeq ($(AMBEDECODEVOICE),1)
PREBUILTLIBS := $(PREBUILTLIBS) mbe
endif
ifeq ($(MP3ENCODEVOICE),1)
PREBUILTLIBS := $(PREBUILTLIBS) mp3lame
endif

include ../../make/Makefile.build.inc
include ../../make/Makefile.common.inc
2 changes: 1 addition & 1 deletion libs/comm/ipsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void ipsc_processpacket(struct ip *ip_packet, uint16_t length) {
// host of the DMR master, and IP packets are just routed through.
if (repeater != NULL || (repeater = repeaters_findbyip(&ip_packet->ip_src)) != NULL) {
console_log(LOGLEVEL_IPSC "ipsc [%s", repeaters_get_display_string_for_ip(&ip_packet->ip_src));
console_log(LOGLEVEL_IPSC "->%s]: decoded dmr ts %u slot type: %s (0x%.4x) call type: %s (0x%.2x) dstid %u srcid %u\n",
console_log(LOGLEVEL_IPSC "->%s]: dmr packet ts %u slot type: %s (0x%.4x) call type: %s (0x%.2x) dstid %u srcid %u\n",
repeaters_get_display_string_for_ip(&ip_packet->ip_dst),
ipsc_packet.timeslot,
ipscpacket_get_readable_slot_type(ipsc_packet.slot_type), ipsc_packet.slot_type,
Expand Down
57 changes: 56 additions & 1 deletion libs/config/config-voicestreams.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,54 @@ int config_voicestreams_get_savedecodedtorawfile(char *streamname) {
return value;
}

int config_voicestreams_get_savedecodedtomp3file(char *streamname) {
GError *error = NULL;
int value = 0;
char *key = "savedecodedtomp3file";
int defaultvalue = 0;

pthread_mutex_lock(config_get_mutex());
value = g_key_file_get_integer(config_get_keyfile(), streamname, key, &error);
if (error) {
value = defaultvalue;
g_key_file_set_integer(config_get_keyfile(), streamname, key, value);
}
pthread_mutex_unlock(config_get_mutex());
return value;
}

int config_voicestreams_get_mp3bitrate(char *streamname) {
GError *error = NULL;
int value = 0;
char *key = "mp3bitrate";
int defaultvalue = 32;

pthread_mutex_lock(config_get_mutex());
value = g_key_file_get_integer(config_get_keyfile(), streamname, key, &error);
if (error) {
value = defaultvalue;
g_key_file_set_integer(config_get_keyfile(), streamname, key, value);
}
pthread_mutex_unlock(config_get_mutex());
return value;
}

int config_voicestreams_get_mp3quality(char *streamname) {
GError *error = NULL;
int value = 0;
char *key = "mp3quality";
int defaultvalue = 0;

pthread_mutex_lock(config_get_mutex());
value = g_key_file_get_integer(config_get_keyfile(), streamname, key, &error);
if (error) {
value = defaultvalue;
g_key_file_set_integer(config_get_keyfile(), streamname, key, value);
}
pthread_mutex_unlock(config_get_mutex());
return value;
}

int config_voicestreams_get_timeslot(char *streamname) {
GError *error = NULL;
int value = 0;
Expand Down Expand Up @@ -238,6 +286,13 @@ void config_voicestreams_init(void) {
free(tmp);
config_voicestreams_get_savetorawfile(voicestreams[i]);
config_voicestreams_get_savedecodedtorawfile(voicestreams[i]);
config_voicestreams_get_savedecodedtomp3file(voicestreams[i]);
#ifndef MP3ENCODEVOICE
if (config_voicestreams_get_savedecodedtomp3file(voicestreams[i]))
console_log("config warning: voice stream %s has mp3 encoding enabled, but mp3 encoding is not compiled in\n", voicestreams[i]);
#endif
config_voicestreams_get_mp3bitrate(voicestreams[i]);
config_voicestreams_get_mp3quality(voicestreams[i]);
config_voicestreams_get_timeslot(voicestreams[i]);
config_voicestreams_get_decodequality(voicestreams[i]);

Expand All @@ -248,7 +303,7 @@ void config_voicestreams_init(void) {
}

console_log("config: loaded %u voice stream configs\n", i);
#ifndef DECODEVOICE
#ifndef AMBEDECODEVOICE
if (i > 0)
console_log("config warning: voice streams defined in config but voice decoding is not compiled in\n");
#endif
Expand Down
3 changes: 3 additions & 0 deletions libs/config/config-voicestreams.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ char *config_voicestreams_get_repeaterhosts(char *streamname);
char *config_voicestreams_get_savefiledir(char *streamname);
int config_voicestreams_get_savetorawfile(char *streamname);
int config_voicestreams_get_savedecodedtorawfile(char *streamname);
int config_voicestreams_get_savedecodedtomp3file(char *streamname);
int config_voicestreams_get_mp3bitrate(char *streamname);
int config_voicestreams_get_mp3quality(char *streamname);
int config_voicestreams_get_timeslot(char *streamname);
int config_voicestreams_get_decodequality(char *streamname);

Expand Down
46 changes: 32 additions & 14 deletions libs/daemon/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <termios.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <fcntl.h>
#include <stdlib.h>
#include <time.h>
Expand Down Expand Up @@ -216,12 +215,27 @@ static flag_t console_isloglevelchar(char loglevel_char) {
}
}

static void console_log_display(char *text, va_list *argptr) {
static int8_t console_loglevel_match(const char *format) {
uint8_t first_non_format_char_pos;
uint8_t i;

first_non_format_char_pos = 0;
while (console_isloglevelchar(format[first_non_format_char_pos]))
first_non_format_char_pos++;

for (i = 0; i < first_non_format_char_pos; i++) {
if (!console_isallowedtodisplay(format[i]))
return -1;
}
return first_non_format_char_pos;
}

static void console_log_display(const char *text, va_list argptr) {
char buffer[CONSOLELOGBUFFERSIZE];
size_t buffer_length = 0;

pthread_mutex_lock(&console_mutex);
vsnprintf(buffer, sizeof(buffer), text, *argptr);
vsnprintf(buffer, sizeof(buffer), text, argptr);
buffer_length = strlen(buffer);

printf("%s", buffer);
Expand All @@ -232,26 +246,30 @@ static void console_log_display(char *text, va_list *argptr) {
pthread_mutex_unlock(&console_mutex);
}

void console_log(char *format, ...) {
void console_log(const char *format, ...) {
va_list argptr;
uint8_t first_non_format_char_pos;
uint8_t i;
int8_t first_non_format_char_pos;

va_start(argptr, format);

first_non_format_char_pos = 0;
while (console_isloglevelchar(format[first_non_format_char_pos]))
first_non_format_char_pos++;
first_non_format_char_pos = console_loglevel_match(format);
if (first_non_format_char_pos < 0)
return;

for (i = 0; i < first_non_format_char_pos; i++) {
if (!console_isallowedtodisplay(format[i]))
return;
}
console_log_display(format+first_non_format_char_pos, &argptr);
console_log_display(format+first_non_format_char_pos, argptr);

va_end(argptr);
}

void console_log_va_list(const char *loglevel, const char *format, va_list argptr) {
int8_t first_non_format_char_pos = console_loglevel_match(loglevel);

if (first_non_format_char_pos < 0)
return;

console_log_display(format, argptr);
}

void console_process(void) {
int r, i;
char buf[CONSOLE_INPUTBUFFERSIZE];
Expand Down
5 changes: 4 additions & 1 deletion libs/daemon/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include <libs/base/types.h>

#include <stdarg.h>

#define LOGLEVEL_DEBUG "\x01"
#define LOGLEVEL_DEBUG_VAL 0x01
#define LOGLEVEL_IPSC "\x02"
Expand Down Expand Up @@ -70,7 +72,8 @@ uint16_t console_get_bufferpos(void);
void console_rxbuf_add(char inputchar, flag_t vt100supported);

void console_addtologfile(char *msg, int msglen);
void console_log(char *format, ...);
void console_log(const char *format, ...);
void console_log_va_list(const char *loglevel, const char *format, va_list argptr);

void console_process(void);
void console_init(void);
Expand Down
4 changes: 2 additions & 2 deletions libs/voicestreams/voicestreams-decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <libs/daemon/console.h>

#ifdef DECODEVOICE
#ifdef AMBEDECODEVOICE

static uint8_t voicestreams_decode_deinterleave_matrix_w[36] = {
0, 1, 0, 1, 0, 1,
Expand Down Expand Up @@ -94,4 +94,4 @@ voicestreams_decoded_frame_t *voicestreams_decode_ambe_frame(dmrpacket_payload_a
return &decoded_frame;
}

#endif /* ifdef DECODEVOICE */
#endif /* ifdef AMBEDECODEVOICE */
Loading

0 comments on commit bbbfb3a

Please sign in to comment.