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

Cleanup 2 #26

Merged
merged 3 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endif(NOT EXISTS ${CMAKE_TOOLCHAIN_FILE})
################################################################################
# top-level project name, version, and languages - this project will have
# several projects, but this is declared as the top level project.
project(neoMedia VERSION 0.1 LANGUAGES C CXX)
project(qmedia VERSION 0.1 LANGUAGES C CXX)

################################################################################
# If this is a Makefile generator and the build type was not defined, then the
Expand All @@ -44,8 +44,6 @@ option(BUILD_EXTERN "build external library" ON)
option(BUILD_TESTS "build tests" ON)
option(BUILD_SEND_VIDEO_FRAME "build sendVideoFrame cmd" ON)
option(CLANG_TIDY "Perform linting with clang-tidy" OFF)
option(BUILD_WITH_QUIC "Build with quic transport" OFF)
option(BUILD_WITH_QUICR "Build with quicr transport" ON)

################################################################################
# dependencies
Expand Down Expand Up @@ -176,27 +174,7 @@ target_include_directories(${LIB_NAME}
$<INSTALL_INTERFACE:include/${PROJECT_NAME}-${PROJECT_VERSION}>
)

if(BUILD_WITH_QUIC)
# picoquic and friends
if (WIN32)
target_link_libraries(${LIB_NAME} picotls-openssl picotls-core picotls-fusion picoquic)
else(WIN32)
target_link_libraries(${LIB_NAME} picotls-openssl picotls-core picotls-fusion picoquic-core)
endif(WIN32)
add_compile_definitions(${LIB_NAME} ENABLE_QUIC)
endif()

if(BUILD_WITH_QUICR)
message(STATUS "PICO = ${Picoquic_LIBRARIES}")
message(STATUS "PICO_TLS = ${PTLS_LIBRARIES}")
# picoquic and friends
if (WIN32)
target_link_libraries(${LIB_NAME} ${QUICR_LIBRARIES} ${Picoquic_LIBRARIES} ${PTLS_LIBRARIES})
else(WIN32)
target_link_libraries(${LIB_NAME} ${QUICR_LIBRARIES} ${Picoquic_LIBRARIES} ${PTLS_LIBRARIES})
endif(WIN32)
add_compile_definitions(${LIB_NAME} ENABLE_QUICR)
endif()
target_link_libraries(${LIB_NAME} ${QUICR_LIBRARIES} ${Picoquic_LIBRARIES} ${PTLS_LIBRARIES})


###
Expand Down
4 changes: 2 additions & 2 deletions cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
add_executable(forty forty-bytes.cc)
target_link_libraries( forty PUBLIC neoMedia)
target_link_libraries( forty PUBLIC qmedia)

find_package(portaudio QUIET)
if(portaudio_FOUND)
add_executable( sound sound.cc)
target_link_libraries( sound PUBLIC neoMedia)
target_link_libraries( sound PUBLIC qmedia)

if (WIN32)
target_link_libraries( sound PUBLIC portaudio)
Expand Down
40 changes: 7 additions & 33 deletions cmd/forty-bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ void send_loop(uint64_t client_id, uint64_t source_id)
}
}


int main(int argc, char *argv[])
{
std::string mode;
Expand All @@ -90,52 +89,28 @@ int main(int argc, char *argv[])
std::cerr << "Must provide mode of operation" << std::endl;
std::cerr << "Usage: forty <transport> <mode> <client-id> "
<< std::endl;
std::cerr << "Transport: q (for quic), r (udp), qr(quicr)"
<< std::endl;
std::cerr << "Mode: sendrecv/send/recv" << std::endl;
std::cerr << "ClientID - a sensible +ve 32 bit integer value"
<< std::endl;
return -1;
}


transport_type.assign(argv[1]);

LoggerPointer logger = std::make_shared<Logger>("FORTY_BYTES");
logger->SetLogFacility(LogFacility::CONSOLE);

transportManager = new ClientTransportManager(
neo_media::NetTransport::QUICR, "127.0.0.1", 7777, nullptr, logger);
transportManager->start();

if (transport_type == "q")
{
std::cout << "Transport is Quic [ !!! Not under active developmenr "
"!!!]\n";
transportManager = new ClientTransportManager(
neo_media::NetTransport::PICO_QUIC, "localhost", 5004);
}
else if (transport_type == "qr")
{
std::cout << "Transport is QuicR\n";
transportManager = new ClientTransportManager(
neo_media::NetTransport::QUICR, "127.0.0.1", 7777, nullptr, logger);
transportManager->start();
}
else
{
std::cout << "Transport is UDP\n";
transportManager = new ClientTransportManager(
neo_media::NetTransport::UDP, "localhost", 5004);
transportManager->start();
}

mode.assign(argv[2]);
mode.assign(argv[1]);
if (mode != "send" && mode != "recv" && mode != "sendrecv")
{
std::cout << "Bad choice for mode.. Bye" << std::endl;
exit(-1);
}

