Skip to content

Commit

Permalink
[sp] roc-streaminggh-183 Rework list of status codes
Browse files Browse the repository at this point in the history
This commit implements a part of roc-streaminggh-183 (pipeline error forwarding),
needed for roc-streaminggh-614 (status codes for frame writers/readers).

It updates the list of status codes to be up-to-date with the task.
Most of the codes are not yet actually used.

Changes:
- add missing codes from task
- rename StatusNoData => StatusDrain
- remove StatusLimit (instead use StatusNoMem)
- remove StatusConflict (instead use StatusNoRoute)
- remove StatusUnknown

Sponsored-by: waspd
  • Loading branch information
gavv committed Jun 20, 2024
1 parent a6c7355 commit 412f1dd
Show file tree
Hide file tree
Showing 33 changed files with 384 additions and 223 deletions.
2 changes: 1 addition & 1 deletion src/internal_modules/roc_audio/depacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ packet::PacketPtr Depacketizer::read_packet_() {
packet::PacketPtr pp;
const status::StatusCode code = reader_.read(pp);
if (code != status::StatusOK) {
if (code != status::StatusNoData) {
if (code != status::StatusDrain) {
// TODO(gh-302): forward status
roc_log(LogError, "depacketizer: failed to read packet: status=%s",
status::code_to_str(code));
Expand Down
8 changes: 4 additions & 4 deletions src/internal_modules/roc_fec/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ status::StatusCode Reader::read(packet::PacketPtr& pp) {

if (!alive_) {
// TODO(gh-183): return StatusDead
return status::StatusNoData;
return status::StatusDrain;
}

status::StatusCode code = read_(pp);
Expand All @@ -83,7 +83,7 @@ status::StatusCode Reader::read(packet::PacketPtr& pp) {
if (!alive_) {
pp = NULL;
// TODO(gh-183): return StatusDead
return status::StatusNoData;
return status::StatusDrain;
}

return code;
Expand Down Expand Up @@ -165,7 +165,7 @@ status::StatusCode Reader::get_next_packet_(packet::PacketPtr& ptr) {

if (pos == source_block_.size()) {
if (source_queue_.size() == 0) {
return status::StatusNoData;
return status::StatusDrain;
}
} else {
pp = source_block_[pos++];
Expand Down Expand Up @@ -304,7 +304,7 @@ status::StatusCode Reader::fetch_packets_(packet::IReader& reader,

status::StatusCode code = reader.read(pp);
if (code != status::StatusOK) {
if (code == status::StatusNoData) {
if (code == status::StatusDrain) {
break;
}
return code;
Expand Down
9 changes: 3 additions & 6 deletions src/internal_modules/roc_node/receiver_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ status::StatusCode ReceiverDecoder::write_packet(address::Interface iface,
"receiver decoder node:"
" can't write to %s interface: interface not activated",
address::interface_to_str(iface));
// TODO(gh-183): return StatusNotFound
return status::StatusUnknown;
return status::StatusBadInterface;
}

return writer->write(packet);
Expand All @@ -187,15 +186,13 @@ status::StatusCode ReceiverDecoder::read_packet(address::Interface iface,
"receiver decoder node:"
" can't read from %s interface: interface not activated",
address::interface_to_str(iface));
// TODO(gh-183): return StatusNotFound
return status::StatusNoData;
return status::StatusBadInterface;
} else {
roc_log(LogError,
"sender encoder node:"
" can't read from %s interface: interface doesn't support reading",
address::interface_to_str(iface));
// TODO(gh-183): return StatusBadOperation
return status::StatusNoData;
return status::StatusBadOperation;
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/internal_modules/roc_node/sender_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ status::StatusCode SenderEncoder::read_packet(address::Interface iface,
"sender encoder node:"
" can't read from %s interface: interface not activated",
address::interface_to_str(iface));
// TODO(gh-183): return StatusNotFound
return status::StatusNoData;
return status::StatusBadInterface;
}

return reader->read(packet);
Expand All @@ -202,15 +201,13 @@ status::StatusCode SenderEncoder::write_packet(address::Interface iface,
"sender encoder node:"
" can't write to %s interface: interface not activated",
address::interface_to_str(iface));
// TODO(gh-183): return StatusNotFound
return status::StatusUnknown;
return status::StatusBadInterface;
} else {
roc_log(LogError,
"sender encoder node:"
" can't write to %s interface: interface doesn't support writing",
address::interface_to_str(iface));
// TODO(gh-183): return StatusBadOperation
return status::StatusUnknown;
return status::StatusBadOperation;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/internal_modules/roc_packet/concurrent_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ status::StatusCode ConcurrentQueue::read(PacketPtr& ptr) {

ptr = queue_.pop_front_exclusive();
if (!ptr) {
return status::StatusNoData;
return status::StatusDrain;
}

return status::StatusOK;
Expand Down
4 changes: 2 additions & 2 deletions src/internal_modules/roc_packet/delayed_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ status::StatusCode DelayedReader::fetch_packets_() {
for (;;) {
status::StatusCode code = reader_.read(pp);
if (code != status::StatusOK) {
if (code == status::StatusNoData) {
if (code == status::StatusDrain) {
break;
}
return code;
Expand All @@ -76,7 +76,7 @@ status::StatusCode DelayedReader::fetch_packets_() {

const stream_timestamp_t qs = queue_size_();
if (qs < delay_) {
return status::StatusNoData;
return status::StatusDrain;
}

roc_log(LogDebug,
Expand Down
2 changes: 1 addition & 1 deletion src/internal_modules/roc_packet/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace packet {
status::StatusCode Queue::read(PacketPtr& packet) {
packet = list_.front();
if (!packet) {
return status::StatusNoData;
return status::StatusDrain;
}
list_.remove(*packet);
return status::StatusOK;
Expand Down
2 changes: 1 addition & 1 deletion src/internal_modules/roc_packet/sorted_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ status::StatusCode SortedQueue::read(PacketPtr& packet) {
return status::StatusOK;
}

return status::StatusNoData;
return status::StatusDrain;
}

status::StatusCode SortedQueue::write(const PacketPtr& packet) {
Expand Down
4 changes: 2 additions & 2 deletions src/internal_modules/roc_pipeline/receiver_session_router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ ReceiverSessionRouter::add_session(const core::SharedPtr<ReceiverSession>& sessi
"session router: conflict:"
" another session already exists for source address %s",
address::socket_addr_to_str(source_addr).c_str());
return status::StatusConflict;
return status::StatusNoRoute;
}

if (session_route_map_.find(session)) {
roc_log(LogError, "session router: conflict: session already registered");
return status::StatusConflict;
return status::StatusNoRoute;
}

if (SourceNode* node = source_route_map_.find(source_id)) {
Expand Down
4 changes: 2 additions & 2 deletions src/internal_modules/roc_rtp/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ status::StatusCode Filter::read(packet::PacketPtr& result_packet) {
}

if (!validate_(next_packet)) {
// TODO(gh-183): return StatusAgain
return status::StatusNoData;
// TODO(gh-183): return StatusRetry
return status::StatusDrain;
}

populate_(next_packet);
Expand Down
45 changes: 36 additions & 9 deletions src/internal_modules/roc_status/code_to_str.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,57 @@
*/

#include "roc_status/code_to_str.h"
#include "roc_core/panic.h"
#include "roc_status/status_code.h"

namespace roc {
namespace status {

const char* code_to_str(StatusCode code) {
switch (code) {
case NoStatus:
break;
case StatusOK:
return "OK";
case StatusUnknown:
return "Unknown";
case StatusNoData:
return "NoData";
case StatusDrain:
return "Drain";
case StatusAbort:
return "Abort";
case StatusEnd:
return "End";
case StatusNoMem:
return "NoMem";
case StatusNoSpace:
return "NoSpace";
case StatusLimit:
return "Limit";
case StatusConflict:
return "Conflict";
case StatusNoRoute:
return "NoRoute";
case StatusErrDevice:
return "ErrDevice";
case StatusErrFile:
return "ErrFile";
case StatusErrNetwork:
return "ErrNetwork";
case StatusErrThread:
return "ErrThread";
case StatusErrRand:
return "ErrRand";
case StatusBadSlot:
return "BadSlot";
case StatusBadInterface:
return "BadInterface";
case StatusBadProtocol:
return "BadProtocol";
case StatusBadConfig:
return "BadConfig";
case StatusBadArg:
return "BadArg";
case StatusBadOperation:
return "BadOperation";
}

return "<invalid>";
// Most likely someone forgot to initialize status to a proper
// value and returned it.
roc_panic("status: corrupted or uninitialized value: code=%d", code);
}

} // namespace status
Expand Down
145 changes: 138 additions & 7 deletions src/internal_modules/roc_status/status_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,144 @@ namespace status {

//! Status code.
enum StatusCode {
StatusOK, //!< Status indicating a success of an operation.
StatusUnknown, //!< Unknown status.
StatusNoData, //!< There is no enough data to perform an operation.
StatusNoMem, //!< Allocation failed during operation.
StatusNoSpace, //!< Not enough space in buffer.
StatusLimit, //!< Operation forbidden because limit exceeded.
StatusConflict //!< Operation forbidden because of conflict.
//! Uninitialized status value.
//! @remark
//! Should be never returned from anywhere.
//! Indicates that we forgot to assign actual status to a variable
//! before returning it.
NoStatus = -1,

//! Operation completed successfully.
StatusOK,

//! Stream is empty currently, but more to come later.
//! @remarks
//! Indicates that we can't read more data right now and should try later,
//! when more data arrives.
//! @note
//! Example: we've read all packets from incoming queue and it became
//! empty (drained), but more packets are expected.
StatusDrain,

//! Stream aborted prematurely.
//! @remarks
//! Indicates that we've can't read or write anymore because stream
//! was abnormally interrupted and terminated.
//! @note
//! Example: session terminated because of no_playback timeout.
StatusAbort,

//! Stream is fully read.
//! @remarks
//! Indicates that we've successfully read everything and there is no
//! more data ever.
//! @note
//! Example: we've got end of file when reading from file, or end of
//! stream when reading from network.
StatusEnd,

//! Insufficient memory.
//! @remarks
//! Indicates low memory or reached memory limit.
//! @note
//! Example: not enough memory when creating new session.
StatusNoMem,

//! Insufficient buffer space.
//! @remarks
//! Indicates that configured buffer size(s) and too small to fulfill request.
//! @note
//! Example: packet size exceeds configured maximum buffer size.
StatusNoSpace,

//! No route found.
//! @remarks
//! Indicates that there is no suitable route to handle request.
//! @note
//! Example: we're trying to write a packet, but there is no exiting session
//! to which it belongs.
StatusNoRoute,

//! Failure with audio device.
//! @remarks
//! Indicates that error occurred when working with audio device.
//! @note
//! Example: can't open device, can't write to device.
StatusErrDevice,

//! Failure with file.
//! @remarks
//! Indicates that error occurred when working with file.
//! @note
//! Example: can't open file, can't write to file.
StatusErrFile,

//! Failure with networking.
//! @remarks
//! Indicates that error occurred when trying to perform network operation.
//! @note
//! Example: can't create a socket or establish connection.
StatusErrNetwork,

//! Failure with threads.
//! @remarks
//! Indicates that error occurred when trying to start thread.
//! @note
//! Example: can't start control loop thread because system limit reached.
StatusErrThread,

//! Failure with PRNG.
//! @remarks
//! Indicates that error occurred when working PRNG.
//! @note
//! Example: can't read bytes from CSPRNG.
StatusErrRand,

//! Bad slot state.
//! @remarks
//! Slot state doesn't allow operation.
//! @note
//! Example: trying to use slot that was marked broken.
StatusBadSlot,

//! Bad interface state.
//! @remarks
//! Interface state doesn't allow operation.
//! @note
//! Example: trying to use interface that was not activated.
StatusBadInterface,

//! Bad protocol value.
//! @remarks
//! Requested protocol is not allowed or supported in this context.
//! @note
//! Example: trying use transport protocol with control interface, or
//! trying to connect using a protocol that supports only binding.
StatusBadProtocol,

//! Bad configuration.
//! @remark
//! Failure caused by improper or inconsistent configuration.
//! @note
//! Example: config fields have invalid values or are not consistent
//! with each other.
StatusBadConfig,

//! Bad argument.
//! @remark
//! One of the provided function arguments has invalid value.
//! @note
//! Example: passing null pointer when it's not allowed, passing
//! invalid enum value.
StatusBadArg,

//! Bad operation.
//! @remark
//! Operation is not allowed or supported in this context.
//! @note
//! Example: trying to push packet for an interface that does not support
//! it, trying to connect using a protocol that doesn't support it.
StatusBadOperation,
};

} // namespace status
Expand Down
2 changes: 1 addition & 1 deletion src/public_api/src/receiver_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ int roc_receiver_decoder_pop_feedback_packet(roc_receiver_decoder* decoder,
const status::StatusCode code = imp_decoder->read_packet(imp_iface, imp_packet);
if (code != status::StatusOK) {
// TODO(gh-183): forward status code to user
if (code != status::StatusNoData) {
if (code != status::StatusDrain) {
roc_log(LogError,
"roc_receiver_decoder_pop_feedback_packet():"
" can't read packet from decoder: status=%s",
Expand Down
Loading

0 comments on commit 412f1dd

Please sign in to comment.