Пример #1
0
 public void TestPreparsedMediaCreate()
 {
     using (VlcMediaLibraryFactory factory = CreateNewFactory()) {
         factory.CreateSinglePlayers = true;
         PlayerOutput nullOutput = new PlayerOutput();
         //
         string path = GetSampleAudioPath();
         if (!System.IO.File.Exists(path))
         {
             Assert.Ignore("The sample file doesn't exists. Ignoring.");
         }
         MediaInput input = new MediaInput(MediaInputType.File,
                                           path);
         //
         using (Player player = factory.CreatePlayer(nullOutput)) {
             PreparsedMedia media = player.ParseMediaInput(input);
             media = player.ParseMediaInput(input);
             //
             Assert.IsTrue(media.ContainsAudio);
             Assert.IsFalse(media.ContainsVideo);
             //
             AudioTrackInfo[] tracks = media.GetAudioTracks();
             Assert.IsTrue(tracks.Length == 1, "There should be one audio track.");
             //
             VideoTrackInfo[] tracksVideo = media.GetVideoTracks();
             Assert.IsTrue(tracksVideo.Length == 0, "There shouldn't be any video tracks.");
         }
     }
 }
Пример #2
0
 internal VlcSinglePlayer(PlayerOutput playerOutput, IInternalObjectsFactory internalObjectsFactory)
     : base(internalObjectsFactory)
 {
     if (playerOutput == null)
     {
         throw new ArgumentNullException("playerOutput");
     }
     if (playerOutput.Window != null && !(playerOutput.Window is DoubleWindowBase))
     {
         //NOTE: it is not realy neccessary for VlcSinglePlayer - should we create simpler Window class?
         throw new ArgumentException("Window property of PlayerOutput should be of class DoubleWindowBase.", "playerOutput");
     }
     if (internalObjectsFactory == null)
     {
         throw new ArgumentNullException("internalObjectsFactory");
     }
     //
     this.playerOutput           = playerOutput;
     this.internalObjectsFactory = internalObjectsFactory;
     //
     stateChangeEventHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
     //
     internalPlayer = internalObjectsFactory.CreateVlcMediaPlayerInternal();
     initializeEvents();
 }
Пример #3
0
 /// <summary>
 /// Creates player which can be used to control media playing.
 /// </summary>
 /// <returns>Player instance.</returns>
 public override Player CreatePlayer(PlayerOutput playerOutput)
 {
     VerifyObjectIsNotDisposed();
     //
     if (playerOutput == null)
     {
         throw new ArgumentNullException("playerOutput");
     }
     //
     return(new VlcPlayer(playerOutput, new InternalObjectsFactory(descriptor), this));
 }
Пример #4
0
 /// <summary>
 /// Creates player with set of necessary filters support.
 /// </summary>
 public override Player CreatePlayer(PlayerOutput playerOutput, IFilterBase filtersRequired)
 {
     VerifyObjectIsNotDisposed();
     //
     if (playerOutput == null)
     {
         throw new ArgumentNullException("playerOutput");
     }
     //
     if (filtersRequired is IAdjustable)
     {
     }
     return(new VlcPlayer(playerOutput, new InternalObjectsFactory(descriptor), this));
 }
Пример #5
0
        private void testPlayerState(MediaLibraryFactory factory)
        {
            PlayerOutput nullOutput = new PlayerOutput();
            //
            string path = GetSampleAudioPath();

            if (!System.IO.File.Exists(path))
            {
                Assert.Ignore("The sample file doesn't exists. Ignoring.");
            }
            MediaInput input = new MediaInput(MediaInputType.File,
                                              path);

            //
            using (Player player = factory.CreatePlayer(nullOutput)) {
                testPlayerState(player, input);
            }
        }
Пример #6
0
 /// <summary>
 /// Creates player which can be used to control media playing.
 /// </summary>
 /// <returns>Player instance.</returns>
 public override Player CreatePlayer(PlayerOutput playerOutput)
 {
     VerifyObjectIsNotDisposed();
     //
     if (playerOutput == null)
     {
         throw new ArgumentNullException("playerOutput");
     }
     //
     if (CreateSinglePlayers)
     {
         return(new VlcSinglePlayer(playerOutput, internalFactory));
     }
     else
     {
         return(new VlcPlayer(playerOutput, internalFactory));
     }
 }
