本地视频曲目添加和删除12次后,视频曲目在WebRTC iOS中中断

本地视频曲目添加和删除12次后,视频曲目在WebRTC iOS中中断,ios,objective-c,video,webrtc,Ios,Objective C,Video,Webrtc,我仅使用RTCEAGLVIDEOVERK创建本地流,并在RTCEAGLVIDEOVERK视图中播放视频曲目。按下btn 24次(即播放12次)后,视频曲目中断,仅显示一张卡住的图片 代码看起来很简单,但我不知道问题出在哪里。 我将代码上传到github,任何人都可以下载该项目,用iphone测试演示 github中的代码: ViewController.m的内容: @interface ViewController () @property (nonatomic, strong) RTCPee

我仅使用RTCEAGLVIDEOVERK创建本地流,并在RTCEAGLVIDEOVERK视图中播放视频曲目。按下btn 24次(即播放12次)后,视频曲目中断,仅显示一张卡住的图片

代码看起来很简单,但我不知道问题出在哪里。 我将代码上传到github,任何人都可以下载该项目,用iphone测试演示

github中的代码:

ViewController.m的内容:

@interface ViewController ()

@property (nonatomic, strong) RTCPeerConnectionFactory *peerFactory;
@property (nonatomic, strong) RTCMediaStream *mediaStream;
@property (nonatomic, strong) RTCEAGLVideoView *videoView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    // create local stream
    [self createLocalStream];

    // button to control the play and unplay video of local stream
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(300, 300, 100, 100);
    [btn addTarget:self action:@selector(playOrUnPlay) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor = [UIColor redColor];
    [self.view addSubview:btn];
}

// control the play and unplay video of local stream
- (void)playOrUnPlay {
    static int flag = 0;
    static int times = 0;
    if (flag % 2 == 0) {
        [self play];
        ++times;
        NSLog(@"play times: %d", times);
    } else {
        [self unplay];
    }
    ++flag;
}

- (void)createLocalStream {
    self.peerFactory = [[RTCPeerConnectionFactory alloc] init];
    self.mediaStream = [self.peerFactory mediaStreamWithStreamId:@"Fuck"];

    // create video track
    RTCAVFoundationVideoSource *source = [self.peerFactory avFoundationVideoSourceWithConstraints:nil];
    RTCVideoTrack *videoTrack = [self.peerFactory videoTrackWithSource:source trackId:@"FuckVideo"];

    // add video track to stream
    if (videoTrack) {
        [self.mediaStream addVideoTrack:videoTrack];
    }

}

// play video of local stream
- (void)play {
    self.videoView = [[RTCEAGLVideoView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
    [self.view addSubview:self.videoView];

    if (self.mediaStream.videoTracks.count > 0) {
        RTCVideoTrack *videoTrack = self.mediaStream.videoTracks.firstObject;
        [videoTrack addRenderer:self.videoView];
    }
}

// stop play video of local stream
- (void)unplay {
    if (self.mediaStream.videoTracks.count > 0) {
        RTCVideoTrack *videoTrack = self.mediaStream.videoTracks.firstObject;
        [videoTrack removeRenderer:self.videoView];
    }
    [self.videoView removeFromSuperview];
}

现在我只创建了一次self.videoView,在播放和取消播放时添加和删除videotrack。那么结果很好。我猜是RTCEAGLVideoView的发布导致了这个问题,但我无法找出详细的原因。现在我创建了self.videoView一次,只在播放和取消播放时添加和删除videotrack。那么结果很好。我猜是RTCEAGLVideoView的发布导致了这个问题,但我无法找出具体原因。