Browse code

moved payload provider to AmRtpStream.

Raphael Coeffic authored on 14/12/2011 11:34:45
Showing 10 changed files
... ...
@@ -55,10 +55,10 @@ struct amci_inoutfmt_t;
55 55
 struct amci_subtype_t;
56 56
 
57 57
 /** Interface that a payload provider needs to implement */
58
-class AmPayloadProviderInterface {
58
+class AmPayloadProvider {
59 59
  public: 
60
-  AmPayloadProviderInterface() { }
61
-  virtual ~AmPayloadProviderInterface() { }
60
+  AmPayloadProvider() { }
61
+  virtual ~AmPayloadProvider() { }
62 62
   
63 63
   /** 
64 64
    * Payload lookup function.
... ...
@@ -83,7 +83,7 @@ class AmPayloadProviderInterface {
83 83
 /**
84 84
  * \brief Container for loaded Plug-ins.
85 85
  */
86
-class AmPlugIn : public AmPayloadProviderInterface
86
+class AmPlugIn : public AmPayloadProvider
87 87
 {
88 88
  private:
89 89
   static AmPlugIn* _instance;
... ...
@@ -97,7 +97,7 @@ class AmPrecodedFileInstance
97 97
 };
98 98
 
99 99
 class AmPrecodedFile 
100
-: public AmPayloadProviderInterface {
100
+: public AmPayloadProvider {
101 101
 
102 102
   std::map<int,precoded_payload_t>  payloads;
103 103
 
... ...
@@ -105,17 +105,19 @@ class AmPrecodedFile
105 105
   AmPrecodedFile();
106 106
   ~AmPrecodedFile();
107 107
 
108
+  /** Open the file */
109
+  int open(const std::string& filename);
110
+
108 111
   /** need to call after open() */
109 112
   void initPlugin();
110 113
 
111
-  int open(const std::string& filename);
114
+  AmPrecodedFileInstance* getFileInstance(int payload_id, 
115
+			     const vector<SdpPayload*>&  m_payloads);
112 116
 
117
+  /** from @AmPayloadProvider */
113 118
   amci_payload_t*  payload(int payload_id) const;
114 119
   int getDynPayload(const string& name, int rate, int encoding_param) const;
115
-
116 120
   void getPayloads(vector<SdpPayload>& pl_vec) const;
117
-
118
-  AmPrecodedFileInstance* getFileInstance(int payload_id, const vector<SdpPayload*>&  m_payloads);
119 121
 };
120 122
 
121 123
 #endif
... ...
@@ -151,13 +151,12 @@ void AmRtpAudio::getSdpAnswer(const SdpMedia& offer, SdpMedia& answer)
151 151
   AmRtpStream::getSdpAnswer(offer,answer);
152 152
 }
153 153
 
154
-int AmRtpAudio::init(AmPayloadProviderInterface* payload_provider,
155
-		      unsigned char media_i, 
156
-		      const AmSdp& local,
157
-		      const AmSdp& remote)
154
+int AmRtpAudio::init(unsigned char media_i, 
155
+		     const AmSdp& local,
156
+		     const AmSdp& remote)
158 157
 {
159 158
   DBG("AmRtpAudio::init(...)\n");
160
-  if(AmRtpStream::init(payload_provider,media_i,local,remote)){
159
+  if(AmRtpStream::init(media_i,local,remote)){
161 160
     return -1;
162 161
   }
163 162
 
... ...
@@ -119,8 +119,7 @@ public:
119 119
   void getSdpOffer(SdpMedia& offer);
120 120
   void getSdpAnswer(const SdpMedia& offer, SdpMedia& answer);
121 121
 
122
-  int init(AmPayloadProviderInterface* payload_provider,
123
-	   unsigned char media_i, 
122
+  int init(unsigned char media_i, 
124 123
 	   const AmSdp& local,
125 124
 	   const AmSdp& remote);
126 125
 
... ...
@@ -441,6 +441,9 @@ AmRtpStream::AmRtpStream(AmSession* _s, int _if)
441 441
   l_ssrc = get_random();
442 442
   sequence = get_random();
443 443
   gettimeofday(&last_recv_time,NULL);
444
+
445
+  // by default the system codecs
446
+  payload_provider = AmPlugIn::instance();
444 447
 }
445 448
 
446 449
 AmRtpStream::~AmRtpStream()
... ...
@@ -563,21 +566,16 @@ void AmRtpStream::getSdp(SdpMedia& m)
563 566
 void AmRtpStream::getSdpOffer(SdpMedia& offer)
564 567
 {
565 568
   getSdp(offer);
566
-
567
-  // TODO: transfer ownership of the payload provider also into AmRtpStream
568
-  session->getPayloadProvider()->getPayloads(offer.payloads);
569
+  payload_provider->getPayloads(offer.payloads);
569 570
 }
570 571
 
571 572
 void AmRtpStream::getSdpAnswer(const SdpMedia& offer, SdpMedia& answer)
572 573
 {
573 574
   getSdp(answer);
574
-
575
-  // TODO: transfer ownership of the payload provider also into AmRtpStream
576
-  offer.calcAnswer(session->getPayloadProvider(),answer);
575
+  offer.calcAnswer(payload_provider,answer);
577 576
 }
578 577
 
579
-int AmRtpStream::init(AmPayloadProviderInterface* payload_provider,
580
-		      unsigned char media_i, 
578
+int AmRtpStream::init(unsigned char media_i, 
581 579
 		      const AmSdp& local,
582 580
 		      const AmSdp& remote)
583 581
 {
... ...
@@ -896,6 +894,11 @@ int AmRtpStream::getLocalTelephoneEventRate()
896 894
   return 0;
897 895
 }
898 896
 
897
+void AmRtpStream::setPayloadProvider(AmPayloadProvider* pl_prov)
898
+{
899
+  payload_provider = pl_prov;
900
+}
901
+
899 902
 void AmRtpStream::sendDtmf(int event, unsigned int duration_ms) {
900 903
   dtmf_send_queue_mut.lock();
901 904
   dtmf_send_queue.push(std::make_pair(event, duration_ms * getLocalTelephoneEventRate() 
... ...
@@ -192,6 +192,8 @@ protected:
192 192
   pair<int, unsigned int> current_send_dtmf;
193 193
   unsigned int current_send_dtmf_ts;
194 194
   int send_dtmf_end_repeat;
195
+  /** Payload provider */
196
+  AmPayloadProvider* payload_provider;
195 197
 
196 198
   /** handle symmetric RTP - if in passive mode, update raddr from rp */
197 199
   void handleSymmetricRtp(AmRtpPacket* rp);
... ...
@@ -283,6 +285,8 @@ public:
283 285
 
284 286
   int getLocalTelephoneEventRate();
285 287
 
288
+  void setPayloadProvider(AmPayloadProvider* pl_prov);
289
+
286 290
   /**
287 291
    * send a DTMF as RTP payload (RFC4733)
288 292
    * @param event event ID (e.g. key press), see rfc
... ...
@@ -310,8 +314,7 @@ public:
310 314
    * @warning It should be called only if the stream has been completly initialized,
311 315
    * @warning and only once per session. Use resume() then.
312 316
    */
313
-  virtual int init(AmPayloadProviderInterface* payload_provider,
314
-		   unsigned char media_i, 
317
+  virtual int init(unsigned char media_i, 
315 318
 		   const AmSdp& local,
316 319
 		   const AmSdp& remote);
317 320
 
... ...
@@ -293,7 +293,7 @@ void AmSdp::clear()
293 293
   l_origin = SdpOrigin();
294 294
 }
295 295
 
296
-void SdpMedia::calcAnswer(const AmPayloadProviderInterface* payload_prov,
296
+void SdpMedia::calcAnswer(const AmPayloadProvider* payload_prov,
297 297
 			  SdpMedia& answer) const
298 298
 {
299 299
   if(!recv) answer.send = false;
... ...
@@ -156,7 +156,7 @@ struct SdpMedia
156 156
    * inserts them into the answer, compute send/recv attributes
157 157
    * and direction according to the offer.
158 158
    */
159
-  void calcAnswer(const AmPayloadProviderInterface* payload_prov, 
159
+  void calcAnswer(const AmPayloadProvider* payload_prov, 
160 160
 		  SdpMedia& answer) const;
161 161
 };
162 162
 
... ...
@@ -272,11 +272,6 @@ int AmSession::getRPort()
272 272
   return RTPStream()->getRPort();
273 273
 }
274 274
 
275
-AmPayloadProviderInterface* AmSession::getPayloadProvider() {
276
-  // by default the system codecs
277
-  return AmPlugIn::instance();
278
-}
279
-
280 275
 #ifdef SESSION_THREADPOOL
281 276
 void AmSession::start() {
282 277
   AmSessionProcessorThread* processor_thread = 
... ...
@@ -1056,7 +1051,7 @@ int AmSession::onSdpCompleted(const AmSdp& local_sdp, const AmSdp& remote_sdp)
1056 1051
   //     should be created or updated   
1057 1052
   //
1058 1053
   lockAudio();
1059
-  int ret = RTPStream()->init(getPayloadProvider(),0,local_sdp,remote_sdp);
1054
+  int ret = RTPStream()->init(0,local_sdp,remote_sdp);
1060 1055
   unlockAudio();
1061 1056
   
1062 1057
   if(ret){
... ...
@@ -371,12 +371,6 @@ public:
371 371
   /** Gets the port number of the remote part of the session */
372 372
   int getRPort();
373 373
 
374
-  /** Set whether on positive reply session should be negotiated */
375
-  //void setNegotiateOnReply(bool n) { negotiate_onreply = n; }
376
-
377
-  /** get the payload provider for the session */
378
-  virtual AmPayloadProviderInterface* getPayloadProvider();
379
-
380 374
   /* ----         Call control                         ---- */
381 375
 
382 376
   /** refresh the session - re-INVITE or UPDATE*/