winlin

add SrsPid and SrsId to client response, add pid to log

@@ -137,6 +137,7 @@ package @@ -137,6 +137,7 @@ package
137 private var srs_server:String = null; 137 private var srs_server:String = null;
138 private var srs_primary_authors:String = null; 138 private var srs_primary_authors:String = null;
139 private var srs_id:String = null; 139 private var srs_id:String = null;
  140 + private var srs_pid:String = null;
140 private function update_context_items():void { 141 private function update_context_items():void {
141 // for context menu 142 // for context menu
142 var customItems:Array = [new ContextMenuItem("SrsPlayer")]; 143 var customItems:Array = [new ContextMenuItem("SrsPlayer")];
@@ -146,6 +147,9 @@ package @@ -146,6 +147,9 @@ package
146 if (srs_primary_authors != null) { 147 if (srs_primary_authors != null) {
147 customItems.push(new ContextMenuItem("PrimaryAuthors: " + srs_primary_authors)); 148 customItems.push(new ContextMenuItem("PrimaryAuthors: " + srs_primary_authors));
148 } 149 }
  150 + if (srs_pid != null) {
  151 + customItems.push(new ContextMenuItem("SrsPid: " + srs_pid));
  152 + }
149 if (srs_id != null) { 153 if (srs_id != null) {
150 customItems.push(new ContextMenuItem("SrsId: " + srs_id)); 154 customItems.push(new ContextMenuItem("SrsId: " + srs_id));
151 } 155 }
@@ -166,6 +170,9 @@ package @@ -166,6 +170,9 @@ package
166 if (evt.info.data.hasOwnProperty("srs_id")) { 170 if (evt.info.data.hasOwnProperty("srs_id")) {
167 srs_id = evt.info.data.srs_id; 171 srs_id = evt.info.data.srs_id;
168 } 172 }
  173 + if (evt.info.data.hasOwnProperty("srs_pid")) {
  174 + srs_pid = evt.info.data.srs_pid;
  175 + }
169 update_context_items(); 176 update_context_items();
170 } 177 }
171 178
@@ -269,6 +269,7 @@ package @@ -269,6 +269,7 @@ package
269 private var srs_server:String = null; 269 private var srs_server:String = null;
270 private var srs_primary_authors:String = null; 270 private var srs_primary_authors:String = null;
271 private var srs_id:String = null; 271 private var srs_id:String = null;
  272 + private var srs_pid:String = null;
272 private function update_context_items():void { 273 private function update_context_items():void {
273 // for context menu 274 // for context menu
274 var customItems:Array = [new ContextMenuItem("SrsPlayer")]; 275 var customItems:Array = [new ContextMenuItem("SrsPlayer")];
@@ -278,6 +279,9 @@ package @@ -278,6 +279,9 @@ package
278 if (srs_primary_authors != null) { 279 if (srs_primary_authors != null) {
279 customItems.push(new ContextMenuItem("PrimaryAuthors: " + srs_primary_authors)); 280 customItems.push(new ContextMenuItem("PrimaryAuthors: " + srs_primary_authors));
280 } 281 }
  282 + if (srs_pid != null) {
  283 + customItems.push(new ContextMenuItem("SrsPid: " + srs_pid));
  284 + }
281 if (srs_id != null) { 285 if (srs_id != null) {
282 customItems.push(new ContextMenuItem("SrsId: " + srs_id)); 286 customItems.push(new ContextMenuItem("SrsId: " + srs_id));
283 } 287 }
@@ -316,6 +320,9 @@ package @@ -316,6 +320,9 @@ package
316 if (evt.info.data.hasOwnProperty("srs_id")) { 320 if (evt.info.data.hasOwnProperty("srs_id")) {
317 srs_id = evt.info.data.srs_id; 321 srs_id = evt.info.data.srs_id;
318 } 322 }
  323 + if (evt.info.data.hasOwnProperty("srs_pid")) {
  324 + srs_pid = evt.info.data.srs_pid;
  325 + }
319 update_context_items(); 326 update_context_items();
320 } 327 }
321 328
@@ -138,6 +138,7 @@ package @@ -138,6 +138,7 @@ package
138 private var srs_server:String = null; 138 private var srs_server:String = null;
139 private var srs_primary_authors:String = null; 139 private var srs_primary_authors:String = null;
140 private var srs_id:String = null; 140 private var srs_id:String = null;
  141 + private var srs_pid:String = null;
