Skip to content

Commit

Permalink
Add support for frame resizing. Handle old stream frame type in encoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Riggs committed Jul 9, 2021
1 parent 5398bc0 commit fc7a25c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 1 addition & 2 deletions TNC/HdlcFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Frame : public list_base_hook<>
}

uint16_t size() const {return data_.size();}
bool resize(uint16_t size) {return data_.resize(size);}

uint16_t crc() const {return crc_;}
uint16_t fcs() const {return fcs_;}
Expand Down Expand Up @@ -170,12 +171,10 @@ class FramePool
free_list_.pop_front();
}
taskEXIT_CRITICAL_FROM_ISR(x);
DEBUG("Acquired frame %p (size after = %d)", result, free_list_.size());
return result;
}

void release(frame_type* frame) {
DEBUG("Released frame %p (size before = %d)", frame, free_list_.size());
frame->clear();
auto x = taskENTER_CRITICAL_FROM_ISR();
free_list_.push_back(*frame);
Expand Down
6 changes: 6 additions & 0 deletions TNC/M17Encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ void M17Encoder::process_stream(tnc::hdlc::IoFrame* frame, FrameType type)
{
send_stream(frame, type); // Consumes frame.
}
else if (frame->size() == 26)
{
// Old-style frame with trailing CRC.
frame->resize(24);
send_stream(frame, type);
}
else
{
WARN("Unexpected AUDIO frame size = %u", frame->size());
Expand Down
17 changes: 17 additions & 0 deletions TNC/SegmentedBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ struct SegmentedBuffer {

uint16_t size() const {return size_;}

bool resize(uint16_t size)
{
if (size <= size_)
{
size_ = size;
}
else
{
for (;size_ != size;)
{
if (!push_back(value_type()))
return false;
}
}
return true;
}

bool push_back(value_type value) {
uint16_t offset = size_ & 0xFF;
if (offset == 0) { // Must allocate.
Expand Down

0 comments on commit fc7a25c

Please sign in to comment.