This commit is contained in:
Genteure 2018-03-21 00:33:34 +08:00
parent ba2b438293
commit 203684ddc0
4 changed files with 102 additions and 40 deletions

View File

@ -7,6 +7,6 @@ namespace BililiveRecorder.Core
public delegate void StreamStatusChangedEvent(object sender, StreamStatusChangedArgs e);
public class StreamStatusChangedArgs
{
public StreamStatus status;
public TriggerType status;
}
}

View File

@ -1,22 +1,112 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace BililiveRecorder.Core
{
public class StreamMonitor
{
public int Roomid { get; private set; } = 0;
public event StreamStatusChangedEvent StreamStatusChanged;
public readonly DanmakuReceiver receiver = new DanmakuReceiver();
public StreamMonitor(int roomid)
{
Roomid = roomid;
receiver.Connected += Receiver_Connected;
receiver.Disconnected += Receiver_Disconnected;
receiver.LogMessage += Receiver_LogMessage;
receiver.ReceivedDanmaku += Receiver_ReceivedDanmaku;
receiver.ReceivedRoomCount += Receiver_ReceivedRoomCount;
}
private void Receiver_ReceivedRoomCount(object sender, ReceivedRoomCountArgs e)
{
throw new NotImplementedException();
}
private void Receiver_ReceivedDanmaku(object sender, ReceivedDanmakuArgs e)
{
switch (e.Danmaku.MsgType)
{
case MsgTypeEnum.LiveStart:
_StartRecord(TriggerType.Danmaku);
break;
case MsgTypeEnum.LiveEnd:
break;
default:
break;
}
}
private void Receiver_LogMessage(object sender, LogMessageArgs e)
{
// TODO: Log
}
private void Receiver_Disconnected(object sender, DisconnectEvtArgs e)
{
if (e.Error != null)
{
}
}
private void Receiver_Connected(object sender, ConnectedEvtArgs e)
{ }
private void _StartRecord(TriggerType status)
{
Task.Run(() => StreamStatusChanged?.Invoke(this, new StreamStatusChangedArgs() { status = status }));
}
public void Start()
{
if (receiver.Connect(Roomid))
{
var info = BililiveAPI.GetRoomInfo(Roomid);
if (info.isStreaming)
{
_StartRecord(TriggerType.HttpApi);
}
}
else
{
throw receiver.Error;
}
}
public void Stop()
{
if (receiver.isConnected)
{
receiver.Disconnect();
}
}
public void Check()
{
throw new NotImplementedException();
var info = BililiveAPI.GetRoomInfo(Roomid);
if (info.isStreaming)
{
_StartRecord(TriggerType.HttpApiRecheck);
}
}
public void CheckAfterSeconeds(uint seconds)
public void CheckAfterSeconeds(int seconds)
{
throw new NotImplementedException();
if (seconds < 0)
throw new ArgumentOutOfRangeException(nameof(seconds), "不能小于0");
Task.Run(() =>
{
Task.Delay(seconds * 1000).Wait();
Check();
});
}
}
}

View File

@ -4,40 +4,11 @@ using System.Text;
namespace BililiveRecorder.Core
{
public class StreamStatus
public enum TriggerType
{
// TODO:
public bool isStreaming
{
get
{
return false;
}
}
public bool HttpAPIStreaming
{
get
{
return false;
}
set
{
}
}
public bool DanmakuStreaming
{
get
{
return false;
}
set
{
}
}
Danmaku,
HttpApi,
HttpApiRecheck,
Manual,
}
}

View File

@ -8,7 +8,7 @@ namespace BililiveRecorder.FlvProcessor
public class FlvClipProcessor : IDisposable
{
public readonly FlvMetadata Header;
public List<FlvTag> Tags;
public readonly List<FlvTag> Tags;
private int target = -1;
public Func<string> GetFileName;
@ -59,6 +59,7 @@ namespace BililiveRecorder.FlvProcessor
fs.Close();
}
Tags.Clear();
ClipFinalized?.Invoke(this, new ClipFinalizedArgs() { ClipProcessor = this });
}