HTTP Live Streaming causes BAD_EXC_ACCESS at GCDAsyncSocket.m / doWriteData

146 views
Skip to first unread message

Ben Skarsgård

unread,
Dec 15, 2014, 12:36:46 AM12/15/14
to cocoaht...@googlegroups.com
Hi Guys,
when I try to stream a NSData (MP4 file) and playing it I got a bad exc access. My buffer ist empty, but I have no idea why and I'm not very common with coding C code.

GCDAsyncSocket.m / -(void)doWriteData
[...]
const uint8_t *buffer = (const uint8_t *)[currentWrite->buffer bytes] + currentWrite->bytesDone; <= BAD_EXC_ACCESS
[...]
enqueued from HTTPConnection.m / -
[...]
[asyncSocket writeData:responseData withTimeout:TIMEOUT_WRITE_HEAD tag:HTTP_PARTIAL_RESPONSE_HEADER];
[...]

What I did:
I've subclassed HTTPConnection:

MyHTTPConnection.m
 - (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path
{
    NSData *data = [NSData dataWithContentsOfFile:[FileHandler videoFilePathWithIdentifier:1]];
    NSError *error;
   self.videoData = [RNDecryptor decryptData:data withSettings:kRNCryptorAES256Settings password:MyCryptoPhrase error:&error];
    
    return [[HTTPDataResponse alloc] initWithData:self.videoData]];
}

The part at the viewcontroller where my videofile should be played:

    httpServer = [[HTTPServer alloc] init];
    [httpServer setType:@"_http._tcp."];
    [httpServer setPort:33566];
    [httpServer setConnectionClass:[MyHTTPConnection class]];
        
    if (![httpServer start:&error]) {
        NSLog(@"Error starting HTTP Server: %@", error);
    }
    
    NSString *server = [NSString stringWithFormat:@"http://localhost:%hu", httpServer.listeningPort];
    NSURL *myURL = [NSURL URLWithString: [NSString stringWithFormat: @"%@", server]];
    
    self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:myURL];
    
    [self.moviePlayerController setControlStyle:MPMovieControlStyleDefault];
    self.moviePlayerController.movieSourceType = MPMovieSourceTypeStreaming;
    [self.moviePlayerController prepareToPlay];
    [self.moviePlayerController.view setFrame: CGRectMake(0, 0, 1024, 768)];
    [self.view addSubview:self.moviePlayerController.view];
    
    [self.moviePlayerController play];

I know loading NSData is not the best idea for videos, but the video files are really small: 3 MB.

Perhaps anyone here has got an idea, I'm really getting desperate.. 

Thanks so far,

Ben


Ben Skarsgård

unread,
Dec 15, 2014, 7:15:18 AM12/15/14
to cocoaht...@googlegroups.com
I have no idea why, but I replaced cocoahttpserver from github with cocoahttpserver used in iphoneHTTPServer.. so now it works.

Thanks,

Ben

isPrivate luo

unread,
Sep 3, 2019, 2:09:38 AM9/3/19
to CocoaHTTPServer
So it's work for you?

在 2014年12月15日星期一 UTC+8下午1:36:46,Ben Skarsgård写道:
Reply all
Reply to author
Forward
0 new messages