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

gh-739: StatutCode Usage in IFrameEncoder/Decoder (begin/end)_frame #798

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

sayedMurtadha
Copy link

Closes #739

@github-actions github-actions bot added the contribution A pull-request by someone else except maintainers label Feb 6, 2025
@sayedMurtadha sayedMurtadha changed the title (gh-739) StatutCode Usage in IFrameEncoder/Decoder (begin/end)_frame gh-739 StatutCode Usage in IFrameEncoder/Decoder (begin/end)_frame Feb 6, 2025
@sayedMurtadha sayedMurtadha changed the title gh-739 StatutCode Usage in IFrameEncoder/Decoder (begin/end)_frame gh-739: StatutCode Usage in IFrameEncoder/Decoder (begin/end)_frame Feb 6, 2025
@gavv gavv added the ready for review Pull request can be reviewed label Feb 7, 2025
Copy link
Member

@gavv gavv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for PR! A few comments.

Comment on lines 271 to 275
if (decoded_samples < requested_samples) {
payload_decoder_.end_frame();
const status::StatusCode status_code = payload_decoder_.end_frame();
packet_ = NULL;
// TODO: what should be the flow in case of error?
roc_panic_if_not(status_code == status::StatusOK);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should forward error to caller and return it from Depacketizer::read().

We can update Depacketizer::read_samples_(), Depacketizer::read_decoded_samples_(), and Depacketizer::read_missing_samples_() to return status codes instead of pointer to new end. We can replace sample_t* buff_end with sample_t** buff_end so that they can return new end via argument.

In places where Depacketizer::read_samples_() returns NULL, it can now return StatusDrain.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be buff_ptr that is being updated instead of buff_end?

Comment on lines 78 to 80
virtual void begin_frame(packet::stream_timestamp_t frame_position,
const void* frame_data,
size_t frame_size) = 0;
virtual status::StatusCode begin_frame(packet::stream_timestamp_t frame_position,
const void* frame_data,
size_t frame_size) = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add ROC_NODISCARD to begin_frame/end_frame in IFrameEncoder, IFrameDecoder, PcmEncoder, PcmDecoder.

(Please rebase on fresh develop, ROC_ATTR_NODISCARD was recently renamed to ROC_NODISCARD).

Comment on lines 49 to 56
status::StatusCode PcmDecoder::begin_frame(packet::stream_timestamp_t frame_position,
const void* frame_data,
size_t frame_size) {
if (!frame_data) {
return status::StatusBadArg;
}

if (frame_data_) {
roc_panic("pcm decoder: unpaired begin/end");
roc_log(LogError, "pcm decoder: unpaired begin/end");
return status::StatusBadState;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to keep these checks panicking.

Null argument and unpaired calls are considered bugs in our own code. They are not caused by external input. Hence we don't want to recover from such errors, instead we should fix the bogus usage.

Same for PcmEncoder.

Comment on lines -80 to +82
encoder.begin_frame(pp->rtp()->payload.data(), pp->rtp()->payload.size());
LONGS_EQUAL(
status::StatusOK,
encoder.begin_frame(pp->rtp()->payload.data(), pp->rtp()->payload.size()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unit tests for packetizer and depacketizer, as described in the issue:

Add unit test for Packetizer to check that it forwards error from encoder to upper level.
Add unit test for Depacketizer to check that it forwards error from decoder to upper level.

The new tests would be similar to TEST(packetizer, forward_error) and TEST(depacketizer, forward_error), but instead of mock packet reader/writer (StatusReader and StatusWriter), I think you'll need to create and use mock encoder and decoder.

@gavv gavv added contribution A pull-request by someone else except maintainers needs revision Pull request should be revised by its author and removed ready for review Pull request can be reviewed contribution A pull-request by someone else except maintainers labels Feb 7, 2025
@sayedMurtadha sayedMurtadha force-pushed the gh-739-iframe-encoder-decoder-begin-end-fn-return-type branch from d5e3582 to 5a6fe74 Compare February 9, 2025 08:50
@sayedMurtadha sayedMurtadha requested a review from gavv February 10, 2025 09:07
@github-actions github-actions bot added ready for review Pull request can be reviewed and removed needs revision Pull request should be revised by its author labels Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution A pull-request by someone else except maintainers ready for review Pull request can be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants