From 93c939f7ac89d6eb45bcdd839c3e5fa9ee2ca428 Mon Sep 17 00:00:00 2001 From: ForeverASilver <77247305+ForeverASilver@users.noreply.github.com> Date: Wed, 18 Oct 2023 19:55:14 +0000 Subject: [PATCH] gh-217 Add broken code for review --- .../roc_pipeline/test_receiver_source.cpp | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/src/tests/roc_pipeline/test_receiver_source.cpp b/src/tests/roc_pipeline/test_receiver_source.cpp index c14cfe044b..26fbe99f7f 100644 --- a/src/tests/roc_pipeline/test_receiver_source.cpp +++ b/src/tests/roc_pipeline/test_receiver_source.cpp @@ -10,6 +10,7 @@ #include "test_helpers/control_writer.h" #include "test_helpers/frame_reader.h" +#include "test_helpers/packet_sender.h" #include "test_helpers/packet_writer.h" #include "roc_address/interface.h" @@ -21,6 +22,10 @@ #include "roc_pipeline/receiver_source.h" #include "roc_rtp/format_map.h" +#include "roc_fec/composer.h" +#include "roc_fec/headers.h" +#include "roc_fec/writer.h" + namespace roc { namespace pipeline { @@ -57,6 +62,11 @@ packet::PacketFactory packet_factory(arena); rtp::FormatMap format_map(arena); +fec::Composer + ldpc_source_composer(&rtp_composer); +fec::Composer + ldpc_repair_composer(NULL); + ReceiverSlot* create_slot(ReceiverSource& source) { ReceiverSlot* slot = source.create_slot(); CHECK(slot); @@ -1744,6 +1754,93 @@ IGNORE_TEST(receiver_source, timestamp_mapping_remixing) { CHECK(first_ts); } +packet::PacketPtr fill_one_packet(size_t sn, + size_t fec_payload_size = 193, + packet::IComposer* composer = NULL) { + CHECK(fec_payload_size > sizeof(rtp::Header)); + const size_t rtp_payload_size = fec_payload_size - sizeof(rtp::Header); + + packet::PacketPtr pp = packet_factory.new_packet(); + CHECK(pp); + + core::Slice bp = byte_buffer_factory.new_buffer(); + CHECK(bp); + + if (!composer) { + composer = &ldpc_source_composer; + } + CHECK(composer->prepare(*pp, bp, rtp_payload_size)); + + pp->set_data(bp); + + UNSIGNED_LONGS_EQUAL(rtp_payload_size, pp->rtp()->payload.size()); + UNSIGNED_LONGS_EQUAL(fec_payload_size, pp->fec()->payload.size()); + + pp->add_flags(packet::Packet::FlagAudio); + + pp->rtp()->source = 555; + pp->rtp()->payload_type = rtp::PayloadType_L16_Stereo; + pp->rtp()->seqnum = packet::seqnum_t(sn); + pp->rtp()->stream_timestamp = packet::stream_timestamp_t(sn * 10); + + for (size_t i = 0; i < rtp_payload_size; i++) { + pp->rtp()->payload.data()[i] = uint8_t(sn + i); + } + + return pp; +} + +TEST(receiver_source, packet_buffer) { + packet::PacketPtr source_packets[20]; + + enum { Rate = SampleRate, Chans = Chans_Stereo, MaxPackets = 10 }; + + init(Rate, Chans, Rate, Chans); + + ReceiverConfig config = make_config(); + config.default_session.prebuf_len = 0; + ReceiverSource receiver(config, format_map, packet_factory, byte_buffer_factory, + sample_buffer_factory, arena); + CHECK(receiver.is_valid()); + + ReceiverSlot* slot = create_slot(receiver); + CHECK(slot); + + packet::IWriter* endpoint1_writer = + create_endpoint(slot, address::Iface_AudioSource, proto1); + CHECK(endpoint1_writer); + + fec::WriterConfig writerConfig; + fec::CodecConfig codecConfig; + codecConfig.scheme = packet::FEC_LDPC_Staircase; + + // setup encoder + core::ScopedPtr encoder( + fec::CodecMap::instance().new_encoder(codecConfig, byte_buffer_factory, arena), + arena); + CHECK(encoder); + + // setup fec writer + fec::Writer fec_writer(writerConfig, packet::FEC_LDPC_Staircase, *encoder, + *endpoint1_writer, ldpc_source_composer, ldpc_repair_composer, + packet_factory, byte_buffer_factory, arena); + CHECK(fec_writer.is_valid()); + + test::PacketWriter packet_writer(arena, fec_writer, ldpc_source_composer, format_map, + packet_factory, byte_buffer_factory, PayloadType_Ch2, + src1, dst1); + + // setup reader + test::FrameReader frame_reader(receiver, sample_buffer_factory); + + packet_writer.write_packets(writerConfig.n_source_packets, SamplesPerPacket, + output_sample_spec); + + receiver.refresh(frame_reader.refresh_ts()); + frame_reader.read_zero_samples(SamplesPerFrame, output_sample_spec); + UNSIGNED_LONGS_EQUAL(0, receiver.num_sessions()); +} + TEST(receiver_source, metrics_sessions) { enum { Rate = SampleRate, Chans = Chans_Stereo, MaxSess = 10 };