2016-06-23 17 views

答えて

2

com.wowza.wms.pushpublish。*パッケージ(Wowzaインストールに付属しているserverapiおよびwowzaサイトに記載されています)を使用して、パブリッシュ・イベントを代行受信し、ストリーム・ターゲットを作成できます)。以下は、同じWowzaアプリケーションに "push-"という接頭辞が付いたRTMPストリームターゲットを作成するサンプルコードです。

package com.wowza.wms.plugin.pushpublish.module; 
 

 
import java.util.*; 
 

 
import com.wowza.wms.amf.AMFPacket; 
 
import com.wowza.wms.application.IApplicationInstance; 
 
import com.wowza.wms.logging.WMSLoggerFactory; 
 
import com.wowza.wms.module.ModuleBase; 
 
import com.wowza.wms.pushpublish.protocol.rtmp.*; 
 
import com.wowza.wms.stream.*; 
 

 
public class ModulePushPublishSimpleExample extends ModuleBase 
 
{ 
 
\t Map<IMediaStream, PushPublishRTMP> publishers = new HashMap<IMediaStream, PushPublishRTMP>(); 
 
\t 
 
\t class StreamNotify implements IMediaStreamActionNotify2 
 
\t { 
 

 
\t \t public void onPlay(IMediaStream stream, String streamName, double playStart, double playLen, int playReset) 
 
\t \t { 
 
\t \t } 
 

 
\t \t public void onPause(IMediaStream stream, boolean isPause, double location) 
 
\t \t { 
 
\t \t } 
 

 
\t \t public void onSeek(IMediaStream stream, double location) 
 
\t \t { 
 
\t \t } 
 

 
\t \t public void onStop(IMediaStream stream) 
 
\t \t { 
 
\t \t } 
 

 
\t \t public void onMetaData(IMediaStream stream, AMFPacket metaDataPacket) 
 
\t \t { 
 
\t \t } 
 

 
\t \t public void onPauseRaw(IMediaStream stream, boolean isPause, double location) 
 
\t \t { 
 
\t \t } 
 
\t \t 
 
\t \t public void onPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) 
 
\t \t { 
 
\t \t \t if (!streamName.startsWith("push-")) // this is here to avoid looping pushes 
 
\t \t \t { 
 
\t \t \t \t try 
 
\t \t \t \t { 
 
\t \t \t \t \t IApplicationInstance appInstance = stream.getStreams().getAppInstance(); 
 
\t \t \t \t \t 
 
\t \t \t \t \t synchronized(publishers) 
 
\t \t \t \t \t { 
 
\t \t \t \t \t \t PushPublishRTMP publisher = new PushPublishRTMP(); 
 
\t \t \t \t \t \t 
 
\t \t \t \t \t \t // Source stream 
 
\t \t \t \t \t \t publisher.setAppInstance(appInstance); 
 
\t \t \t \t \t \t publisher.setSrcStreamName(streamName); 
 

 
\t \t \t \t \t \t // Destination stream 
 
\t \t \t \t \t \t String dstHost = "localhost"; 
 
\t \t \t \t \t \t int dstPort = 1935; 
 
\t \t \t \t \t \t String dstApplication = appInstance.getApplication().getName(); 
 
\t \t \t \t \t \t String dstStreamName = "push-"+streamName; 
 
\t \t \t \t \t \t String flashVersion = PushPublishRTMP.CURRENTFMLEVERSION; 
 
\t \t \t \t \t \t 
 
\t \t \t \t \t \t // Uncomment and update with Akamai account info if pushing to Akamai 
 
\t \t \t \t \t \t //String streamId = "32637"; 
 
\t \t \t \t \t \t //String akamaiUsername = "134706"; 
 
\t \t \t \t \t \t //String akamaiPassword = "wowza"; 
 
\t \t \t \t \t \t //boolean isPrimary = true; 
 
\t \t \t \t \t \t //dstHost = (isPrimary?"p":"b")+".ep"+streamId+".i.akamaientrypoint.net"; 
 
\t \t \t \t \t \t //dstApplication = "EntryPoint"; 
 
\t \t \t \t \t \t //dstStreamName = streamName+"_1_950"+"@"+streamId; 
 
\t \t \t \t \t \t //flashVersion = PushPublishRTMP.CURRENTFLASHVERSION; 
 
\t \t \t \t \t \t // 
 
\t \t \t \t \t \t //publisher.setAkamaiUserName(akamaiUsername); 
 
\t \t \t \t \t \t //publisher.setAkamaiPassword(akamaiPassword); 
 

 
\t \t \t \t \t \t // Destination stream 
 
\t \t \t \t \t \t publisher.setHost(dstHost); 
 
\t \t \t \t \t \t publisher.setPort(dstPort); 
 
\t \t \t \t \t \t publisher.setDstApplicationName(dstApplication); 
 
\t \t \t \t \t \t publisher.setDstStreamName(dstStreamName); 
 
\t \t \t \t \t \t publisher.setConnectionFlashVersion(flashVersion); 
 
\t \t \t \t \t \t 
 
\t \t \t \t \t \t // Uncomment if pushing to Adobe Media Server 
 
\t \t \t \t \t \t //publisher.setSendOriginalTimecodes(true); 
 
\t \t \t \t \t \t //publisher.setOriginalTimecodeThreshold(0x100000); 
 

 
\t \t \t \t \t \t // SecureToken shared secret 
 
\t \t \t \t \t \t //publisher.setSecureTokenSharedSecret("#ed%h0#[email protected]"); 
 
\t \t \t 
 
\t \t \t \t \t \t publisher.setSendFCPublish(true); 
 
\t \t \t \t \t \t publisher.setSendReleaseStream(true); 
 
\t \t \t \t \t \t publisher.setSendOnMetadata(true); 
 
\t \t \t \t \t \t publisher.setDebugLog(true); 
 
\t \t \t \t \t \t publisher.setDebugPackets(false); 
 
\t \t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t // Uncomment if target server protected using RTMP authentication 
 
\t \t \t \t \t \t //PushPublishRTMPAuthProviderAdobe adobeRTMPAuthProvider = new PushPublishRTMPAuthProviderAdobe(); 
 
\t \t \t \t \t \t //adobeRTMPAuthProvider.init(publisher); 
 
\t \t \t \t \t \t //adobeRTMPAuthProvider.setUserName("username"); 
 
\t \t \t \t \t \t //adobeRTMPAuthProvider.setPassword("password"); 
 
\t \t \t \t \t \t //publisher.setRTMPAuthProvider(adobeRTMPAuthProvider); 
 
\t \t \t \t \t \t 
 
\t \t \t \t \t \t publisher.connect(); 
 
\t \t \t \t \t \t publishers.put(stream, publisher); 
 
\t \t \t \t \t } 
 
\t \t \t \t } 
 
\t \t \t \t catch(Exception e) 
 
\t \t \t \t { 
 
\t \t \t \t \t WMSLoggerFactory.getLogger(null).error("ModulePushPublishSimpleExample#StreamNotify.onPublish: "+e.toString()); 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t } 
 

 
\t \t public void onUnPublish(IMediaStream stream, String streamName, boolean isRecord, boolean isAppend) 
 
\t \t { 
 
\t \t \t stopPublisher(stream); 
 
\t \t } 
 
\t } 
 
\t 
 
\t public void stopPublisher(IMediaStream stream) 
 
\t { 
 
\t \t try 
 
\t \t { 
 
\t \t \t synchronized(publishers) 
 
\t \t \t { 
 
\t \t \t \t PushPublishRTMP publisher = publishers.remove(stream); 
 
\t \t \t \t if (publisher != null) 
 
\t \t \t \t \t publisher.disconnect(); 
 
\t \t \t } 
 
\t \t } 
 
\t \t catch(Exception e) 
 
\t \t { 
 
\t \t \t WMSLoggerFactory.getLogger(null).error("ModulePushPublishSimpleExample#StreamNotify.onPublish: "+e.toString()); 
 
\t \t } 
 
\t } 
 
\t 
 
\t public void onStreamCreate(IMediaStream stream) 
 
\t { 
 
\t \t stream.addClientListener(new StreamNotify()); 
 
\t } 
 
\t 
 
\t public void onStreamDestory(IMediaStream stream) 
 
\t { 
 
\t \t stopPublisher(stream); 
 
\t } 
 
}

+0

おかげでミシェル。私はこれを試して、結果を見てみましょう。 – Sutha

関連する問題