本文整理汇总了C#中AtomCollection.SetChanInfoStreamExt方法的典型用法代码示例。如果您正苦于以下问题:C# AtomCollection.SetChanInfoStreamExt方法的具体用法?C# AtomCollection.SetChanInfoStreamExt怎么用?C# AtomCollection.SetChanInfoStreamExt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AtomCollection
的用法示例。
在下文中一共展示了AtomCollection.SetChanInfoStreamExt方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public ParsedContent Read(Stream stream)
{
var chunks = 0;
var res = new ParsedContent();
var pos = Channel.ContentPosition;
try {
while (chunks<8) {
var chunk = ASFChunk.Read(stream);
chunks++;
switch (chunk.KnownType) {
case ASFChunk.ChunkType.Header: {
var header = ASFHeader.Read(chunk);
var info = new AtomCollection(Channel.ChannelInfo.Extra);
info.SetChanInfoBitrate(header.Bitrate);
if (header.Streams.Any(type => type==ASFHeader.StreamType.Video)) {
info.SetChanInfoType("WMV");
info.SetChanInfoStreamType("video/x-ms-wmv");
info.SetChanInfoStreamExt(".wmv");
}
else if (header.Streams.Any(type => type==ASFHeader.StreamType.Audio)) {
info.SetChanInfoType("WMA");
info.SetChanInfoStreamType("audio/x-ms-wma");
info.SetChanInfoStreamExt(".wma");
}
else {
info.SetChanInfoType("ASF");
info.SetChanInfoStreamType("video/x-ms-asf");
info.SetChanInfoStreamExt(".asf");
}
res.ChannelInfo = new ChannelInfo(info);
streamIndex = Channel.GenerateStreamID();
streamOrigin = DateTime.Now;
res.ContentHeader = new Content(streamIndex, TimeSpan.Zero, pos, chunk.ToByteArray());
pos += chunk.TotalLength;
}
break;
case ASFChunk.ChunkType.Data:
if (res.Contents==null) res.Contents = new System.Collections.Generic.List<Content>();
res.Contents.Add(new Content(streamIndex, DateTime.Now-streamOrigin, pos, chunk.ToByteArray()));
pos += chunk.TotalLength;
break;
case ASFChunk.ChunkType.Unknown:
break;
}
}
}
catch (EndOfStreamException) {
if (chunks==0) throw;
}
return res;
}
示例2: Read
public ParsedContent Read(Stream stream)
{
if (stream.Length-stream.Position<=0) throw new EndOfStreamException();
var res = new ParsedContent();
var pos = Channel.ContentPosition;
if (Channel.ContentHeader==null) {
streamIndex = Channel.GenerateStreamID();
streamOrigin = DateTime.Now;
res.ContentHeader = new Content(streamIndex, TimeSpan.Zero, pos, new byte[] { });
var channel_info = new AtomCollection(Channel.ChannelInfo.Extra);
channel_info.SetChanInfoType("RAW");
channel_info.SetChanInfoStreamType("application/octet-stream");
channel_info.SetChanInfoStreamExt("");
res.ChannelInfo = new ChannelInfo(channel_info);
}
res.Contents = new List<Content>();
while (stream.Length-stream.Position>0) {
var bytes = new byte[Math.Min(8192, stream.Length-stream.Position)];
var sz = stream.Read(bytes, 0, bytes.Length);
if (sz>0) {
Array.Resize(ref bytes, sz);
res.Contents.Add(new Content(streamIndex, DateTime.Now-streamOrigin, pos, bytes));
pos += sz;
}
}
return res;
}
示例3: OnMetaData
private void OnMetaData(DataMessage msg)
{
this.metadata = msg;
var info = new AtomCollection();
info.SetChanInfoType("FLV");
info.SetChanInfoStreamType("video/x-flv");
info.SetChanInfoStreamExt(".flv");
if (metadata.Arguments[0].Type==AMF.AMFValueType.ECMAArray || metadata.Arguments[0].Type==AMF.AMFValueType.Object){
var bitrate = 0.0;
var val = metadata.Arguments[0]["maxBitrate"];
if (!AMF.AMFValue.IsNull(val)) {
double maxBitrate;
string maxBitrateStr = System.Text.RegularExpressions.Regex.Replace((string)val, @"([\d]+)k", "$1");
if (double.TryParse(maxBitrateStr, out maxBitrate)) {
bitrate += maxBitrate;
}
}
else if (!AMF.AMFValue.IsNull(val = metadata.Arguments[0]["videodatarate"])) {
bitrate += (double)val;
}
if (!AMF.AMFValue.IsNull(val = metadata.Arguments[0]["audiodatarate"])) {
bitrate += (double)val;
}
info.SetChanInfoBitrate((int)bitrate);
}
OnChannelInfoChanged(info);
OnHeaderChanged(msg);
OnContentChanged(msg);
}
示例4: OnFLVHeader
public void OnFLVHeader()
{
var info = new AtomCollection();
info.SetChanInfoType("FLV");
info.SetChanInfoStreamType("video/x-flv");
info.SetChanInfoStreamExt(".flv");
OnChannelInfoChanged(info);
}
示例5: Read
public ParsedContent Read(Stream stream)
{
var res = new ParsedContent();
var bodies = new List<Element>();
var info = new AtomCollection(Channel.ChannelInfo.Extra);
var processed = false;
var eos = false;
while (!eos) {
var start_pos = stream.Position;
try {
var elt = Element.ReadHeader(stream);
if (ebml.MaxIDLength <elt.ID.Length ||
ebml.MaxSizeLength<elt.Size.Length) {
throw new BadDataException();
}
switch (state) {
case ReaderState.EBML:
if (elt.ID.BinaryEquals(Elements.EBML)) {
elt.ReadBody(stream);
ebml = new EBML(elt);
state = ReaderState.Segment;
}
else {
throw new BadDataException();
}
break;
case ReaderState.Segment:
if (elt.ID.BinaryEquals(Elements.Segment)) {
segment = new Segment(elt);
state = ReaderState.EndOfHeader;
}
else if (elt.ID.BinaryEquals(Elements.EBML)) {
stream.Position = elt.Position;
state = ReaderState.EBML;
continue;
}
else if (elt.ID.BinaryEquals(Elements.Void) ||
elt.ID.BinaryEquals(Elements.CRC32)) {
elt.ReadBody(stream);
}
else {
throw new BadDataException();
}
break;
case ReaderState.EndOfHeader:
if (elt.ID.BinaryEquals(Elements.Segment)) {
stream.Position = elt.Position;
state = ReaderState.Segment;
continue;
}
else if (elt.ID.BinaryEquals(Elements.EBML)) {
stream.Position = elt.Position;
state = ReaderState.EBML;
continue;
}
else if (elt.ID.BinaryEquals(Elements.Cluster)) {
stream.Position = elt.Position;
state = ReaderState.Cluster;
clusters.Clear();
MemoryStream header;
using (header=new MemoryStream()) {
ebml.Element.Write(header);
segment.Element.Write(header);
foreach (var c in segment.HeaderElements) {
c.Write(header);
}
}
streamIndex = Channel.GenerateStreamID();
streamOrigin = DateTime.Now;
res.ContentHeader = new Content(streamIndex, TimeSpan.Zero, 0, header.ToArray());
if (ebml.DocType=="webm") {
info.SetChanInfoType("WEBM");
info.SetChanInfoStreamType("video/webm");
info.SetChanInfoStreamExt(".webm");
}
else {
info.SetChanInfoType("MKV");
info.SetChanInfoStreamType("video/x-matroska");
info.SetChanInfoStreamExt(".mkv");
}
res.ChannelInfo = new ChannelInfo(info);
}
else {
elt.ReadBody(stream);
segment.AddHeader(elt);
}
break;
case ReaderState.Cluster:
if (elt.ID.BinaryEquals(Elements.Segment)) {
stream.Position = elt.Position;
state = ReaderState.Segment;
continue;
}
else if (elt.ID.BinaryEquals(Elements.EBML)) {
stream.Position = elt.Position;
state = ReaderState.EBML;
continue;
}
else if (elt.ID.BinaryEquals(Elements.Cluster)) {
if (clusters.Count>0) {
//.........这里部分代码省略.........
示例6: ReadAsync
public async Task ReadAsync(IContentSink sink, Stream stream, CancellationToken cancel_token)
{
var state = ReaderState.EBML;
var position = 0L;
var stream_index = -1;
var stream_origin = DateTime.Now;
var timecode_scale = 1000000.0;
var ebml = new EBML();
var clusters = new LinkedList<Cluster>();
var headers = new List<Element>();
var eos = false;
while (!eos) {
try {
var elt = await Element.ReadHeaderAsync(stream, cancel_token);
if (ebml.MaxIDLength <elt.ID.Length ||
ebml.MaxSizeLength<elt.Size.Length) {
throw new BadDataException();
}
parse_retry:
switch (state) {
case ReaderState.EBML:
if (elt.ID.BinaryEquals(Elements.EBML)) {
await elt.ReadBodyAsync(stream, cancel_token);
headers.Clear();
headers.Add(elt);
ebml = new EBML(elt);
state = ReaderState.Segment;
}
else {
throw new BadDataException();
}
break;
case ReaderState.Segment:
if (elt.ID.BinaryEquals(Elements.Segment)) {
headers.Add(elt);
state = ReaderState.EndOfHeader;
}
else if (elt.ID.BinaryEquals(Elements.EBML)) {
state = ReaderState.EBML;
goto parse_retry;
}
else if (elt.ID.BinaryEquals(Elements.Void) ||
elt.ID.BinaryEquals(Elements.CRC32)) {
await elt.ReadBodyAsync(stream, cancel_token);
headers.Add(elt);
}
else {
throw new BadDataException();
}
break;
case ReaderState.EndOfHeader:
if (elt.ID.BinaryEquals(Elements.Segment)) {
state = ReaderState.Segment;
goto parse_retry;
}
else if (elt.ID.BinaryEquals(Elements.EBML)) {
state = ReaderState.EBML;
goto parse_retry;
}
else if (elt.ID.BinaryEquals(Elements.Cluster)) {
clusters.Clear();
MemoryStream header;
using (header=new MemoryStream()) {
foreach (var c in headers) {
c.Write(header);
}
}
headers.Clear();
stream_index = Channel.GenerateStreamID();
stream_origin = DateTime.Now;
position = 0;
sink.OnContentHeader(
new Content(stream_index, TimeSpan.Zero, 0, header.ToArray())
);
position += header.ToArray().LongLength;
var info = new AtomCollection();
if (ebml.DocType=="webm") {
info.SetChanInfoType("WEBM");
info.SetChanInfoStreamType("video/webm");
info.SetChanInfoStreamExt(".webm");
}
else {
info.SetChanInfoType("MKV");
info.SetChanInfoStreamType("video/x-matroska");
info.SetChanInfoStreamExt(".mkv");
}
sink.OnChannelInfo(new ChannelInfo(info));
state = ReaderState.Cluster;
goto parse_retry;
}
else if (elt.ID.BinaryEquals(Elements.Info)) {
await elt.ReadBodyAsync(stream, cancel_token);
var s = new MemoryStream(elt.Data);
while (s.Position<s.Length) {
var child = Element.ReadHeader(s);
if (child.ID.BinaryEquals(Elements.TimecodeScale)) {
timecode_scale = Element.ReadUInt(s, child.Size.Value) * 1.0;
//.........这里部分代码省略.........
示例7: Read
public ParsedContent Read(Stream stream)
{
var res = new ParsedContent();
var info = new AtomCollection(Channel.ChannelInfo.Extra);
var processed = false;
var eos = false;
while (!eos) {
var start_pos = stream.Position;
try {
switch (state) {
case ReaderState.Header:
{
var bin = ReadBytes(stream, 13);
var header = new FileHeader(bin);
if (header.IsValid) {
Logger.Info("FLV Header found");
fileHeader = header;
bin = header.Binary;
res.ContentHeader = new Content(position, bin);
res.Contents = null;
info.SetChanInfoType("FLV");
info.SetChanInfoStreamType("video/x-flv");
info.SetChanInfoStreamExt(".flv");
res.ChannelInfo = new ChannelInfo(info);
position = bin.Length;
tags.Clear();
state = ReaderState.Body;
}
else {
throw new BadDataException();
}
}
break;
case ReaderState.Body:
{
var bin = ReadBytes(stream, 11);
var read_valid = false;
var body = new FLVTag(bin);
if (body.IsValidHeader) {
body.ReadBody(stream);
body.ReadFooter(stream);
if (body.IsValidFooter) {
read_valid = true;
bin = body.Binary;
if (res.Contents==null) res.Contents = new List<Content>();
res.Contents.Add(new Content(position, bin));
tags.AddLast(new TagDesc { Timestamp=body.Timestamp/1000.0, DataSize=body.DataSize });
var timespan = tags.Last.Value.Timestamp-tags.First.Value.Timestamp;
if (timespan>=30.0) {
var sz = tags.Take(tags.Count-1).Sum(t => t.DataSize);
info.SetChanInfoBitrate((int)(sz*8/timespan+900)/1000);
res.ChannelInfo = new ChannelInfo(info);
while (tags.Count>1) tags.RemoveFirst();
}
position += bin.Length;
}
}
if (!read_valid) {
stream.Position = start_pos;
var header = new FileHeader(ReadBytes(stream, 13));
if (header.IsValid) {
Logger.Info("New FLV Header found");
read_valid = true;
fileHeader = header;
bin = header.Binary;
res.ContentHeader = new Content(0, bin);
res.Contents = null;
info.SetChanInfoType("FLV");
info.SetChanInfoStreamType("video/x-flv");
info.SetChanInfoStreamExt(".flv");
res.ChannelInfo = new ChannelInfo(info);
tags.Clear();
position = bin.Length;
}
}
if (!read_valid) throw new BadDataException();
}
break;
}
processed = true;
}
catch (EndOfStreamException) {
if (!processed) throw;
stream.Position = start_pos;
eos = true;
}
catch (BadDataException) {
stream.Position = start_pos+1;
}
}
return res;
}