Пример #7
0
 private void initializePlayer()
 {
     // that code will initialize factory if it is not initialized
     if (factory == null)
     {
         // this part of code will try to deploy VLC if it is necessary.
         // main idea - unzip libraries to specific place.
         VlcDeployment deployment = VlcDeployment.Default;
         // install library if it doesn't exist
         // NOTE: first parameter tells to check hash of deployed files to be sure about vlc version without loading it.
         // since vlc library can be initialized only once it is important not to load it during check
         // but it is still possible to check vlc version using libvlc_get_version, so if you want - pass second parameter
         // as 'true'.
         if (!deployment.CheckVlcLibraryExistence(false, false))
         {
             // install library
             deployment.Install(true);
         }
         // this is path to plugins. very important part of initialization of vlc.
         string path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "plugins");
         // we can use a lot of parameters there.
         // refer to vlc --help to learn more.
         factory = new VlcMediaLibraryFactory(new string[] { "--reset-config",
                                                             "--no-snapshot-preview",
                                                             "--aspect-ratio=16:9",
                                                             "--ignore-config",
                                                             "--intf", "rc",
                                                             "--no-osd",
                                                             "--plugin-path", path });
         // tell our factory to create new version of players
         // NOTE: if you change this to 'false' old version of implementation will be created
         // NOTE: old implementation remains for backward compatibility
         factory.CreateSinglePlayers = true;
         // we going to output to NSView instance:
         PlayerOutput output = new PlayerOutput(new VlcNativeMediaWindow(VideoView.NativePointer, VlcWindowType.NSObject));
         // we can save stream to a file:
         // output.Files.Add(new OutFile("filePath"));
         player = (VlcSinglePlayer)factory.CreatePlayer(output);
         // add event receiver to get known about player events
         player.EventsReceivers.Add(new EventReceiver(this));
     }
 }
        public void TestFrequencyTables()
        {
            var po = new PlayerOutput
            {
                PlayerType = "RBs Scores",
                ScoreType  = Constants.K_SCORE_TD_RUN,
                ScoreSlot  = "1",
                wRange     = { startWeek = new NFLWeek(2012, 1), endWeek = new NFLWeek(2012, 17) },
                Scorer     = new GS4Scorer(Utility.CurrentNFLWeek())
                {
                    ScoresOnly = true
                }
            };

            po.Load();
            po.Render(po.PlayerType, po.wRange.startWeek.Season);
            var fileOut = po.FileName;

            Assert.IsTrue(File.Exists(fileOut), string.Format("Cannot find {0}", fileOut));
        }
Пример #9
0
        public void TestStreaming()
        {
            VlcMediaLibraryFactory factory = this.CreateNewFactory(new string[] {
            });
            VlcSinglePlayer playerStream   = (VlcSinglePlayer)factory.CreatePlayer(new
                                                                                   PlayerOutput(":sout=#transcode{vcodec=mp4v,vb=1024,acodec=mp4a,ab=192}:standard{mux=ts,dst=127.0.0.1:8080,access=udp}"));

            //
            string       filePath = GetTemporaryFilePath();
            PlayerOutput output   = new PlayerOutput();

            output.Files.Add(new OutFile(filePath));
            //
            VlcSinglePlayer playerReceive = (VlcSinglePlayer)factory.CreatePlayer(output);

            try {
                playerReceive.SetMediaInput(new MediaInput(MediaInputType.UnparsedMrl, "udp://127.0.0.1:8080"));
                playerStream.SetMediaInput(new MediaInput(MediaInputType.UnparsedMrl, "file://" + GetSampleVideoPath()));
                //
                playerStream.Play();
                //
                Thread.Sleep(1000);
                //
                playerReceive.Play();
                //
                Thread.Sleep(5000);
                //
                Assert.IsTrue(File.Exists(filePath));
                FileInfo info = new FileInfo(filePath);
                Assert.Greater(info.Length, 0);
                //
                playerReceive.Stop();
                playerStream.Stop();
            } finally {
                playerStream.Dispose();
                playerReceive.Dispose();
                factory.Dispose();
            }
        }
