Skip to content

Commit

Permalink
roc-streaminggh-183 Rework list of status codes
Browse files Browse the repository at this point in the history
This commit implements small part of roc-streaminggh-183, needed for status codes
in frame readers & writers (roc-streaminggh-614), which in turn is needed for
partial reads & PLC.

Changes:
- add 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 May 8, 2024
1 parent 61c6f29 commit 648d9cf
Show file tree
Hide file tree
Showing 31 changed files with 213 additions and 148 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 @@ -65,7 +65,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 @@ -75,7 +75,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 @@ -157,7 +157,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 @@ -290,7 +290,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 @@ -161,8 +161,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 @@ -182,15 +181,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 @@ -176,8 +176,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 @@ -197,15 +196,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
28 changes: 20 additions & 8 deletions src/internal_modules/roc_status/code_to_str.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,30 @@ const char* code_to_str(StatusCode code) {
switch (code) {
case StatusOK:
return "OK";
case StatusUnknown:
return "Unknown";
case StatusNoData:
return "NoData";
case StatusRetry:
return "Retry";
case StatusDrain:
return "Drain";
case StatusDead:
return "Dead";
case StatusNoMem:
return "NoMem";
case StatusNoRes:
return "NoRes";
case StatusNoSpace:
return "NoSpace";
case StatusLimit:
return "Limit";
case StatusConflict:
return "Conflict";
case StatusNoRoute:
return "NoRoute";
case StatusBadSlot:
return "BadSlot";
case StatusBadInterface:
return "BadInterface";
case StatusBadArg:
return "BadArg";
case StatusBadConfig:
return "BadConfig";
case StatusBadOperation:
return "BadOperation";
}

return "<invalid>";
Expand Down
76 changes: 69 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,75 @@ 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.
//! Operation completed successfully.
StatusOK,

//! Retry is required.
//! @remarks
//! Indicates that operation was interrupted for some reason, and a retry
//! is needed to proceed.
StatusRetry,

//! No more data in pipeline queue.
//! @remarks
//! Indicates that the request can not be fulfilled right now, and should
//! be retried later when more data arrives. Typically this status is not
//! treated as an error and is not forwarded to user.
StatusDrain,

//! Pipeline died.
//! @remarks
//! Indicates that the (sub-)pipeline (typically session) is dead and should
//! be terminated. No more data can be retrieved ever.
StatusDead,

//! Allocation error.
//! @remarks
//! Can be also triggered by reaching a memory limit.
StatusNoMem,

//! System resource not available.
//! @remarks
//! Triggered when an OS resource can't be acquired, e.g. failed to create
//! a new thread, open a network connection, etc.
StatusNoRes,

//! Insufficient buffer space.
//! @remarks
//! Usually triggered when maximum packet or frame size is not enough
//! to complete the operation.
StatusNoSpace,

//! No route found for a packet.
//! @remarks
//! Triggered when the packet can't be routed anywhere (e.g. there is no
//! suitable session and a new one is not allowed).
StatusNoRoute,

//! Bad slot state.
//! @remarks
//! Slot state doesn't allow operation (e.g. marked broken).
StatusBadSlot,

//! Bad interface state.
//! @remarks
//! Interface state doesn't allow operation (e.g. not activated).
StatusBadInterface,

//! Bad argument.
//! @remark
//! One of the provided arguments has invalid value.
StatusBadArg,

//! Bad configuration.
//! @remark
//! Failure caused by improper configuration.
StatusBadConfig,

//! Bad operation.
//! @remark
//! Operation is not allowed or supported in this context.
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 @@ -262,7 +262,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
2 changes: 1 addition & 1 deletion src/public_api/src/sender_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ int roc_sender_encoder_pop_packet(roc_sender_encoder* encoder,
const status::StatusCode code = imp_encoder->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_sender_encoder_pop_packet():"
" can't read packet from encoder: status=%s",
Expand Down
2 changes: 1 addition & 1 deletion src/tests/public_api/test_helpers/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class Proxy : private packet::IWriter {
packet::PacketPtr pp;
status::StatusCode code = reader.read(pp);
if (code != status::StatusOK) {
UNSIGNED_LONGS_EQUAL(status::StatusNoData, code);
UNSIGNED_LONGS_EQUAL(status::StatusDrain, code);
CHECK(!pp);
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/tests/roc_audio/test_depacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class TestReader : public packet::IReader {
}

private:
static const status::StatusCode default_code_ = status::StatusUnknown;
static const status::StatusCode default_code_ = status::StatusRetry;

packet::IReader& reader_;

Expand Down Expand Up @@ -738,8 +738,8 @@ TEST(depacketizer, timestamp_small_non_zero_cts) {

TEST(depacketizer, read_after_error) {
const status::StatusCode codes[] = {
status::StatusUnknown,
status::StatusNoData,
status::StatusDrain,
status::StatusRetry,
};

for (unsigned n = 0; n < ROC_ARRAY_SIZE(codes); ++n) {
Expand Down
Loading

0 comments on commit 648d9cf

Please sign in to comment.