<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'><span style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);">Hi</span><br style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"><span style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"> </span><br style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"><span style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);">I am trying to setup live555 to stream rtsp with an ondemandserver from a microphone, but I am not sure how to do so. I have attempted to do this by overriding OnDemandServerMediaSubsession and FramedSource, but I am running into issues where I hear a bit of sound for half a second and then quiet, in VLC the Messages say "buffer arrived way too early"...</span><br style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"><span style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"> </span><br style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"><span style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);">I am encoding using ffmpeg to encode the audio as mp2.</span><br style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"><span style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"> </span><br style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"><span style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);">I have attached what I am doing here:</span><div><span style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"><br></span></div><div><pre lang="c++" id="pre0" style="padding: 6px; font-size: 9pt; font-family: Consolas, 'Courier New', Courier, mono; white-space: pre-wrap; border: 1px solid rgb(251, 237, 187); word-wrap: break-word; margin-top: 0px; overflow: auto !important; background-color: rgb(251, 237, 187);">#ifndef _FRAMED_SOURCE_HH
<span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;">#include</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;"> <span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">"</span><span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">FramedSource.hh"</span>
</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;">#include</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;"> <span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">"</span><span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">ImageTransfer.h"</span>
</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;">#endif</span>
 
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">class</span> MP2DeviceSource : <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">public</span> FramedSource {
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">public</span>:
        <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">static</span> MP2DeviceSource* createNew(UsageEnvironment& env, <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">unsigned</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">int</span> stream_id,
                                                AudioTransfer * audioTransfer);
 
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">public</span>:
        EventTriggerId eventTriggerId;
 
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">protected</span>:
        MP2DeviceSource(UsageEnvironment& env,
                                ImageTransfer * imageTransfer );
        <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">virtual</span> ~MP2DeviceSource();
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">private</span>:
        <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">virtual</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">void</span> doGetNextFrame();
 
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">private</span>:
        <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">static</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">void</span> deliverFrame0(<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">void</span>* clientData);
        <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">void</span> deliverFrame();
 
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">private</span>:
        
        AudioTransfer * audioTx;
 
};
</pre><span style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"> </span><br style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"><br style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"><div class="pre-action-link" id="premain1" width="100%" style="margin: 0px; padding: 0px; border-width: 0px 0px 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-size: 11px; text-align: right; color: rgb(0, 87, 130); font-family: 'Segoe UI', Arial, sans-serif; background-color: rgb(255, 255, 255);"><img id="preimg1" src="http://www.codeproject.com/images/minus.gif" height="9" width="9" preid="1" style="margin: 0px; padding: 0px; border: 0px; cursor: pointer;"><span id="precollapse1" preid="1" style="margin: 0px; padding: 0px; border: 0px; cursor: pointer;"> Collapse</span><span style="margin: 0px; padding: 0px; border: 0px;"> | </span><a href="http://www.codeproject.com/Questions/809366/Creating-a-livesource-audio-class-for-live?arn=0#" preid="1" style="margin: 0px; padding: 0px; border: 0px; text-decoration: none; color: purple;">Copy Code</a></div><pre lang="c++" id="pre1" style="padding: 6px; font-size: 9pt; font-family: Consolas, 'Courier New', Courier, mono; white-space: pre-wrap; border: 1px solid rgb(251, 237, 187); word-wrap: break-word; margin-top: 0px; overflow: auto !important; background-color: rgb(251, 237, 187);"><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;">#include</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;"> <span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">"</span><span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">MP2DeviceSource.h"</span>
</span>
MP2DeviceSource* 
MP2DeviceSource::createNew(UsageEnvironment& env, <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">unsigned</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">int</span> stream_id,
                                AudioTransfer * audioTransfer)
{
        <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">return</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">new</span> MaxMP2DeviceSource(env, audioTransfer);
}
 
MP2DeviceSource::MP2DeviceSource(UsageEnvironment& env, AudioTransfer * audioTransfer) 
        : FramedSource(env), audioTx(audioTransfer)
{
        <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">if</span> (eventTriggerId == <span class="code-digit" style="margin: 0px; padding: 0px; border: 0px; color: navy;">0</span>)
                eventTriggerId = envir().taskScheduler().createEventTrigger(deliverFrame0);
}
 