Пример #10
0
        public void PlayerOutputRBTest()
        {
            //SeasonFreqTableGs4("Kickers", Constants.K_SCORE_FIELD_GOAL, "1", scoresOnly: false);
            //SeasonFreqTableGs4("QBs Scores", Constants.K_SCORE_TD_PASS, "2", scoresOnly: true);
            //SeasonFreqTableGs4("RBs Scores", Constants.K_SCORE_TD_RUN, "1", scoresOnly: true);
            //SeasonFreqTableGs4("WRs Scores", Constants.K_SCORE_TD_PASS, "1", scoresOnly: true);
            var po = new PlayerOutput
            {
                PlayerType = "RBs Scores",
                ScoreType  = Constants.K_SCORE_TD_RUN,
                ScoreSlot  = "1",
                wRange     = { startWeek = new NFLWeek(2012, 1), endWeek = new NFLWeek(2012, 17) },
                Scorer     = new GS4Scorer(Utility.CurrentNFLWeek())
                {
                    ScoresOnly = true
                }
            };

            po.Load();
            po.Render(po.PlayerType, po.wRange.startWeek.Season);

            Assert.IsTrue(true);
        }
Пример #11
0
 /// <summary>
 /// Creates player which can be used to control media playing.
 /// </summary>
 /// <returns>Player instance.</returns>
 public abstract Player CreatePlayer(PlayerOutput playerOutput);
Пример #12
0
 /// <summary>
 /// Creates player with set of necessary filters.
 /// </summary>
 public abstract Player CreatePlayer(PlayerOutput playerOutput, IFilterBase filtersRequired);
Пример #13
0
        public void SetOutput(PlayerOutput playerOutput)
        {
            if (playerOutput == null)
            {
                throw new ArgumentNullException("playerOutput");
            }
            //
            VerifyObjectIsNotDisposed();
            //
            if (string.IsNullOrEmpty(playerOutput.OutMrl))
            {
                if ((playerOutput.Files.Count == 0) && (playerOutput.NetworkStreams.Count == 0))
                {
                    //
                    //addOption("--video-filter=adjust@my_label");
                    //
                    return;
                }

                //string transcodeString = "vcodec=WMV2,vb=800,scale=1,acodec=wma,ab=128,channels=2";
                const string transcodeString = "vcodec=WMV2,vb=1024,scale=1";

                // Здесь media должна знать, будет ли она дублироваться на экран
                string duplicateString = (playerOutput.Window != null) ? "dst=display" : String.Empty;
                foreach (OutFile file in playerOutput.Files)
                {
                    //dst=std{access=file,mux=ps,dst=\"{0}\"}
                    string s = String.Format("dst=std[access=file,mux=ps,dst=\"{0}\"]", file.FileName);

                    if (String.IsNullOrEmpty(duplicateString))
                    {
                        duplicateString = s;
                    }
                    else
                    {
                        duplicateString += "," + s;
                    }
                }

                foreach (OutputNetworkStream stream in playerOutput.NetworkStreams)
                {
                    //dst=std{access=http,mux=asf,dst=172.28.1.4:8888}
                    //dst=rtp{dst=1231232,mux=asf,port=1234,port-audio=12367,port-video=31236}
                    string s;
                    if (stream.Protocol != NetworkProtocol.RTP)
                    {
                        s = String.Format("dst=std[access={0},mux=asf,dst={1}:{2}]",
                                          stream.Protocol.ToString().ToLower(), stream.Ip, stream.Port);
                    }
                    else
                    {
                        s = String.Format("dst=rtp[dst={0},mux=asf,port={1},port-audio={2},port-video={3}]",
                                          stream.Ip, stream.Port, stream.RtpPortAudio, stream.RtpPortVideo);
                    }

                    if (String.IsNullOrEmpty(duplicateString))
                    {
                        duplicateString = s;
                    }
                    else
                    {
                        duplicateString += "," + s;
                    }
                }

                string optionsString = String.Format(":sout=#transcode[{0}]:duplicate[{1}]", transcodeString, duplicateString);

                addOption(optionsString.Replace('[', '{').Replace(']', '}'));
            }
            else
            {
                addOption(playerOutput.OutMrl);
            }
        }