Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split main() into a few functions #656

Open
gavv opened this issue Dec 6, 2023 · 6 comments
Open

Split main() into a few functions #656

gavv opened this issue Dec 6, 2023 · 6 comments
Assignees
Labels
command-line easy hacks The solution is expected to be straightforward even if you are new to the project help wanted An important and awaited task but we have no human resources for it yet refactoring

Comments

@gavv
Copy link
Member

gavv commented Dec 6, 2023

CLI tools main() became too large and needs refactoring. We could extract several functions, e.g.: building io config, building pipeline config, running pump.

This should be done for all three tools: roc-send, roc-recv, roc-copy.

Code: https://github.com/roc-streaming/roc-toolkit/tree/develop/src/tools
Docs: https://roc-streaming.org/toolkit/docs/manuals.html

@gavv gavv added refactoring help wanted An important and awaited task but we have no human resources for it yet easy hacks The solution is expected to be straightforward even if you are new to the project labels Dec 6, 2023
@gavv gavv added this to Frontlog in kanban board Dec 6, 2023
@gavv gavv moved this from Frontlog to Help wanted in kanban board Dec 6, 2023
@nolan-veed
Copy link
Contributor

I'll do.

@gavv
Copy link
Member Author

gavv commented Dec 28, 2023

Great!

@nolan-veed
Copy link
Contributor

I'm having a hard time understanding the dependencies. I'm looking at roc_send main.cpp for example.

Various objects needs to be setup using args, and also depend on each other. So, any pointers on how to approach this will help. Right now, I'm a bit lost.

@gavv
Copy link
Member Author

gavv commented Dec 30, 2023

Yeah, that code definitely needs more love. Here is a little overview, HTH, and hopefully your refactoring will make it clearer.

High level goal of roc-send and roc-recv is to build source, sink, and pump.

Source is from where you can read samples. Sink is where you can write samples. Pump transfers samples from source to sink.

In roc-send, source is implemented by roc_sndio, and reads samples from file or device. And sink is provided by roc_node, specifically node::Sender, which sends samples written to it to remote receiver.

Internally, node::Sender creates pipeline (pipeline::SenderLoop) and network loop (netio::NetworkLoop) and connects them together.

pipeline::SenderLoop implements sink interface. When you write samples to it, it produces packets, which are then written to network loop and queued for sending.

main() builds two configs: pipeline::SenderConfig (for sending sink) and sndio::Config (for file/device source). I think building these two configs can be extracted into two functions.

Then main() parses endpoints and tells node::Sender to use them. This probably can also be extracted into a function.

The, finally, main() constructs Pump and tells it to transfer samples from source to sink. This can become a function as well.

Feel free to ask specific questions if you'll have more.

See also https://github.com/roc-streaming/roc-toolkit/blob/develop/docs%2Fsphinx%2Finternals%2Faudio_backends.rst

and https://roc-streaming.org/toolkit/docs/internals/code_structure.html

@nolan-veed
Copy link
Contributor

Hey, thanks for the pointers. I didn't manage to spend a lot of time last month, so I'm looking at this now.

@gavv
Copy link
Member Author

gavv commented Feb 10, 2024

Cool, welcome back! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
command-line easy hacks The solution is expected to be straightforward even if you are new to the project help wanted An important and awaited task but we have no human resources for it yet refactoring
Projects
kanban board
Help wanted
Development

No branches or pull requests

2 participants