MP2DeviceSource::~MP2DeviceSource()
{
        envir().taskScheduler().deleteEventTrigger(eventTriggerId);
        eventTriggerId = <span class="code-digit" style="margin: 0px; padding: 0px; border: 0px; color: navy;">0</span>;
}
 
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">void</span> MP2DeviceSource::doGetNextFrame()
{
        deliverFrame();
}
 
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">void</span> MP2DeviceSource::deliverFrame0(<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">void</span> *clientData)
{
        ((MP2DeviceSource*)clientData)->deliverFrame();
}
 
   <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">static</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">const</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">unsigned</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">__int64</span> epoch = <span class="code-digit" style="margin: 0px; padding: 0px; border: 0px; color: navy;">116444736000000000</span>;
   <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">int</span>
   gettimeofday(<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">struct</span> timeval * tp, <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">struct</span> timezone * tzp)
   {
       FILETIME    file_time;
       SYSTEMTIME  system_time;
       ULARGE_INTEGER ularge;
   
       GetSystemTime(&system_time);
       SystemTimeToFileTime(&system_time, &file_time);
       ularge.LowPart = file_time.dwLowDateTime;
       ularge.HighPart = file_time.dwHighDateTime;
   
       tp->tv_sec = (<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">long</span>) ((ularge.QuadPart - epoch) / 10000000L);
       tp->tv_usec = (<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">long</span>) (system_time.wMilliseconds * <span class="code-digit" style="margin: 0px; padding: 0px; border: 0px; color: navy;">1000</span>);
   
       <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">return</span> <span class="code-digit" style="margin: 0px; padding: 0px; border: 0px; color: navy;">0</span>;
  }
 

<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">void</span> MP2DeviceSource::deliverFrame()
{
 
gettimeofday(&fPresentationTime, NULL);
 
    audioTx->GetMP2Image( &fTo, &fFrameSize );
    fDurationInMicroseconds = <span class="code-digit" style="margin: 0px; padding: 0px; border: 0px; color: navy;">26000</span>;
        
        FramedSource::afterGetting(<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">this</span>);
}
</pre><span style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"> </span><br style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"><br style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"><div class="pre-action-link" id="premain2" width="100%" style="margin: 0px; padding: 0px; border-width: 0px 0px 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-size: 11px; text-align: right; color: rgb(0, 87, 130); font-family: 'Segoe UI', Arial, sans-serif; background-color: rgb(255, 255, 255);"><img id="preimg2" src="http://www.codeproject.com/images/minus.gif" height="9" width="9" preid="2" style="margin: 0px; padding: 0px; border: 0px; cursor: pointer;"><span id="precollapse2" preid="2" style="margin: 0px; padding: 0px; border: 0px; cursor: pointer;"> Collapse</span><span style="margin: 0px; padding: 0px; border: 0px;"> | </span><a href="http://www.codeproject.com/Questions/809366/Creating-a-livesource-audio-class-for-live?arn=0#" preid="2" style="margin: 0px; padding: 0px; border: 0px; text-decoration: none; color: purple;">Copy Code</a></div><pre lang="c++" id="pre2" style="padding: 6px; font-size: 9pt; font-family: Consolas, 'Courier New', Courier, mono; white-space: pre-wrap; border: 1px solid rgb(251, 237, 187); word-wrap: break-word; margin-top: 0px; overflow: auto !important; background-color: rgb(251, 237, 187);">#ifndef _ON_DEMAND_SERVER_MEDIA_SUBSESSION_HH
<span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;">#include</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;"> <span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">"</span><span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">OnDemandServerMediaSubsession.hh"</span>
</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;">#endif</span>
 
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">class</span> MP2AudioMediaSubsession: <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">public</span> OnDemandServerMediaSubsession {
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">public</span>:
   <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">static</span> MP2AudioMediaSubsession* createNew(UsageEnvironment& evn, 
                                                <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">unsigned</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">int</span> sid, 
                                                <span class="code-sdkkeyword" style="margin: 0px; padding: 0px; border: 0px; color: rgb(51, 153, 153);">Boolean</span> requestFirstSource,
                                                AudioTransfer * audioTransfer);
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">protected</span>:
   MP2AudioMediaSubsession(UsageEnvironment& env, 
                           <span class="code-sdkkeyword" style="margin: 0px; padding: 0px; border: 0px; color: rgb(51, 153, 153);">Boolean</span> reuseFirstSource, 
                           AudioTransfer * audioTransfer);
 
   <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">virtual</span> ~MP2AudioMediaSubsession();
 
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">protected</span>:
   <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">virtual</span> FramedSource* createNewStreamSource(<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">unsigned</span> clientSessionId,            
                                                unsigned& estBitrate);
 
   <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">virtual</span> RTPSink* createNewRTPSink(Groupsock* rtpGroupSock, 
                                     <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">unsigned</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">char</span> rtpPayloadTypeIfDynamic, 
                                     FramedSource* inputSource);
 
<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">protected</span>:
  <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">unsigned</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">int</span> id;
  AudioTransfer * audioTx;
};
</pre><span style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"> </span><br style="color: rgb(17, 17, 17); font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);"><div class="pre-action-link" id="premain3" width="100%" style="margin: 0px; padding: 0px; border-width: 0px 0px 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-size: 11px; text-align: right; color: rgb(0, 87, 130); font-family: 'Segoe UI', Arial, sans-serif; background-color: rgb(255, 255, 255);"><img id="preimg3" src="http://www.codeproject.com/images/minus.gif" height="9" width="9" preid="3" style="margin: 0px; padding: 0px; border: 0px; cursor: pointer;"><span id="precollapse3" preid="3" style="margin: 0px; padding: 0px; border: 0px; cursor: pointer;"> Collapse</span><span style="margin: 0px; padding: 0px; border: 0px;"> | </span><a href="http://www.codeproject.com/Questions/809366/Creating-a-livesource-audio-class-for-live?arn=0#" preid="3" style="margin: 0px; padding: 0px; border: 0px; text-decoration: none; color: purple;">Copy Code</a></div><pre lang="c++" id="pre3" style="padding: 6px; font-size: 9pt; font-family: Consolas, 'Courier New', Courier, mono; white-space: pre-wrap; border: 1px solid rgb(251, 237, 187); word-wrap: break-word; margin-top: 0px; overflow: auto !important; background-color: rgb(251, 237, 187);"><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;">#include</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;"> <span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">"</span><span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">MP2MediaSubsession.h"</span>
</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;">#include</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;"> <span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">"</span><span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">MP2DeviceSource.h"</span>
</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;">#include</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;"> <span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">"</span><span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">MPEG1or2AudioRTPSink.hh"</span>
</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;">#include</span><span class="code-preprocessor" style="margin: 0px; padding: 0px; border: 0px; color: navy;"> <span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">"</span><span class="code-string" style="margin: 0px; padding: 0px; border: 0px; color: purple;">MPEG1or2AudioStreamFramer.hh"</span>
</span>
 
