Skip to content

Commit

Permalink
Scons fmt formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrick87 committed Feb 25, 2024
1 parent 6c6176a commit 92ac7a4
Show file tree
Hide file tree
Showing 15 changed files with 269 additions and 207 deletions.
2 changes: 1 addition & 1 deletion src/internal_modules/roc_sndio/ibackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IBackend {
const char* path,
const Config& config,
core::IArena& arena) = 0;

virtual const char* name() const = 0;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ IDevice* PulseaudioBackend::open_device(DeviceType device_type,
return device.release();
}

const char* PulseaudioBackend::name() const{
const char* PulseaudioBackend::name() const {
return "PulseAudio";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,55 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include "roc_sndio/sndfile_backend.h"
#include "roc_core/log.h"
#include "roc_core/scoped_ptr.h"
#include "roc_sndio/sndfile_backend.h"
#include "roc_sndio/sndfile_extension_table.h"
#include "roc_sndio/sndfile_sink.h"
#include "roc_sndio/sndfile_source.h"
#include "roc_sndio/sndfile_extension_table.h"

namespace roc {
namespace sndio {

SndfileBackend::SndfileBackend(){
SndfileBackend::SndfileBackend() {
roc_log(LogDebug, "sndfile backend: initializing");
}

void SndfileBackend::discover_drivers(core::Array<DriverInfo, MaxDrivers>& driver_list) {

SF_FORMAT_INFO format_info;
int total_number_of_drivers;

if (int errnum = sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT,
&total_number_of_drivers, sizeof(int))) {
roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR_COUNT) failed %s", sf_error_number(errnum));
}
roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR_COUNT) failed %s",
sf_error_number(errnum));
}

for (int format_index = 0; format_index < total_number_of_drivers; format_index++) {
format_info.format = format_index;
if (int errnum = sf_command(NULL, SFC_GET_FORMAT_MAJOR, &format_info,
sizeof(format_info))) {
roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR) failed %s", sf_error_number(errnum));
roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR) failed %s",
sf_error_number(errnum));
}

const char* driver = format_info.extension;