141 private function update_context_items():void { 142 private function update_context_items():void {
142 // for context menu 143 // for context menu
143 var customItems:Array = [new ContextMenuItem("SrsPlayer")]; 144 var customItems:Array = [new ContextMenuItem("SrsPlayer")];
@@ -147,6 +148,9 @@ package @@ -147,6 +148,9 @@ package
147 if (srs_primary_authors != null) { 148 if (srs_primary_authors != null) {
148 customItems.push(new ContextMenuItem("PrimaryAuthors: " + srs_primary_authors)); 149 customItems.push(new ContextMenuItem("PrimaryAuthors: " + srs_primary_authors));
149 } 150 }
  151 + if (srs_pid != null) {
  152 + customItems.push(new ContextMenuItem("SrsPid: " + srs_pid));
  153 + }
150 if (srs_id != null) { 154 if (srs_id != null) {
151 customItems.push(new ContextMenuItem("SrsId: " + srs_id)); 155 customItems.push(new ContextMenuItem("SrsId: " + srs_id));
152 } 156 }
@@ -215,6 +219,9 @@ package @@ -215,6 +219,9 @@ package
215 if (evt.info.data.hasOwnProperty("srs_id")) { 219 if (evt.info.data.hasOwnProperty("srs_id")) {
216 srs_id = evt.info.data.srs_id; 220 srs_id = evt.info.data.srs_id;
217 } 221 }
  222 + if (evt.info.data.hasOwnProperty("srs_pid")) {
  223 + srs_pid = evt.info.data.srs_pid;
  224 + }
218 update_context_items(); 225 update_context_items();
219 } 226 }
220 227
@@ -265,26 +265,26 @@ bool SrsFastLog::generate_header(bool error, const char* tag, int context_id, co @@ -265,26 +265,26 @@ bool SrsFastLog::generate_header(bool error, const char* tag, int context_id, co
265 if (error) { 265 if (error) {
266 if (tag) { 266 if (tag) {
267 log_header_size = snprintf(log_data, LOG_MAX_SIZE, 267 log_header_size = snprintf(log_data, LOG_MAX_SIZE,
268 - "[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%d] ", 268 + "[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%d][%d] ",
269 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000), 269 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000),
270 - level_name, tag, context_id, errno); 270 + level_name, tag, getpid(), context_id, errno);
271 } else { 271 } else {
272 log_header_size = snprintf(log_data, LOG_MAX_SIZE, 272 log_header_size = snprintf(log_data, LOG_MAX_SIZE,
273 - "[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%d] ", 273 + "[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%d][%d] ",
274 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000), 274 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000),
275 - level_name, context_id, errno); 275 + level_name, getpid(), context_id, errno);
276 } 276 }
277 } else { 277 } else {
278 if (tag) { 278 if (tag) {
279 log_header_size = snprintf(log_data, LOG_MAX_SIZE, 279 log_header_size = snprintf(log_data, LOG_MAX_SIZE,
280 - "[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d] ", 280 + "[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%d] ",
281 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000), 281 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000),
282 - level_name, tag, context_id); 282 + level_name, tag, getpid(), context_id);
283 } else { 283 } else {
284 log_header_size = snprintf(log_data, LOG_MAX_SIZE, 284 log_header_size = snprintf(log_data, LOG_MAX_SIZE,
285 - "[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d] ", 285 + "[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%d] ",
286 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000), 286 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000),
287 - level_name, context_id); 287 + level_name, getpid(), context_id);
288 } 288 }
289 } 289 }
290 290
@@ -492,7 +492,33 @@ int SrsRtmpClient::connect_app(string app, string tc_url) @@ -492,7 +492,33 @@ int SrsRtmpClient::connect_app(string app, string tc_url)
492 } 492 }
493 SrsAutoFree(SrsMessage, msg); 493 SrsAutoFree(SrsMessage, msg);
494 SrsAutoFree(SrsConnectAppResPacket, pkt); 494 SrsAutoFree(SrsConnectAppResPacket, pkt);
495 - srs_info("get connect app response message"); 495 +
  496 + // server info
  497 + std::string srs_version;
  498 + std::string srs_server_ip;
  499 + int srs_id = 0;
  500 + int srs_pid = 0;
  501 +
  502 + SrsAmf0Any* data = pkt->info->get_property("data");
  503 + if (data && data->is_ecma_array()) {
  504 + SrsAmf0EcmaArray* arr = data->to_ecma_array();
  505 +
  506 + SrsAmf0Any* prop = NULL;
  507 + if ((prop = arr->ensure_property_string("srs_version")) != NULL) {
  508 + srs_version = prop->to_str();
  509 + }
  510 + if ((prop = arr->ensure_property_string("srs_server_ip")) != NULL) {
  511 + srs_server_ip = prop->to_str();
  512 + }
  513 + if ((prop = arr->ensure_property_number("srs_id")) != NULL) {
  514 + srs_id = (int)prop->to_number();
  515 + }
  516 + if ((prop = arr->ensure_property_number("srs_pid")) != NULL) {
  517 + srs_pid = (int)prop->to_number();
  518 + }
  519 + }
  520 + srs_trace("connected, version=%s, ip=%s, identity=[%d][%d]",
  521 + srs_version.c_str(), srs_server_ip.c_str(), srs_pid, srs_id);
496 522
497 return ret; 523 return ret;
498 } 524 }
@@ -867,6 +893,7 @@ int SrsRtmpServer::response_connect_app(SrsRequest *req, const char* server_ip) @@ -867,6 +893,7 @@ int SrsRtmpServer::response_connect_app(SrsRequest *req, const char* server_ip)
867 data->set("srs_server_ip", SrsAmf0Any::str(server_ip)); 893 data->set("srs_server_ip", SrsAmf0Any::str(server_ip));
868 } 894 }
869 // for edge to directly get the id of client. 895 // for edge to directly get the id of client.
  896 + data->set("srs_pid", SrsAmf0Any::number(getpid()));
870 data->set("srs_id", SrsAmf0Any::number(_srs_context->get_id())); 897 data->set("srs_id", SrsAmf0Any::number(_srs_context->get_id()));
871 898
872 if ((ret = protocol->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { 899 if ((ret = protocol->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) {