本文整理汇总了C#中MediaStreamType类的典型用法代码示例。如果您正苦于以下问题:C# MediaStreamType类的具体用法?C# MediaStreamType怎么用?C# MediaStreamType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MediaStreamType类属于命名空间,在下文中一共展示了MediaStreamType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSampleAsync
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{
MediaStreamSample audioSample = null;
if (!sample_enumerator.MoveNext ())
{
// If you are near the end of the file, return a null stream, which
// tells the MediaStreamSource and MediaElement to close down.
audioSample = new MediaStreamSample(
this.audioStreamDescription,
null,
0,
0,
0,
emptyDict);
this.ReportGetSampleCompleted(audioSample);
}
else
{
// FIXME: Stream should not be created every time.
SampleBuffer buf = (SampleBuffer) sample_enumerator.Current;
audioSample = new MediaStreamSample(
this.audioStreamDescription,
new MemoryStream (buf.Data, buf.Index, buf.Count, false),
buf.Index,
buf.Count,
timePosition,
emptyDict);
timePosition += buf.Count * 10000000 / (44100 * 2 * 2);
this.ReportGetSampleCompleted(audioSample);
}
}
示例2: GetSampleAsync
//private int AlignUp(int a, int b)
//{
// int tmp = a + b - 1;
// return tmp - (tmp % b);
//}
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{
int numSamples = ChannelCount * 256;
int bufferByteCount = BitsPerSample / 8 * numSamples;
// fill the stream with noise
for (int i = 0; i < numSamples; i++)
{
short sample = (short)_random.Next(
short.MinValue, short.MaxValue);
_stream.Write(BitConverter.GetBytes(sample),
0,
sizeof(short));
}
// Send out the next sample
MediaStreamSample msSamp = new MediaStreamSample(
_audioDesc,
_stream,
_currentPosition,
bufferByteCount,
_currentTimeStamp,
_emptySampleDict);
// Move our timestamp and position forward
_currentTimeStamp += _waveFormat.AudioDurationFromBufferSize(
(uint)bufferByteCount);
_currentPosition += bufferByteCount;
ReportGetSampleCompleted(msSamp);
}
示例3: GetMediaStreamTypes
/// <summary>
/// メディアストリームタイプ一覧を得る
/// </summary>
/// <param name="deviceIndex">デバイスインデックス</param>
/// <returns>一覧</returns>
public async Task<string[]> GetMediaStreamTypes(int deviceIndex)
{
if (!(deviceIndex < _Devices.Count))
{
// 無効なindexを排除する
return null;
}
selectedId = _Devices[deviceIndex].Id;
_Settings.VideoDeviceId = selectedId;
await _MediaCapture.InitializeAsync(_Settings);
var types = new MediaStreamType[] { MediaStreamType.Photo, MediaStreamType.VideoPreview, MediaStreamType.VideoRecord };
_MediaStreamTypes = new List<MediaStreamType>();
foreach (var type in types)
{
var properties = _MediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(type);
// VideoEncodingProperty/ImageEncodngPropertyの区別が必要
if (properties.Count > 0)
{
_MediaStreamTypes.Add(type);
}
}
var result = new List<string>();
foreach (var type in _MediaStreamTypes)
{
result.Add(type.ToString());
}
return result.ToArray();
}
示例4: MediaChunk
/// <summary>
/// Initializes a new instance of the MediaChunk class
/// </summary>
/// <param name="chunkId">the id of this chunk</param>
/// <param name="mediaType">the media type of this chunk</param>
/// <param name="streamId">the id of the stream this chunk is contained in</param>
public MediaChunk(int chunkId, MediaStreamType mediaType, int streamId)
{
ChunkId = chunkId;
MediaType = mediaType;
StreamId = streamId;
DownloadedPiece = null;
}
示例5: GetSampleAsync
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{
for (int i = 0; i < numSamples; i++)
{
if (this.index < this.StartPoint |
this.index > this.EndPoint)
this.index = this.StartPoint;
memoryStream.WriteByte(this.sourceData[index]);
memoryStream.WriteByte(this.sourceData[index + 1]);
memoryStream.WriteByte(this.sourceData[index + 2]);
memoryStream.WriteByte(this.sourceData[index + 3]);
index += 4;
}
MediaStreamSample mediaStreamSample =
new MediaStreamSample(
mediaStreamDescription,
memoryStream,
currentPosition,
bufferByteCount,
currentTimeStamp,
emptySampleDict);
currentTimeStamp += bufferByteCount * 10000000L / byteRate;
currentPosition += bufferByteCount;
ReportGetSampleCompleted(mediaStreamSample);
}
示例6: GetSampleAsync
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{
for (int i = 0; i < numSamples; i++)
{
StereoSample sample;
if (this.Input != null)
sample = this.Input.GetSample();
else
sample = new StereoSample();
//left channel
memoryStream.WriteByte(
(byte)(sample.LeftSample & 0xFF));
memoryStream.WriteByte(
(byte)(sample.LeftSample >> 8));
//right channel
memoryStream.WriteByte(
(byte)(sample.RightSample & 0xFF));
memoryStream.WriteByte(
(byte)(sample.RightSample >> 8));
}
MediaStreamSample mediaStreamSample =
new MediaStreamSample(mediaStreamDescription, memoryStream, currentPosition,
bufferByteCount, currentTimeStamp, emptySampleDict);
currentTimeStamp += bufferByteCount * 10000000L / byteRate;
currentPosition += bufferByteCount;
ReportGetSampleCompleted(mediaStreamSample);
}
示例7: GetSampleAsync
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{
lock (_syncRoot)
{
if (_pendingPackets.Count > 0)
{
var frame = _pendingPackets.First.Value;
_pendingPackets.RemoveFirst();
long ts = frame.getTimeStamp();
ts *= 10000;
var attrs = frame.isFrameTypeI() ? _iSampleAttrs : _pSampleAttrs;
attrs[MediaSampleAttributeKeys.FrameWidth] = frame.getWidth().ToString();
attrs[MediaSampleAttributeKeys.FrameHeight] = frame.getHeight().ToString();
Debug.WriteLine("GetSample completed");
ReportGetSampleCompleted(new MediaStreamSample(_mediaStreamDescription,
new ARDroneVideoPacketStream(frame),
0,
frame.getDataLength(),
ts, attrs));
}
else
{
++_waitingForPacket;
Debug.WriteLine("GetSample progress");
ReportGetSampleProgress(0);
}
}
}
示例8: GetSampleAsync
protected override void GetSampleAsync (MediaStreamType mediaStreamType)
{
Mp3Frame frame;
MediaStreamSample sample;
Dictionary<MediaSampleAttributeKeys, string> attribs = new Dictionary<MediaSampleAttributeKeys, string> ();
//string format = "HH:mm:ss.ffff";
//if (opened == DateTime.MinValue)
// opened = DateTime.Now;
//Debug.WriteLine ("{0} GetSampleAsync stamp: {1}", (DateTime.Now - opened).ToString (), TimeSpan.FromMilliseconds (current_pts / 10000).ToString ());
try {
if (this.frame != null) {
frame = this.frame;
this.frame = null;
} else {
frame = Mp3Frame.Read (stream);
}
sample = new MediaStreamSample (description, new MemoryStream (frame.data), 0, frame.data.Length, current_pts, attribs);
current_pts += frame.Duration;
ReportGetSampleCompleted (sample);
} catch (System.IO.EndOfStreamException ex) {
Console.WriteLine (ex);
sample = new MediaStreamSample (description, null, 0, 0, 0, attribs);
ReportGetSampleCompleted (sample);
} catch (Exception ex) {
Console.WriteLine (ex);
ReportGetSampleCompleted (null);
}
}
示例9: GetSampleAsync
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{
CameraStreamSourceDataSingleton dataSource = CameraStreamSourceDataSingleton.Instance;
if (frameStreamOffset + dataSource.FrameBufferSize > dataSource.FrameStreamSize)
{
dataSource.FrameStream.Seek(0, SeekOrigin.Begin);
frameStreamOffset = 0;
}
Task tsk = dataSource.CameraEffect.GetNewFrameAndApplyEffect().AsTask();
// Wait that the asynchroneous call completes, and proceed by reporting
// the MediaElement that new samples are ready.
tsk.ContinueWith((task) =>
{
dataSource.FrameStream.Position = 0;
MediaStreamSample msSamp = new MediaStreamSample(
videoStreamDescription,
dataSource.FrameStream,
frameStreamOffset,
dataSource.FrameBufferSize,
currentTime,
emptySampleDict);
ReportGetSampleCompleted(msSamp);
currentTime += frameTime;
frameStreamOffset += dataSource.FrameBufferSize;
});
}
示例10: GetSampleAsync
protected override void GetSampleAsync(
MediaStreamType mediaStreamType)
{
while (mediaStreamSamples_[mediaStreamType].Count == 0)
{
Sample sample;
Error ec = demuxer_.get_sample(out sample);
if (ec == Error.success)
{
Dictionary<MediaSampleAttributeKeys, string> mediaSampleAttributes =
new Dictionary<MediaSampleAttributeKeys, string>();
if (sample.is_sync)
{
mediaSampleAttributes[MediaSampleAttributeKeys.KeyFrameFlag] = bool.TrueString;
}
MediaStreamType type = mediaStreamTypes_[(int)sample.index];
MediaStreamSample sample2 = new MediaStreamSample(
mediaStreamDescriptions_[type],
new System.IO.MemoryStream(sample.data),
0,
sample.data.Length,
(long)sample.time,
mediaSampleAttributes);
mediaStreamSamples_[type].Add(sample2);
}
else
{
if (ec == Error.would_block)
{
if (pending_)
{
System.Threading.Thread.Sleep(100);
continue;
}
else
{
pending_ = true;
System.Threading.ThreadPool.QueueUserWorkItem(
GetSamplePending, mediaStreamType);
}
}
else if (ec == Error.stream_end)
{
ReportGetSampleCompleted(null);
}
else
{
ErrorOccurred(ec.ToString());
}
return;
}
}
pending_ = false;
MediaStreamSample sample3 = mediaStreamSamples_[mediaStreamType][0];
mediaStreamSamples_[mediaStreamType].RemoveAt(0);
ReportGetSampleCompleted(sample3);
}
示例11: MediaChunkQueue
/// <summary>
/// Initializes a new instance of the MediaChunkQueue class
/// </summary>
/// <param name="count">the number of chunks in the queue</param>
/// <param name="mediaType">the media type of the queue</param>
/// <param name="streamId">the id of the stream this queue belongs to</param>
public MediaChunkQueue(int count, MediaStreamType mediaType, int streamId)
{
m_dataQueue = new MediaChunk[count];
for (int i = 0; i < count; i++)
{
m_dataQueue[i] = new MediaChunk(i, mediaType, streamId);
}
}
示例12: GetSampleAsync
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{
int blocksPlayed = this.Asap.GetBlocksPlayed();
int bufferLen = this.Asap.Generate(buffer, buffer.Length, BitsPerSample == 8 ? ASAPSampleFormat.U8 : ASAPSampleFormat.S16LE);
Stream s = bufferLen == 0 ? null : new MemoryStream(buffer);
MediaStreamSample mss = new MediaStreamSample(this.MediaStreamDescription, s, 0, bufferLen,
blocksPlayed * 10000000L / ASAP.SampleRate, SampleAttributes);
ReportGetSampleCompleted(mss);
}
示例13: StreamInfo
/// <summary>
/// Initializes a new instance of the StreamInfo class
/// </summary>
/// <param name="baseUrl">the base url for chunks in this stream</param>
/// <param name="language">the language of this stream</param>
/// <param name="numberOfChunks">the number of chunks in this stream</param>
/// <param name="mediaType">the MediaStreamType of this stream</param>
/// <param name="streamId">the id of this stream</param>
public StreamInfo(string baseUrl, string language, int numberOfChunks, MediaStreamType mediaType, int streamId)
{
m_baseUrl = baseUrl;
m_mediaType = mediaType;
m_language = language;
m_numberOfChunksInStream = numberOfChunks;
// Initialize our queue of chunks
m_chunksQueue = new MediaChunkQueue(numberOfChunks, MediaType, streamId);
}
示例14: GetSampleAsync
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{
if (mediaStreamType != MediaStreamType.Audio)
throw new InvalidOperationException ("Only audio stream type is supported");
q.BeginGetNextSample ((result) => {
var sample = q.EndGetNextSample (result);
ArraySegment<byte> buf = sample.Buffer;
position += ToTick (sample.Duration);
var s = new MediaStreamSample (media_desc, new MemoryStream (buf.Array), buf.Offset, buf.Count, position, empty_atts);
this.ReportGetSampleCompleted (s);
}, null);
}
示例15: GetSampleAsync
protected override void GetSampleAsync(MediaStreamType mediaStreamType)
{
switch (mediaStreamType)
{
case MediaStreamType.Video:
GetVideoSample();
break;
case MediaStreamType.Audio:
Debug.WriteLine("audio?!");
break;
}
}