コード例 #1
0
        /// <summary>
        /// Loads movie with audio. It will be ready for playback
        /// </summary>
        /// <param name="source">Source</param>
        /// <param name="targetFramebuffer">Target framebuffer</param>
        /// <param name="targetAudioBuffer">Target audio buffer</param>
        /// <param name="loadOptions">Load options</param>
        public static Movie Load(MovieSource source, out Texture2D targetFramebuffer, out AudioClip targetAudioBuffer, LoadOptions loadOptions = null)
        {
            if (loadOptions == null)
                loadOptions = LoadOptions.Default;

            if (source.stream == null && source.url == null) {
                throw new MpException ("Either source.stream or source.url must be provided");
            }

            targetFramebuffer = null;
            targetAudioBuffer = null;

            var movie = new Movie ();
            movie.sourceStream = source.stream; // can be NULL

            // create and initialize demux for the source data
            if (source.url != null) {
                movie.demux = loadOptions.demuxOverride != null ? loadOptions.demuxOverride : Streamer.forUrl (source.url);
                ((Streamer)movie.demux).Connect (source.url, loadOptions);
            } else {
                movie.demux = loadOptions.demuxOverride != null ? loadOptions.demuxOverride : Demux.forSource (source.stream);
                movie.demux.Init (source.stream, loadOptions);
            }

            if (movie.demux.hasVideo && !loadOptions.skipVideo) {
                var vsi = movie.demux.videoStreamInfo;
                movie.videoDecoder = VideoDecoder.CreateFor (vsi);
                movie.videoDecoder.Init (out targetFramebuffer, movie.demux, loadOptions);

                if(loadOptions.preloadVideo) {
                    movie.frameUV = UnpackFramesToAtlas(movie.videoDecoder, ref targetFramebuffer, vsi.frameCount);
                } else {
                    movie.frameUV = new Rect[1] { new Rect(0, 0, 1, 1) };
                }
            }
            if (movie.demux.hasAudio && !loadOptions.skipAudio) {
                movie.audioDecoder = AudioDecoder.CreateFor (movie.demux.audioStreamInfo);
                movie.audioDecoder.Init (out targetAudioBuffer, movie.demux, loadOptions);
            }
            return movie;
        }
コード例 #2
0
ファイル: AudioDecoder.cs プロジェクト: sawakun/Sphere_screen
 public abstract void Init(out AudioClip audioClip, Demux demux, LoadOptions loadOptions = null);
コード例 #3
0
 public static Movie Load(Stream srcStream, out Texture2D targetFramebuffer, out AudioClip targetAudioBuffer, LoadOptions loadOptions = null)
 {
     return Load (new MovieSource () { stream = srcStream }, out targetFramebuffer, out targetAudioBuffer, loadOptions);
 }
コード例 #4
0
 public static Movie Load(string srcUrl, out Texture2D targetFramebuffer, out AudioClip targetAudioBuffer, LoadOptions loadOptions = null)
 {
     return Load (new MovieSource () { url = srcUrl }, out targetFramebuffer, out targetAudioBuffer, loadOptions);
 }
コード例 #5
0
ファイル: VideoDecoder.cs プロジェクト: sawakun/Sphere_screen
 public abstract void Init(out Texture2D framebuffer, Demux demux, LoadOptions loadOptions = null);
コード例 #6
0
        public override void Init(Stream sourceStream, LoadOptions loadOptions = null)
        {
            // skip the video if asked not to load it
            if (loadOptions != null && loadOptions.skipVideo)
                return;

            // check the arguments
            if (sourceStream == null) {
                throw new System.ArgumentException ("sourceStream is required");
            }

            // measure load time
            var watch = new System.Diagnostics.Stopwatch ();
            watch.Start ();

            reader = new AtomicBinaryReader (sourceStream);

            // for detecting the buffer size
            int maxRawJpgSize = 0;

            // the stream can't be seeked unless there is an index. create it
            frameStartIndex.Clear ();
            frameSize.Clear ();

            long markerCount = 0;
            long startIndex = -1;
            bool markerStart = false;
            int bytesRead = -1;
            long i = 0;
            var buffer = new byte[FILE_READ_BUFFER_SIZE];

            // read the file in chunks (more than 30x faster than reading by byte)
            long p = 0;
            do {
                bytesRead = reader.Read (ref p, buffer, 0, FILE_READ_BUFFER_SIZE);

                for (int j = 0; j < bytesRead; j++) {
                    byte b = buffer [j];

                    // wait for marker start
                    if (b == 0xFF) {
                        markerStart = true;
                    } else if (markerStart) {
                        // read the other marker byte and decide what to do
                        switch (b) {
                        case 0xD8: // Start of image
                            startIndex = i + j - 1;
                            break;
                        case 0xD9: // End of image
                            frameStartIndex.Add (startIndex);
                            int size = (int)(i + j - startIndex + 1);
                            if (size > maxRawJpgSize)
                                maxRawJpgSize = size;
                            frameSize.Add (size);
                            //Debug.Log("Found frame OFFS: " + startIndex + " SIZE: " + size);
                            break;
                        }
                        markerStart = false;
                        markerCount++;
                    }
                }
                i += bytesRead;
            } while(bytesRead >= FILE_READ_BUFFER_SIZE);

            // create a buffer for holding raw jpg data when decoding a frame
            rawJpgBuffer = new byte[maxRawJpgSize];

            watch.Stop ();
            #if MP_DEBUG
            Debug.Log("Recreated index for raw MJPEG stream in " + (watch.Elapsed.TotalMilliseconds * 0.001f) + " seconds." +
                "Frames: " + frameStartIndex.Count + ". Max jpg size: " + maxRawJpgSize + ". Markers: " + markerCount);
            #endif

            // set all the info about the video stream we know
            if (loadOptions != null && loadOptions.videoStreamInfo != null) {
                videoStreamInfo = loadOptions.videoStreamInfo;
            } else {
                videoStreamInfo = new VideoStreamInfo ();
                videoStreamInfo.codecFourCC = VideoDecoderMJPEG.FOURCC_MJPG;
            }
            videoStreamInfo.frameCount = frameSize.Count;
            videoStreamInfo.lengthBytes = reader.StreamLength;
        }
