TXUGCPublish.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #import "TXUGCPublish.h"
  2. #import "TVCHeader.h"
  3. //#import "log.h"
  4. //#import "TXRTMPAPI.h"
  5. #import "TXUGCPublishUtil.h"
  6. #import "TVCClient.h"
  7. #undef _MODULE_
  8. #define _MODULE_ "TXUGCPublish"
  9. @implementation TXPublishParam
  10. - (id)init {
  11. if ((self = [super init])) {
  12. _enableHTTPS = NO;
  13. _enableResume = YES;
  14. }
  15. return self;
  16. }
  17. @end
  18. @implementation TXPublishResult
  19. @end
  20. @interface TXUGCPublish ()
  21. {
  22. BOOL _publishing;
  23. TVCConfig* _tvcConfig;
  24. TVCUploadParam* _tvcParam;
  25. TVCClient* _tvcClient;
  26. NSString* _userID;
  27. }
  28. @end
  29. @implementation TXUGCPublish
  30. -(id)init
  31. {
  32. self = [super init];
  33. if(self != nil)
  34. {
  35. _userID = @"";
  36. }
  37. return self;
  38. }
  39. -(id) initWithUserID:(NSString *) userID{
  40. self = [super init];
  41. if(self != nil)
  42. {
  43. _userID = userID;
  44. }
  45. return self;
  46. }
  47. -(int) publishVideo:(TXPublishParam*)param{
  48. if (_publishing == YES) {
  49. //NSLog(@"there is existing uncompleted publish task");
  50. return -1;
  51. }
  52. // NSString* strVer = [TXLiveBase getSDKVersionStr];
  53. // [TXDRApi txReportDAU:DR_DAU_EVENT_ID_UGC_PUBLISH
  54. // withErrCode:0
  55. // withErrInfo:@""
  56. // withSdkId:DR_SDK_ID_RTMPSDK
  57. // withSdkVersion:strVer];
  58. if (param == nil) {
  59. // NSLog(@"publishVideo: invalid param");
  60. return -2;
  61. }
  62. // if (param.secretId == nil || param.secretId.length == 0) {
  63. // NSLog(@"publishVideo: invalid secretId");
  64. // return -3;
  65. // }
  66. if (param.signature == nil || param.signature.length == 0) {
  67. NSLog(@"publishVideo: invalid signature");
  68. return -4;
  69. }
  70. if (param.videoPath == nil || param.videoPath.length == 0 || [[NSFileManager defaultManager] fileExistsAtPath:param.videoPath] == NO) {
  71. NSLog(@"publishVideo: invalid video file");
  72. return -5;
  73. }
  74. _publishing = YES;
  75. _tvcConfig = [[TVCConfig alloc] init];
  76. _tvcConfig.signature = param.signature;
  77. _tvcConfig.enableHttps = param.enableHTTPS;
  78. _tvcConfig.userID = _userID;
  79. _tvcConfig.enableResume = param.enableResume;
  80. //_tvcConfig.cosRegion = param.cosRegion;
  81. _tvcParam = [[TVCUploadParam alloc] init];
  82. _tvcParam.videoPath = param.videoPath;
  83. _tvcParam.coverPath = param.coverPath;
  84. _tvcParam.videoName = param.fileName;
  85. _tvcClient = [[TVCClient alloc] initWithConfig:_tvcConfig];
  86. [_tvcClient uploadVideo:_tvcParam result:^(TVCUploadResponse *resp) {
  87. if (resp) {
  88. NSLog(@"publish video result: retCode = %d descMsg = %s videoId = %s videoUrl = %s coverUrl = %s", resp.retCode, [resp.descMsg UTF8String], [resp.videoId UTF8String], [resp.videoURL UTF8String], [resp.coverURL UTF8String]);
  89. TXPublishResult * result = [[TXPublishResult alloc] init];
  90. result.retCode = resp.retCode;
  91. result.descMsg = resp.descMsg;
  92. result.videoId = resp.videoId;
  93. result.videoURL= resp.videoURL;
  94. result.coverURL= resp.coverURL;
  95. dispatch_async(dispatch_get_main_queue(), ^{
  96. if (self.delegate && [self.delegate respondsToSelector:@selector(onPublishComplete:)]) {
  97. [self.delegate onPublishComplete:result];
  98. }
  99. });
  100. }
  101. _publishing = NO;
  102. } progress:^(uint64_t bytesUpload, uint64_t bytesTotal) {
  103. dispatch_async(dispatch_get_main_queue(), ^{
  104. if (self.delegate && [self.delegate respondsToSelector:@selector(onPublishProgress:totalBytes:)]) {
  105. [self.delegate onPublishProgress:bytesUpload totalBytes:bytesTotal];
  106. }
  107. });
  108. }];
  109. return 0;
  110. }
  111. /*
  112. * ȡ�����Ƶ����
  113. * ����ֵ��
  114. * YES �ɹ���
  115. * NO ʧ�ܣ�
  116. -(BOOL) canclePublish;
  117. */
  118. -(BOOL) canclePublish
  119. {
  120. BOOL result = NO;
  121. if (_tvcClient != nil) {
  122. result = [_tvcClient cancleUploadVideo];
  123. }
  124. if (result) {
  125. _publishing = NO;
  126. }
  127. return result;
  128. }
  129. /*
  130. * 获取上报信息
  131. */
  132. -(NSDictionary *)getStatusInfo {
  133. if (_tvcClient != nil) {
  134. return [_tvcClient getStatusInfo];
  135. }
  136. return nil;
  137. }
  138. @end