package com.foxx.androidcast.receiver.av;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class ReceiverAvPipelineFactoryTest {

    @Test
    public void passthroughChainLeavesPcmUnchangedAtZeroIntensity() {
        AudioFilterChain chain = new AudioFilterChain(new AudioFilter[] {new BassBoostAudioFilter()}, 0);
        byte[] pcm = new byte[] {0, 0x40, 0, 0, (byte) 0x80, (byte) 0xFF, 0, 0};
        byte[] copy = pcm.clone();
        chain.process(copy, copy.length, 48_000, 2);
        assertEquals(pcm[0], copy[0]);
        assertEquals(pcm[1], copy[1]);
    }

    @Test
    public void bassBoostChangesSamplesAtHighIntensity() {
        AudioFilterChain chain = new AudioFilterChain(new AudioFilter[] {new BassBoostAudioFilter()}, 10);
        chain.reset(48_000, 2);
        byte[] pcm = new byte[4096];
        for (int i = 0; i < pcm.length; i += 2) {
            pcm[i] = (byte) (i & 0xff);
            pcm[i + 1] = 0;
        }
        byte[] copy = pcm.clone();
        chain.process(copy, copy.length, 48_000, 2);
        boolean changed = false;
        for (int i = 0; i < pcm.length; i++) {
            if (pcm[i] != copy[i]) {
                changed = true;
                break;
            }
        }
        org.junit.Assert.assertTrue(changed);
    }

    @Test
    public void videoPassthroughOnFrameDecodedNoOp() {
        ReceiverVideoPipeline p = ReceiverVideoPipeline.passthrough();
        assertNotNull(p);
        p.onFrameDecoded(1L);
    }
}