std::string client_id_str;
client_id_str.assign(argv[3]);
client_id_str.assign(argv[2]);
if (client_id_str.empty())
{
std::cout << "Bad choice for clientId .. Bye" << std::endl;
Expand All @@ -149,9 +124,8 @@ int main(int argc, char *argv[])
std::weak_ptr<NetTransportQUICR> tmp =
std::static_pointer_cast<NetTransportQUICR>(transport.lock());
auto quicr_transport = tmp.lock();
quicr_transport->subscribe(source_id,
Packet::MediaType::Opus,
"forty_bytes_alice");
quicr_transport->subscribe(
source_id, Packet::MediaType::Opus, "forty_bytes_alice");

// start the transport
quicr_transport->start();
Expand Down
69 changes: 35 additions & 34 deletions cmd/sound.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,24 @@ void recordThreadFunc(Neo *neo)
PaError err;
{
std::lock_guard<std::mutex> lock(audioReadMutex);
while( ( err = Pa_IsStreamActive( audioStream ) ) == 1 )
while ((err = Pa_IsStreamActive(audioStream)) == 1)
{
long toRead = Pa_GetStreamReadAvailable(audioStream);
printf("available: %ld frames_per_buffer: %d\n", toRead, frames_per_buffer);
if (toRead == 0) {
printf("available: %ld frames_per_buffer: %d\n",
toRead,
frames_per_buffer);
if (toRead == 0)
{
Pa_Sleep(10);
continue;
}
if (toRead > frames_per_buffer)
toRead = frames_per_buffer;

if (toRead == frames_per_buffer) {
if (toRead > frames_per_buffer) toRead = frames_per_buffer;

// You may get underruns or overruns if the output is not primed by PortAudio.
err = Pa_ReadStream( audioStream, audioBuff, toRead );
if (toRead == frames_per_buffer)
{
// You may get underruns or overruns if the output is not
// primed by PortAudio.
err = Pa_ReadStream(audioStream, audioBuff, toRead);
if (err)
{
logger->error << "Failed to read PA stream: "
Expand All @@ -93,17 +96,16 @@ void recordThreadFunc(Neo *neo)
logger->debug << "0" << std::flush;
}

timestamp = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
timestamp =
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();

neo->sendAudio(audioBuff, buff_size, timestamp, sourceID);
logger->debug << "-" << std::flush;
Pa_Sleep(10);
}

}

}
free(audioBuff);
}
Expand Down Expand Up @@ -281,7 +283,7 @@ void streamCallBack(uint64_t clientID,

int main(int argc, char *argv[])
{
const uint64_t conference_id = 123456;
const uint64_t conference_id = 123456;
#if defined(_WIN32)
timeBeginPeriod(1); // timerstonk - push minimum resolution down to 1
// ms
Expand All @@ -292,12 +294,10 @@ int main(int argc, char *argv[])
std::cerr << "Usage: sound <remote-address> <mode> <name> <source-id> "
<< std::endl;
std::cerr << "Mode: pub/sub/pubsub" << std::endl;
std::cerr << ""
<< std::endl;
std::cerr << "" << std::endl;
return -1;
}


std::string remote_address;
remote_address.assign(argv[1]);

Expand Down Expand Up @@ -325,7 +325,6 @@ int main(int argc, char *argv[])
exit(-1);
}


std::ostringstream oss;
std::chrono::steady_clock::time_point timePoint =
std::chrono::steady_clock::now();
Expand Down Expand Up @@ -367,7 +366,6 @@ int main(int argc, char *argv[])
assert(0); // TODO
}


PaStreamParameters inputParameters;
PaStreamParameters outputParameters;

Expand Down Expand Up @@ -416,35 +414,39 @@ int main(int argc, char *argv[])
assert(0); // TODO
}


if(mode == "pub") {
if (mode == "pub")
{
std::thread recordThread(recordThreadFunc, &neo);
} else if (mode == "sub") {
}
else if (mode == "sub")
{
std::thread playThread(playThreadFunc, &neo);
playThread.detach();
}

std::cout << "Mode:" << mode << std::endl;
if(mode == "pub")
if (mode == "pub")
{
// todo : use stringstream inseatd
auto url = "quicr://" + std::to_string(conference_id) + "/" + std::to_string(clientID)
+ "/" + name + "/" + source;
auto url = "quicr://" + std::to_string(conference_id) + "/" +
std::to_string(clientID) + "/" + name + "/" + source;
std::cout << "quicr publish url:" << url << std::endl;
neo.publish(1, Packet::MediaType::Opus, url);
} else if (mode == "sub")
}
else if (mode == "sub")
{
auto url = "quicr://" + std::to_string(conference_id) + "/" + std::to_string(clientID)
+ "/" + name + "/" + source;
auto url = "quicr://" + std::to_string(conference_id) + "/" +
std::to_string(clientID) + "/" + name + "/" + source;
std::cout << "quicr subscribe url:" << url << std::endl;
neo.subscribe(1, Packet::MediaType::Opus, url);
} else {
}
else
{
// pub/sub mode
std::cout << "Pub and Sub together isn't supported\n";
exit(-1);
}


logger->info << "Starting" << std::flush;
int count = 0;
while (!shutDown)
Expand All @@ -459,9 +461,8 @@ int main(int argc, char *argv[])
}
logger->info << "Shutting down" << std::flush;


//recordThread.join();
//playThread.join();
// recordThread.join();
// playThread.join();

err = Pa_StopStream(audioStream);
if (err != paNoError)
Expand Down
2 changes: 1 addition & 1 deletion include/h264_encoder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public:
unsigned int video_max_frame_rate,
unsigned int video_max_bitrate,
std::uint32_t video_pixel_format,
const LoggerPointer& logger);
const LoggerPointer &logger);

~H264Encoder();

Expand Down
6 changes: 3 additions & 3 deletions include/neo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public:

enum struct MediaDirection
{
publish_only = 1, // sendonly
subscribe_only, // recvonly
publish_subscribe, //sendrecv
publish_only = 1, // sendonly
subscribe_only, // recvonly
publish_subscribe, // sendrecv
unknown
};

Expand Down
Loading