Module: sems
Branch: master
Commit: ac6eae34af37cb8110bf129b7ce9a66f8cb50051
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=ac6eae34af37cb8110bf129b7ce9a66f8cb50051

Author: Raphael Coeffic <[email protected]>
Committer: Raphael Coeffic <[email protected]>
Date:   Wed Mar  7 10:53:01 2012 +0100

moved advertized_rate from AmAudioFormat to AmAudioRtpFormat.

---

 core/AmAudio.cpp    |   37 +++++++++++++------------------------
 core/AmAudio.h      |   27 +++++++++++----------------
 core/AmRtpAudio.cpp |   11 +++++++----
 3 files changed, 31 insertions(+), 44 deletions(-)

diff --git a/core/AmAudio.cpp b/core/AmAudio.cpp
index 61c68ad..7023dcf 100644
--- a/core/AmAudio.cpp
+++ b/core/AmAudio.cpp
@@ -52,7 +52,9 @@ struct CodecContainer
 };
 
 AmAudioRtpFormat::AmAudioRtpFormat()
-  : AmAudioFormat(), codec_id(-1)
+  : AmAudioFormat(), 
+    codec_id(-1),
+    advertized_rate(-1)
 {
   
 }
@@ -80,7 +82,7 @@ AmAudioRtpFormat::~AmAudioRtpFormat()
 }
 
 AmAudioFormat::AmAudioFormat()
