|
| 1 | +package org.red5.server.stream; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | +import static org.junit.Assert.assertTrue; |
| 5 | + |
| 6 | +import java.util.List; |
| 7 | + |
| 8 | +import org.apache.mina.core.buffer.IoBuffer; |
| 9 | +import org.junit.Test; |
| 10 | +import org.red5.codec.AbstractVideo; |
| 11 | +import org.red5.codec.IVideoStreamCodec; |
| 12 | +import org.red5.codec.VideoCodec; |
| 13 | +import org.red5.io.utils.IOUtils; |
| 14 | + |
| 15 | +import ch.qos.logback.classic.Level; |
| 16 | +import ch.qos.logback.classic.Logger; |
| 17 | +import ch.qos.logback.classic.spi.ILoggingEvent; |
| 18 | +import ch.qos.logback.core.read.ListAppender; |
| 19 | + |
| 20 | +public class VideoCodecFactoryTest { |
| 21 | + |
| 22 | + @Test |
| 23 | + public void testEnhancedAv1SequenceStartDoesNotUseRejectingProbeCodec() { |
| 24 | + assertEnhancedSequenceStartDoesNotUseRejectingProbeCodec("av01", VideoCodec.AV1, new byte[] { (byte) 0x81, 0x08, 0x0d }); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + public void testEnhancedHevcSequenceStartDoesNotUseRejectingProbeCodec() { |
| 29 | + assertEnhancedSequenceStartDoesNotUseRejectingProbeCodec("hvc1", VideoCodec.HEVC, new byte[] { 0x01, 0x01, 0x60, 0x00 }); |
| 30 | + } |
| 31 | + |
| 32 | + private static void assertEnhancedSequenceStartDoesNotUseRejectingProbeCodec(String fourcc, VideoCodec expectedCodec, byte[] configPrefix) { |
| 33 | + Logger logger = (Logger) org.slf4j.LoggerFactory.getLogger(AbstractVideo.class); |
| 34 | + ListAppender<ILoggingEvent> appender = new ListAppender<>(); |
| 35 | + appender.start(); |
| 36 | + logger.addAppender(appender); |
| 37 | + try { |
| 38 | + IoBuffer data = IoBuffer.allocate(16); |
| 39 | + data.put((byte) 0x90); |
| 40 | + data.putInt(IOUtils.makeFourcc(fourcc)); |
| 41 | + data.put(configPrefix); |
| 42 | + data.flip(); |
| 43 | + |
| 44 | + IVideoStreamCodec codec = VideoCodecFactory.getVideoCodec(data); |
| 45 | + |
| 46 | + assertEquals(expectedCodec, codec.getCodec()); |
| 47 | + assertTrue("Codec factory must not emit AbstractVideo rejection while probing enhanced FourCC", rejectLogs(appender.list).isEmpty()); |
| 48 | + } finally { |
| 49 | + logger.detachAppender(appender); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + private static List<ILoggingEvent> rejectLogs(List<ILoggingEvent> events) { |
| 54 | + return events.stream().filter(event -> event.getLevel().isGreaterOrEqual(Level.WARN)).filter(event -> event.getFormattedMessage().contains("AbstractVideo rejected")).toList(); |
| 55 | + } |
| 56 | +} |
0 commit comments