2011-11-12 39 views
2

我正在使用EC4 SP2 SDK在c#中編寫應用程序。編碼器SDK 4 - 推送到發佈點

我想將我的文件發佈到媒體服務器發佈點。我搜索了2個關於發佈點的驗證和認證的例子,但是它們都來自舊的sdk's或者不工作(並且用於控制檯)。基本上我的應用程序不編碼任何東西,就好像它沒有任何編碼。 當在消除模式checkpont我可以看到源文件和服務器的正確屬性。

編碼過程需要0secs來處理。我檢查了服務器事件上的日誌,並收到警告「安全系統已收到並且無法解碼的身份驗證請求」。我只是沒有什麼知識可以比這個更進一步。任何幫助,將不勝感激。

這是一段代碼:

private void broadcastSourceFileToMediaServer2() 
    {    
     using (LiveJob job = new LiveJob()) 
     { 
      String filetoencode = @"c:\temp\niceday.wmv"; 

      LiveFileSource filesource = job.AddFileSource(filetoencode); 
      filesource.PlaybackMode = FileSourcePlaybackMode.Loop; 
      job.ActivateSource(filesource); 
      job.ApplyPreset(LivePresets.VC1Broadband4x3); 

      //don't know which one is good to use 
      job.AcquireCredentials += new EventHandler<AcquireCredentialsEventArgs>(job_AcquireCredentials); 
      _myUserName = "indes"; 
      _pw = PullPW("indes");    

      Uri url = new Uri("http://192.168.1.74:8080/live"); 
      PushBroadcastPublishFormat pubpoint = new PushBroadcastPublishFormat(); 
      pubpoint.PublishingPoint = url; 

      pubpoint.UserName = _myUserName; 
      pubpoint.Password = _pw; 

      job.PublishFormats.Add(pubpoint);  

      job.PreConnectPublishingPoint(); 

      job.StartEncoding(); 
      statusBox.Text = job.NumberOfEncodedSamples.ToString(); 

      job.StopEncoding(); 
      job.Dispose(); 
     } 
    } 




    public static string _myUserName { get; set; } 

    public static SecureString _pw { get; set; } 

    //codificação de Password a enviar 
    private static SecureString PullPW(string pw) 
    { 
     SecureString s = new SecureString(); 
     foreach (char c in pw) s.AppendChar(c); 
     return s; 
    } 

static void job_AcquireCredentials(object sender, AcquireCredentialsEventArgs e) 
    { 
     e.UserName = _myUserName; 
     e.Password = _pw; 
     e.Modes = AcquireCredentialModes.None; 
    } 

回答

2

進展:

我設法驗證(至少可以得到一個正面的審計事件)的服務器上。

我從此改變:

//don't know which one is good to use 
     job.AcquireCredentials += new EventHandler<AcquireCredentialsEventArgs>(job_AcquireCredentials); 
     _myUserName = "indes"; 
     _pw = PullPW("indes");    

     Uri url = new Uri("http://192.168.1.74:8080/live"); 
     PushBroadcastPublishFormat pubpoint = new PushBroadcastPublishFormat(); 
     pubpoint.PublishingPoint = url; 

     pubpoint.UserName = _myUserName; 
     pubpoint.Password = _pw; 

要這樣:

 job.AcquireCredentials += new EventHandler<AcquireCredentialsEventArgs>(job_AcquireCredentials); 
     _myUserName = @"mediaservername\user"; 
     _pw = PullPW("user_password");    

     Uri url = new Uri("http://192.168.1.74:8080/live"); 
     PushBroadcastPublishFormat pubpoint = new PushBroadcastPublishFormat(); 
     pubpoint.PublishingPoint = url; 

如果你在一邊看是否必須包括用戶名前域(域或計算機名)。這改變了服務器上失敗的審計事件,所以我可以刪除手動證書pubpoint.username和pubpoint.Password。

