示例#1
0
        void IDisposable.Dispose()
        {
            if (shutdownHandle)
            {
                shutdownHandle.set();
            }

            decoder?.Dispose();
            decoder = null;
            audioPlayer?.Dispose();
            audioPlayer = null;
            file?.Dispose();
            file = null;
            h264?.Dispose();

            shutdownHandle.finalize();
        }
示例#2
0
 public PresentationClock(StatefulVideoDecoder videoDecoder)
 {
     this.videoDecoder = videoDecoder;
 }
示例#3
0
        /// <summary>Load an mp4 media file; this runs on a background thread from the thread pool.</summary>
        void loadMediaImpl(string url, TaskCompletionSource <bool> completionSource)
        {
            try
            {
                // Deal with paths starting from "~/", transform that into user's home folder
                if (url.StartsWith("~/"))
                {
                    string rel  = url.Substring(2);
                    string home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                    url = Path.Combine(home, rel);
                }

                // Parse the complete MP4, except the largest `mdat` box which has the actual payload of the video.
                file = OpenMedia.openMedia(File.OpenRead(url));

                if (!shutdownHandle)
                {
                    shutdownHandle = EventHandle.create();
                }

                // Initialize the video
                if (null == file.videoTrack)
                {
                    throw new ApplicationException("The file doesn’t have a video track");
                }
                decoder?.Dispose();
                decoder = new StatefulVideoDecoder(h264.device, shutdownHandle);

                int videoEncodedBuffers = encodedBuffersCount;
                int audioEncodedBuffers = this.audioEncodedBuffers;

                decoder.initialize(file.videoTrack, videoEncodedBuffers);
                decodedSize = file.videoTrack.decodedSize;
                decoder.captureSetup(file.videoTrack, decodedBuffersCount, decodedSize);

                // Initialize the audio
                audioPlayer?.Dispose();
                audioPlayer = null;
                if (null != file.audioTrack)
                {
                    try
                    {
                        audioPlayer = Audio.Player.create(file.audioTrack, audioEncodedBuffers, shutdownHandle);
                    }
                    catch (Exception ex)
                    {
                        // Logger.logError( ex.ToString() );
                        ex.logError("Error initializing audio");
                    }
                }
                else
                {
                    Logger.logWarning("The file doesn’t have an audio track");
                }

                // Initialize presentation clock source
                if (null != audioPlayer)
                {
                    // Use audio player for the source of presentation time
                    if (displayRefresh.HasValue)
                    {
                        presentationClock = new Clocks.AudioWithTimer(decoder, audioPlayer, displayRefresh.Value);
                    }
                    else
                    {
                        presentationClock = new Clocks.Audio(decoder, audioPlayer);
                    }
                }
                else
                {
                    // Use eClock.Monotonic OS clock for presentation time
                    presentationClock = new Clocks.Video(decoder);
                }
                m_state = eState.Prepared;
                if (m_autoPlay)
                {
                    play();
                }

                completionSource.SetResult(true);
            }
            catch (Exception ex)
            {
                completionSource.SetException(ex);
            }
        }