-  : channels(-1), rate(-1), advertized_rate(-1), codec(NULL),
+  : channels(-1), rate(-1), codec(NULL),
     frame_size(20*SYSTEM_SAMPLECLOCK_RATE/1000), frame_encoded_size(320)
 {
 
@@ -340,17 +342,13 @@ void AmAudio::close()
 // returns bytes read, else -1 if error (0 is OK)
 int AmAudio::get(unsigned int user_ts, unsigned char* buffer, int 
output_sample_rate, unsigned int nb_samples)
 {
-  int size = 0;
-  if (output_sample_rate < fmt->rate) {
-    float rfactor = (float)fmt->rate / (float)output_sample_rate;
-    size = calcBytesToRead((int)((float)nb_samples * rfactor));
-  } else {
-    float rdivisor = (float)output_sample_rate / (float)fmt->rate;
-    size = calcBytesToRead((int)((float)nb_samples / rdivisor));
-  }
+  int size = calcBytesToRead((int)((float)nb_samples * (float)fmt->rate
+                                  / (float)output_sample_rate));
+
+  unsigned int rd_ts = user_ts * ((double)fmt->getTSRate()
+                                 / (double)SYSTEM_SAMPLECLOCK_RATE);
 
-  size = read(user_ts,size);
-  //DBG("size = %d\n",size);
+  size = read(rd_ts,size);
   if(size <= 0){
     return size;
   }
@@ -385,13 +383,11 @@ int AmAudio::put(unsigned int user_ts, unsigned char* 
buffer, int input_sample_r
 
   int s = encode(size);
   if(s>0){
-    //DBG("%s\n",typeid(this).name());
+
     incRecordTime(bytes2samples(size));
 
-    unsigned int wr_ts = user_ts * ((double) (fmt->advertized_rate > 0 ?
-                                             fmt->advertized_rate
-                                             : fmt->rate)
-                                   / (double) SYSTEM_SAMPLECLOCK_RATE);
+    unsigned int wr_ts = user_ts * ((double)fmt->getTSRate()
+                                   / (double)SYSTEM_SAMPLECLOCK_RATE);
 
     return write(wr_ts,(unsigned int)s);
   }
@@ -602,12 +598,5 @@ void DblBuffer::swap()
 
 int AmAudioRtpFormat::getCodecId()
 {
-  // if(!m_currentPayloadP){
-  //   ERROR("AmAudioRtpFormat::getCodecId: could not find payload %i\n", 
m_currentPayload);
-  //   return -1;
-  // }
-  // else 
-  //   return m_currentPayloadP->codec_id;
-
   return codec_id;
 }
diff --git a/core/AmAudio.h b/core/AmAudio.h
index 2e6732c..4db422f 100644
--- a/core/AmAudio.h
+++ b/core/AmAudio.h
@@ -121,9 +121,6 @@ public:
   /** Sampling rate. */
   int rate;
 
-  /** Sampling rate as advertized in SDP (differs from actual rate for G722) 
**/
-  int advertized_rate;
-
   /* frame length in ms (frame based codecs) - unused */
   //int frame_length;
   /* frame size in samples */
@@ -140,6 +137,12 @@ public:
   virtual amci_codec_t*    getCodec();
   void resetCodec();
 
+  /** return the real sampling rate */
+  virtual int getRate() { return rate; }
+
+  /** return the timestamp sampling rate */
+  virtual int getTSRate() { return rate; }
+
   /** @return Handler returned by the codec's init function.*/
   long             getHCodec();
   long             getHCodecNoInit() { return h_codec; } // do not initialize
@@ -185,28 +188,20 @@ public:
 /** \brief RTP audio format */
 class AmAudioRtpFormat: public AmAudioFormat
 {
-  // vector<SdpPayload *> m_payloads;
-  // int m_currentPayload;
-  // amci_payload_t *m_currentPayloadP;
-  // std::map<int, SdpPayload *> m_sdpPayloadByPayload;
-  // std::map<int, amci_payload_t *> m_payloadPByPayload;
-  // std::map<int, CodecContainer *> m_codecContainerByPayload;
-
   int codec_id;
 
+  /** Sampling rate as advertized in SDP (differs from actual rate for G722) 
**/
+  int advertized_rate;
+
 protected:
   virtual int getCodecId();
 
 public:
-  /**
-   * Constructor for payload based formats.
-   * All the information are taken from the 
-   * payload description in the originating plug-in.
-   */
-  //AmAudioRtpFormat(const vector<SdpPayload *>& payloads);
   AmAudioRtpFormat();
   ~AmAudioRtpFormat();
 
+  virtual int getTSRate() { return advertized_rate; }
+
   /**
    * changes payload. returns != 0 on error.
    */
diff --git a/core/AmRtpAudio.cpp b/core/AmRtpAudio.cpp
index ee39aa9..1d66f5f 100644
--- a/core/AmRtpAudio.cpp
+++ b/core/AmRtpAudio.cpp
@@ -56,7 +56,7 @@ bool AmRtpAudio::checkInterval(unsigned int ts)
     last_check   = ts;
   }
   else {
-    if(((ts - last_check) / getSampleRateDivisor()) >= getFrameSize()){
+    if(resampleTS(ts - last_check) >= getFrameSize()){
       send_int = true;
       last_check = ts;
     }
@@ -85,7 +85,7 @@ int AmRtpAudio::receive(unsigned int wallclock_ts)
   int size;
   unsigned int rtp_ts;
   int new_payload = -1;
-  wallclock_ts /= getSampleRateDivisor();
+  wallclock_ts = resampleTS(wallclock_ts);
 
   while(true) {
     size = AmRtpStream::receive((unsigned char*)samples,
@@ -110,8 +110,11 @@ int AmRtpAudio::receive(unsigned int wallclock_ts)
       return -1;
     }
 
-    unsigned int adjusted_rtp_ts = rtp_ts * ((double)fmt->rate / 
(double)fmt->advertized_rate);
-    playout_buffer->write(wallclock_ts, adjusted_rtp_ts, 
(ShortSample*)((unsigned char *)samples),
+    unsigned int adjusted_rtp_ts = (double)rtp_ts * 
+      ((double)fmt->getRate() / (double)fmt->getTSRate());
+
+    playout_buffer->write(wallclock_ts, adjusted_rtp_ts,
+                         (ShortSample*)((unsigned char *)samples),
                          PCM16_B2S(size), begin_talk);
   }
   return size;

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to