RTMPMinaConnection - 使用xuggler将RTP编码为RTMP时,传入的消息处理失败

时间:2014-05-27 21:45:30

标签: red5 rtp xuggler

我最近发布了一个关于我遇到PixelType错误的问题。您可以阅读该帖子here

我认为我通过创建以下类来解决该问题。

package com.mwallace.xuggler.tools;

import com.xuggle.mediatool.IMediaReader; import com.xuggle.mediatool.IMediaWriter; import com.xuggle.mediatool.MediaToolAdapter; import com.xuggle.mediatool.ToolFactory; import com.xuggle.mediatool.event.AudioSamplesEvent; import com.xuggle.mediatool.event.IAddStreamEvent; import com.xuggle.mediatool.event.IAudioSamplesEvent; import com.xuggle.mediatool.event.IVideoPictureEvent; import com.xuggle.mediatool.event.VideoPictureEvent; import com.xuggle.xuggler.IAudioResampler; import com.xuggle.xuggler.IAudioSamples; import com.xuggle.xuggler.IError; import com.xuggle.xuggler.IPixelFormat; import com.xuggle.xuggler.IStreamCoder; import com.xuggle.xuggler.IVideoPicture; import com.xuggle.xuggler.IVideoResampler; import com.xuggle.xuggler.ICodec;

public class ConvertVideo extends MediaToolAdapter implements Runnable
{
    private int VIDEO_WIDTH = 640;
    private int VIDEO_HEIGHT = 480;

    private IMediaWriter writer;
    private IMediaReader reader;
    private String outputFile;

    private IVideoResampler videoResampler = null;
    private IAudioResampler audioResampler = null;

    public ConvertVideo(String inputFile, String outputFile)
    {
        this.outputFile = outputFile;
        reader = ToolFactory.makeReader(inputFile);
        reader.addListener(this);
    }

    @Override
    public void onAddStream(IAddStreamEvent event)
    {
        int streamIndex = event.getStreamIndex();
        IStreamCoder streamCoder = event.getSource().getContainer()
                .getStream(streamIndex).getStreamCoder();
        if (streamCoder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO)
        {
            writer.addAudioStream(streamIndex, streamIndex, 2, 44100);
        } else if (streamCoder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO)
        {
            streamCoder.setWidth(VIDEO_WIDTH);
            streamCoder.setHeight(VIDEO_HEIGHT);
            writer.addVideoStream(streamIndex, streamIndex, VIDEO_WIDTH,
                    VIDEO_HEIGHT);
        }
        super.onAddStream(event);
    }

    @Override
    public void onVideoPicture(IVideoPictureEvent event)
    {
        IVideoPicture pic = event.getPicture();
        if (videoResampler == null)
        {
            videoResampler = IVideoResampler.make(VIDEO_WIDTH, VIDEO_HEIGHT,
                    pic.getPixelType(), pic.getWidth(), pic.getHeight(),
                    pic.getPixelType());

            System.out.println("width and height : " + pic.getPictureType() + " : " + pic.getWidth() + " : " + pic.getHeight());
        }

            IVideoPicture out = IVideoPicture.make(IPixelFormat.Type.YUV420P, VIDEO_WIDTH,
                    VIDEO_HEIGHT);
            videoResampler.resample(out, pic);

            IVideoPictureEvent asc = new VideoPictureEvent(event.getSource(), out,
                    event.getStreamIndex());
            super.onVideoPicture(asc);
            out.delete();

    }

    @Override
    public void onAudioSamples(IAudioSamplesEvent event)
    {
        IAudioSamples samples = event.getAudioSamples();
        if (audioResampler == null)
        {
            audioResampler = IAudioResampler.make(2, samples.getChannels(),
                    44100, samples.getSampleRate());
        }
        if (event.getAudioSamples().getNumSamples() > 0)
        {
            IAudioSamples out = IAudioSamples.make(samples.getNumSamples(),
                    samples.getChannels());
            audioResampler.resample(out, samples, samples.getNumSamples());

            AudioSamplesEvent asc = new AudioSamplesEvent(event.getSource(),
                    out, event.getStreamIndex());
            super.onAudioSamples(asc);
            out.delete();
        }
    }

