Exemple #1
0
        /// <summary>
        /// Factory method for instantiating the right decoder instance based on streamInfo.
        /// </summary>
        public static VideoDecoder CreateFor(VideoStreamInfo streamInfo)
        {
            if (streamInfo == null)
            {
                throw new System.ArgumentException("Can't choose VideoDecoder without streamInfo (with at least codecFourCC)");
            }

            // list of FourCC codes http://www.fourcc.org/codecs.php
            switch (streamInfo.codecFourCC)
            {
            case VideoDecoderMJPEG.FOURCC_MJPG:
            case VideoDecoderMJPEG.FOURCC_CJPG:
            case VideoDecoderMJPEG.FOURCC_ffds:
                return(new VideoDecoderMJPEG(streamInfo));

            case VideoDecoderMPNG.FOURCC_MPNG:
                return(new VideoDecoderMPNG(streamInfo));

            case VideoDecoderRGB.FOURCC_DIB_:
            case VideoDecoderRGB.FOURCC_NULL:
                return(new VideoDecoderRGB(streamInfo));
            }
            throw new MpException("No decoder for video fourCC 0x" + streamInfo.codecFourCC.ToString("X") +
                                  " (" + RiffParser.FromFourCC(streamInfo.codecFourCC) + ")");
        }
Exemple #2
0
        private string GetSourceInfo()
        {
            // Has the source changed? if so, cache it's length, because it's too resouce hungry to call freely.
            if (mp.source != lastSource)
            {
                if (mp.source != null)
                {
                    sourceSize = mp.source.bytes.Length;
                }
                lastSource = mp.source;
            }

            // build source info string
            StringBuilder infoSb = new StringBuilder("");

            if (mp.source == null)
            {
                infoSb.Append("Movie not loaded");
            }
            else
            {
                // Source info
                infoSb.Append(mp.source.name).Append(" ").Append(((float)sourceSize / 1000000f).ToString("#.##")).Append(" Mb\n");

                // Video info
                infoSb.Append("Video: ");
                if (mp.movie != null && mp.movie.demux != null && mp.movie.demux.videoStreamInfo != null)
                {
                    var videoStreamInfo = mp.movie.demux.videoStreamInfo;
                    infoSb.AppendFormat("{0} {1}fps {2}x{3} ({4:#} kbps)\n", RiffParser.FromFourCC(videoStreamInfo.codecFourCC),
                                        videoStreamInfo.framerate, videoStreamInfo.width, videoStreamInfo.height,
                                        0.001f * videoStreamInfo.lengthBytes / videoStreamInfo.lengthSeconds);
                }
                else
                {
                    infoSb.Append("N/A\n");
                }

                // Audio info
                infoSb.Append("Audio: ");
                if (mp.movie != null && mp.movie.demux != null && mp.movie.demux.audioStreamInfo != null)
                {
                    var audioStreamInfo = mp.movie.demux.audioStreamInfo;
                    var audioFourCC     = RiffParser.FromFourCC(audioStreamInfo.codecFourCC);
                    infoSb.AppendFormat("{0} {1}kHz {2}ch ({3:#} kbps)", audioFourCC,
                                        audioStreamInfo.sampleRate / 1000f, audioStreamInfo.channels,
                                        0.001f * audioStreamInfo.lengthBytes / audioStreamInfo.lengthSeconds);
                }
                else
                {
                    infoSb.Append("N/A");
                }
            }
            return(infoSb.ToString());
        }
Exemple #3
0
        /// <summary>
        /// Factory method for instantiating the right audio decoder based on stream info.
        /// </summary>
        public static AudioDecoder CreateFor(AudioStreamInfo streamInfo)
        {
            if (streamInfo == null)
            {
                throw new System.ArgumentException("Can't choose AudioDecoder without streamInfo (with at least codecFourCC)");
            }

            switch (streamInfo.codecFourCC)
            {
            case AudioDecoderPCM.FOURCC_MS:
                return(new AudioDecoderPCM(streamInfo));
            }
            throw new MpException("No decoder for audio fourCC 0x" + streamInfo.codecFourCC.ToString("X") +
                                  " (" + RiffParser.FromFourCC(streamInfo.codecFourCC) + ")");
        }