Skip to content

Commit

Permalink
gh-217 Support FEC in PacketWriter test helpers
Browse files Browse the repository at this point in the history
- test::PacketWriter and test::PacketReader now create parsers
  and composers by themselves

- test::PacketWriter now has two ctors: for using with and
  without FEC support

- test::PacketReader is updated to match new API of PacketWriter

- test::PacketSender is renamed to PacketProxy to avoid confusion
  • Loading branch information
gavv committed Nov 2, 2023
1 parent 2a805e7 commit 3f4d3ed
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#ifndef ROC_PIPELINE_TEST_HELPERS_PACKET_SENDER_H_
#define ROC_PIPELINE_TEST_HELPERS_PACKET_SENDER_H_
#ifndef ROC_PIPELINE_TEST_HELPERS_PACKET_PROXY_H_
#define ROC_PIPELINE_TEST_HELPERS_PACKET_PROXY_H_

#include <CppUTest/TestHarness.h>

Expand All @@ -21,12 +21,12 @@ namespace roc {
namespace pipeline {
namespace test {

class PacketSender : public packet::IWriter, core::NonCopyable<> {
class PacketProxy : public packet::IWriter, core::NonCopyable<> {
public:
PacketSender(packet::PacketFactory& packet_factory,
packet::IWriter* source_writer,
packet::IWriter* repair_writer,
packet::IWriter* control_writer)
PacketProxy(packet::PacketFactory& packet_factory,
packet::IWriter* source_writer,
packet::IWriter* repair_writer,
packet::IWriter* control_writer)
: packet_factory_(packet_factory)
, source_writer_(source_writer)
, repair_writer_(repair_writer)
Expand Down Expand Up @@ -112,4 +112,4 @@ class PacketSender : public packet::IWriter, core::NonCopyable<> {
} // namespace pipeline
} // namespace roc

#endif // ROC_PIPELINE_TEST_HELPERS_PACKET_SENDER_H_
#endif // ROC_PIPELINE_TEST_HELPERS_PACKET_PROXY_H_
26 changes: 15 additions & 11 deletions src/tests/roc_pipeline/test_helpers/packet_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#define ROC_PIPELINE_TEST_HELPERS_PACKET_READER_H_

#include <CppUTest/TestHarness.h>
#include <CppUTest/UtestMacros.h>

#include "test_helpers/utils.h"

Expand All @@ -21,24 +20,23 @@
#include "roc_packet/ireader.h"
#include "roc_packet/packet_factory.h"
#include "roc_rtp/format_map.h"
#include "roc_rtp/parser.h"
#include "roc_status/status_code.h"

namespace roc {
namespace pipeline {
namespace test {

//! Reads, parses, and validates packets.
class PacketReader : public core::NonCopyable<> {
public:
PacketReader(core::IArena& arena,
packet::IReader& reader,
packet::IParser& parser,
rtp::FormatMap& format_map,
packet::PacketFactory& packet_factory,
rtp::PayloadType pt,
const address::SocketAddr& dst_addr)
const address::SocketAddr& dst_addr,
rtp::PayloadType pt)
: reader_(reader)
, parser_(parser)
, payload_decoder_(new_decoder_(arena, format_map, pt), arena)
, packet_factory_(packet_factory)
, dst_addr_(dst_addr)
, source_(0)
Expand All @@ -48,6 +46,7 @@ class PacketReader : public core::NonCopyable<> {
, offset_(0)
, abs_offset_(0)
, first_(true) {
construct_(arena, format_map, pt);
}

void read_packet(size_t samples_per_packet,
Expand Down Expand Up @@ -113,12 +112,17 @@ class PacketReader : public core::NonCopyable<> {
private:
enum { MaxSamples = 4096 };

static audio::IFrameDecoder*
new_decoder_(core::IArena& arena, rtp::FormatMap& format_map, rtp::PayloadType pt) {
void
construct_(core::IArena& arena, rtp::FormatMap& format_map, rtp::PayloadType pt) {
// payload decoder
const rtp::Format* fmt = format_map.find_by_pt(pt);
CHECK(fmt);
payload_decoder_.reset(fmt->new_decoder(arena, fmt->pcm_format, fmt->sample_spec),
arena);
CHECK(payload_decoder_);

return fmt->new_decoder(arena, fmt->pcm_format, fmt->sample_spec);
// rtp parser
parser_.reset(new (arena) rtp::Parser(format_map, NULL), arena);
}

packet::PacketPtr read_packet_() {
Expand All @@ -140,7 +144,7 @@ class PacketReader : public core::NonCopyable<> {
packet::PacketPtr pp = packet_factory_.new_packet();
CHECK(pp);

CHECK(parser_.parse(*pp, bp));
CHECK(parser_->parse(*pp, bp));
CHECK(pp->flags() & packet::Packet::FlagRTP);

if (first_) {
Expand Down Expand Up @@ -186,7 +190,7 @@ class PacketReader : public core::NonCopyable<> {

packet::IReader& reader_;

packet::IParser& parser_;
core::ScopedPtr<packet::IParser> parser_;
core::ScopedPtr<audio::IFrameDecoder> payload_decoder_;

packet::PacketFactory& packet_factory_;
Expand Down
Loading

0 comments on commit 3f4d3ed

Please sign in to comment.