コード例 #7
0
 public abstract void Init(out AudioClip audioClip, Demux demux, LoadOptions loadOptions = null);
コード例 #8
0
ファイル: VideoDecoder.cs プロジェクト: lanchu/SkyZoneVR
 public abstract void Init(out Texture2D framebuffer, Demux demux, LoadOptions loadOptions = null);
コード例 #9
0
        /// <summary>
        /// Loads movie with audio. It will be ready for playback
        /// </summary>
        /// <param name="source">Source</param>
        /// <param name="targetFramebuffer">Target framebuffer</param>
        /// <param name="targetAudioBuffer">Target audio buffer</param>
        /// <param name="loadOptions">Load options</param>
        public static Movie Load(MovieSource source, out Texture2D targetFramebuffer, out AudioClip targetAudioBuffer, LoadOptions loadOptions = null)
        {
            if (loadOptions == null)
            {
                loadOptions = LoadOptions.Default;
            }

            if (source.stream == null && source.url == null)
            {
                throw new MpException("Either source.stream or source.url must be provided");
            }

            targetFramebuffer = null;
            targetAudioBuffer = null;

            var movie = new Movie();

            movie.sourceStream = source.stream;             // can be NULL

            // create and initialize demux for the source data
            if (source.url != null)
            {
                movie.demux = loadOptions.demuxOverride != null ? loadOptions.demuxOverride : Streamer.forUrl(source.url);
                ((Streamer)movie.demux).Connect(source.url, loadOptions);
            }
            else
            {
                movie.demux = loadOptions.demuxOverride != null ? loadOptions.demuxOverride : Demux.forSource(source.stream);
                movie.demux.Init(source.stream, loadOptions);
            }

            if (movie.demux.hasVideo && !loadOptions.skipVideo)
            {
                movie.videoDecoder = VideoDecoder.CreateFor(movie.demux.videoStreamInfo);
                movie.videoDecoder.Init(out targetFramebuffer, movie.demux, loadOptions);
            }
            if (movie.demux.hasAudio && !loadOptions.skipAudio)
            {
                movie.audioDecoder = AudioDecoder.CreateFor(movie.demux.audioStreamInfo);
                movie.audioDecoder.Init(out targetAudioBuffer, movie.demux, loadOptions);
            }
            return(movie);
        }
コード例 #10
0
ファイル: Demux.cs プロジェクト: louistb/ProjectionsPK
 public abstract void Init(Stream sourceStream, LoadOptions loadOptions = null);
コード例 #11
0
 public static Movie Load(string srcUrl, out Texture2D targetFramebuffer, out AudioClip targetAudioBuffer, LoadOptions loadOptions = null)
 {
     return(Load(new MovieSource()
     {
         url = srcUrl
     }, out targetFramebuffer, out targetAudioBuffer, loadOptions));
 }
コード例 #12
0
 public static Movie Load(Stream srcStream, out Texture2D targetFramebuffer, out AudioClip targetAudioBuffer, LoadOptions loadOptions = null)
 {
     return(Load(new MovieSource()
     {
         stream = srcStream
     }, out targetFramebuffer, out targetAudioBuffer, loadOptions));
 }
コード例 #13
0
ファイル: Streamer.cs プロジェクト: lanchu/SkyZoneVR
 public override void Init(Stream stream, LoadOptions loadOptions = null)
 {
     throw new MpException("Streamer requires you to call Connect() instead of Init()");
 }
コード例 #14
0
ファイル: Streamer.cs プロジェクト: lanchu/SkyZoneVR
 public abstract void Connect(string url, LoadOptions loadOptions = null);
コード例 #15
0
ファイル: Demux.cs プロジェクト: sawakun/Sphere_screen
 public abstract void Init(Stream sourceStream, LoadOptions loadOptions = null);