示例#1
0
 /// <summary>
 /// Write the sample or stream sample in the correct way given the payload and the segment
 /// compression settings.  In the case of uncompressed video, also reconfigure the writer input properties
 /// if the newstream flag is set.  Keyframe and discontinuity flags are only relevant when writing
 /// compressed video.
 /// </summary>
 /// <param name="payload"></param>
 /// <param name="sample"></param>
 /// <param name="timestamp"></param>
 /// <param name="newstream"></param>
 /// <returns></returns>
 private void writeSample(PayloadType payload, BufferChunk sample, ulong timestamp, bool newstream, bool keyframe, bool discontinuity)
 {
     if (payload == PayloadType.dynamicAudio)
     {
         if (norecompression)
         {
             writer.WriteCompressedAudio(timestamp, (uint)sample.Length, (byte[])sample);
         }
         else
         {
             writer.WriteAudio((uint)sample.Length, sample, timestamp);
         }
     }
     else if (payload == PayloadType.dynamicVideo)
     {
         if (norecompression)
         {
             writer.WriteCompressedVideo(timestamp, (uint)sample.Length, (byte[])sample, keyframe, discontinuity);
         }
         else
         {
             if (newstream)
             {
                 //PRI3: don't need to reconfig unless MT changed.  Probably does no harm though
                 if (useSlideStream)
                 {
                     //writer.ConfigSlideStreamVideo(slideStream.UncompressedMediaType);
                     writer.ConfigVideo(slideStream.UncompressedMediaType);
                 }
                 else
                 {
                     writer.ConfigVideo(videoStream.GetUncompressedVideoMediaType());
                 }
             }
             writer.WriteVideo((uint)sample.Length, sample, timestamp);
         }
     }
 }
示例#2
0
        /// <summary>
        /// Recompress audio from mixer into a temp file using the native profile.  This is used to implement mixing
        /// in the 'norecompression' scenario.
        /// </summary>
        /// <param name="progressTracker"></param>
        /// <returns></returns>
        public bool Recompress(ProgressTracker progressTracker)
        {
            cancel = false;

            if (audioMgr.Length == 0)
            {
                return(false);
            }

            //String useProfile;
            ProfileData profileData = null;

            if (this.compatibleStreamID >= 0)
            {
                profileData = ProfileUtility.StreamIdToProfileData(compatibleStreamID, MSR.LST.Net.Rtp.PayloadType.dynamicAudio);
                //Debug.WriteLine("Mixer.Recompress: using audio profile from streamID: " + compatibleStreamID.ToString());
            }
            else
            {
                //Under what circumstances could we get here??
                profileData = audioMgr[0].StreamProfileData;
            }

            WMWriter wmWriter = new WMWriter();

            wmWriter.Init();

            if (!wmWriter.ConfigProfile(profileData))
            {
                return(false);
            }

            String tempFileName = Utility.GetTempFilePath("wma");

            wmWriter.ConfigFile(tempFileName);
            wmWriter.GetInputProps();
            wmWriter.ConfigAudio(audioMgr[0].GetUncompressedAudioMediaType());

            wmWriter.Start();

            //Write samples
            progressTracker.CurrentValue = 0;
            BufferChunk audioSample = null;
            long        audioTime = long.MaxValue;
            long        refTime = 0, endTime = 0;
            long        lastWriteTime = 0;

            while (!cancel)
            {
                if (audioSample == null)
                {
                    endTime = audioTime;
                    if (!GetNextSample(out audioSample, out audioTime))
                    {
                        break;
                    }
                }

                if (audioSample != null)
                {
                    //write audio
                    if (refTime == 0)
                    {
                        refTime = audioTime;
                    }
                    //Debug.WriteLine("mixer.Recompress write audio: " + (audioTime-refTime).ToString() + ";length=" + audioSample.Length.ToString());
                    lastWriteTime = audioTime - refTime;
                    wmWriter.WriteAudio((uint)audioSample.Length, audioSample, (ulong)(audioTime - refTime));
                    audioSample = null;
                }
                else
                {
                    break;
                }
                progressTracker.CurrentValue = (int)(lastWriteTime / (Constants.TicksPerSec));
            }

            wmWriter.Stop();
            wmWriter.Cleanup();
            wmWriter = null;

            //Prepare a filestreamPlayer to read back compressed samples.
            fileStreamPlayer = new FileStreamPlayer(tempFileName, refTime, endTime, true, -1);

            return(true);
        }