mediasoup-client-aiortc looping stream/track

Sorry if this is the wrong place for this, but I didnt see a dedicated category for the aiortc client and didn’t want to create an issue in the repo.

I am wondering if there is any way to simply loop the input file being used. I poked around the aiortc repo a bit but I am not great with python, but it looks like the media player provides simple start/stop functionality. I’m not sure if just issuing a stop/start would reset the timestamps/frames used by the underlying player process.

I am trying to write a light-weight test client for load testing, and I want each client to run indefinitely and actually provide valid audio data while active. This will help me to profile and generate load graphs as I connect/disconnect different numbers of clients. I was hoping to just be able to use a simple 16 second mp4 sample for this rather than needing to use some larger ~30 min audio sample.

I also tried something like this, but it didn’t quite work:

    let producer = null;

    for (let i = 0; i < 3; i++) {
      console.log(`Playback count: ${i + 1}`);

      const stream = await worker.getUserMedia({
        video: false,
        audio: {
          source: 'file',
          file: testFilePath,
        },
      });

      const track = stream.getAudioTracks()[0];

      if (!producer) {
        producer = await sendTransport.produce({
          track,
          paused: false,
          codecOptions: {
            opusFec: true,
            opusDtx: true,
            opusMaxPlaybackRate: 48000,
          },
        });
      } else {
        await producer.replaceTrack({track});
      }

      await Promise.delay(18000);

      track.stop();
      stream.close();
    }

    producer.close();

    sendTransport.close();
    recvTransport.close();

It did work if I instead created an entirely new producer instead of using replaceTrack but that introduces additional code-paths (managing the producers in my server application code) that I don’t really want involved in this testing scenario.

Just wondering if you had any thoughts/suggestions on this.

Thanks, this client is really cool and exactly what I needed for automated testing.

No idea about how to play a file in loop mode in aiortc, but that’s definitely a question that does not fit well in this forum :slight_smile:

Regarding replaceTrack(), please check aiortc open issues. It does not work well at all. We have also such an issue referenced in the issues of our mediasoup-client-aiortc.

BTW, something that works fine in aiortc (and hence in mediasoup-client-aiortc) is consuming a remote real audio/video track, and calling sendTransport.produce({ track: consumer.track }).

1 Like

Yeah, sorry about that. At first I was not sure if this is something that needed to happen at the client level, or the aiortc worker level (or both).

Ah yes I overlooked this in the “TODO” issue. Thanks.