if((strcmp(format_info.extension, "wav") == 0) || (strcmp(format_info.extension, "mat") == 0)){
for(size_t map_index = 0; map_index < ROC_ARRAY_SIZE(file_type_map); map_index++){
if(file_type_map[map_index].format_id == format_info.format){
if ((strcmp(format_info.extension, "wav") == 0)
|| (strcmp(format_info.extension, "mat") == 0)) {
for (size_t map_index = 0; map_index < ROC_ARRAY_SIZE(file_type_map);
map_index++) {
if (file_type_map[map_index].format_id == format_info.format) {
driver = file_type_map[map_index].driver_name;
}
}
}
}

if (!driver_list.push_back(DriverInfo(driver, DriverType_File,
DriverFlag_SupportsSource
| DriverFlag_SupportsSink,
this))) {
roc_panic("sndfile backend: driver_list.push_back(DriverInfo) failed to add driver");
if (!driver_list.push_back(
DriverInfo(driver, DriverType_File,
DriverFlag_SupportsSource | DriverFlag_SupportsSink, this))) {
roc_panic("sndfile backend: driver_list.push_back(DriverInfo) failed to add "
"driver");
}
}
}
Expand Down Expand Up @@ -112,7 +115,7 @@ IDevice* SndfileBackend::open_device(DeviceType device_type,
}

const char* SndfileBackend::name() const {
return "sndfile";
return "sndfile";
}
} // namespace sndio
} // namespace roc
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class SndfileBackend : public IBackend, core::NonCopyable<> {
virtual const char* name() const;
};



} // namespace sndio
} // namespace roc

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/*
* Copyright (c) 2024 Roc Streaming authors
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

//! @file roc_sndio/target_sndfile/roc_sndio/sndfile_extension_table.h
//! @brief TODO.

#ifndef ROC_SNDIO_SNDFILE_EXTENSION_TABLE_H_
#define ROC_SNDIO_SNDFILE_EXTENSION_TABLE_H_

#pragma once

#ifndef ROC_SNDIO_SNDFILE_FILEMAP_H_
Expand All @@ -13,9 +27,11 @@ struct FileMap {
const char* driver_name;
//! File extension associatied with driver and SF_FORMAT if it exists.
const char* file_extension;
}; static FileMap file_type_map[5]= {
{ SF_FORMAT_MAT4, "mat4", NULL}, { SF_FORMAT_MAT5, "mat5", NULL}, { SF_FORMAT_WAV, "wav", "wav" },
{ SF_FORMAT_NIST, "nist", NULL }, { SF_FORMAT_WAVEX, "wavex", NULL }
};
static FileMap file_type_map[5] = { { SF_FORMAT_MAT4, "mat4", NULL },
{ SF_FORMAT_MAT5, "mat5", NULL },
{ SF_FORMAT_WAV, "wav", "wav" },
{ SF_FORMAT_NIST, "nist", NULL },
{ SF_FORMAT_WAVEX, "wavex", NULL } };

#endif
#endif // ROC_SNDIO_SNDFILE_EXTENSION_TABLE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#define FORMAT_COUNT 2 //Number of major formats that don't allow for subtype SF_FORMAT_PCM_32;

#define FORMAT_COUNT \
2 // Number of major formats that don't allow for subtype SF_FORMAT_PCM_32;
#define BUFFER_SIZE 512

#include "roc_sndio/sndfile_sink.h"
Expand All @@ -29,59 +31,62 @@ bool map_to_sndfile(const char** driver, const char* path, SF_INFO& sfinfo) {
file_extension = dot + 1;

int format_enum = 0;

if(*driver == NULL){
for(size_t file_map_index = 0; file_map_index < ROC_ARRAY_SIZE(file_type_map); file_map_index++){
if(file_type_map[file_map_index].file_extension != NULL){
if(strcmp(file_extension, file_type_map[file_map_index].file_extension) == 0){

if (*driver == NULL) {
for (size_t file_map_index = 0; file_map_index < ROC_ARRAY_SIZE(file_type_map);
file_map_index++) {
if (file_type_map[file_map_index].file_extension != NULL) {
if (strcmp(file_extension, file_type_map[file_map_index].file_extension)
== 0) {
format_enum = file_type_map[file_map_index].format_id;
*driver = file_extension;
break;
}
}
}
}
else{
for(size_t file_map_index = 0; file_map_index < ROC_ARRAY_SIZE(file_type_map); file_map_index++){
if(strcmp(*driver, file_type_map[file_map_index].driver_name) == 0){
} else {
for (size_t file_map_index = 0; file_map_index < ROC_ARRAY_SIZE(file_type_map);
file_map_index++) {
if (strcmp(*driver, file_type_map[file_map_index].driver_name) == 0) {
format_enum = file_type_map[file_map_index].format_id;
break;
}
}
}

if(format_enum == 0){
SF_FORMAT_INFO info ;
if (format_enum == 0) {
SF_FORMAT_INFO info;
int major_count, format_index;
if (int errnum = sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT,
&major_count, sizeof(int))) {
roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR_COUNT) failed %s", sf_error_number(errnum));
if (int errnum =
sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof(int))) {
roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR_COUNT) failed %s",
sf_error_number(errnum));
}

for (format_index = 0 ; format_index < major_count ; format_index++){
info.format = format_index ;
if (int errnum = sf_command(NULL, SFC_GET_FORMAT_MAJOR, &info,
sizeof(info))) {
roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR) failed %s", sf_error_number(errnum));
for (format_index = 0; format_index < major_count; format_index++) {
info.format = format_index;
if (int errnum =
sf_command(NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof(info))) {
roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR) failed %s",
sf_error_number(errnum));
}

if(*driver == NULL){
if(strcmp(info.extension, file_extension) == 0){
if (*driver == NULL) {
if (strcmp(info.extension, file_extension) == 0) {
format_enum = info.format;
*driver = file_extension;
break;
}
}
else{
if(strcmp(info.extension, *driver) == 0){
} else {
if (strcmp(info.extension, *driver) == 0) {
format_enum = info.format;
break;
}
}
}
}

if(format_enum == 0){
if (format_enum == 0) {
return false;
}

Expand Down Expand Up @@ -126,7 +131,6 @@ bool map_to_sndfile(const char** driver, const char* path, SF_INFO& sfinfo) {
SndfileSink::SndfileSink(core::IArena& arena, const Config& config)
: file_(NULL)
, valid_(false) {

if (config.sample_spec.num_channels() == 0) {
roc_log(LogError, "sndfile sink: # of channels is zero");
return;
Expand Down Expand Up @@ -267,7 +271,7 @@ bool SndfileSink::has_clock() const {

void SndfileSink::write(audio::Frame& frame) {
roc_panic_if(!valid_);

audio::sample_t* frame_data = frame.raw_samples();
sf_count_t frame_left = (sf_count_t)frame.num_raw_samples();

Expand All @@ -284,21 +288,24 @@ bool SndfileSink::open_(const char* driver, const char* path) {
unsigned long in_rate = (unsigned long)file_info_.samplerate;

unsigned long out_rate = (unsigned long)file_info_.samplerate;

if (!map_to_sndfile(&driver, path, file_info_)) {
roc_log(LogDebug,
"sndfile sink: map_to_sndfile(): Cannot find valid subtype format for major format type");
"sndfile sink: map_to_sndfile(): Cannot find valid subtype format for "
"major format type");
return false;
}

file_ = sf_open(path, SFM_WRITE, &file_info_);
if (!file_) {
roc_log(LogDebug, "sndfile sink: %s, can't open: driver=%s path=%s", sf_strerror(file_), driver, path);
roc_log(LogDebug, "sndfile sink: %s, can't open: driver=%s path=%s",
sf_strerror(file_), driver, path);
return false;
}

if(sf_command(file_, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0){
roc_log(LogDebug, "sndfile sink: sf_command(SFC_SET_UPDATE_HEADER_AUTO) returned false");
if (sf_command(file_, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) == 0) {
roc_log(LogDebug,
"sndfile sink: sf_command(SFC_SET_UPDATE_HEADER_AUTO) returned false");
return false;
}

Expand All @@ -309,11 +316,9 @@ bool SndfileSink::open_(const char* driver, const char* path) {
" opened: out_rate=%lu in_rate=%lu ch=%lu",
out_rate, in_rate, (unsigned long)file_info_.channels);


sf_count_t err = sf_seek(file_, 0, SEEK_SET);
if (err == -1) {
roc_log(LogError,
"sndfile sink: sf_seek(): %s", sf_strerror(file_));
roc_log(LogError, "sndfile sink: sf_seek(): %s", sf_strerror(file_));
return false;
}

Expand All @@ -329,7 +334,8 @@ void SndfileSink::close_() {

int err = sf_close(file_);
if (err != 0) {
roc_panic("sndfile sink: sf_close() failed. Cannot close output: %s", sf_error_number(err));
roc_panic("sndfile sink: sf_close() failed. Cannot close output: %s",
sf_error_number(err));
}

file_ = NULL;
Expand Down
Loading

0 comments on commit 92ac7a4

Please sign in to comment.