智慧城市 v1.2.1版本的 MD5 值为:d4aeacb5153a2710d0b6882be5dd2b15
以下内容为反编译后的 StcS3VideoMediaUploader.java 源代码,内容仅作参考
package io.rong.imlib.filetransfer.upload.uploader;
import android.net.Uri;
import com.daasuu.mp4compose.composer.Mp4Composer;
import io.rong.common.FileInfo;
import io.rong.common.FileUtils;
import io.rong.common.LibStorageUtils;
import io.rong.common.fwlog.FwLog;
import io.rong.common.rlog.RLog;
import io.rong.imkit.picture.tools.PictureFileUtils;
import io.rong.imlib.NativeClient;
import io.rong.imlib.NativeObject;
import io.rong.imlib.filetransfer.Call;
import io.rong.imlib.filetransfer.CallDispatcher;
import io.rong.imlib.filetransfer.Configuration;
import io.rong.imlib.filetransfer.FtConst;
import io.rong.imlib.filetransfer.FtUtilities;
import io.rong.imlib.filetransfer.Request;
import io.rong.imlib.filetransfer.RequestOption;
import io.rong.imlib.filetransfer.SliceRequestCallBack;
import io.rong.imlib.filetransfer.StcSliceCompleteRequest;
import io.rong.imlib.filetransfer.StcSliceInitRequest;
import io.rong.imlib.filetransfer.StcSliceUploadRequest;
import io.rong.imlib.filetransfer.download.BaseRequest;
import io.rong.imlib.filetransfer.upload.FilePlatformInfo;
import io.rong.imlib.filetransfer.upload.MediaUploadAuthorInfo;
import io.rong.imlib.filetransfer.upload.MediaUploadEngine;
import io.rong.imlib.filetransfer.upload.StcSliceUploadResult;
import io.rong.imlib.filetransfer.upload.uploader.BaseMediaUploader;
import io.rong.imlib.model.Message;
import io.rong.imlib.model.Size;
import io.rong.message.MediaMessageContent;
import io.rong.message.SightMessage;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class StcS3VideoMediaUploader extends BaseMediaUploader implements SliceRequestCallBack {
private static final String TAG = "StcS3VideoMediaUploader";
private boolean compressFinish;
int currentProgress;
private CallDispatcher dispatcher;
private int errorCode;
private int errorProgress;
private List<StcSliceUploadResult> mResultList;
private FtConst.MediaType mediaType;
private String mimeKey;
private FtConst.MimeType mimeType;
private int partCount;
@Override
public Request buildRequest() {
return null;
}
@Override
protected Configuration getConfiguration() {
return null;
}
public StcS3VideoMediaUploader(FilePlatformInfo filePlatformInfo, NativeObject nativeObject, Message message) {
super(filePlatformInfo, nativeObject, message);
this.partCount = 0;
this.compressFinish = true;
this.errorCode = 0;
this.mResultList = new ArrayList();
this.currentProgress = 0;
this.errorProgress = 0;
}
private Request buildInitRequest() {
StcSliceInitRequest stcSliceInitRequest = new StcSliceInitRequest(this.configuration, this);
stcSliceInitRequest.setContext(NativeClient.getApplicationContext());
stcSliceInitRequest.mimeType = this.option.getMimeType();
stcSliceInitRequest.method = "POST";
stcSliceInitRequest.filePath = this.option.getFilePath();
stcSliceInitRequest.tag = String.valueOf(this.option.getMessageId());
stcSliceInitRequest.fileName = this.option.getFileName();
stcSliceInitRequest.isMessage = true;
stcSliceInitRequest.uploadId = this.uploadId;
return stcSliceInitRequest;
}
@Override
public void buildDownloadUrl(String str, final BaseMediaUploader.IGetUrlResultCallback iGetUrlResultCallback) {
onProgress(99);
FileInfo fileInfoByUri = FileUtils.getFileInfoByUri(NativeClient.getApplicationContext(), Uri.parse(this.option.getFilePath()));
FwLog.write(3, 1, FwLog.LogTag.L_MEDIA_URL_T.getTag(), "id|type", Long.valueOf(this.uploadId), "SS3");
if (fileInfoByUri != null) {
this.nativeObj.GetDownloadUrl(this.option.getMediaType().getValue(), this.option.getFileName(), fileInfoByUri.getName(), new NativeObject.TokenListener() {
@Override
public void OnError(int i, String str2) {
if (i == 0) {
StcS3VideoMediaUploader.this.onProgress(100);
FwLog.write(3, 1, FwLog.LogTag.L_MEDIA_URL_R.getTag(), "id|type|code", Long.valueOf(StcS3VideoMediaUploader.this.uploadId), "SS3", 0);
iGetUrlResultCallback.onSuccess(str2);
return;
}
FwLog.write(3, 1, FwLog.LogTag.L_MEDIA_URL_R.getTag(), "id|type|code", Long.valueOf(StcS3VideoMediaUploader.this.uploadId), "SS3", Integer.valueOf(i));
String str3 = StcS3VideoMediaUploader.TAG;
RLog.d(str3, "GetDownloadUrl onError code =" + i);
iGetUrlResultCallback.onError(i);
}
}, 3);
}
}
private Request buildSliceUploadRequest(UploadFileInfo uploadFileInfo) {
StcSliceUploadRequest stcSliceUploadRequest = new StcSliceUploadRequest(this.configuration, this, uploadFileInfo);
stcSliceUploadRequest.setContext(NativeClient.getApplicationContext());
stcSliceUploadRequest.mimeType = this.option.getMimeType();
stcSliceUploadRequest.method = BaseRequest.METHOD_PUT;
stcSliceUploadRequest.filePath = this.option.getFilePath();
stcSliceUploadRequest.tag = String.valueOf(this.option.getMessageId());
stcSliceUploadRequest.fileName = this.option.getFileName();
stcSliceUploadRequest.isMessage = true;
stcSliceUploadRequest.uploadId = this.uploadId;
return stcSliceUploadRequest;
}
private Request buildEndRequest(String str) {
Collections.sort(this.mResultList, new Comparator<StcSliceUploadResult>() {
@Override
public int compare(StcSliceUploadResult stcSliceUploadResult, StcSliceUploadResult stcSliceUploadResult2) {
return stcSliceUploadResult.getPartNumber() - stcSliceUploadResult2.getPartNumber();
}
});
StcSliceCompleteRequest stcSliceCompleteRequest = new StcSliceCompleteRequest(this.configuration, this, this.mResultList);
stcSliceCompleteRequest.setContext(NativeClient.getApplicationContext());
stcSliceCompleteRequest.mimeType = this.option.getMimeType();
stcSliceCompleteRequest.method = "POST";
stcSliceCompleteRequest.filePath = this.option.getFilePath();
stcSliceCompleteRequest.tag = String.valueOf(this.option.getMessageId());
stcSliceCompleteRequest.fileName = this.option.getFileName();
stcSliceCompleteRequest.isMessage = true;
return stcSliceCompleteRequest;
}
@Override
public void run(CallDispatcher callDispatcher, FileInfo fileInfo, MediaUploadEngine.IMediaUploadResultCallback iMediaUploadResultCallback) {
this.callback = iMediaUploadResultCallback;
this.mimeType = FtUtilities.getMimeType(this.message);
this.mediaType = FtUtilities.getMediaType(this.message);
this.mimeKey = FtUtilities.generateKey(this.mAppKey, this.mCurUserId) + FtUtilities.getSuffixName(fileInfo.getName());
this.dispatcher = callDispatcher;
this.option = RequestOption.Upload.newBuilder(((MediaMessageContent) this.message.getContent()).getLocalPath(), this.mimeKey, this.mimeType, this.mediaType, this.message, this.message.getMessageId(), this.platform.getHost()).build();
this.request = buildInitRequest();
Call.create(callDispatcher, this.request).enqueue();
}
@Override
public void onSliceInitComplete(String str) {
this.compressFinish = false;
final String uri = ((MediaMessageContent) this.message.getContent()).getLocalPath().toString();
try {
Size calculateVideo = calculateVideo(NativeClient.getApplicationContext(), uri);
final String str2 = LibStorageUtils.getMediaDownloadDir(NativeClient.getApplicationContext(), "video") + File.separator + "RONGCLOUD_" + str + PictureFileUtils.POST_VIDEO;
final VideoSliceHelper videoSliceHelper = new VideoSliceHelper(Uri.parse(str2), str);
RLog.d("upload", "compress start");
compress(NativeClient.getApplicationContext(), uri, str2, calculateVideo, new Mp4Composer.Listener() {
int compressProgress = 0;
@Override
public void onCurrentWrittenVideoTime(long j) {
}
@Override
public void onProgress(double d) {
if (StcS3VideoMediaUploader.this.errorCode != 0) {
return;
}
int i = (int) (d * 100.0d);
int i2 = (i * 4) / 10;
int i3 = this.compressProgress;
if (i3 < i2) {
StcS3VideoMediaUploader.this.onSliceProgress(i2 - i3);
this.compressProgress = i2;
}
UploadFileInfo checkProgressUpload = videoSliceHelper.checkProgressUpload(i);
if (checkProgressUpload != null) {
StcS3VideoMediaUploader.this.uploadPart(checkProgressUpload);
}
}
@Override
public void onCompleted() {
RLog.d("upload", "compress completed");
StcS3VideoMediaUploader.this.compressFinish = true;
String format = String.format("file://%s", str2);
if (StcS3VideoMediaUploader.this.message.getContent() instanceof SightMessage) {
Uri parse = Uri.parse(format);
FileInfo fileInfoByUri = FileUtils.getFileInfoByUri(NativeClient.getApplicationContext(), parse);
((SightMessage) StcS3VideoMediaUploader.this.message.getContent()).setLocalPath(parse);
((SightMessage) StcS3VideoMediaUploader.this.message.getContent()).setSize(fileInfoByUri.getSize());
}
if (StcS3VideoMediaUploader.this.errorCode != 0) {
StcS3VideoMediaUploader.this.callback.onError(StcS3VideoMediaUploader.this.errorCode, StcS3VideoMediaUploader.this.platform.getHost());
return;
}
int i = this.compressProgress;
if (i < 40) {
StcS3VideoMediaUploader.this.onSliceProgress(40 - i);
this.compressProgress = 40;
}
for (UploadFileInfo uploadFileInfo : videoSliceHelper.checkCompletedUpload()) {
if (uploadFileInfo != null) {
StcS3VideoMediaUploader.this.uploadPart(uploadFileInfo);
}
}
}
@Override
public void onCanceled() {
StcS3VideoMediaUploader.this.compressFinish = true;
if (StcS3VideoMediaUploader.this.errorCode != 0) {
StcS3VideoMediaUploader.this.callback.onError(StcS3VideoMediaUploader.this.errorCode, StcS3VideoMediaUploader.this.platform.getHost());
}
}
@Override
public void onFailed(Exception exc) {
StcS3VideoMediaUploader.this.compressFinish = true;
io.rong.common.RLog.e(StcS3VideoMediaUploader.TAG, "compress video error", exc);
StcS3VideoMediaUploader.this.callback.onError(34012, uri);
}
});
} catch (Exception e) {
this.compressFinish = true;
io.rong.common.RLog.e(TAG, "compress video error", e);
this.callback.onError(34012, uri);
}
}
public void uploadPart(UploadFileInfo uploadFileInfo) {
synchronized (this) {
this.partCount++;
}
this.option = RequestOption.Upload.newBuilder(((MediaMessageContent) this.message.getContent()).getLocalPath(), this.mimeKey, this.mimeType, this.mediaType, this.message, this.message.getMessageId(), this.platform.getHost()).build();
Call.create(this.dispatcher, buildSliceUploadRequest(uploadFileInfo)).enqueue();
}
@Override
public void onSliceUploadComplete(StcSliceUploadResult stcSliceUploadResult) {
this.mResultList.add(stcSliceUploadResult);
if (this.compressFinish && this.partCount == this.mResultList.size()) {
onProgress(98);
RLog.d("upload", "auth upload end start");
this.option = RequestOption.Upload.newBuilder(((MediaMessageContent) this.message.getContent()).getLocalPath(), this.mimeKey, this.mimeType, this.mediaType, this.message, this.message.getMessageId(), this.platform.getHost()).build();
this.request = buildEndRequest(stcSliceUploadResult.getUploadId());
Call.create(this.dispatcher, this.request).enqueue();
}
}
@Override
public void onSliceProgress(int i) {
synchronized (this) {
int i2 = this.errorProgress;
if (i2 == 0) {
int i3 = this.currentProgress + i;
this.currentProgress = i3;
if (i3 > 97) {
this.currentProgress = 97;
}
} else if (i2 >= i) {
this.errorProgress = i2 - i;
} else {
this.errorProgress = 0;
int i4 = this.currentProgress + (i - i2);
this.currentProgress = i4;
if (i4 > 97) {
this.currentProgress = 97;
}
}
}
onProgress(this.currentProgress);
}
@Override
public void onError(Request request, int i) {
if (request.retry > 0) {
this.dispatcher.cancel(String.valueOf(this.message.getMessageId()), null);
if (this.compressFinish) {
if (this.callback != null) {
this.callback.onError(i, this.platform.getHost());
}
this.errorCode = 0;
return;
}
this.errorCode = i;
return;
}
if (request instanceof StcSliceUploadRequest) {
synchronized (this) {
this.errorProgress += ((StcSliceUploadRequest) request).getCurProportion();
}
}
request.retry++;
Call.create(this.dispatcher, request).enqueue();
}
@Override
public boolean doAuth(Request request) {
if (request instanceof StcSliceInitRequest) {
MediaUploadAuthorInfo auth = getAuth(this.option.getMediaType().getValue(), this.option.getFileName(), "POST", "uploads");
if (auth != null) {
request.stcAuthorization = auth.getStcAuthorization();
request.stcContentSha256 = auth.getStcContentSha256();
request.stcDate = auth.getStcDate();
String str = this.option.getServerIp() + "/" + auth.getStcBucketName() + "/" + this.option.getFileName() + "?uploads";
if (!str.toLowerCase().startsWith("http")) {
str = "https://" + str;
}
request.serverIp = str;
return true;
}
return false;
} else if (request instanceof StcSliceUploadRequest) {
UploadFileInfo uploadFileInfo = ((StcSliceUploadRequest) request).getUploadFileInfo();
MediaUploadAuthorInfo auth2 = getAuth(this.option.getMediaType().getValue(), this.option.getFileName(), BaseRequest.METHOD_PUT, "partNumber=" + uploadFileInfo.getPartNumber() + "&uploadId=" + uploadFileInfo.getUploadId());
if (auth2 != null) {
request.stcAuthorization = auth2.getStcAuthorization();
request.stcContentSha256 = auth2.getStcContentSha256();
request.stcDate = auth2.getStcDate();
String str2 = this.option.getServerIp() + "/" + auth2.getStcBucketName() + "/" + this.option.getFileName() + "?partNumber=" + uploadFileInfo.getPartNumber() + "&uploadId=" + uploadFileInfo.getUploadId();
if (!str2.toLowerCase().startsWith("http")) {
str2 = "https://" + str2;
}
request.serverIp = str2;
return true;
}
return false;
} else {
if (request instanceof StcSliceCompleteRequest) {
String uploadId = ((StcSliceCompleteRequest) request).getUploadId();
MediaUploadAuthorInfo auth3 = getAuth(this.option.getMediaType().getValue(), this.option.getFileName(), "POST", "uploadId=" + uploadId);
if (auth3 != null) {
request.stcAuthorization = auth3.getStcAuthorization();
request.stcContentSha256 = auth3.getStcContentSha256();
request.stcDate = auth3.getStcDate();
String str3 = this.option.getServerIp() + "/" + auth3.getStcBucketName() + "/" + this.option.getFileName() + "?uploadId=" + uploadId;
if (!str3.toLowerCase().startsWith("http")) {
str3 = "https://" + str3;
}
request.serverIp = str3;
return true;
}
}
return false;
}
}
}