[rtmpdump] comments are a subtle hint
Peter Miller
pmiller at opensource.org.au
Fri Apr 8 12:45:15 CEST 2011
This patch converts all of the C++ comments to be C comments.
Yes, I know: C99 allows // comments. Working in both languages, and
having to shift gears numerous times per day, the comment format
provides a subtle but distinct reminder which language I am reading at
the time.
Another thing you may notice is the increased use of #if 0 because
indent(1) will format that code as well, indenting and formatting
automatically. If it was a comment, the results aren't as good.
--
Regards
Peter Miller <pmiller at opensource.org.au>
/\/\* http://miller.emu.id.au/pmiller/
PGP public key ID: 1024D/D0EDB64D
fingerprint = AD0A C5DF C426 4F03 5D53 2BDB 18D8 A4E2 D0ED B64D
See http://www.keyserver.net or any PGP keyserver for public key.
"Always code as if the guy who ends up maintaining your code will be a
violent psychopath who knows where you live." -- Martin Golding
-------------- next part --------------
MIME-Version: 1.0
Content-Type: application/aegis-patch
Subject: rtmpdump.2.3 - C comments
Content-Name: rtmpdump.2.3.C019.patch
Content-Disposition: attachment; filename=rtmpdump.2.3.C019.patch
X-Aegis-Project-Name: rtmpdump.2.3
X-Aegis-Change-Number: 19
#
# This change set converts all of the C++ comments to be C comments.
#
# Yes, I know: C99 allows // comments. Working in both languages, and
# having to shift gears numerous times per day, the comment format
# provides a subtle but distinct reminder which language I am reading at
# the time.
#
# Another change you will notice is the increaed use of #if 0 because
# indent(1) will format that code as well, indenting and formatting
# automatically.
#
# Aegis-Change-Set-Begin
# QlpoMzFBWSZTWeh6QEsAAPXfgAAQWG//+iggBK6/79/qQAKdO5zg7KBoRMmjRJ4NTJ6EnqaG
# hoNNAxCKntKb0yTBQGmhoAAAAASqeQhTaPIU3qaTNQwIyabQmjCYSQiNAp6NCPVP1TTZT1Mj
# 0m0mIaMjeZjFm/4Ae4MJPCcJpHL9N38u9HmQJgYP2jGhzQcNO/1kYgo5Yvkd90KjvzNchjlW
# h0SimlNXEKAlokRHfRrqYBxXrnlU1A9pUKp0/G7SDxwowd6YgNItXjhf1Ccs/91Pvuzb8eAd
# Gqv9umluoWmD17de/f5yES3zguJvKuPGtLlc7Nsy7OAxbSsyfQjHUnCdgQRYMyLIZ2kEJlFY
# i9GQk6CzmE0vySaSoyRrxdKJxgSTqqWTSSh4Ba9iAqF+HyCTsoDMQvzDoZnXiDH0GKtOT0bi
# 4V0z27tuzLPTdMbHUGBxDuOrVqNGcGOZsKRhLmRucvsJTO6NVbMq7ubHCBvtTpwxAnFs8TRj
# k7lSgRsCpw8yLCIN4EhBBNu3VaktonsT3bjOT4WmwDVNvyyAOzQB+aa9qhJkcijkl0TYTQK3
# AREt8KKsoN7NPMK6lXUYMwLLlXLapOtSg5hTqwLCk4ZdqW7oLXthfmBmTyGIKJAwpHKF81hg
# 2GQjb0gsRzIYr5r2AXgTCUbHhDGW1TT9noxCSGAvtmw1ObeBqk8Qig1UEcLKeqKDnyxUMLZV
# otCVpNiamKPYHtyCRcMIYPe3ZYE2RFLTHAJEQipJsf90rhoc+oMlFd5e2DOyLzoVNoTfauiq
# DigPIsI/YMmkv2sY+tiwbOjRBgKJIx5OgY3VA9JSCqdeW2WLEK0JxFubarkNNnK6sMMC4NeI
# UMK3UUC4uyLyaoirSpHQFCy4eEU11UadzvQHmo3ZBOwD/i7kinChIdD0gJY=
# Aegis-Change-Set-End
#
Index: rtmpdump.c
--- rtmpdump.c
+++ rtmpdump.c
@@ -27,7 +27,7 @@
#include <math.h>
#include <stdio.h>
-#include <signal.h> // to catch Ctrl-C
+#include <signal.h> /* to catch Ctrl-C */
#include <getopt.h>
#include "librtmp/rtmp_sys.h"
@@ -51,7 +51,7 @@
#define DEF_BUFTIME (10 * 60 * 60 * 1000) /* 10 hours default */
#define DEF_SKIPFRM 0
-// starts sockets
+/* starts sockets */
int
InitSockets()
{
@@ -93,7 +93,7 @@
{
RTMP_ctrlC = TRUE;
RTMP_LogPrintf("Caught signal: %d, cleaning up, just a second...\n", sig);
- // ignore all these signals now and let the connection close
+ /* ignore all these signals now and let the connection close */
signal(SIGINT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
#ifndef WIN32
@@ -130,12 +130,14 @@
static const AVal av_true = AVC("true");
int
-OpenResumeFile(const char *flvFile, // file name [in]
- FILE ** file, // opened file [out]
- off_t * size, // size of the file [out]
- char **metaHeader, // meta data read from the file [out]
- uint32_t * nMetaHeaderSize, // length of metaHeader [out]
- double *duration) // duration of the stream in ms [out]
+OpenResumeFile(const char *flvFile, /* file name [in] */
+ FILE **file, /* opened file [out] */
+ off_t *size, /* size of the file [out] */
+ char **metaHeader, /* meta data read from the file
+ * [out] */
+ uint32_t *nMetaHeaderSize, /* length of metaHeader [out] */
+ double *duration) /* duration of the stream in ms
+ * [out] */
{
size_t bufferSize = 0;
char hbuf[16], *buffer = NULL;
@@ -145,7 +147,10 @@
*file = fopen(flvFile, "r+b");
if (!*file)
- return RD_SUCCESS; // RD_SUCCESS, because we go to fresh file mode instead of quiting
+ {
+ /* RD_SUCCESS, because we go to fresh file mode instead of quiting */
+ return RD_SUCCESS;
+ }
fseek(*file, 0, SEEK_END);
*size = ftello(*file);
@@ -153,10 +158,10 @@
if (*size > 0)
{
- // verify FLV format and read header
+ /* verify FLV format and read header */
uint32_t prevTagSize = 0;
- // check we've got a valid FLV file to continue!
+ /* check we've got a valid FLV file to continue! */
if (fread(hbuf, 1, 13, *file) != 13)
{
RTMP_Log(RTMP_LOGERROR, "Couldn't read FLV file header!");
@@ -192,7 +197,7 @@
prevTagSize);
}
- // go through the file to find the meta data!
+ /* go through the file to find the meta data! */
off_t pos = dataOffset + 4;
int bFoundMetaHeader = FALSE;
@@ -243,7 +248,7 @@
*metaHeader = (char *) malloc(*nMetaHeaderSize);
memcpy(*metaHeader, buffer, *nMetaHeaderSize);
- // get duration
+ /* get duration */
AMFObjectProperty prop;
if (RTMP_FindFirstMatchingProperty
(&metaObj, &av_duration, &prop))
@@ -255,8 +260,6 @@
bFoundMetaHeader = TRUE;
break;
}
- //metaObj.Reset();
- //delete obj;
}
pos += (dataSize + 11 + 4);
}
@@ -270,12 +273,17 @@
}
int
-GetLastKeyframe(FILE * file, // output file [in]
- int nSkipKeyFrames, // max number of frames to skip when searching for key frame [in]
- uint32_t * dSeek, // offset of the last key frame [out]
- char **initialFrame, // content of the last keyframe [out]
- int *initialFrameType, // initial frame type (audio/video) [out]
- uint32_t * nInitialFrameSize) // length of initialFrame [out]
+GetLastKeyframe(FILE *file, /* output file [in] */
+ int nSkipKeyFrames, /* max number of frames to skip
+ * when searching for key frame
+ * [in] */
+ uint32_t *dSeek, /* offset of the last key frame
+ * [out] */
+ char **initialFrame, /* content of the last keyframe
+ * [out] */
+ int *initialFrameType, /* initial frame type
+ * (audio/video) [out] */
+ uint32_t *nInitialFrameSize) /* length of initialFrame [out] */
{
const size_t bufferSize = 16;
char buffer[bufferSize];
@@ -295,15 +303,20 @@
RTMP_Log(RTMP_LOGDEBUG, "bAudioOnly: %d, size: %llu", bAudioOnly,
(unsigned long long) size);
- // ok, we have to get the timestamp of the last keyframe (only keyframes are seekable) / last audio frame (audio only streams)
+ /* ok, we have to get the timestamp of the last keyframe (only
+ * keyframes are seekable) / last audio frame (audio only streams) */
- //if(!bAudioOnly) // we have to handle video/video+audio different since we have non-seekable frames
- //{
- // find the last seekable frame
+#if 0
+ if(!bAudioOnly)
+ {
+ /* we have to handle video/video+audio different since we have
+ * non-seekable frames */
+#endif
+ /* find the last seekable frame */
off_t tsize = 0;
uint32_t prevTagSize = 0;
- // go through the file and find the last video keyframe
+ /* go through the file and find the last video keyframe */
do
{
int xread;
@@ -323,7 +336,9 @@
}
prevTagSize = AMF_DecodeInt32(buffer);
- //RTMP_Log(RTMP_LOGDEBUG, "Last packet: prevTagSize: %d", prevTagSize);
+#if 0
+ RTMP_Log(RTMP_LOGDEBUG, "Last packet: prevTagSize: %d", prevTagSize);
+#endif
if (prevTagSize == 0)
{
@@ -340,26 +355,25 @@
}
tsize += prevTagSize + 4;
- // read header
+ /* read header */
fseeko(file, size - tsize, SEEK_SET);
if (fread(buffer, 1, 12, file) != 12)
{
RTMP_Log(RTMP_LOGERROR, "Couldn't read header!");
return RD_FAILED;
}
- //*
+
#ifdef _DEBUG
uint32_t ts = AMF_DecodeInt24(buffer + 4);
ts |= (buffer[7] << 24);
RTMP_Log(RTMP_LOGDEBUG, "%02X: TS: %d ms", buffer[0], ts);
-#endif //*/
+#endif
- // this just continues the loop whenever the number of skipped frames is > 0,
- // so we look for the next keyframe to continue with
- //
- // this helps if resuming from the last keyframe fails and one doesn't want to start
- // the download from the beginning
- //
+ /* This just continues the loop whenever the number of skipped frames is
+ * > 0, so we look for the next keyframe to continue with.
+ *
+ * This helps if resuming from the last keyframe fails and one doesn't
+ * want to start the download from the beginning. */
if (nSkipKeyFrames > 0
&& !(!bAudioOnly
&& (buffer[0] != 0x09 || (buffer[11] & 0xf0) != 0x10)))
@@ -372,10 +386,13 @@
goto skipkeyframe;
}
+ /* as long as we don't have a keyframe / last audio frame */
}
- while ((bAudioOnly && buffer[0] != 0x08) || (!bAudioOnly && (buffer[0] != 0x09 || (buffer[11] & 0xf0) != 0x10))); // as long as we don't have a keyframe / last audio frame
+ while ((bAudioOnly && buffer[0] != 0x08)
+ || (!bAudioOnly
+ && (buffer[0] != 0x09 || (buffer[11] & 0xf0) != 0x10)));
- // save keyframe to compare/find position in stream
+ /* save keyframe to compare/find position in stream */
*initialFrameType = buffer[0];
*nInitialFrameSize = prevTagSize - 11;
*initialFrame = (char *) malloc(*nInitialFrameSize);
@@ -387,12 +404,16 @@
return RD_FAILED;
}
- *dSeek = AMF_DecodeInt24(buffer + 4); // set seek position to keyframe tmestamp
+ /* set seek position to keyframe tmestamp */
+ *dSeek = AMF_DecodeInt24(buffer + 4);
*dSeek |= (buffer[7] << 24);
- //}
- //else // handle audio only, we can seek anywhere we'd like
- //{
- //}
+#if 0
+ }
+ else
+ {
+ /* handle audio only, we can seek anywhere we'd like */
+ }
+#endif
if (*dSeek < 0)
{
@@ -424,23 +445,41 @@
if (*dSeek != 0)
{
- // seek to position after keyframe in our file (we will ignore the keyframes resent by the server
- // since they are sent a couple of times and handling this would be a mess)
+ /* seek to position after keyframe in our file (we will ignore the
+ * keyframes resent by the server since they are sent a couple of
+ * times and handling this would be a mess). */
fseeko(file, size - tsize + prevTagSize + 4, SEEK_SET);
- // make sure the WriteStream doesn't write headers and ignores all the 0ms TS packets
- // (including several meta data headers and the keyframe we seeked to)
- //bNoHeader = TRUE; if bResume==true this is true anyway
+#if 0
+ /* make sure the WriteStream doesn't write headers and ignores all
+ * the 0ms TS packets (including several meta data headers and the
+ * keyframe we seeked to). if bResume==true this is true anyway. */
+ bNoHeader = TRUE;
+#endif
}
- //}
-
return RD_SUCCESS;
}
int
-Download(RTMP * rtmp, // connected RTMP object
- FILE * file, uint32_t dSeek, uint32_t dStopOffset, double duration, int bResume, char *metaHeader, uint32_t nMetaHeaderSize, char *initialFrame, int initialFrameType, uint32_t nInitialFrameSize, int nSkipKeyFrames, int bStdoutMode, int bLiveStream, int bHashes, int bOverrideBufferTime, uint32_t bufferTime, double *percent) // percentage downloaded [out]
+Download(RTMP *rtmp, /* connected RTMP object */
+ FILE *file,
+ uint32_t dSeek,
+ uint32_t dStopOffset,
+ double duration,
+ int bResume,
+ char *metaHeader,
+ uint32_t nMetaHeaderSize,
+ char *initialFrame,
+ int initialFrameType,
+ uint32_t nInitialFrameSize,
+ int nSkipKeyFrames,
+ int bStdoutMode,
+ int bLiveStream,
+ int bHashes,
+ int bOverrideBufferTime,
+ uint32_t bufferTime,
+ double *percent) /* percentage downloaded [out] */
{
int32_t now, lastUpdate;
int bufferSize = 64 * 1024;
@@ -465,8 +504,7 @@
}
else
{
- // print initial status
- // Workaround to exit with 0 if the file is fully (> 99.9%) downloaded
+ /* print initial status */
if (duration > 0)
{
if ((double) rtmp->m_read.timestamp >= (double) duration * 999.0)
@@ -474,6 +512,8 @@
RTMP_LogPrintf("Already Completed at: %.3f sec Duration=%.3f sec\n",
(double) rtmp->m_read.timestamp / 1000.0,
(double) duration / 1000.0);
+ /* Workaround to exit with 0 if the file is fully
+ * (> 99.9%) downloaded. */
return RD_SUCCESS;
}
else
@@ -511,7 +551,9 @@
do
{
nRead = RTMP_Read(rtmp, buffer, bufferSize);
- //RTMP_LogPrintf("nRead: %d\n", nRead);
+#if 0
+ RTMP_LogPrintf("nRead: %d\n", nRead);
+#endif
if (nRead > 0)
{
if (fwrite(buffer, sizeof(unsigned char), nRead, file) !=
@@ -525,16 +567,23 @@
}
size += nRead;
- //RTMP_LogPrintf("write %dbytes (%.1f kB)\n", nRead, nRead/1024.0);
- if (duration <= 0) // if duration unknown try to get it from the stream (onMetaData)
- duration = RTMP_GetDuration(rtmp);
+#if 0
+ RTMP_LogPrintf("write %dbytes (%.1f kB)\n", nRead, nRead/1024.0);
+#endif
+ if (duration <= 0)
+ {
+ /* if duration unknown try to get it from the stream
+ * (onMetaData). */
+ duration = RTMP_GetDuration(rtmp);
+ }
if (duration > 0)
{
- // make sure we claim to have enough buffer time!
+ /* make sure we claim to have enough buffer time! */
if (!bOverrideBufferTime && bufferTime < (duration * 1000.0))
{
- bufferTime = (uint32_t) (duration * 1000.0) + 5000; // extra 5sec to make sure we've got enough
+ /* extra 5sec to make sure we've got enough */
+ bufferTime = (uint32_t) (duration * 1000.0) + 5000;
RTMP_Log(RTMP_LOGDEBUG,
"Detected that buffer time is less than duration, resetting to: %dms",
@@ -729,23 +778,27 @@
double percent = 0;
double duration = 0.0;
- int nSkipKeyFrames = DEF_SKIPFRM; // skip this number of keyframes when resuming
+ int nSkipKeyFrames = DEF_SKIPFRM; /* skip this number of keyframes when
+ * resuming */
- int bOverrideBufferTime = FALSE; // if the user specifies a buffer time override this is true
- int bStdoutMode = TRUE; // if true print the stream directly to stdout, messages go to stderr
- int bResume = FALSE; // true in resume mode
- uint32_t dSeek = 0; // seek position in resume mode, 0 otherwise
+ int bOverrideBufferTime = FALSE; /* if the user specifies a buffer time
+ * override this is true */
+ int bStdoutMode = TRUE; /* if true print the stream directly to stdout,
+ * messages go to stderr */
+ int bResume = FALSE; /* true in resume mode */
+ uint32_t dSeek = 0; /* seek position in resume mode, 0 otherwise */
uint32_t bufferTime = DEF_BUFTIME;
- // meta header and initial frame for the resume mode (they are read from the file and compared with
- // the stream we are trying to continue
+ /* Meta header and initial frame for the resume mode (they are read
+ * from the file and compared with the stream we are trying to
+ * continue. */
char *metaHeader = 0;
uint32_t nMetaHeaderSize = 0;
- // video keyframe for matching
+ /* video keyframe for matching */
char *initialFrame = 0;
uint32_t nInitialFrameSize = 0;
- int initialFrameType = 0; // tye: audio or video
+ int initialFrameType = 0; /* tye: audio or video */
AVal hostname = { 0, 0 };
AVal playpath = { 0, 0 };
@@ -753,11 +806,11 @@
int port = -1;
int protocol = RTMP_PROTOCOL_UNDEFINED;
int retries = 0;
- int bLiveStream = FALSE; // is it a live stream? then we can't seek/resume
- int bHashes = FALSE; // display byte counters not hashes by default
+ int bLiveStream = FALSE; /* is it a live stream? then we can't seek/resume */
+ int bHashes = FALSE; /* display byte counters not hashes by default */
- long int timeout = DEF_TIMEOUT; // timeout connection after 120 seconds
- uint32_t dStartOffset = 0; // seek position in non-live mode
+ long int timeout = DEF_TIMEOUT; /* timeout connection after 120 seconds */
+ uint32_t dStartOffset = 0; /* seek position in non-live mode */
uint32_t dStopOffset = 0;
RTMP rtmp = { 0 };
@@ -789,7 +842,7 @@
RTMP_debuglevel = RTMP_LOGINFO;
- // Check for --quiet option before printing any output
+ /* Check for --quiet option before printing any output */
int index = 0;
while (index < argc)
{
@@ -810,7 +863,9 @@
return RD_FAILED;
}
- /* sleep(30); */
+#if 0
+ sleep(30);
+#endif
RTMP_Init(&rtmp);
@@ -939,7 +994,7 @@
break;
}
case 'v':
- bLiveStream = TRUE; // no seeking or resuming possible!
+ bLiveStream = TRUE; /* no seeking or resuming possible! */
break;
case 'd':
STR2AVAL(subscribepath, optarg);
@@ -1165,12 +1220,12 @@
int first = 1;
- // User defined seek offset
+ /* User defined seek offset */
if (dStartOffset > 0)
{
- // Live stream
if (bLiveStream)
{
+ /* Live stream */
RTMP_Log(RTMP_LOGWARNING,
"Can't seek in a live stream, ignoring --start option");
dStartOffset = 0;
@@ -1187,7 +1242,8 @@
off_t size = 0;
- // ok, we have to get the timestamp of the last keyframe (only keyframes are seekable) / last audio frame (audio only streams)
+ /* ok, we have to get the timestamp of the last keyframe (only
+ * keyframes are seekable) / last audio frame (audio only streams). */
if (bResume)
{
nStatus =
@@ -1198,8 +1254,10 @@
if (!file)
{
- // file does not exist, so go back into normal mode
- bResume = FALSE; // we are back in fresh file mode (otherwise finalizing file won't be done)
+ /* file does not exist, so go back into normal mode */
+ bResume = FALSE;
+ /* We are back in fresh file mode (otherwise finalizing file
+ * won't be done). */
}
else
{
@@ -1262,10 +1320,10 @@
RTMP_Log(RTMP_LOGINFO, "Connected...");
- // User defined seek offset
+ /* User defined seek offset */
if (dStartOffset > 0)
{
- // Don't need the start offset if resuming an existing file
+ /* Don't need the start offset if resuming an existing file */
if (bResume)
{
RTMP_Log(RTMP_LOGWARNING,
@@ -1278,10 +1336,10 @@
}
}
- // Calculate the length of the stream to still play
+ /* Calculate the length of the stream to still play */
if (dStopOffset > 0)
{
- // Quit if start seek is past required stop offset
+ /* Quit if start seek is past required stop offset */
if (dStopOffset <= dSeek)
{
RTMP_LogPrintf("Already Completed\n");
Index: rtmpgw.c
--- rtmpgw.c
+++ rtmpgw.c
@@ -69,7 +69,7 @@
} STREAMING_SERVER;
-STREAMING_SERVER *httpServer = 0; // server structure pointer
+STREAMING_SERVER *httpServer = 0; /* server structure pointer */
STREAMING_SERVER *startStreaming(const char *address, int port);
void stopStreaming(STREAMING_SERVER * server);
@@ -79,9 +79,9 @@
AVal hostname;
int rtmpport;
int protocol;
- int bLiveStream; // is it a live stream? then we can't seek/resume
+ int bLiveStream; /* is it a live stream? then we can't seek/resume */
- long int timeout; // timeout connection after 120 seconds
+ long int timeout; /* timeout connection after 120 seconds */
uint32_t bufferTime;
char *rtmpurl;
@@ -235,9 +235,7 @@
{
if (strncmp(data + src_x, "%", 1) == 0 && src_x + 2 < length)
{
- //
- // Since we encountered a '%' we know this is an escaped character
- //
+ /* Since we encountered a '%' we know this is an escaped character */
hex[0] = data[src_x + 1];
hex[1] = data[src_x + 2];
data[dst_x] = (char) strtol(hex, &stp, 16);
@@ -246,19 +244,16 @@
}
else if (src_x != dst_x)
{
- //
- // This doesn't need to be unescaped. If we didn't unescape anything previously
- // there is no need to copy the string either
- //
+ /* This doesn't need to be unescaped. If we didn't unescape anything
+ * previously there is no need to copy the string either. */
data[dst_x] = data[src_x];
src_x += 1;
dst_x += 1;
}
else
{
- //
- // This doesn't need to be unescaped, however we need to copy the string
- //
+ /* This doesn't need to be unescaped, however we need to copy
+ * the string. */
src_x += 1;
dst_x += 1;
}
@@ -287,51 +282,55 @@
TFRET();
}
-/*
-ssize_t readHTTPLine(int sockfd, char *buffer, size_t length)
+#if 0
+ssize_t
+readHTTPLine(int sockfd, char *buffer, size_t length)
{
- size_t i=0;
+ size_t i = 0;
- while(i < length-1) {
- char c;
- int n = read(sockfd, &c, 1);
+ while (i < length - 1)
+ {
+ char c;
+ int n = read(sockfd, &c, 1);
- if(n == 0)
- break;
+ if (n == 0)
+ break;
- buffer[i] = c;
- i++;
+ buffer[i] = c;
+ i++;
- if(c == '\n')
- break;
- }
- buffer[i]='\0';
- i++;
+ if (c == '\n')
+ break;
+ }
+ buffer[i] = '\0';
+ i++;
- return i;
+ return i;
}
-int isHTTPRequestEOF(char *line, size_t length)
+int
+isHTTPRequestEOF(char *line, size_t length)
{
- if(length < 2)
- return TRUE;
+ if (length < 2)
+ return TRUE;
- if(line[0]=='\r' && line[1]=='\n')
- return TRUE;
+ if (line[0] == '\r' && line[1] == '\n')
+ return TRUE;
- return FALSE;
+ return FALSE;
}
-*/
+#endif
-void processTCPrequest(STREAMING_SERVER * server, // server socket and state (our listening socket)
- int sockfd // client connection socket
- )
+void
+processTCPrequest(STREAMING_SERVER *server, /* server socket and state (our
+ * listening socket) */
+ int sockfd) /* client connection socket */
{
- char buf[512] = { 0 }; // answer buffer
- char header[2048] = { 0 }; // request header
- char *filename = NULL; // GET request: file name //512 not enuf
- char *buffer = NULL; // stream buffer
- char *ptr = NULL; // header pointer
+ char buf[512] = { 0 }; /* answer buffer */
+ char header[2048] = { 0 }; /* request header */
+ char *filename = NULL; /* GET request: file name //512 not enuf */
+ char *buffer = NULL; /* stream buffer */
+ char *ptr = NULL; /* header pointer */
int len;
size_t nRead = 0;
@@ -343,21 +342,24 @@
server->state = STREAMING_IN_PROGRESS;
RTMP rtmp = { 0 };
- uint32_t dSeek = 0; // can be used to start from a later point in the stream
+ uint32_t dSeek = 0; /* can be used to start from a later point in the stream */
- // reset RTMP options to defaults specified upon invokation of streams
+ /* reset RTMP options to defaults specified upon invokation of streams */
RTMP_REQUEST req;
memcpy(&req, &defaultRTMPRequest, sizeof(RTMP_REQUEST));
- // timeout for http requests
+ /* timeout for http requests */
fd_set fds;
struct timeval tv;
memset(&tv, 0, sizeof(struct timeval));
tv.tv_sec = 5;
- // go through request lines
- //do {
+ /* go through request lines */
+#if 0
+ do
+ {
+#endif
FD_ZERO(&fds);
FD_SET(sockfd, &fds);
@@ -375,7 +377,7 @@
if (strstr(header, "Range: bytes=") != 0)
{
- // TODO check range starts from 0 and asking till the end.
+ /* TODO check range starts from 0 and asking till the end. */
RTMP_LogPrintf("%s, Range request not supported\n", __FUNCTION__);
len = sprintf(buf, "HTTP/1.0 416 Requested Range Not Satisfiable%s\r\n",
srvhead);
@@ -387,7 +389,7 @@
{
filename = header + 4;
- // filter " HTTP/..." from end of request
+ /* filter " HTTP/..." from end of request */
char *p = filename;
while (*p != '\0')
{
@@ -400,17 +402,21 @@
}
}
}
- //} while(!isHTTPRequestEOF(header, nRead));
+#if 0
+ }
+ while (!isHTTPRequestEOF(header, nRead));
+#endif
- // if we got a filename from the GET method
+ /* if we got a filename from the GET method */
if (filename != NULL)
{
RTMP_Log(RTMP_LOGDEBUG, "%s: Request header: %s", __FUNCTION__, filename);
if (filename[0] == '/')
- { // if its not empty, is it /?
+ {
+ /* if its not empty, is it /? */
ptr = filename + 1;
- // parse parameters
+ /* parse parameters */
if (*ptr == '?')
{
ptr++;
@@ -421,12 +427,12 @@
char ich = *ptr;
ptr++;
if (*ptr != '=')
- goto filenotfound; // long parameters not (yet) supported
+ goto filenotfound; /* long parameters not (yet) supported */
ptr++;
len -= 2;
- // get position of the next '&'
+ /* get position of the next '&' */
char *temp;
unsigned int nArgLen = len;
@@ -439,7 +445,10 @@
memcpy(arg, ptr, nArgLen * sizeof(char));
arg[nArgLen] = '\0';
- //RTMP_Log(RTMP_LOGDEBUG, "%s: unescaping parameter: %s", __FUNCTION__, arg);
+#if 0
+ RTMP_Log(RTMP_LOGDEBUG, "%s: unescaping parameter: %s",
+ __FUNCTION__, arg);
+#endif
http_unescape(arg);
RTMP_Log(RTMP_LOGDEBUG, "%s: parameter: %c, arg: %s", __FUNCTION__,
@@ -467,7 +476,8 @@
__FUNCTION__);
}
- // do necessary checks right here to make sure the combined request of default values and GET parameters is correct
+ /* Do necessary checks right here to make sure the combined request of
+ * default values and GET parameters is correct. */
if (!req.hostname.av_len)
{
RTMP_Log(RTMP_LOGERROR,
@@ -526,14 +536,14 @@
#endif
}
- // after validation of the http request send response header
+ /* after validation of the http request send response header */
len = sprintf(buf, "HTTP/1.0 200 OK%sContent-Type: video/flv\r\n\r\n", srvhead);
send(sockfd, buf, len, 0);
- // send the packets
+ /* send the packets */
buffer = (char *) calloc(PACKET_SIZE, 1);
- // User defined seek offset
+ /* User defined seek offset */
if (req.dStartOffset > 0)
{
if (req.bLiveStream)
@@ -586,14 +596,22 @@
{
RTMP_Log(RTMP_LOGERROR, "%s, sending failed, error: %d", __FUNCTION__,
GetSockError());
- goto cleanup; // we are in STREAMING_IN_PROGRESS, so we'll go to STREAMING_ACCEPTING
+ /* We are in STREAMING_IN_PROGRESS, so we'll go to
+ * STREAMING_ACCEPTING. */
+ goto cleanup;
}
size += nRead;
- //RTMP_LogPrintf("write %dbytes (%.1f KB)\n", nRead, nRead/1024.0);
- if (duration <= 0) // if duration unknown try to get it from the stream (onMetaData)
- duration = RTMP_GetDuration(&rtmp);
+#if 0
+ RTMP_LogPrintf("write %dbytes (%.1f KB)\n", nRead, nRead/1024.0);
+#endif
+ if (duration <= 0)
+ {
+ /* If duration unknown try to get it from the stream
+ * (onMetaData). */
+ duration = RTMP_GetDuration(&rtmp);
+ }
if (duration > 0)
{
@@ -663,7 +681,7 @@
if (sockfd > 0)
{
- // Create a new process and transfer the control to that
+ /* Create a new process and transfer the control to that */
RTMP_Log(RTMP_LOGDEBUG, "%s: accepted connection from %s\n", __FUNCTION__,
inet_ntoa(addr.sin_addr));
processTCPrequest(server, sockfd);
@@ -693,7 +711,7 @@
}
addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = inet_addr(address); //htonl(INADDR_ANY);
+ addr.sin_addr.s_addr = inet_addr(address); /* htonl(INADDR_ANY); */
addr.sin_port = htons(port);
if (bind(sockfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) ==
@@ -730,7 +748,7 @@
{
server->state = STREAMING_STOPPING;
- // wait for streaming threads to exit
+ /* wait for streaming threads to exit */
while (server->state != STREAMING_STOPPED)
msleep(1);
}
@@ -773,11 +791,12 @@
return l/2;
}
-// this will parse RTMP related options as needed
-// excludes the following options: h, d, g
-
-// Return values: true (option parsing ok)
-// false (option not parsed/invalid)
+/* The ParseOption function will parse RTMP related options as needed
+ * excludes the following options: h, d, g
+ *
+ * Return values: true (option parsing ok)
+ * false (option not parsed/invalid)
+ */
int
ParseOption(char opt, char *arg, RTMP_REQUEST * req)
{
@@ -845,7 +864,7 @@
break;
}
case 'v':
- req->bLiveStream = TRUE; // no seeking or resuming possible!
+ req->bLiveStream = TRUE; /* no seeking or resuming possible! */
break;
case 'd':
STR2AVAL(req->subscribepath, arg);
@@ -933,11 +952,15 @@
break;
case 'A':
req->dStartOffset = (int)(atof(arg) * 1000.0);
- //printf("dStartOffset = %d\n", dStartOffset);
+#if 0
+ printf("dStartOffset = %d\n", dStartOffset);
+#endif
break;
case 'B':
req->dStopOffset = (int)(atof(arg) * 1000.0);
- //printf("dStartOffset = %d\n", dStartOffset);
+#if 0
+ printf("dStartOffset = %d\n", dStartOffset);
+#endif
break;
case 'T':
STR2AVAL(req->token, arg);
@@ -965,23 +988,30 @@
{
int nStatus = RD_SUCCESS;
- // http streaming server
- char DEFAULT_HTTP_STREAMING_DEVICE[] = "0.0.0.0"; // 0.0.0.0 is any device
+ /* http streaming server */
+ /* 0.0.0.0 is any device */
+ char DEFAULT_HTTP_STREAMING_DEVICE[] = "0.0.0.0";
+
+ /* streaming device, default 0.0.0.0 */
+ char *httpStreamingDevice = DEFAULT_HTTP_STREAMING_DEVICE;
- char *httpStreamingDevice = DEFAULT_HTTP_STREAMING_DEVICE; // streaming device, default 0.0.0.0
- int nHttpStreamingPort = 80; // port
+ int nHttpStreamingPort = 80; /* port */
RTMP_LogPrintf("HTTP-RTMP Stream Gateway %s\n", RTMPDUMP_VERSION);
RTMP_LogPrintf("(c) 2010 Andrej Stepanchuk, Howard Chu; license: GPL\n\n");
- // init request
+ /* init request */
memset(&defaultRTMPRequest, 0, sizeof(RTMP_REQUEST));
defaultRTMPRequest.rtmpport = -1;
defaultRTMPRequest.protocol = RTMP_PROTOCOL_UNDEFINED;
- defaultRTMPRequest.bLiveStream = FALSE; // is it a live stream? then we can't seek/resume
- defaultRTMPRequest.timeout = 120; // timeout connection after 120 seconds
+ /* is it a live stream? then we can't seek/resume */
+ defaultRTMPRequest.bLiveStream = FALSE;
+
+ /* timeout connection after 120 seconds */
+ defaultRTMPRequest.timeout = 120;
+
defaultRTMPRequest.bufferTime = 20 * 1000;
defaultRTMPRequest.swfAge = 30;
@@ -1009,11 +1039,11 @@
{"conn", 1, NULL, 'C'},
{"flashVer", 1, NULL, 'f'},
{"live", 0, NULL, 'v'},
- //{"flv", 1, NULL, 'o'},
- //{"resume", 0, NULL, 'e'},
+ /* {"flv", 1, NULL, 'o'}, */
+ /* {"resume", 0, NULL, 'e'}, */
{"timeout", 1, NULL, 'm'},
{"buffer", 1, NULL, 'b'},
- //{"skip", 1, NULL, 'k'},
+ /* {"skip", 1, NULL, 'k'}, */
{"device", 1, NULL, 'D'},
{"sport", 1, NULL, 'g'},
{"subscribe", 1, NULL, 'd'},
@@ -1114,7 +1144,7 @@
RTMP_LogPrintf("packet.\n\n");
return RD_SUCCESS;
break;
- // streaming server specific options
+ /* streaming server specific options */
case 'D':
if (inet_addr(optarg) == INADDR_NONE)
{
@@ -1143,7 +1173,9 @@
break;
}
default:
- //RTMP_LogPrintf("unknown option: %c\n", opt);
+#if 0
+ RTMP_LogPrintf("unknown option: %c\n", opt);
+#endif
if (!ParseOption(opt, optarg, &defaultRTMPRequest))
return RD_FAILED;
break;
@@ -1155,12 +1187,12 @@
netstackdump_read = fopen("netstackdump_read", "wb");
#endif
- // start text UI
+ /* start text UI */
ThreadCreate(controlServerThread, 0);
- // start http streaming
- if ((httpServer =
- startStreaming(httpStreamingDevice, nHttpStreamingPort)) == 0)
+ /* start http streaming */
+ httpServer = startStreaming(httpStreamingDevice, nHttpStreamingPort);
+ if (httpServer == 0)
{
RTMP_Log(RTMP_LOGERROR, "Failed to start HTTP server, exiting!");
return RD_FAILED;
Index: rtmpsrv.c
--- rtmpsrv.c
+++ rtmpsrv.c
@@ -91,7 +91,7 @@
} STREAMING_SERVER;
-STREAMING_SERVER *rtmpServer = 0; // server structure pointer
+STREAMING_SERVER *rtmpServer = 0; /* server structure pointer */
STREAMING_SERVER *startStreaming(const char *address, int port);
void stopStreaming(STREAMING_SERVER * server);
@@ -101,9 +101,9 @@
char *hostname;
int rtmpport;
int protocol;
- int bLiveStream; // is it a live stream? then we can't seek/resume
+ int bLiveStream; /* is it a live stream? then we can't seek/resume */
- long int timeout; // timeout connection afte 300 seconds
+ long int timeout; /* timeout connection afte 300 seconds */
uint32_t bufferTime;
char *rtmpurl;
@@ -173,7 +173,7 @@
AMFObjectProperty p, op;
AVal av;
- packet.m_nChannel = 0x03; // control channel (invoke)
+ packet.m_nChannel = 0x03; /* control channel (invoke) */
packet.m_headerType = 1; /* RTMP_PACKET_SIZE_MEDIUM; */
packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
packet.m_nTimeStamp = 0;
@@ -234,7 +234,7 @@
RTMPPacket packet;
char pbuf[256], *pend = pbuf+sizeof(pbuf);
- packet.m_nChannel = 0x03; // control channel (invoke)
+ packet.m_nChannel = 0x03; /* control channel (invoke) */
packet.m_headerType = 1; /* RTMP_PACKET_SIZE_MEDIUM; */
packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
packet.m_nTimeStamp = 0;
@@ -268,7 +268,7 @@
RTMPPacket packet;
char pbuf[512], *pend = pbuf+sizeof(pbuf);
- packet.m_nChannel = 0x03; // control channel (invoke)
+ packet.m_nChannel = 0x03; /* control channel (invoke) */
packet.m_headerType = 1; /* RTMP_PACKET_SIZE_MEDIUM; */
packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
packet.m_nTimeStamp = 0;
@@ -300,7 +300,7 @@
RTMPPacket packet;
char pbuf[512], *pend = pbuf+sizeof(pbuf);
- packet.m_nChannel = 0x03; // control channel (invoke)
+ packet.m_nChannel = 0x03; /* control channel (invoke) */
packet.m_headerType = 1; /* RTMP_PACKET_SIZE_MEDIUM; */
packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
packet.m_nTimeStamp = 0;
@@ -456,7 +456,7 @@
return ptr;
}
-// Returns 0 for OK/Failed/error, 1 for 'Stop or Complete'
+/* Returns 0 for OK/Failed/error, 1 for 'Stop or Complete' */
int
ServeInvoke(STREAMING_SERVER *server, RTMP * r, RTMPPacket *packet, unsigned int offset)
{
@@ -467,7 +467,7 @@
body = packet->m_body + offset;
nBodySize = packet->m_nBodySize - offset;
- if (body[0] != 0x02) // make sure it is a string method name we start with
+ if (body[0] != 0x02) /* make sure it is a string method name we start with */
{
RTMP_Log(RTMP_LOGWARNING, "%s, Sanity failed. no string method in invoke packet",
__FUNCTION__);
@@ -745,90 +745,116 @@
switch (packet->m_packetType)
{
- case 0x01:
- // chunk size
-// HandleChangeChunkSize(r, packet);
+ case RTMP_PACKET_TYPE_CHUNK_SIZE:
+ /* chunk size */
+#if 0
+ HandleChangeChunkSize(r, packet);
+#endif
break;
- case 0x03:
- // bytes read report
+ case RTMP_PACKET_TYPE_BYTES_READ_REPORT:
+ /* bytes read report */
break;
- case 0x04:
- // ctrl
-// HandleCtrl(r, packet);
+ case RTMP_PACKET_TYPE_CONTROL:
+ /* ctrl */
+#if 0
+ HandleCtrl(r, packet);
+#endif
break;
- case 0x05:
- // server bw
-// HandleServerBW(r, packet);
+ case RTMP_PACKET_TYPE_SERVER_BW:
+ /* server bw */
+#if 0
+ HandleServerBW(r, packet);
+#endif
break;
- case 0x06:
- // client bw
- // HandleClientBW(r, packet);
+ case RTMP_PACKET_TYPE_CLIENT_BW:
+ /* client bw */
+#if 0
+ HandleClientBW(r, packet);
+#endif
break;
- case 0x08:
- // audio data
- //RTMP_Log(RTMP_LOGDEBUG, "%s, received: audio %lu bytes", __FUNCTION__, packet.m_nBodySize);
+ case RTMP_PACKET_TYPE_AUDIO:
+ /* audio data */
+#if 0
+ RTMP_Log(RTMP_LOGDEBUG, "%s, received: audio %lu bytes", __FUNCTION__,
+ packet.m_nBodySize);
+#endif
break;
- case 0x09:
- // video data
- //RTMP_Log(RTMP_LOGDEBUG, "%s, received: video %lu bytes", __FUNCTION__, packet.m_nBodySize);
+ case RTMP_PACKET_TYPE_VIDEO:
+ /* video data */
+#if 0
+ RTMP_Log(RTMP_LOGDEBUG, "%s, received: video %lu bytes", __FUNCTION__,
+ packet.m_nBodySize);
+#endif
break;
- case 0x0F: // flex stream send
+ case RTMP_PACKET_TYPE_FLEX_STREAM_SEND:
+ /* flex stream send */
break;
- case 0x10: // flex shared object
+ case RTMP_PACKET_TYPE_FLEX_SHARED_OBJECT:
+ /* flex shared object */
break;
- case 0x11: // flex message
+ case RTMP_PACKET_TYPE_FLEX_MESSAGE:
+ /* flex message */
{
- RTMP_Log(RTMP_LOGDEBUG, "%s, flex message, size %lu bytes, not fully supported",
- __FUNCTION__, packet->m_nBodySize);
- //RTMP_LogHex(packet.m_body, packet.m_nBodySize);
-
- // some DEBUG code
- /*RTMP_LIB_AMFObject obj;
- int nRes = obj.Decode(packet.m_body+1, packet.m_nBodySize-1);
- if(nRes < 0) {
- RTMP_Log(RTMP_LOGERROR, "%s, error decoding AMF3 packet", __FUNCTION__);
- //return;
- }
+ RTMP_Log(RTMP_LOGDEBUG,
+ "%s, flex message, size %lu bytes, not fully supported",
+ __FUNCTION__, packet->m_nBodySize);
+#if 0
+ RTMP_LogHex(packet.m_body, packet.m_nBodySize);
+#endif
- obj.Dump(); */
+ /* some DEBUG code */
+#if 0
+ RTMP_LIB_AMFObject obj;
+ int nRes = obj.Decode(packet.m_body+1, packet.m_nBodySize-1);
+ if (nRes < 0)
+ {
+ RTMP_Log(RTMP_LOGERROR, "%s, error decoding AMF3 packet",
+ __FUNCTION__);
+ return;
+ }
+ obj.Dump();
+#endif
if (ServeInvoke(server, r, packet, 1))
RTMP_Close(r);
break;
}
- case 0x12:
- // metadata (notify)
+
+ case RTMP_PACKET_TYPE_INFO:
+ /* metadata (notify) */
break;
- case 0x13:
+ case RTMP_PACKET_TYPE_SHARED_OBJECT:
/* shared object */
break;
- case 0x14:
- // invoke
+ case RTMP_PACKET_TYPE_INVOKE:
+ /* invoke */
RTMP_Log(RTMP_LOGDEBUG, "%s, received: invoke %lu bytes", __FUNCTION__,
- packet->m_nBodySize);
- //RTMP_LogHex(packet.m_body, packet.m_nBodySize);
-
+ packet->m_nBodySize);
+#if 0
+ RTMP_LogHex(packet.m_body, packet.m_nBodySize);
+#endif
if (ServeInvoke(server, r, packet, 0))
RTMP_Close(r);
break;
- case 0x16:
+ case RTMP_PACKET_TYPE_FLASH_VIDEO:
/* flv */
- break;
+ break;
+
default:
- RTMP_Log(RTMP_LOGDEBUG, "%s, unknown packet type received: 0x%02x", __FUNCTION__,
- packet->m_packetType);
+ RTMP_Log(RTMP_LOGDEBUG, "%s, unknown packet type received: 0x%02x",
+ __FUNCTION__, packet->m_packetType);
#ifdef _DEBUG
RTMP_LogHex(RTMP_LOGDEBUG, packet->m_body, packet->m_nBodySize);
#endif
@@ -858,16 +884,17 @@
}
-void doServe(STREAMING_SERVER * server, // server socket and state (our listening socket)
- int sockfd // client connection socket
- )
+void
+doServe(STREAMING_SERVER *server, /* server socket and state (our listening
+ * socket) */
+ int sockfd) /* client connection socket */
{
server->state = STREAMING_IN_PROGRESS;
RTMP rtmp = { 0 }; /* our session with the real client */
RTMPPacket packet = { 0 };
- // timeout for http requests
+ /* timeout for http requests */
fd_set fds;
struct timeval tv;
@@ -979,7 +1006,7 @@
(char *) &tmp, sizeof(tmp) );
addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = inet_addr(address); //htonl(INADDR_ANY);
+ addr.sin_addr.s_addr = inet_addr(address); /* htonl(INADDR_ANY); */
addr.sin_port = htons(port);
if (bind(sockfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) ==
@@ -1016,7 +1043,7 @@
{
server->state = STREAMING_STOPPING;
- // wait for streaming threads to exit
+ /* wait for streaming threads to exit */
while (server->state != STREAMING_STOPPED)
msleep(1);
}
@@ -1045,11 +1072,14 @@
{
int nStatus = RD_SUCCESS;
- // http streaming server
- char DEFAULT_HTTP_STREAMING_DEVICE[] = "0.0.0.0"; // 0.0.0.0 is any device
+ /* http streaming server */
+ /* 0.0.0.0 is any device */
+ char DEFAULT_HTTP_STREAMING_DEVICE[] = "0.0.0.0";
- char *rtmpStreamingDevice = DEFAULT_HTTP_STREAMING_DEVICE; // streaming device, default 0.0.0.0
- int nRtmpStreamingPort = 1935; // port
+ /* streaming device, default 0.0.0.0 */
+ char *rtmpStreamingDevice = DEFAULT_HTTP_STREAMING_DEVICE;
+
+ int nRtmpStreamingPort = 1935; /* port */
RTMP_LogPrintf("RTMP Server %s\n", RTMPDUMP_VERSION);
RTMP_LogPrintf("(c) 2010 Andrej Stepanchuk, Howard Chu; license: GPL\n\n");
@@ -1059,14 +1089,18 @@
if (argc > 1 && !strcmp(argv[1], "-z"))
RTMP_debuglevel = RTMP_LOGALL;
- // init request
+ /* init request */
memset(&defaultRTMPRequest, 0, sizeof(RTMP_REQUEST));
defaultRTMPRequest.rtmpport = -1;
defaultRTMPRequest.protocol = RTMP_PROTOCOL_UNDEFINED;
- defaultRTMPRequest.bLiveStream = FALSE; // is it a live stream? then we can't seek/resume
- defaultRTMPRequest.timeout = 300; // timeout connection afte 300 seconds
+ /* is it a live stream? then we can't seek/resume */
+ defaultRTMPRequest.bLiveStream = FALSE;
+
+ /* timeout connection afte 300 seconds */
+ defaultRTMPRequest.timeout = 300;
+
defaultRTMPRequest.bufferTime = 20 * 1000;
@@ -1082,12 +1116,12 @@
InitSockets();
- // start text UI
+ /* start text UI */
ThreadCreate(controlServerThread, 0);
- // start http streaming
- if ((rtmpServer =
- startStreaming(rtmpStreamingDevice, nRtmpStreamingPort)) == 0)
+ /* start http streaming */
+ rtmpServer = startStreaming(rtmpStreamingDevice, nRtmpStreamingPort);
+ if (rtmpServer == 0)
{
RTMP_Log(RTMP_LOGERROR, "Failed to start RTMP server, exiting!");
return RD_FAILED;
Index: rtmpsuck.c
--- rtmpsuck.c
+++ rtmpsuck.c
@@ -98,7 +98,7 @@
} STREAMING_SERVER;
-STREAMING_SERVER *rtmpServer = 0; // server structure pointer
+STREAMING_SERVER *rtmpServer = 0; /* server structure pointer */
STREAMING_SERVER *startStreaming(const char *address, int port);
void stopStreaming(STREAMING_SERVER * server);
@@ -153,7 +153,7 @@
static const char *cst[] = { "client", "server" };
-// Returns 0 for OK/Failed/error, 1 for 'Stop or Complete'
+/* Returns 0 for OK/Failed/error, 1 for 'Stop or Complete' */
int
ServeInvoke(STREAMING_SERVER *server, int which, RTMPPacket *pack, const char *body)
{
@@ -163,7 +163,8 @@
if (body > pack->m_body)
nBodySize--;
- if (body[0] != 0x02) // make sure it is a string method name we start with
+ /* make sure it is a string method name we start with */
+ if (body[0] != 0x02)
{
RTMP_Log(RTMP_LOGWARNING, "%s, Sanity failed. no string method in invoke packet",
__FUNCTION__);
@@ -311,9 +312,9 @@
FILE *out;
char *file, *p, *q;
char flvHeader[] = { 'F', 'L', 'V', 0x01,
- 0x05, // video + audio, we finalize later if the value is different
+ 0x05, /* video + audio, we finalize later if the value is different */
0x00, 0x00, 0x00, 0x09,
- 0x00, 0x00, 0x00, 0x00 // first prevTagSize=0
+ 0x00, 0x00, 0x00, 0x00 /* first prevTagSize=0 */
};
int count = 0, flen;
@@ -430,7 +431,7 @@
server->rc.m_bPlaying = TRUE;
}
- // Return 1 if this is a Play.Complete or Play.Stop
+ /* Return 1 if this is a Play.Complete or Play.Stop */
if (AVMATCH(&code, &av_NetStream_Play_Complete)
|| AVMATCH(&code, &av_NetStream_Play_Stop))
{
@@ -462,55 +463,69 @@
switch (packet->m_packetType)
{
case RTMP_PACKET_TYPE_CHUNK_SIZE:
- // chunk size
-// HandleChangeChunkSize(r, packet);
+ /* chunk size */
+#if 0
+ HandleChangeChunkSize(r, packet);
+#endif
break;
case RTMP_PACKET_TYPE_BYTES_READ_REPORT:
- // bytes read report
+ /* bytes read report */
break;
case RTMP_PACKET_TYPE_CONTROL:
- // ctrl
-// HandleCtrl(r, packet);
+ /* ctrl */
+#if 0
+ HandleCtrl(r, packet);
+#endif
break;
case RTMP_PACKET_TYPE_SERVER_BW:
- // server bw
-// HandleServerBW(r, packet);
+ /* server bw */
+#if 0
+ HandleServerBW(r, packet);
+#endif
break;
case RTMP_PACKET_TYPE_CLIENT_BW:
- // client bw
- // HandleClientBW(r, packet);
+ /* client bw */
+#if 0
+ HandleClientBW(r, packet);
+#endif
break;
case RTMP_PACKET_TYPE_AUDIO:
- // audio data
- //RTMP_Log(RTMP_LOGDEBUG, "%s, received: audio %lu bytes", __FUNCTION__, packet.m_nBodySize);
+ /* audio data */
+#if 0
+ RTMP_Log(RTMP_LOGDEBUG, "%s, received: audio %lu bytes", __FUNCTION__,
+ packet.m_nBodySize);
+#endif
break;
case RTMP_PACKET_TYPE_VIDEO:
- // video data
- //RTMP_Log(RTMP_LOGDEBUG, "%s, received: video %lu bytes", __FUNCTION__, packet.m_nBodySize);
+ /* video data */
+#if 0
+ RTMP_Log(RTMP_LOGDEBUG, "%s, received: video %lu bytes", __FUNCTION__,
+ packet.m_nBodySize);
+#endif
break;
case RTMP_PACKET_TYPE_FLEX_STREAM_SEND:
- // flex stream send
+ /* flex stream send */
break;
case RTMP_PACKET_TYPE_FLEX_SHARED_OBJECT:
- // flex shared object
+ /* flex shared object */
break;
case RTMP_PACKET_TYPE_FLEX_MESSAGE:
- // flex message
+ /* flex message */
{
ret = ServeInvoke(server, which, packet, packet->m_body + 1);
break;
}
case RTMP_PACKET_TYPE_INFO:
- // metadata (notify)
+ /* metadata (notify) */
break;
case RTMP_PACKET_TYPE_SHARED_OBJECT:
@@ -518,17 +533,17 @@
break;
case RTMP_PACKET_TYPE_INVOKE:
- // invoke
+ /* invoke */
ret = ServeInvoke(server, which, packet, packet->m_body);
break;
case RTMP_PACKET_TYPE_FLASH_VIDEO:
/* flv */
- break;
+ break;
default:
- RTMP_Log(RTMP_LOGDEBUG, "%s, unknown packet type received: 0x%02x", __FUNCTION__,
- packet->m_packetType);
+ RTMP_Log(RTMP_LOGDEBUG, "%s, unknown packet type received: 0x%02x",
+ __FUNCTION__, packet->m_packetType);
#ifdef _DEBUG
RTMP_LogHex(RTMP_LOGDEBUG, packet->m_body, packet->m_nBodySize);
#endif
@@ -537,8 +552,8 @@
}
int
-WriteStream(char **buf, // target pointer, maybe preallocated
- unsigned int *plen, // length of buffer if preallocated
+WriteStream(char **buf, /* target pointer, maybe preallocated */
+ unsigned int *plen, /* length of buffer if preallocated */
uint32_t *nTimeStamp,
RTMPPacket *packet)
{
@@ -550,7 +565,7 @@
char *packetBody = packet->m_body;
unsigned int nPacketLen = packet->m_nBodySize;
- // skip video info/command packets
+ /* skip video info/command packets */
if (packet->m_packetType == RTMP_PACKET_TYPE_VIDEO &&
nPacketLen == 2 && ((*packetBody & 0xf0) == 0x50))
{
@@ -579,7 +594,7 @@
RTMP_Log(RTMP_LOGDEBUG, "frametype: %02X", (*packetBody & 0xf0));
#endif
- // calculate packet size and reallocate buffer if necessary
+ /* calculate packet size and reallocate buffer if necessary */
unsigned int size = nPacketLen
+
((packet->m_packetType == RTMP_PACKET_TYPE_AUDIO
@@ -595,7 +610,7 @@
if (*buf == 0)
{
RTMP_Log(RTMP_LOGERROR, "Couldn't reallocate memory!");
- ret = -1; // fatal error
+ ret = -1; /* fatal error */
break;
}
}
@@ -608,8 +623,11 @@
|| packet->m_packetType == RTMP_PACKET_TYPE_VIDEO
|| packet->m_packetType == RTMP_PACKET_TYPE_INFO)
{
- // set data type
- //*dataType |= (((packet->m_packetType == RTMP_PACKET_TYPE_AUDIO)<<2)|(packet->m_packetType == RTMP_PACKET_TYPE_VIDEO));
+ /* set data type */
+#if 0
+ *dataType |= (((packet->m_packetType == RTMP_PACKET_TYPE_AUDIO) << 2)
+ | (packet->m_packetType == RTMP_PACKET_TYPE_VIDEO));
+#endif
(*nTimeStamp) = packet->m_nTimeStamp;
prevTagSize = 11 + nPacketLen;
@@ -620,21 +638,22 @@
*ptr = (char) (((*nTimeStamp) & 0xFF000000) >> 24);
ptr++;
- // stream id
+ /* stream id */
ptr = AMF_EncodeInt24(ptr, pend, 0);
}
memcpy(ptr, packetBody, nPacketLen);
unsigned int len = nPacketLen;
- // correct tagSize and obtain timestamp if we have an FLV stream
+ /* correct tagSize and obtain timestamp if we have an FLV stream */
if (packet->m_packetType == RTMP_PACKET_TYPE_FLASH_VIDEO)
{
unsigned int pos = 0;
while (pos + 11 < nPacketLen)
{
- uint32_t dataSize = AMF_DecodeInt24(packetBody + pos + 1); // size without header (11) and without prevTagSize (4)
+ /* size without header (11) and without prevTagSize (4) */
+ uint32_t dataSize = AMF_DecodeInt24(packetBody + pos + 1);
*nTimeStamp = AMF_DecodeInt24(packetBody + pos + 4);
*nTimeStamp |= (packetBody[pos + 7] << 24);
@@ -656,7 +675,7 @@
}
RTMP_Log(RTMP_LOGWARNING, "No tagSize found, appending!");
- // we have to append a last tagSize!
+ /* we have to append a last tagSize! */
prevTagSize = dataSize + 11;
AMF_EncodeInt32(ptr + pos + 11 + dataSize, pend, prevTagSize);
size += 4;
@@ -687,15 +706,18 @@
}
}
- pos += prevTagSize + 4; //(11+dataSize+4);
+ pos += prevTagSize + 4; /* (11 + dataSize + 4) */
}
}
ptr += len;
if (packet->m_packetType != RTMP_PACKET_TYPE_FLASH_VIDEO)
- { // FLV tag packets contain their own prevTagSize
+ {
+ /* FLV tag packets contain their own prevTagSize */
AMF_EncodeInt32(ptr, pend, prevTagSize);
- //ptr += 4;
+#if 0
+ ptr += 4;
+#endif
}
ret = size;
@@ -705,7 +727,7 @@
if (len > *plen)
*plen = len;
- return ret; // no more media packets
+ return ret; /* no more media packets */
}
TFTYPE
@@ -730,7 +752,8 @@
TFRET();
}
-TFTYPE doServe(void *arg) // server socket and state (our listening socket)
+TFTYPE
+doServe(void *arg) /* server socket and state (our listening socket) */
{
STREAMING_SERVER *server = arg;
RTMPPacket pc = { 0 }, ps = { 0 };
@@ -740,7 +763,7 @@
int paused = FALSE;
int sockfd = server->socket;
- // timeout for http requests
+ /* timeout for http requests */
fd_set rfds;
struct timeval tv;
@@ -1071,7 +1094,7 @@
(char *) &tmp, sizeof(tmp) );
addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = inet_addr(address); //htonl(INADDR_ANY);
+ addr.sin_addr.s_addr = inet_addr(address); /* htonl(INADDR_ANY); */
addr.sin_port = htons(port);
if (bind(sockfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) ==
@@ -1110,7 +1133,7 @@
{
server->state = STREAMING_STOPPING;
- // wait for streaming threads to exit
+ /* wait for streaming threads to exit */
while (server->state != STREAMING_STOPPED)
msleep(1);
}
@@ -1139,11 +1162,14 @@
{
int nStatus = RD_SUCCESS;
- // rtmp streaming server
- char DEFAULT_RTMP_STREAMING_DEVICE[] = "0.0.0.0"; // 0.0.0.0 is any device
+ /* rtmp streaming server */
+ /* 0.0.0.0 is any device */
+ char DEFAULT_RTMP_STREAMING_DEVICE[] = "0.0.0.0";
+
+ /* streaming device, default 0.0.0.0 */
+ char *rtmpStreamingDevice = DEFAULT_RTMP_STREAMING_DEVICE;
- char *rtmpStreamingDevice = DEFAULT_RTMP_STREAMING_DEVICE; // streaming device, default 0.0.0.0
- int nRtmpStreamingPort = 1935; // port
+ int nRtmpStreamingPort = 1935; /* port */
RTMP_LogPrintf("RTMP Proxy Server %s\n", RTMPDUMP_VERSION);
RTMP_LogPrintf("(c) 2010 Andrej Stepanchuk, Howard Chu; license: GPL\n\n");
@@ -1165,10 +1191,10 @@
InitSockets();
- // start text UI
+ /* start text UI */
ThreadCreate(controlServerThread, 0);
- // start http streaming
+ /* start http streaming */
if ((rtmpServer =
startStreaming(rtmpStreamingDevice, nRtmpStreamingPort)) == 0)
{
More information about the rtmpdump
mailing list