<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
code
        {mso-style-priority:99;
        font-family:"Courier New";}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.vote-count-post
        {mso-style-name:vote-count-post;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Courier New";}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">                Dear rtmpdump <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">                Could you help to fix the following issu.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" style="background:white;border-collapse:collapse">
<tbody>
<tr>
<td width="60" valign="top" style="width:45.0pt;background:transparent;padding:0in 0in 0in 0in">
<p class="MsoNormal" align="center" style="text-align:center;mso-line-height-alt:9.0pt;vertical-align:baseline">
<b><span style="font-size:23.5pt;font-family:"Arial","sans-serif";color:#808185;border:none windowtext 1.0pt;padding:0in"><br>
<br>
</span></b><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:black"><o:p></o:p></span></p>
</td>
<td valign="bottom" style="background:transparent;padding:0in 0in 0in 0in;background-position:initial initial;background-repeat:initial initial">
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;line-height:13.5pt;vertical-align:baseline;word-wrap: break-word;background-position:initial initial;background-repeat:initial initial">
<span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:black">I'm trying to use the librtmp library and it worked pretty well to pull a stream. But now I am trying to publish a stream and for that I believe I have to use the RTMP_Write function.<o:p></o:p></span></p>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;line-height:13.5pt;vertical-align:baseline;word-wrap: break-word;background-position:initial initial;background-repeat:initial initial">
<span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:black">What I am trying to accomplish here is a simple c++ program that will read from a file and try to push the stream to a crtmp server. The connection and stream creation is ok, but I'm
 quite puzzled by the use of RTMP_Write.<o:p></o:p></span></p>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;line-height:13.5pt;vertical-align:baseline;word-wrap: break-word;background-position:initial initial;background-repeat:initial initial">
<span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:black">Here is what I did:<o:p></o:p></span></p>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline;max-height: 600px;background-position:initial initial;background-repeat:initial initial;overflow:auto"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">int Upload(RTMP * rtmp, FILE * file){<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">        int nRead = 0;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">        unsigned int nWrite = 0;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">        int diff = 0;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">        int bufferSize = 64 * 1024;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">        int byteSum = 0;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">        int count  = 0;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">        char * buffer;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">        buffer = (char *) malloc(bufferSize);<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">        do{<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                nRead = fread(buffer+diff,1,bufferSize-diff,file);<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                if(nRead != bufferSize){<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                        if(feof(file)){<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                                RTMP_LogPrintf("End of file reached!\n");<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                                break;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                        }else if(ferror(file)){<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                                RTMP_LogPrintf("Error reading from file stream detected\n");<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                                break;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                        }<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                }<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                count += 1;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                byteSum += nRead;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                RTMP_LogPrintf("Read %d from file, Sum: %d, Count: %d\n",nRead,byteSum,count);<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                nWrite = RTMP_Write(rtmp,buffer,nRead);<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                if(nWrite != nRead){<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                        diff  = nRead - nWrite;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                        memcpy(buffer,(const void*)(buffer+bufferSize-diff),diff);<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">                }<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">        }while(!RTMP_ctrlC && RTMP_IsConnected(rtmp) && !RTMP_IsTimedout(rtmp));<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">        free(buffer);<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">        return RD_SUCCESS;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">}<o:p></o:p></span></code></pre>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;line-height:13.5pt;vertical-align:baseline;word-wrap: break-word;background-position:initial initial;background-repeat:initial initial">
<span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:black">In this Upload function I am receiving the already initiallized RTMP structure and a pointer to an open file.<o:p></o:p></span></p>
<p style="margin:0in;margin-bottom:.0001pt;line-height:13.5pt;vertical-align:baseline;word-wrap: break-word;background-position:initial initial;background-repeat:initial initial">
<span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:black">This actually works and I can see some video being displayed, but it soon gets lost and stops sending packages. I managed to understand that it happens whenever the buffer that I setup
 (and which I randomly required to be 64k, no special reason for that) happens to split the flv tag (<a href="http://osflash.org/flv#flv_format"><span style="color:#4A6B82;border:none windowtext 1.0pt;padding:0in;text-decoration:none">http://osflash.org/flv#flv_format</span></a>)
 of a new package.<o:p></o:p></span></p>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;line-height:13.5pt;vertical-align:baseline;word-wrap: break-word;background-position:initial initial;background-repeat:initial initial">
<span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:black">For that I modified the RTMP_Write function and told it to verify if it will be able to decode the whole flv tag (packet type, body size, timestamp, etc..) and if it will not, then
 it should just return the amount of useful bytes left in the buffer.<o:p></o:p></span></p>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline;max-height: 600px;background-position:initial initial;background-repeat:initial initial;overflow:auto"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">  if(s2 - 11 <= 0){<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">      rest = size - s2;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">      return rest;<o:p></o:p></span></code></pre>
<pre style="line-height:13.5pt;background:#EEEEEE;vertical-align:baseline"><code><span style="font-size:10.5pt;font-family:Consolas;color:black;border:none windowtext 1.0pt;padding:0in;background:#EEEEEE">  }<o:p></o:p></span></code></pre>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;line-height:13.5pt;vertical-align:baseline;word-wrap: break-word;background-position:initial initial;background-repeat:initial initial">
<span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:black">The code above takes notice of this, and if the value returned by RTMP_Write is not the amount of bytes it was supposed to send, then it knows that value is the amount of useful bytes
 left in the buffer. I then copy these bytes to the beginning of the buffer and read more from the file.<o:p></o:p></span></p>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;line-height:13.5pt;vertical-align:baseline;word-wrap: break-word;background-position:initial initial;background-repeat:initial initial">
<span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:black">But I keep getting problems with it, so I was wondering: what is the correct use of this function anyway? is there a specific buffer value that I should be using? (don't think so) or
 is it buggy by itself?<o:p></o:p></span></p>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;line-height:13.5pt;vertical-align:baseline;word-wrap: break-word;background-position:initial initial;background-repeat:initial initial">
<span style="font-size:10.5pt;font-family:"Arial","sans-serif";color:black">Thanks<o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>