All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.antmedia.plugin.FrameFeeder Maven / Gradle / Ivy

Go to download

Ant Media Server supports RTMP, RTSP, MP4, HLS, WebRTC, Adaptive Streaming, etc.

There is a newer version: 2.11.3
Show newest version
package io.antmedia.plugin;

import java.util.ArrayList;

import org.bytedeco.ffmpeg.avutil.AVFrame;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.antmedia.plugin.api.IFrameListener;

public class FrameFeeder {

	private String streamId;
	
	private ArrayList listeners = new ArrayList<>();
	private static final Logger logger = LoggerFactory.getLogger(FrameFeeder.class);


	public FrameFeeder(String streamId) {
		this.streamId = streamId;
	}

	public AVFrame onVideoFrame(AVFrame frame) {
		AVFrame processedFrame = frame;
		for (IFrameListener iFrameListener : listeners) {
			processedFrame = iFrameListener.onVideoFrame(streamId, processedFrame);
			if(processedFrame == null) {
				break;
			}
		}

		return processedFrame;
	}
	
	public AVFrame onAudioFrame(AVFrame frame) {
		AVFrame processedFrame = frame;
		for (IFrameListener iFrameListener : listeners) {
			processedFrame = iFrameListener.onAudioFrame(streamId, processedFrame);
			if(processedFrame == null) {
				break;
			}
		}

		return processedFrame;
	}

	public void addListener(IFrameListener listener) {
		listeners.add(listener);
	}
	
	public void writeTrailer() {
		for (IFrameListener iFrameListener : listeners) {
			iFrameListener.writeTrailer(streamId);
		}
	}

	public void removeFrameListener(IFrameListener listener) {
		listeners.remove(listener);		
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy