//public bool doCancel() //{ // if (this.mVideoContext != null) // { // CDNComService.Instance.cancelUploadMedia(this.mVideoContext.mVideoTrans.strClientMsgId); // base.cancel(); // this.mVideoContext.mStatus = 4; // this.doSceneFinished(); // } // return true; //} //private void doReportInfo(int retCode) //{ // int num = this.mVideoContext.mVideoTrans.nTotalDataLen + this.mVideoContext.mThumbTotalLength; // string str = string.Concat(new object[] { retCode, ",", 1, ",", (long) this.mVideoContext.startTimestamp, ",", (long) Util.getNowMilliseconds(), ",", ReportService.getReportNetworkType(), ",", CdnMediaType.MediaType_VIDEO, ",", num, ",", this.mCdnComReportInfo }); // NetSceneKVReport.addReportItem(0x28b5, str); //} //public void doScene(UploadVideoContext videoContext) //{ // if ((videoContext.mStatus != 0) && (videoContext.mStatus != 4)) // { // Log.e("NetSceneUploadVideo", "doScene videoContext.mStatus error, status = " + videoContext.mStatus); // } // else // { // videoContext.mStatus = 1; // this.mVideoContext = videoContext; // this.mVideoContext.mSceneHandle = this; // this.doSceneToCDN(); // } //} //public void doSceneFinished() //{ // if (this.mVideoContext != null) // { // this.mVideoContext.updateProgressInfo(0); // this.mVideoContext.updateContext(); // this.mVideoContext.onFinished(); // this.mVideoContext.mSceneHandle = null; // this.mVideoContext = null; // Log.d("NetSceneUploadVideo", "scene Finished. "); // } //} //private int doSceneToCDN() //{ // RTCDNUploadPara para = new RTCDNUploadPara { // fileFullPath = this.mVideoContext.mVideoTrans.strImagePath, // filetype = 4, // toUser = this.mVideoContext.mVideoTrans.strToUserName, // clientMediaID = this.mVideoContext.mChatMsg.strClientMsgId, // arg = 0, // hasThumb = true, // thumbfileFullPath = this.mVideoContext.mVideoTrans.strThumbnail // }; // this.mVideoContext.doCloseFile(); // para.needStorage = false; // para.isStreamMedia = false; // para.priority = 2; // if (this.mVideoContext.mChatMsg.nMsgType == 0x3e) // { // para.smallVideoFlag = 1; // } // if (this.mVideoContext.mOrigChatMsg != null) // { // Log.d("NetSceneUploadVideo", "forward video msg , mOrigChatMsg = " + this.mVideoContext.mOrigChatMsg.strMsg); // VideoDetailInfo info = UploadVideoService.parseVideoMsgXML(this.mVideoContext.mOrigChatMsg.strMsg); // if (((info != null) && !string.IsNullOrEmpty(info.mCdnAesKey)) && !string.IsNullOrEmpty(info.mCdnVideoUrl)) // { // para.fileid = info.mCdnVideoUrl; // para.aeskey = info.mCdnAesKey; // para.fileLength = (uint) info.nTotalDataLen; // } // else // { // Log.d("NetSceneUploadVideo", "Parse video msg xml failed: " + this.mVideoContext.mOrigChatMsg.strMsg); // } // } // return CDNComService.Instance.startupUploadMedia(para, this); //} public void doSceneToCGI(string toUsername, MsgTrans videoinfo, DownloadVideoContext contextInfo, int nMsgType) { base.beginBuilder(); base.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0); base.mBuilder.FromUserName = videoinfo.strToUserName; base.mBuilder.ToUserName = toUsername; base.mBuilder.ClientMsgId = videoinfo.nMsgSvrID.ToString(); base.mBuilder.PlayLength = (uint)videoinfo.nDuration; base.mBuilder.NetworkEnv = 1; base.mBuilder.CameraType = 2; base.mSessionPack.mCmdID = 0x27; base.mSessionPack.mNeedCompress = false; base.mBuilder.VideoTotalLen = (uint)videoinfo.nTotalDataLen; base.mBuilder.VideoStartPos = 0; base.mBuilder.VideoData = Util.toSKBuffer(new byte[0]); base.mBuilder.ThumbTotalLen = (uint)contextInfo.mCdnThumbLength; base.mBuilder.ThumbStartPos = 0; base.mBuilder.ThumbData = Util.toSKBuffer(new byte[0]); base.mBuilder.CDNVideoUrl = contextInfo.mCdnVideoUrl; base.mBuilder.AESKey = contextInfo.mCdnAesKey; base.mBuilder.EncryVer = 1; base.mBuilder.CDNThumbUrl = contextInfo.mCdnThumbUrl; base.mBuilder.CDNThumbImgSize = contextInfo.mCdnThumbLength; base.mBuilder.CDNThumbImgWidth = 0x84; base.mBuilder.CDNThumbImgHeight = 0x63; base.mBuilder.CDNThumbAESKey = contextInfo.mCdnThumbAesKey; if (nMsgType == 0x3e)//小视频 { base.mBuilder.FuncFlag = 3; base.mBuilder.VideoMd5 = Util.nullAsNil(""); } base.endBuilder(); }
protected override void onSuccess(DownloadVideoRequest request, DownloadVideoResponse response) { DownloadVideoContext mContext = base.mContext as DownloadVideoContext; if ((mContext == null) || !mContext.isRunning()) { Log.e("NetSceneDwVideoEx", "scene is finished, ignored response. "); } else { RetConst ret = (RetConst)response.BaseResponse.Ret; if (ret != RetConst.MM_OK) { Log.e("NetSceneDwVideoEx", "download video failed, ret = " + ret); mContext.mStatus = 4; mContext.onFinishedEx(); } else { Log.d("NetSceneDwVideoEx", string.Concat(new object[] { "download response success(rtt=", base.mMiniRTT, ") , startpos = ", response.StartPos, ", total = ", response.TotalLen, ", datalen = ", response.Data.Buffer.Length, ", tranLen=", mContext.mVideoInfo.nTransDataLen })); if ((response.StartPos < 0) || ((response.StartPos + response.Data.Buffer.Length) > response.TotalLen)) { Log.e("NetSceneDwVideoEx", "download failed "); mContext.mStatus = 4; mContext.onFinishedEx(); } else { mContext.mVideoInfo.nTotalDataLen = (int)response.TotalLen; mContext.appendDownData(response.Data.Buffer.ToByteArray(), response.StartPos, (uint)response.Data.Buffer.Length); mContext.mVideoInfo.nTransDataLen += response.Data.Buffer.Length; base.mOffsetPos += response.Data.Buffer.Length; if (base.mOffsetPos >= base.mEndPos) { Log.d("NetSceneDwVideoEx", string.Concat(new object[] { "download video block complete... [", base.mStartPos, "---", base.mEndPos, "]" })); mContext.onBlockCompleted(base.mSceneID); if (mContext.isDownloadCompleted()) { Log.d("NetSceneDwVideoEx", "all videos downlaod completed."); mContext.mStatus = 5; mContext.onFinishedEx(); } } else { mContext.updateProgressInfo(0); this.doDownScene(); } } } } }
protected override void onFailed(DownloadVideoRequest request, DownloadVideoResponse response) { DownloadVideoContext mContext = base.mContext as DownloadVideoContext; if ((mContext == null) || !mContext.isRunning()) { Log.e("NetSceneDwVideoEx", "scene is finished, ignored onFailed. "); } else { mContext.mStatus = 4; mContext.onFinishedEx(); } }
//public static void cleanSendingStatus() //{ // List<ChatMsg> collection = StorageMgr.chatMsg.searhCacheMsg(0x2b, 0, 0); // List<ChatMsg> list2 = StorageMgr.chatMsg.searhCacheMsg(0x3e, 0, 0); // List<ChatMsg> list3 = new List<ChatMsg>(); // if ((collection != null) && (collection.Count > 0)) // { // list3.AddRange(collection); // } // if ((list2 != null) && (list2.Count > 0)) // { // list3.AddRange(list2); // } // if (list3.Count != 0) // { // foreach (ChatMsg msg in list3) // { // Log.i("DownloadVideoService", string.Concat(new object[] { "Failed to clean status-downing , ", msg.strClientMsgId, " nMsgType = ", msg.nMsgType })); // msg.nStatus = 1; // } // StorageMgr.chatMsg.updateMsgList(collection); // } //} public bool doCancelScene(int msgSvrId, bool isThumb = false) { DownloadVideoContext context = DownloadVideoContextMgr.getInstance().findBySrvMsgID(msgSvrId, isThumb); if (context == null) { return(false); } if ((context.mStatus == 5) || (context.mStatus == 4)) { return(false); } context.mStatus = 4; context.doCancelAll(); return(true); }
public void onVideoDownContextDispatcher(object sender, EventArgs e) { DownloadVideoContextMgr.getInstance().clearnFinishedContext(); if (DownloadVideoContextMgr.getInstance().getCount() <= 0) { Log.d("DownloadVideoService", "all ready, close dispatcher timer. "); mTimerObject.stop(); mTimerObject = null; } else if (DownloadVideoContextMgr.getInstance().countRunningContext() < MAX_RUNNING) { DownloadVideoContext context = DownloadVideoContextMgr.getInstance().getFirstContextNeedHandle(); if (context != null) { Log.i("DownloadVideoService", "new task startup, msgid = " + context.mVideoInfo.nMsgSvrID); context.startScene(); } } }
protected override bool doDownScene() { DownloadVideoContext mContext = base.mContext as DownloadVideoContext; if (mContext == null) { return(false); } base.beginBuilder(); base.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0); base.mBuilder.TotalLen = (uint)mContext.mVideoInfo.nTotalDataLen; base.mBuilder.StartPos = (uint)base.mOffsetPos; base.mBuilder.NetworkEnv = 1; base.mBuilder.MsgId = (uint)mContext.mVideoInfo.nMsgSvrID; base.mSessionPack.mCmdID = 40; if (base.mUseHttp) { base.mSessionPack.mConnectMode = 2; } base.endBuilder(); return(true); }
private bool doSceneEx(int msgSvrId, string talker, bool isThumb, ChatMsg msg) { MsgTrans trans; if (msgSvrId == 0) { Log.e("DownloadVideoService", "Not found the chatmsg , invalid msgid = " + msgSvrId); return(false); } DownloadVideoContext context = DownloadVideoContextMgr.getInstance().findBySrvMsgID(msgSvrId, isThumb); if ((context != null) && !context.needToClean()) { Log.e("DownloadVideoService", "already downloading video by msgid = " + msgSvrId); return(false); } // ChatMsg msg = StorageMgr.chatMsg.getBySvrID(talker, msgSvrId); if (msg == null) { Log.e("DownloadVideoService", "Not found the chatmsg by msgid = " + msgSvrId); return(false); } Log.d("DownloadVideoService", "begin downLoad video thumb...msgid = " + msgSvrId); trans = new MsgTrans(); trans.nTransType = 6; trans.nMsgSvrID = msgSvrId; trans.nMsgLocalID = msg.nMsgLocalID; trans.strThumbnail = msg.strThumbnail; trans.strFromUserName = talker; trans.strToUserName = AccountMgr.getCurAccount().strUsrName; DownloadVideoContext contextInfo = new DownloadVideoContext { mVideoInfo = trans, mChatMsg = msg, mIsThumbMode = isThumb }; if (!parseVideoMsgXML(msg.strMsg, trans, contextInfo)) { Log.e("DownloadVideoService", "parseVideoMsgXML failed! "); return(false); } if (Directory.Exists(System.IO.Directory.GetCurrentDirectory() + "\\ReplyRes\\Video\\") == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(System.IO.Directory.GetCurrentDirectory() + "\\ReplyRes\\Video"); } //using (FileStream sw = new FileStream(System.IO.Directory.GetCurrentDirectory() + "\\ReplyRes\\Video\\" + msgSvrId.ToString() + ".xml", FileMode.CreateNew)) //{ // byte[] myByte = System.Text.Encoding.UTF8.GetBytes(msg.strMsg); // sw.Write(myByte, 0, myByte.Length); // sw.Close(); //} new NetSceneUploadCdnVideo().doSceneToCGI(talker, trans, contextInfo, msg.nMsgType); return(true); contextInfo.updateProgressInfo(0); contextInfo.updateChatMsg(); DownloadVideoContextMgr.getInstance().putToHead(contextInfo); this.checkReadyContextDispatcher(); return(true); }
public static bool parseVideoMsgXML(string xmlStr, MsgTrans videoinfo, DownloadVideoContext contextInfo = null) { if (string.IsNullOrEmpty(xmlStr) || (videoinfo == null)) { Log.d("DownloadVideoService", "failed to parse msg xml, input invalid para"); return(false); } xmlStr = Util.preParaXml(xmlStr); XElement element = null; try { element = XDocument.Parse(xmlStr).Element("msg").Element("videomsg"); XAttribute attribute = element.Attribute("clientmsgid"); if (attribute != null) { videoinfo.strClientMsgId = attribute.Value; } attribute = element.Attribute("length"); if (attribute != null) { videoinfo.nTotalDataLen = int.Parse(attribute.Value); } attribute = element.Attribute("playlength"); if (attribute != null) { videoinfo.nDuration = int.Parse(attribute.Value); } attribute = element.Attribute("fromusername"); if (attribute != null) { videoinfo.strFromUserName = attribute.Value; } if (contextInfo != null) { attribute = element.Attribute("aeskey"); if (attribute != null) { contextInfo.mCdnAesKey = attribute.Value; contextInfo.mCdnThumbAesKey = attribute.Value; } attribute = element.Attribute("cdnthumbaeskey"); if (attribute != null) { contextInfo.mCdnThumbAesKey = attribute.Value; } attribute = element.Attribute("cdnvideourl"); if (attribute != null) { contextInfo.mCdnVideoUrl = attribute.Value; } attribute = element.Attribute("cdnthumburl"); if (attribute != null) { contextInfo.mCdnThumbUrl = attribute.Value; } attribute = element.Attribute("cdnthumblength"); if (attribute != null) { contextInfo.mCdnThumbLength = int.Parse(attribute.Value); } attribute = element.Attribute("cdnthumbheight"); if (attribute != null) { contextInfo.mCdnThumbHeight = int.Parse(attribute.Value); } attribute = element.Attribute("cdnthumbwidth"); if (attribute != null) { contextInfo.mCdnThumbWidth = int.Parse(attribute.Value); } } } catch (Exception exception) { Log.d("DownloadVideoService", exception.Message); return(false); } return(true); }