MP2AudioMediaSubsession* 
MP2AudioMediaSubsession::createNew(UsageEnvironment& env,
                                        <span class="code-sdkkeyword" style="margin: 0px; padding: 0px; border: 0px; color: rgb(51, 153, 153);">Boolean</span> reuseFirstSource, 
                                        AudioTransfer * audioTransfer)
{
        <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">return</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">new</span> MP2AudioMediaSubsession(env, reuseFirstSource, imageTransfer );
}
 
MP2AudioMediaSubsession::MP2AudioMediaSubsession(UsageEnvironment& env, 
                                                        <span class="code-sdkkeyword" style="margin: 0px; padding: 0px; border: 0px; color: rgb(51, 153, 153);">Boolean</span> reuseFirstSource,
                                                        AudioTransfer * audioTransfer)
        : OnDemandServerMediaSubsession(env, reuseFirstSource), audioTx(audioTransfer) 
{
}
FramedSource* MP2AudioMediaSubsession::createNewStreamSource(<span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">unsigned</span> clientSessionId,
                                                                <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">unsigned</span> &estBitrate)
{
   estBitrate = <span class="code-digit" style="margin: 0px; padding: 0px; border: 0px; color: navy;">44100</span>;
   MP2DeviceSource *source =  MP2DeviceSource::createNew(envir(), id, audioTx);
   <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">return</span> MPEG1or2AudioStreamFramer::createNew(envir(), source );
}
 
RTPSink* MP2AudioMediaSubsession::createNewRTPSink(Groupsock* rtpGroupSock,
                                                <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">unsigned</span> <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">char</span> rtpPayloadTypeIfDynamic,
                                                FramedSource* inputSource)
{
        <span class="code-keyword" style="margin: 0px; padding: 0px; border: 0px; color: blue;">return</span> MPEG1or2AudioRTPSink::createNew( envir(), rtpGroupSock );
}
 
MP2AudioMediaSubsession::~MP2AudioMediaSubsession()
{
}</pre></div>                                         </div></body>
</html>