現在我只是處理缺乏輸出格式異常。在它上面。

0

我將您的代碼更改爲以下內容,看起來效果不錯。我想你的問題是你放置了LiveJob類的實例。在完成對整個流的編碼之前,您必須保持實例處於活動狀態。因此,改變使用部分,並刪除StopEncoding和處置將是確定的。

private void broadcastSourceFileToMediaServer2() 
    { 
     LiveJob job = new LiveJob(); 
     String filetoencode = @"c:\temp\niceday.wmv"; 

     LiveFileSource filesource = job.AddFileSource(filetoencode); 
     filesource.PlaybackMode = FileSourcePlaybackMode.Loop; 
     job.ActivateSource(filesource); 
     job.ApplyPreset(LivePresets.VC1Broadband4x3); 

     //don't know which one is good to use 
     job.AcquireCredentials += new EventHandler<AcquireCredentialsEventArgs>(job_AcquireCredentials); 
     _myUserName = "indes"; 
     _pw = PullPW("indes");    

     Uri url = new Uri("http://192.168.1.74:8080/live"); 
     PushBroadcastPublishFormat pubpoint = new PushBroadcastPublishFormat(); 
     pubpoint.PublishingPoint = url; 

     pubpoint.UserName = _myUserName; 
     pubpoint.Password = _pw; 

     job.PublishFormats.Add(pubpoint);  

     job.PreConnectPublishingPoint(); 

     job.StartEncoding(); 
     statusBox.Text = job.NumberOfEncodedSamples.ToString(); 
    } 

    public static string _myUserName { get; set; } 

    public static SecureString _pw { get; set; } 

    //codificação de Password a enviar 
    private static SecureString PullPW(string pw) 
    { 
     SecureString s = new SecureString(); 
     foreach (char c in pw) s.AppendChar(c); 
     return s; 
    } 

    static void job_AcquireCredentials(object sender, AcquireCredentialsEventArgs e) 
    { 
     e.UserName = _myUserName; 
     e.Password = _pw; 
     e.Modes = AcquireCredentialModes.None; 
    } 
1

如何使用流暢的流,我設法讓我的項目去,但我並沒有得到更多的超出下面看,到具有發佈開關類型的部分。忽略文件部分

