Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
aous72 committed Apr 19, 2024
1 parent 9f21be6 commit 6e51a71
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 55 deletions.
70 changes: 28 additions & 42 deletions src/apps/ojph_stream_expand/ojph_stream_expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool get_arguments(int argc, char *argv[],
char *&src_addr, char *&src_port,
char *&target_name, ojph::ui32& num_threads,
ojph::ui32& num_inflight_packets,
bool& display, bool& decode, bool& store, bool& quiet)
bool& display, bool& quiet)
{
ojph::cli_interpreter interpreter;
interpreter.init(argc, argv);
Expand All @@ -68,8 +68,6 @@ bool get_arguments(int argc, char *argv[],
interpreter.reinterpret("-num_packets", num_inflight_packets);

display = interpreter.reinterpret("-display");
decode = interpreter.reinterpret("-decode");
store = interpreter.reinterpret("-store");
quiet = interpreter.reinterpret("-quiet");

if (interpreter.is_exhausted() == false) {
Expand All @@ -94,11 +92,6 @@ bool get_arguments(int argc, char *argv[],
printf("Please use \"-port\" to provide a port number.\n");
return false;
}
if (store && target_name == NULL)
{
printf("Please use \"-o\" to provide a target file name.\n");
return false;
}
if (num_threads < 1)
{
printf("Please set \"-num_threads\" to 1 or more.\n");
Expand All @@ -121,8 +114,6 @@ int main(int argc, char* argv[])
ojph::ui32 num_threads = 1;
ojph::ui32 num_inflight_packets = 5;
bool display = false;
bool decode = false;
bool store = false;
bool quiet = false;

if (argc <= 1) {
Expand All @@ -149,27 +140,25 @@ int main(int argc, char* argv[])
" -num_packets <integer> number of in-flight packets; this is the\n"
" maximum number of packets to wait before an out-of-order\n"
" or lost packet is considered lost.\n"
" -target_name <string> target file name without extension; the same\n"
" -o <string> target file name without extension; the same\n"
" printf formating can be used. For example, output_%%05d.\n"
" An extension will be added, either .j2c for original\n"
" frames, or .ppm for decoded images.\n"
" -display use this to display decoded frames.\n"
" -decode use this to decode files and store them.\n"
" -store use this to store encoded files.\n."
" -quiet use to stop printing informative messages.\n."
"\n"
);
exit(-1);
}
if (!get_arguments(argc, argv, recv_addr, recv_port, src_addr, src_port,
target_name, num_threads, num_inflight_packets,
display, decode, store, quiet))
display, quiet))
{
exit(-1);
}

ojph::stex::frames_handler frames_handler;
frames_handler.init(quiet, num_threads, store, target_name, decode, display);
frames_handler.init(quiet, num_threads, target_name, display);
ojph::stex::packets_handler packets_handler;
packets_handler.init(quiet, num_inflight_packets, &frames_handler);
ojph::net::socket_manager smanager;
Expand Down Expand Up @@ -239,38 +228,35 @@ int main(int argc, char* argv[])

bool src_printed = false;
ojph::stex::rtp_packet* packet = NULL;
while(1)
while (1)
{
packet = packets_handler.exchange(packet);
while (1)
struct sockaddr_in si_other;
socklen_t socklen = sizeof(si_other);
// receive data -- this is a blocking call
packet->num_bytes = (int)recvfrom(s.intern(), (char*)packet->data,
buffer_size, 0, (struct sockaddr *) &si_other, &socklen);
if (packet->num_bytes < 0)
{
struct sockaddr_in si_other;
socklen_t socklen = sizeof(si_other);
// receive data -- this is a blocking call
packet->num_bytes = (int)recvfrom(s.intern(), packet->data, buffer_size,
0, (struct sockaddr *) &si_other, &socklen);
if (packet->num_bytes < 0)
{
std::string err = smanager.get_last_error_message();
OJPH_INFO(0x02000008, "Failed to receive data : %s\n", err.data());
continue; // if we wish to continue
}
if ((src_addr && saddr != smanager.get_addr(si_other)) ||
(src_port && sport != si_other.sin_port))
continue;
if (!quiet && !src_printed)
{
constexpr int buf_size = 128;
char buf[buf_size];
if (!inet_ntop(AF_INET, &si_other, buf, buf_size)) {
std::string err = smanager.get_last_error_message();
OJPH_INFO(0x02000008, "Failed to receive data : %s\n", err.data());
continue; // if we wish to continue
}
if ((src_addr && saddr != smanager.get_addr(si_other)) ||
(src_port && sport != si_other.sin_port))
continue;
if (!quiet && !src_printed)
{
constexpr int buf_size = 128;
char buf[buf_size];
if (!inet_ntop(AF_INET, &si_other, buf, buf_size)) {
std::string err = smanager.get_last_error_message();
OJPH_INFO(0x02000009,
"Error converting source address.\n", err.data());
}
printf("Receiving data from %s, port %d\n",
buf, ntohs(si_other.sin_port));
src_printed = true;
OJPH_INFO(0x02000009,
"Error converting source address.\n", err.data());
}
printf("Receiving data from %s, port %d\n",
buf, ntohs(si_other.sin_port));
src_printed = true;
}
}

Expand Down
20 changes: 14 additions & 6 deletions src/apps/ojph_stream_expand/stream_expand_support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,24 @@ void packets_handler::init(bool quiet, ui32 num_packets,
///////////////////////////////////////////////////////////////////////////////
rtp_packet* packets_handler::exchange(rtp_packet* p)
{
if (avail != NULL)

if (p != NULL)
{ // check validity/supported features in p
}

if (p)
{
ui32 packet_type = p->get_packet_type();
if (packet_type == rtp_packet::packet_type::PT_MAIN)
printf("A new frame %d\n", p->get_time_stamp());
}


if (avail != NULL)
{
}
else
{

}
return packet_store;
}
Expand All @@ -94,14 +105,11 @@ frames_handler::~frames_handler()

///////////////////////////////////////////////////////////////////////////////
void frames_handler::init(bool quiet, ui32 num_threads,
bool store, const char *target_name,
bool decode, bool display)
const char *target_name, bool display)
{
this->quiet = quiet;
this->num_threads = num_threads;
this->store = store;
this->target_name = target_name;
this->decode = decode;
this->display = display;

num_files = num_threads + 1;
Expand Down
10 changes: 3 additions & 7 deletions src/apps/ojph_stream_expand/stream_expand_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct rtp_packet
public:
static constexpr int max_size = 2048; //!<maximum packet size
// ethernet packet are only 1500
char data[max_size]; //!<data in the packet
ui8 data[max_size]; //!<data in the packet
int num_bytes; //!<number of bytes
rtp_packet* next; //!<used for linking packets
};
Expand Down Expand Up @@ -211,24 +211,20 @@ class frames_handler
{
quiet = false;
num_threads = 0;
store = false;
target_name = NULL;
decode = display = false;
num_files = 0;
files = NULL;
}
~frames_handler();

public:
void init(bool quiet, ui32 num_threads, bool store, const char *target_name,
bool decode, bool display);
void init(bool quiet, ui32 num_threads, const char *target_name,
bool display);

private:
bool quiet; //!<no informational info is printed when true
ui32 num_threads; //!<max number of threads used for decoding/display
bool store; //!<files are stored when true
const char *target_name; //!<target file name template
bool decode; //!<files are decoded when true
bool display; //!<images are displayed when true
ui32 num_files; //!<maximum number of in-flight files.
stex_file* files; //!<address for allocated files
Expand Down

0 comments on commit 6e51a71

Please sign in to comment.