Skip to content

Commit

Permalink
Merge pull request #144 from toniebox-reverse-engineering/develop
Browse files Browse the repository at this point in the history
v0.4.1
  • Loading branch information
SciLor authored Mar 29, 2024
2 parents bd2e9fd + 9100022 commit 2a6a2d6
Show file tree
Hide file tree
Showing 28 changed files with 1,509 additions and 621 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ CYCLONE_SOURCES = \
# remove cyclone sources for which modifications exist
CYCLONE_SOURCES := $(filter-out \
cyclone/common/debug.c \
cyclone/common/error.c \
cyclone/cyclone_tcp/http/http_server.c \
cyclone/cyclone_tcp/http/http_server_misc.c \
cyclone/cyclone_ssl/tls_certificate.c \
Expand All @@ -338,6 +339,7 @@ CYCLONE_SOURCES := $(filter-out \
# and add modified ones
CYCLONE_SOURCES += \
src/cyclone/common/debug.c \
src/cyclone/common/error.c \
src/cyclone/cyclone_crypto/mpi.c \
src/cyclone/cyclone_tcp/http/http_server.c \
src/cyclone/cyclone_tcp/http/http_server_misc.c \
Expand Down
2 changes: 2 additions & 0 deletions include/fs_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@

void fsFixPath(char_t *path);
FsFile *fsOpenFileEx(const char_t *path, char *mode);
error_t fsCompareFiles(const char_t *source_path, const char_t *target_path, size_t *diff_position);
error_t fsCopyFile(const char_t *source_path, const char_t *target_path, bool_t overwrite);
error_t fsMoveFile(const char_t *source_path, const char_t *target_path, bool_t overwrite);
12 changes: 10 additions & 2 deletions include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define TONIESV2_CUSTOM_JSON_FILE "tonies.custom.json"
#define CONFIG_FILE "config.ini"
#define CONFIG_OVERLAY_FILE "config.overlay.ini"
#define CONFIG_VERSION 6
#define CONFIG_VERSION 8
#define MAX_OVERLAYS 16 + 1

typedef enum
Expand Down Expand Up @@ -71,9 +71,16 @@ typedef struct
bool prioCustomContent;
bool updateOnLowerAudioId;
bool dumpRuidAuthContentJson;
uint32_t ffmpeg_stream_buffer_ms;
} settings_cloud_t;

typedef struct
{
uint32_t bitrate;
uint32_t ffmpeg_stream_buffer_ms;
bool ffmpeg_stream_restart;

} settings_encode_t;

typedef struct
{
bool enabled;
Expand Down Expand Up @@ -248,6 +255,7 @@ typedef struct
char *boxName;
settings_core_t core;
settings_cloud_t cloud;
settings_encode_t encode;
settings_mqtt_t mqtt;
settings_hass_t hass;
settings_toniebox_t toniebox;
Expand Down
2 changes: 2 additions & 0 deletions include/toniebox_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

#include <stdbool.h>
#include <stdint.h>
#include "toniefile.h"

typedef struct
{
const char *id;
const char *name;
ffmpeg_stream_ctx_t ffmpeg_ctx;
} toniebox_state_box_t;

typedef struct
Expand Down
24 changes: 18 additions & 6 deletions include/toniefile.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

#pragma once
#include <stdint.h>

#include "fs_ext.h"

#define OPUS_FRAME_SIZE_MS OPUS_FRAMESIZE_60_MS
#define OPUS_SAMPLING_RATE 48000
#define OPUS_BIT_RATE 96000
#define OPUS_FRAME_SIZE 2880 /* samples: 60ms at 48kHz */
// #define OPUS_BIT_RATE 96000
#define OPUS_FRAME_SIZE OPUS_SAMPLING_RATE * 60 / 1000 /* samples: 60ms at 48kHz */
#define OPUS_CHANNELS 2
#define OPUS_PACKET_PAD 64
#define OPUS_PACKET_MINSIZE 64
Expand All @@ -15,6 +15,18 @@
#define TONIEFILE_MAX_CHAPTERS 100
#define TONIEFILE_PAD_END 64

#define OGG_HEADER_LENGTH 27
/*
quint32 Signature;
quint8 Version;
quint8 Flags;
quint64 GranulePosition;
quint32 SerialNumber;
quint32 SequenceNumber;
quint32 Checksum;
quint8 TotalSegments;
*/

typedef struct toniefile_s toniefile_t;

typedef struct
Expand All @@ -23,13 +35,13 @@ typedef struct
char *source;
size_t skip_seconds;
char *targetFile;
bool_t append;
OsTaskId taskId;
error_t error;
bool_t quit;

} ffmpeg_stream_ctx_t;

toniefile_t *toniefile_create(const char *fullPath, uint32_t audio_id);
toniefile_t *toniefile_create(const char *fullPath, uint32_t audio_id, bool append);
error_t toniefile_close(toniefile_t *ctx);
error_t toniefile_encode(toniefile_t *ctx, int16_t *sample_buffer, size_t samples_available);
error_t toniefile_write_header(toniefile_t *ctx);
Expand All @@ -39,6 +51,6 @@ FILE *ffmpeg_decode_audio_start(const char *input_source);
FILE *ffmpeg_decode_audio_start_skip(const char *input_source, size_t skip_seconds);
error_t ffmpeg_decode_audio_end(FILE *ffmpeg_pipe, error_t error);
error_t ffmpeg_decode_audio(FILE *ffmpeg_pipe, int16_t *buffer, size_t size, size_t *bytes_read);
error_t ffmpeg_stream(char source[99][PATH_LEN], size_t source_len, const char *target_taf, size_t skip_seconds, bool_t *active);
error_t ffmpeg_stream(char source[99][PATH_LEN], size_t source_len, const char *target_taf, size_t skip_seconds, bool_t *active, bool_t append);
error_t ffmpeg_convert(char source[99][PATH_LEN], size_t source_len, const char *target_taf, size_t skip_seconds);
void ffmpeg_stream_task(void *param);
6 changes: 6 additions & 0 deletions proto/toniebox.pb.taf-header.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ message TonieboxAudioFileHeader {
required uint32 audio_id = 3;
repeated uint32 track_page_nums = 4 [packed=true];
required bytes _fill = 5;
//custom_fields_start
optional uint64 ogg_granule_position = 6;
optional uint64 ogg_packet_count = 7;
optional uint64 taf_block_num = 8;
optional uint64 pageno = 9;
//custom_fields_end
}
2 changes: 1 addition & 1 deletion src/cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ error_t cert_generate_signed(const char *subject, const uint8_t *serial_number,
error_t error = x509CreateCertificate(rand_get_algo(), rand_get_context(), &cert_req, &cert_pubkey, self_sign ? NULL : &issuer_cert, &serial, &validity, &algo, self_sign ? &cert_privkey : &issuer_priv, cert_der_data, &cert_der_size);
if (error != NO_ERROR)
{
TRACE_ERROR("x509CreateCertificate failed: %d\r\n", error);
TRACE_ERROR("x509CreateCertificate failed: %s\r\n", error2text(error));
return ERROR_FAILURE;
}

Expand Down
8 changes: 4 additions & 4 deletions src/cloud_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ error_t web_request(const char *server, int port, bool https, const char *uri, c
if (error)
{
// Debug message
TRACE_ERROR("Failed to connect to HTTP server! Error=%u\r\n", error);
TRACE_ERROR("Failed to connect to HTTP server! Error=%s\r\n", error2text(error));
if (isCloud)
stats_update("cloud_failed", 1);
break;
Expand All @@ -235,7 +235,7 @@ error_t web_request(const char *server, int port, bool https, const char *uri, c
if (error)
{
// Debug message
TRACE_ERROR("Failed to set content length! Error=%u\r\n", error);
TRACE_ERROR("Failed to set content length! Error=%s\r\n", error2text(error));
if (isCloud)
stats_update("cloud_failed", 1);
break;
Expand Down Expand Up @@ -268,7 +268,7 @@ error_t web_request(const char *server, int port, bool https, const char *uri, c
if (error)
{
// Debug message
TRACE_ERROR("Failed to write HTTP request header, error=%u!\r\n", error);
TRACE_ERROR("Failed to write HTTP request header, error=%s!\r\n", error2text(error));
if (isCloud)
stats_update("cloud_failed", 1);
break;
Expand All @@ -282,7 +282,7 @@ error_t web_request(const char *server, int port, bool https, const char *uri, c
if (error)
{
// Debug message
TRACE_ERROR("Failed to write HTTP request body, error=%u!\r\n", error);
TRACE_ERROR("Failed to write HTTP request body, error=%s!\r\n", error2text(error));
if (isCloud)
stats_update("cloud_failed", 1);
break;
Expand Down
Loading

0 comments on commit 2a6a2d6

Please sign in to comment.