/**********
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
more details.
**********/
#include "rtsp_example.h"
int main(int argc, char** argv)
{
char* url = argv[1];
int socketNum = -1;
struct timeb startTime;
struct timeb currentTime;
char *timeline;
struct ResultData data;
struct MediaAttribute Attribute;
int Finished = -1;
unsigned char* streamBuf;
unsigned int video_count=0;
unsigned int audio_count=0;
if (argc != 2)
{
fprintf(stderr,"Usage:%s <url>\n",argv[0]);
return(0);
}
memset(Attribute.fConfigAsc,0,100);
memset(Attribute.fConfigHex,0,50);
Attribute.fVideoFrameRate = 0;
Attribute.fTimeIncBits = 0;
Attribute.fVideoWidth = 0;
Attribute.fVideoHeight = 0;
socketNum = init_rtsp(url,&Attribute);
if(socketNum<0) return 0;
ftime(&startTime);
timeline = ctime( & ( startTime.time ) );
fprintf(stderr,"Start receive streaming....\n");
fprintf(stderr,"Start time is: %.19s.%hu %s\n",timeline, startTime.millitm, &timeline[20]);
streamBuf = (unsigned char *)malloc(MAX_PACKET_SIZE*sizeof(unsigned char));
if(streamBuf == NULL)
{
fprintf(stderr,"alloc streamBuf failed\n");
clearup(socketNum);
return 0;
}
data.buffer = streamBuf;
while(1)
{
memset(data.buffer,0,MAX_PACKET_SIZE);
data.len = 0;
data.fRTPPayloadFormat = 0;
data.frtpTimestamp = 0;
//Finished = tcpReadHandler(socketNum,&data);
Finished = RTP_ReadHandler(socketNum,&data);
if(data.fRTPPayloadFormat == 96)
{
video_count+=data.len;
fprintf(stderr,"video: %d bytes,audio:%d bytes\r",video_count,audio_count);
}
else if(data.fRTPPayloadFormat == 97)
{
audio_count+=data.len;
fprintf(stderr,"video: %d bytes,audio:%d bytes\r",video_count,audio_count);
}
if(!Finished)
{
//Attribute.fVideoFrameRate = VFrameRate;
fprintf(stderr,"MediaAttribute fVideoFrequency is %u\n",Attribute.fVideoFrequency);
fprintf(stderr,"MediaAttribute fVideoPayloadFormat is %u\n",Attribute.fVideoPayloadFormat);
fprintf(stderr,"MediaAttribute fConfigAsc is %s\n",Attribute.fConfigAsc);
fprintf(stderr,"MediaAttribute fVideoFrameRate is %u\n",Attribute.fVideoFrameRate);
fprintf(stderr,"MediaAttribute fTimeIncBits is %u\n",Attribute.fTimeIncBits);
fprintf(stderr,"MediaAttribute fixed_vop_rate is %u\n",Attribute.fixed_vop_rate);
fprintf(stderr,"MediaAttribute fVideoWidth is %u\n",Attribute.fVideoWidth);
fprintf(stderr,"MediaAttribute fVideoHeight is %u\n",Attribute.fVideoHeight);
fprintf(stderr,"MediaAttribute fAudioFrequency is %u\n",Attribute.fAudioFrequency);
fprintf(stderr,"MediaAttribute fAudioPayloadFormat is %u\n",Attribute.fAudioPayloadFormat);
fprintf(stderr,"MediaAttribute fTrackNum is %u\n",Attribute.fTrackNum);
ftime(¤tTime);
timeline = ctime( & ( currentTime.time ) );
fprintf(stderr,"Receive successful\n");
fprintf(stderr,"End time is: %.19s.%hu %s\n",timeline, currentTime.millitm, &timeline[20]);
break;
}
}
clearup(socketNum);
return 0;
}