    @Override
    public void run()
    {
        writer = ToolFactory.makeWriter(outputFile, reader);
        //writer.addListener(ToolFactory.makeViewer(true));
        this.addListener(writer);

        while (reader.readPacket() == null)
        {
            System.out.println("reading packet");        
            IError err = null;
                    if (reader != null)
                    {
                        err = reader.readPacket();

                    }

            if(err != null ){
                System.out.println("Error: " + err);
                break;
            }
        }
    }

}

在我的Flash客户端成功连接之后,我在服务器上调用一个名为helloXuggler()的方法,该方法在我的主应用程序文件中看起来像这样。

public static void helloXuggler()
    {


        String sourceUrl = "rtsp://10.0.1.68:8554/CH001.sdp?AuthMode=Web&AuthValue=6049";
        String destinationUrl = "./webapps/AEWings/streams/xuggler.flv";

        //this.convertVideo = new ConvertVideo(sourceURL, destinationURL);
        System.out.printf("transcode %s -> %s\n", sourceUrl, destinationUrl);

        ConvertVideo converter = new ConvertVideo(sourceUrl, destinationUrl);
        converter.run();

        // read packets from the source file, which dispatch events to the
        // writer, this will continue until 

    }

一切似乎进展顺利,一切都连接起来,方法被调用但是大约30秒后我得到了下面的堆栈跟踪,我不知道该怎么办。

[WARN] [NioProcessor-2] org.red5.server.net.rtmp.RTMPMinaConnection - Incoming message handling failed on HFQIN76JSTZXW
org.springframework.core.task.TaskRejectedException: Executor [java.util.concurrent.ThreadPoolExecutor@68e415b8] did not accept task: org.springframework.util.concurrent.ListenableFutureTask@4279ae24
    at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.submitListenable(ThreadPoolTaskExecutor.java:297) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
    at org.red5.server.net.rtmp.RTMPMinaConnection.handleMessageReceived(RTMPMinaConnection.java:159) ~[red5-server.jar:na]
    at org.red5.server.net.rtmp.RTMPMinaIoHandler.messageReceived(RTMPMinaIoHandler.java:167) [red5-server.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:690) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765) [mina-core-2.0.7.jar:na]
    at org.apache.mina.filter.codec.ProtocolCodecFilter$ProtocolDecoderOutputImpl.flush(ProtocolCodecFilter.java:407) [mina-core-2.0.7.jar:na]
    at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:236) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765) [mina-core-2.0.7.jar:na]
    at org.red5.server.net.rtmpe.RTMPEIoFilter.messageReceived(RTMPEIoFilter.java:132) [red5-server.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.filterchain.IoFilterAdapter.messageReceived(IoFilterAdapter.java:109) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireMessageReceived(DefaultIoFilterChain.java:410) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.read(AbstractPollingIoProcessor.java:710) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:664) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:653) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$600(AbstractPollingIoProcessor.java:67) [mina-core-2.0.7.jar:na]
    at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1124) [mina-core-2.0.7.jar:na]
    at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64) [mina-core-2.0.7.jar:na]
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) [na:1.6.0_65]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) [na:1.6.0_65]
    at java.lang.Thread.run(Thread.java:695) [na:1.6.0_65]
Caused by: java.util.concurrent.RejectedExecutionException: null
    at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1774) ~[na:1.6.0_65]
    at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:768) ~[na:1.6.0_65]
    at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:656) ~[na:1.6.0_65]
    at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.submitListenable(ThreadPoolTaskExecutor.java:293) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
    ... 27 common frames omitted

0 个答案:

没有答案