internal bool StartStream() 
{ 
    Busy = true; 
    // Instantiates a new job for encoding 
    // 

    //***************************************Live Stream Archive****************************** 
    if (blnRecordFromFile) 
    { 

     // Sets up publishing format for file archival type 
     FileArchivePublishFormat fileOut = new FileArchivePublishFormat(); 



     // job.ApplyPreset(LivePresets.VC1512kDSL16x9); 

     // Gets timestamp and edits it for filename 
     string timeStamp = DateTime.Now.ToString(); 
     timeStamp = timeStamp.Replace("/", "-"); 
     timeStamp = timeStamp.Replace(":", "."); 

     // Sets file path and name 
     string path = "C:\\output\\"; 
     string filename = "Capture" + timeStamp + ".ismv"; 
     if (!Directory.Exists(path)) 
      Directory.CreateDirectory(path); 

     fileOut.OutputFileName = Path.Combine(path, filename); 

     // Adds the format to the job. You can add additional formats as well such as 
     // Publishing streams or broadcasting from a port 
     job.PublishFormats.Add(fileOut); 

    } 
    //******************************END OF Stream PORTION**************************************** 

    //////////////////////////////////////////////////////////////////////////////////////////////////// 
    //*************************************** Process Files or Live Stream****************************** 
    if (blnRecordFromFile) 
    { 
     job.ApplyPreset(LivePresets.VC1IISSmoothStreaming720pWidescreen); 

     job = new LiveJob(); 
     // Verifies all information is entered 
     if (string.IsNullOrWhiteSpace(sourcePath) || string.IsNullOrWhiteSpace(destinationPath)) 
      return false; 

     job.Status += new EventHandler<EncodeStatusEventArgs>(StreamStatus); 

     LiveFileSource fileSource; 
     try 
     { 
      // Sets file to active source and checks if it is valid 
      fileSource = job.AddFileSource(sourcePath); 
     } 
     catch (InvalidMediaFileException) 
     { 
      return false; 
     } 

     // Sets to loop media for streaming 
     // fileSource.PlaybackMode = FileSourcePlaybackMode.Loop; 

     // Makes this file the active source. Multiple files can be added 
     // and cued to move to each other at their ends 
     job.ActivateSource(fileSource); 
    } 
    //******************************END OF FILE PORTION**************************************** 


    // Sets up variable for fomat data 
    switch (publishType) 
    { 
     case Output.Archive: 
      // Verifies destination path exists and if not creates it 
      try 
     { 
      if (!Directory.Exists(destinationPath)) 
       Directory.CreateDirectory(destinationPath); 
     } 
      catch (IOException) 
      { 
       return false; 
      } 

      FileArchivePublishFormat archiveFormat = new FileArchivePublishFormat(); 

      // Gets the location of the old extention and removes it 
      string filename = Path.GetFileNameWithoutExtension(sourcePath); 

      // Sets the archive path and file name 
      archiveFormat.OutputFileName = Path.Combine(destinationPath, filename + ".ismv"); 
      job.PublishFormats.Add(archiveFormat); 
     break; 

     case Output.Publish: 
      // Setups streaming of media to publishing point 
      job = new LiveJob(); 

      // Aquires audio and video devices 
      Collection<EncoderDevice> devices = EncoderDevices.FindDevices(EncoderDeviceType.Video); 
      EncoderDevice video = devices.Count > 0 ? devices[0] : null; 
      for (int i = 0; i < devices.Count; ++i) 
       // devices[i].Dispose(); 
       devices.Clear(); 

      devices = EncoderDevices.FindDevices(EncoderDeviceType.Audio); 
      EncoderDevice audio = devices.Count > 0 ? devices[0] : null; 
      for (int i = 1; i < devices.Count; ++i) 
       devices[i].Dispose(); 
      devices.Clear(); 

      // Checks for a/v devices 
      if (video != null && audio != null) 
      { 


       //job.ApplyPreset(Preset.FromFile(@"C:\Tempura\LivePreset3.xml")); 
       job.ApplyPreset(LivePresets.H264IISSmoothStreamingLowBandwidthStandard); 
       job.OutputFormat.VideoProfile.SmoothStreaming = true; 
       deviceSource = job.AddDeviceSource(video, audio); 

       // Make this source the active one 
       job.ActivateSource(deviceSource); 
      } 
      else 
      { 
       error = true; 
      } 

      PushBroadcastPublishFormat publishFormat = new PushBroadcastPublishFormat(); 
      try 
     { 
      // checks the path for a valid publishing point 
      publishFormat.PublishingPoint = new Uri(destinationPath); 

     } 
      catch (UriFormatException) 
      { 
       return false; 
      } 

      // Adds the publishing format to the job 

      try 
     { 




      // job.ApplyPreset(LivePresets.VC1IISSmoothStreaming480pWidescreen); 
      job.PublishFormats.Add(publishFormat); 
      job.PreConnectPublishingPoint(); 
     } 
      catch (Exception e) 
      { 
       MessageBox.Show(e.StackTrace.ToString()); 
      } 

     break; 
     default: 
     return false; 
    } 
    job.StartEncoding(); 

    return true; 
} 
0

可悲的是我沒有足夠的代表評論,所以我必須寫它作爲答案。

由於您正在開始一項實時工作,爲了流式傳輸,您不應在StartEncoding之後立即調用job.StopEncoding()。我想通常你會使用一個事件來停止編碼。如果你開始編碼並立即停止它,那麼只有邏輯上你沒有,或者只有非常小的輸出。