Browse code

precoded announcement fixes by Andrey Samusenko

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1655 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Stefan Sayer authored on 10/03/2010 01:10:08
Showing 7 changed files
... ...
@@ -49,8 +49,7 @@ int PrecodedFactory::onLoad()
49 49
       return -1;
50 50
     }
51 51
 
52
-    AmPrecodedFile::initPrecodedCodec();
53
-
52
+    precoded_file.initPlugin();
54 53
     return 0;
55 54
 }
56 55
 
... ...
@@ -72,13 +71,25 @@ AmPayloadProviderInterface* PrecodedDialog::getPayloadProvider() {
72 71
   return file_def;
73 72
 }
74 73
 
75
-void PrecodedDialog::onSessionStart(const AmSipRequest& req)
76
-{
74
+AmAudioRtpFormat* PrecodedDialog::getNewRtpFormat() {
75
+  if (m_payloads.empty()) {
76
+    ERROR("can not create RTP format without payloads.\n");
77
+    return NULL;
78
+  }
77 79
 
78
-  int current_payload=rtp_str.getCurrentPayload();
79
-  if ((current_payload == -1) && !m_payloads.empty()) {
80
-    current_payload = m_payloads[0]->payload_type;
80
+  current_payload = m_payloads[0]->payload_type;
81
+    
82
+  precoded_payload_t *precoded_payload = 
83
+    static_cast<precoded_payload_t*>(file_def->payload(current_payload));
84
+  if (precoded_payload == NULL) {
85
+    ERROR("new payload not provided\n");
86
+    return NULL;
81 87
   }
88
+  return new AmPrecodedRtpFormat(*precoded_payload, m_payloads);
89
+}
90
+
91
+void PrecodedDialog::onSessionStart(const AmSipRequest& req)
92
+{
82 93
   AmPrecodedFileInstance* file = file_def->getFileInstance(current_payload, 
83 94
 							   m_payloads);
84 95
   if (!file) {
... ...
@@ -91,8 +102,6 @@ void PrecodedDialog::onSessionStart(const AmSipRequest& req)
91 102
     return;
92 103
   }
93 104
  
94
-  rtp_str.setFormat(file->getRtpFormat());
95
-
96 105
   setOutput(file);
97 106
   setReceiving(false);
98 107
 }
... ...
@@ -50,6 +50,11 @@ class PrecodedDialog : public AmSession
50 50
     
51 51
   AmPrecodedFile* file_def;
52 52
 
53
+  int current_payload;
54
+
55
+protected:
56
+  AmAudioRtpFormat* getNewRtpFormat();
57
+
53 58
  public:
54 59
   PrecodedDialog(AmPrecodedFile* file_def);
55 60
   ~PrecodedDialog();
... ...
@@ -30,6 +30,8 @@
30 30
 #include "log.h"
31 31
 #include <fstream>
32 32
 
33
+#include <libgen.h>
34
+
33 35
 unsigned int precoded_bytes2samples(long h_codec, unsigned int num_bytes) {
34 36
   return ((AmAudioFormat*)h_codec)->frame_size;
35 37
 }
... ...
@@ -49,9 +51,11 @@ amci_codec_t _codec_precoded = {
49 51
   precoded_samples2bytes
50 52
 };
51 53
 
52
-
53
-void AmPrecodedFile::initPrecodedCodec() {
54
+void AmPrecodedFile::initPlugin() {
54 55
   AmPlugIn::instance()->addCodec(&_codec_precoded);
56
+  for(std::map<int,precoded_payload_t>::iterator it = 
57
+	payloads.begin(); it != payloads.end(); ++it)
58
+    AmPlugIn::instance()->addPayload(&it->second);
55 59
 }
56 60
 
57 61
 AmPrecodedRtpFormat::AmPrecodedRtpFormat(precoded_payload_t& precoded_payload,
... ...
@@ -62,7 +66,6 @@ AmPrecodedRtpFormat::AmPrecodedRtpFormat(precoded_payload_t& precoded_payload,
62 66
   rate = precoded_payload.sample_rate;
63 67
   // frame_size is in samples, precoded_payload.frame_size in millisec
64 68
   frame_size = precoded_payload.frame_ms * precoded_payload.sample_rate / 1000;
65
-  // fill unused stuff
66 69
   frame_length = precoded_payload.frame_ms;
67 70
   frame_encoded_size = precoded_payload.frame_bytes;
68 71
   h_codec = (long)this;
... ...
@@ -119,7 +122,7 @@ int precoded_file_close(FILE* fp, struct amci_file_desc_t* fmt_desc, int options
119 122
 
120 123
 AmPrecodedFileInstance::AmPrecodedFileInstance(precoded_payload_t& precoded_payload, 
121 124
 					       const vector<SdpPayload*>&  payloads) 
122
-  : precoded_payload(precoded_payload), payloads(payloads)
125
+  : AmAudioFile(), precoded_payload(precoded_payload), payloads(payloads)
123 126
 {
124 127
   memset(&m_iofmt, 0, sizeof(amci_inoutfmt_t));
125 128
   m_iofmt.open = &precoded_file_open;
... ...
@@ -149,12 +152,16 @@ AmPrecodedFile::AmPrecodedFile()
149 152
 AmPrecodedFile::~AmPrecodedFile() {
150 153
 }
151 154
 
152
-int AmPrecodedFile::open(std::string filename) {
155
+int AmPrecodedFile::open(const std::string& filename) {
153 156
   std::ifstream ifs(filename.c_str());
154 157
   if (!ifs.good()) {
155 158
     return -1;
156 159
   }
157 160
 
161
+  char *dir = strdup(filename.c_str());
162
+  string str_dir(dirname(dir));
163
+  str_dir += "/";
164
+
158 165
   while (ifs.good() && !ifs.eof()) {
159 166
     string codec_line;
160 167
     getline(ifs, codec_line);
... ...
@@ -187,14 +194,15 @@ int AmPrecodedFile::open(std::string filename) {
187 194
     pl.format_parameters = codec_def[4];
188 195
     get_uint_item(frame_ms, 5, "frame ms");
189 196
     get_uint_item(frame_bytes, 6, "frame bytes");
190
-    pl.filename=codec_def[7];
197
+    pl.filename=str_dir + codec_def[7];
191 198
 #undef get_uint_item
192 199
 
193 200
     DBG("inserting codec '%s' file '%s' and id %d\n",
194 201
 	pl.name, pl.filename.c_str(), pl.payload_id);
195 202
     payloads[pl.payload_id]=pl;
196 203
   }
197
-
204
+  free(dir);
205
+  ifs.close();
198 206
   return 0; // OK
199 207
 }
200 208
 
... ...
@@ -46,6 +46,8 @@ struct precoded_payload_t : public amci_payload_t {
46 46
   unsigned int frame_ms;
47 47
   unsigned int frame_bytes;
48 48
   string filename;
49
+
50
+  precoded_payload_t() {codec_id = PRECODED_CODEC_ID;}
49 51
 };
50 52
 
51 53
 class AmPrecodedFileFormat : public AmAudioFileFormat {
... ...
@@ -102,9 +104,11 @@ class AmPrecodedFile
102 104
  public: 
103 105
   AmPrecodedFile();
104 106
   ~AmPrecodedFile();
105
-  static void initPrecodedCodec();
106 107
 
107
-  int open(std::string filename);
108
+  /** need to call after open() */
109
+  void initPlugin();
110
+
111
+  int open(const std::string& filename);
108 112
 
109 113
   amci_payload_t*  payload(int payload_id);
110 114
   int getDynPayload(const string& name, int rate, int encoding_param);
... ...
@@ -143,7 +143,7 @@ void AmRtpAudio::init(const vector<SdpPayload*>& sdp_payloads)
143 143
 {
144 144
   DBG("AmRtpAudio::init(...)\n");
145 145
   AmRtpStream::init(sdp_payloads);
146
-  fmt.reset(new AmAudioRtpFormat(sdp_payloads));
146
+  fmt.reset(session->getNewRtpFormat());
147 147
 }
148 148
 
149 149
 int AmRtpAudio::setCurrentPayload(int payload)
... ...
@@ -216,6 +216,13 @@ AmPayloadProviderInterface* AmSession::getPayloadProvider() {
216 216
   return AmPlugIn::instance();
217 217
 }
218 218
 
219
+// todo: - move this back into AmRtpAudio
220
+//       - simplify payloads handling and move to AmRtpAudio
221
+//         entirely
222
+AmAudioRtpFormat* AmSession::getNewRtpFormat() {
223
+  return new AmAudioRtpFormat(m_payloads);
224
+}
225
+
219 226
 void AmSession::negotiate(const string& sdp_body,
220 227
 			  bool force_symmetric_rtp,
221 228
 			  string* sdp_reply)
... ...
@@ -85,6 +85,11 @@ protected:
85 85
   vector<SdpPayload *>  m_payloads;
86 86
   bool         negotiate_onreply;
87 87
 
88
+  friend class AmRtpAudio;
89
+
90
+  /** get new RTP format for the session */
91
+  virtual AmAudioRtpFormat* getNewRtpFormat();
92
+
88 93
 private:
89 94
   AmDtmfDetector   m_dtmfDetector;
90 95
   AmDtmfEventQueue m_dtmfEventQueue;