I’m developing publish video app for iOS
H264 / AAC Encoder is developed using VideoToolbox and AudioToolbox
I was checked RTP transport is correctly run.
I was found some issue.
- We must transport stream encapsulate format “MPEG4” or “MPEG2-TS”. Raw H264 or AAC is not playable in other player. But server is successfully receive the stream packet.
-
This is my question.
-
I’m trying RECORD method. Server has successfully created stream. But not received stream yet.
-
How to transport stream? Is there some parameter exist on RTSP?
This is my code
#pragma mark - RTSP Handshake
- (void)sendANNOUNCE
{
NSString* rtpHeader = [NSString stringWithFormat:@"ANNOUNCE %@ RTSP/1.0\r\n", [NSString stringWithFormat:@"rtsp://%@:%ld/live/mp4:%@", self.address, self.port, self.streamName]];
rtpHeader = [rtpHeader stringByAppendingFormat:@"CSeq: %d\r\n",cseq++];
if(self.sessionid != nil) rtpHeader = [rtpHeader stringByAppendingFormat:@"Session: %@\r\n", self.sessionid];
rtpHeader = [rtpHeader stringByAppendingFormat:@"Content-Type: application/sdp\r\n"];
// rtpHeader = [rtpHeader stringByAppendingFormat:@"Content-Length: 0\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"\r\n"];
NSLog(@"%@", rtpHeader);
rtspSeq = SEQ_ANNOUNCE;
[self sendMessage:[rtpHeader dataUsingEncoding:NSUTF8StringEncoding] tag:SEQ_ANNOUNCE];
}
- (void)sendSETUP
{
NSString* rtpHeader = [NSString stringWithFormat:@"SETUP %@ RTSP/1.0\r\n", [NSString stringWithFormat:@"rtsp://%@:%ld/live/mp4:%@", self.address, self.port, self.streamName]];
rtpHeader = [rtpHeader stringByAppendingFormat:@"CSeq: %d\r\n",cseq++];
if(self.sessionid != nil) rtpHeader = [rtpHeader stringByAppendingFormat:@"Session: %@\r\n", self.sessionid];
rtpHeader = [rtpHeader stringByAppendingFormat:@"Transport: RTP/AVP;unicast;client_port=%d\r\n", RTP_PORT];
// rtpHeader = [rtpHeader stringByAppendingFormat:@"Content-Base: %@\r\n", [NSString stringWithFormat:@"rtsp://%@:%ld/live/mp4:%@", self.address, self.port, self.streamName]];
rtpHeader = [rtpHeader stringByAppendingString:@"Content-Type: application/sdp\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"m=video 0 RTP/AVP 96\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"a=control:streamid=0\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"a=rtpmap:96 MP4V-ES/5544\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"a=mimetype:string;\"video/MP4V-ES\"\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"a=AvgBitRate:integer;550000\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"m=audio 0 RTP/AVP 97\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"a=control:streamid=1\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"a=rtpmap:97 mpeg4-generic/32000/2\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"a=mimetype:string;\"audio/mpeg4-generic\"\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"a=AvgBitRate:integer;64000\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"\r\n"];
NSLog(@"%@", rtpHeader);
rtspSeq = SEQ_SETUP;
[self sendMessage:[rtpHeader dataUsingEncoding:NSUTF8StringEncoding] tag:SEQ_SETUP];
}
- (void)sendRECORD
{
NSString* rtpHeader = [NSString stringWithFormat:@"RECORD %@ RTSP/1.0\r\n", [NSString stringWithFormat:@"rtsp://%@:%ld/live/mp4:%@", self.address, self.port, self.streamName]];
rtpHeader = [rtpHeader stringByAppendingFormat:@"CSeq: %d\r\n",cseq++];
if(self.sessionid != nil) rtpHeader = [rtpHeader stringByAppendingFormat:@"Session: %@\r\n", self.sessionid];
rtpHeader = [rtpHeader stringByAppendingString:@"Content-Type: application/sdp\r\n"];
rtpHeader = [rtpHeader stringByAppendingFormat:@"\r\n"];
NSLog(@"%@", rtpHeader);
rtspSeq = SEQ_RECORD;
[self sendMessage:[rtpHeader dataUsingEncoding:NSUTF8StringEncoding] tag:SEQ_RECORD];
}
- (void)sendTEARDOWN
{
NSString* rtpHeader = [NSString stringWithFormat:@"TEARDOWN %@ RTSP/1.0\r\n", [NSString stringWithFormat:@"rtsp://%@:%ld/live/mp4:%@", self.address, self.port, self.streamName]];
rtpHeader = [rtpHeader stringByAppendingFormat:@"CSeq: %d\r\n",cseq++];
if(self.sessionid != nil) rtpHeader = [rtpHeader stringByAppendingFormat:@"Session: %@\r\n", self.sessionid];
rtpHeader = [rtpHeader stringByAppendingFormat:@"\r\n"];
NSLog(@"%@", rtpHeader);
rtspSeq = SEQ_TEARDOWN;
[self sendMessage:[rtpHeader dataUsingEncoding:NSUTF8StringEncoding] tag:SEQ_TEARDOWN];
}
I think some rtsp header is wrong.
I will transport real video/audio data via RTP.