[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/rtmp r10098: decodeMsgBody() now returns a
From: |
rob |
Subject: |
[Gnash-commit] /srv/bzr/gnash/rtmp r10098: decodeMsgBody() now returns a boost:shared_ptr instead of a real pointer. |
Date: |
Wed, 01 Apr 2009 16:53:00 -0600 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 10098
committer: address@hidden
branch nick: rtmp
timestamp: Wed 2009-04-01 16:53:00 -0600
message:
decodeMsgBody() now returns a boost:shared_ptr instead of a real pointer.
modified:
cygnal/rtmp_server.cpp
libcore/asobj/NetConnection_as.cpp
libnet/rtmp.cpp
libnet/rtmp.h
utilities/rtmpget.cpp
=== modified file 'cygnal/rtmp_server.cpp'
--- a/cygnal/rtmp_server.cpp 2009-03-16 23:34:13 +0000
+++ b/cygnal/rtmp_server.cpp 2009-04-01 22:53:00 +0000
@@ -904,7 +904,7 @@
string url, filespec;
url = docroot;
bool done = false;
- RTMPMsg *body = 0;
+ boost::shared_ptr<RTMPMsg> body;
static bool initialize = true;
static bool echo = false;
bool sendfile = false;
=== modified file 'libcore/asobj/NetConnection_as.cpp'
--- a/libcore/asobj/NetConnection_as.cpp 2009-03-28 22:45:43 +0000
+++ b/libcore/asobj/NetConnection_as.cpp 2009-04-01 22:53:00 +0000
@@ -298,6 +298,7 @@
string swfUrl; // the swfUrl field
string filename; // the filename to play
string pageUrl; // the pageUrl field
+ boost::shared_ptr<RTMP::rtmp_head_t> rthead;
log_debug("%s: URI is %s, URL protocol is %s, path is %s, hostname is %s,
port is %s", __PRETTY_FUNCTION__,
_uri,
@@ -389,28 +390,21 @@
return;
} else {
log_debug("RTMP handshake completed");
- notifyStatus(CONNECT_SUCCESS);
- _isConnected = true;
- }
- boost::shared_ptr<amf::Buffer> msg1 = _rtmp_client->recvMsg();
-#if 0
- boost::shared_ptr<amf::Buffer> head2 =
_rtmp_client->encodeHeader(0x3, RTMP::HEADER_12, total_size,
- RTMP::INVOKE,
RTMPMsg::FROM_CLIENT);
- head2->dump();
- boost::shared_ptr<amf::Buffer> buf3(new
amf::Buffer(head2->allocated() + buf2->allocated()));
- *buf3 = *head2;
- *buf3 += *buf2;
- boost::shared_ptr<amf::Buffer> msg1 = _rtmp_client->recvMsg();
- RTMP::queues_t *que = split(msg1);
-
- // the connectino process is complete
- if (msg1->getStatus() == RTMPMsg::NC_CONNECT_SUCCESS) {
notifyStatus(CONNECT_SUCCESS);
- } else {
- notifyStatus(CONNECT_FAILED);
- return;
- }
-#endif
+ _isConnected = true;
+ }
+ // although recvMsg() does a select() while waiting for data,
+ // We've found things work better if we pause a second to let
+ // the server response. Not doing this means we sometimes get
+ // a fragemented first packet. Luckily we only have to wait
+ // when making the initial connection.
+ sleep(1);
+
+ // Usually after waiting we get a PING Clear message, and sometimes
+ // several other system channe messages which should
+ // then be followed by the result of the connection being made
+ // to the server.
+ boost::shared_ptr<RTMPMsg> msg = _rtmp_client->recvResponse();
} // end of 'if RTMP'
#if 0
// FIXME: do a GET request for the crossdomain.xml file
@@ -442,7 +436,7 @@
boost::shared_ptr<amf::Element> data(new amf::Element);
data->makeStrictArray();
for (size_t i=firstArg; i<args.size(); i++) {
- cerr << "FIXME: NetConnection::" << __FUNCTION__ << "(): " <<
args[i].to_string() << endl;
+ log_debug("%s: Converting AS Object to Element %s",
__PRETTY_FUNCTION__, args[i].to_string());
boost::shared_ptr<amf::Element> el = args[i].to_element();
// el->dump();
data->addProperty(el);
@@ -490,38 +484,36 @@
_rtmp_client->sendMsg(0x3, RTMP::HEADER_12, request->allocated(),
RTMP::INVOKE, RTMPMsg::FROM_CLIENT, *request);
-#if 0
- boost::shared_ptr<amf::Buffer> response = _rtmp_client->recvMsg();
- response->dump();
- boost::shared_ptr<RTMP::rtmp_head_t> rthead;
- boost::shared_ptr<RTMP::queues_t> que = _rtmp_client->split(*response);
- log_debug("%s: There are %d messages in the RTMP input queue",
__PRETTY_FUNCTION__, que->size());
- while (que->size()) {
- boost::shared_ptr<amf::Buffer> ptr = que->front()->pop();
- if (ptr) { // If there is legit data
- rthead = _rtmp_client->decodeHeader(ptr->reference());
- RTMPMsg *msg = _rtmp_client->decodeMsgBody(ptr->reference() +
rthead->head_size, rthead->bodysize);
- msg->dump();
- if (msg->getMethodName() == "_error") {
- log_error("Got an error: %s", msg->getMethodName());
- msg->at(0)->dump();
- notifyStatus(CALL_FAILED);
- }
- if (msg->getMethodName() == "_result") {
- log_debug("Got a result: %s", msg->getMethodName());
- if (msg->getElements().size() > 0) {
- msg->at(0)->dump();
- as_value tmp(*msg->at(0));
-// string_table::key methodKey = tdata->st->find(methodName);
- string_table::key methodKey =
tdata->st->find("onResult");
- asCallback->callMethod(methodKey, tmp);
- }
- }
- }
- }
-#endif
-
-
+// #if 0
+// boost::shared_ptr<amf::Buffer> response = _rtmp_client->recvMsg();
+// response->dump();
+// boost::shared_ptr<RTMP::rtmp_head_t> rthead;
+// boost::shared_ptr<RTMP::queues_t> que = _rtmp_client->split(*response);
+// log_debug("%s: There are %d messages in the RTMP input queue",
__PRETTY_FUNCTION__, que->size());
+// while (que->size()) {
+// boost::shared_ptr<amf::Buffer> ptr = que->front()->pop();
+// if (ptr) { // If there is legit data
+// rthead = _rtmp_client->decodeHeader(ptr->reference());
+// RTMPMsg *msg = _rtmp_client->decodeMsgBody(ptr->reference() +
rthead->head_size, rthead->bodysize);
+// msg->dump();
+// if (msg->getMethodName() == "_error") {
+// log_error("Got an error: %s", msg->getMethodName());
+// msg->at(0)->dump();
+// notifyStatus(CALL_FAILED);
+// }
+// if (msg->getMethodName() == "_result") {
+// log_debug("Got a result: %s", msg->getMethodName());
+// if (msg->getElements().size() > 0) {
+// msg->at(0)->dump();
+// as_value tmp(*msg->at(0));
+// // string_table::key methodKey = tdata->st->find(methodName);
+// string_table::key methodKey =
tdata->st->find("onResult");
+// asCallback->callMethod(methodKey, tmp);
+// }
+// }
+// }
+// }
+// #endif
}
// Start a thread to wait for the response
@@ -659,8 +651,7 @@
{
static boost::intrusive_ptr<as_object> o;
- if ( o == NULL )
- {
+ if ( o == NULL ) {
o = new as_object(getObjectInterface());
attachNetConnectionInterface(*o);
}
@@ -754,11 +745,10 @@
args->network->setTimeout(50);
if (args->network->getProtocol() == "rtmp") {
-#if 1
do {
RTMPClient *client = reinterpret_cast<RTMPClient *>(args->network);
boost::shared_ptr<amf::Buffer> response = client->recvMsg();
- response->dump();
+// response->dump();
boost::shared_ptr<RTMP::rtmp_head_t> rthead;
boost::shared_ptr<RTMP::queues_t> que = client->split(*response);
@@ -768,8 +758,8 @@
log_debug("%s: There are %d messages in the RTMP input queue",
__PRETTY_FUNCTION__, que->size());
if (ptr) { // If there is legit data
rthead = client->decodeHeader(ptr->reference());
- RTMPMsg *msg = client->decodeMsgBody(ptr->reference() +
rthead->head_size, rthead->bodysize);
- msg->dump();
+ boost::shared_ptr<RTMPMsg> msg =
client->decodeMsgBody(ptr->reference() + rthead->head_size, rthead->bodysize);
+// msg->dump();
if (msg->getMethodName() == "_error") {
log_error("Got an error: %s", msg->getMethodName());
msg->at(0)->dump();
@@ -778,8 +768,8 @@
if (msg->getMethodName() == "_result") {
log_debug("Got a result: %s", msg->getMethodName());
if (msg->getElements().size() > 0) {
- msg->at(0)->dump();
- as_value tmp(*msg->at(0));
+ msg->at(1)->dump();
+ as_value tmp(*msg->at(1));
// string_table::key methodKey =
tdata->st->find(methodName);
string_table::key methodKey =
args->st->find("onResult");
args->callback->callMethod(methodKey, tmp);
@@ -791,7 +781,6 @@
}
}
} while (!done);
-#endif
} else if (args->network->getProtocol() == "http") {
// Suck all the data waiting for us in the network
boost::shared_ptr<amf::Buffer> buf(new amf::Buffer);
=== modified file 'libnet/rtmp.cpp'
--- a/libnet/rtmp.cpp 2009-03-28 22:45:03 +0000
+++ b/libnet/rtmp.cpp 2009-04-01 22:53:00 +0000
@@ -94,7 +94,8 @@
"Blank 0x11",
"Notify",
"Shared object",
- "Invoke"
+ "Invoke",
+ "FLV Data"
};
const char *ping_str[] = {
@@ -322,8 +323,9 @@
}
}
- log_debug("RTMP %s: channel: %d, type: %s, header_size %d, bodysize: %d",
- content_str[head->type], head->channel, head->head_size,
head->bodysize);
+// log_debug("RTMP %s: channel: %d, type: %s, header_size %d, bodysize:
%d",
+// content_str[head->type], head->channel, head->head_size,
head->bodysize);
+
// switch(head->type) {
// case CHUNK_SIZE:
// case BYTES_READ:
@@ -631,7 +633,7 @@
// 10629:3086592224] 20:01:20 DEBUG: read 29 bytes from fd 3 from port 0
// address@hidden
// 43 00 00 00 00 00 15 14 02 00 08 6f 6e 42 57 44 6f 6e 65 00 40 00 00 00 00
00 00 00 05
-RTMPMsg *
+boost::shared_ptr<RTMPMsg>
RTMP::decodeMsgBody(boost::uint8_t *data, size_t size)
{
// GNASH_REPORT_FUNCTION;
@@ -639,6 +641,7 @@
boost::uint8_t *ptr = data;
boost::uint8_t* tooFar = ptr + size;
bool status = false;
+ boost::shared_ptr<RTMPMsg> msg(new RTMPMsg);
// The first data object is the method name of this object.
boost::shared_ptr<amf::Element> name = amf_obj.extractAMF(ptr, tooFar);
@@ -646,7 +649,8 @@
ptr += name->getDataSize() + AMF_HEADER_SIZE; // skip the length bytes
too
} else {
log_error("Name field of RTMP Message corrupted!");
- return 0;
+ msg.reset();
+ return msg;
}
// The stream ID is the second data object. All messages have these two
objects
@@ -660,14 +664,10 @@
}
} else {
log_error("Stream ID field of RTMP Message corrupted!");
- return 0;
+ msg.reset();
+ return msg;
}
- // This will need to be deleted manually later after usage, it is not
- // automatically deallocated.
- RTMPMsg *msg = new RTMPMsg;
-// memset(msg, 0, sizeof(RTMPMsg));
-
if (name->to_string() != 0) {
msg->setMethodName(name->to_string());
}
@@ -698,7 +698,7 @@
return msg;
}
-RTMPMsg *
+boost::shared_ptr<RTMPMsg>
RTMP::decodeMsgBody(amf::Buffer &buf)
{
// GNASH_REPORT_FUNCTION;
@@ -1098,7 +1098,7 @@
boost::shared_ptr<amf::Buffer>
RTMP::recvMsg(int fd)
{
- GNASH_REPORT_FUNCTION;
+// GNASH_REPORT_FUNCTION;
int ret = 0;
//bool nopacket = true;
@@ -1139,7 +1139,6 @@
return buf;
}
-
// Split a large buffer into multiple smaller ones of the default chunksize
// of 128 bytes. We read network data in big chunks because it's more
efficient,
// but RTMP uses a weird scheme of a standard header, and then every chunksize
=== modified file 'libnet/rtmp.h'
--- a/libnet/rtmp.h 2009-03-20 00:00:54 +0000
+++ b/libnet/rtmp.h 2009-04-01 22:53:00 +0000
@@ -236,8 +236,8 @@
int getMysteryWord() { return _mystery_word; };
// Decode an RTMP message
- RTMPMsg *decodeMsgBody(boost::uint8_t *data, size_t size);
- RTMPMsg *decodeMsgBody(amf::Buffer &buf);
+ boost::shared_ptr<RTMPMsg> decodeMsgBody(boost::uint8_t *data, size_t
size);
+ boost::shared_ptr<RTMPMsg> decodeMsgBody(amf::Buffer &buf);
virtual boost::shared_ptr<rtmp_ping_t> decodePing(boost::uint8_t *data);
boost::shared_ptr<rtmp_ping_t> decodePing(amf::Buffer &buf);
=== modified file 'utilities/rtmpget.cpp'
--- a/utilities/rtmpget.cpp 2009-04-01 00:11:33 +0000
+++ b/utilities/rtmpget.cpp 2009-04-01 22:53:00 +0000
@@ -434,7 +434,7 @@
log_debug("Got a Ping, type %s", ping_str[ping->type]);
continue;
}
- RTMPMsg *msg = client.decodeMsgBody(ptr->reference() +
rthead->head_size, rthead->bodysize);
+ boost::shared_ptr<RTMPMsg> msg =
client.decodeMsgBody(ptr->reference() + rthead->head_size, rthead->bodysize);
if (msg) {
// msg->dump();
if (msg->getStatus() == RTMPMsg::NC_CONNECT_SUCCESS) {
@@ -459,7 +459,6 @@
#endif
}
}
- delete msg;
} else {
log_error("Couldn't decode RTMP message Body");
continue;
@@ -527,7 +526,7 @@
continue;
}
- RTMPMsg *msg = client.decodeMsgBody(ptr->reference() +
rthead->head_size, rthead->bodysize);
+ boost::shared_ptr<RTMPMsg> msg =
client.decodeMsgBody(ptr->reference() + rthead->head_size, rthead->bodysize);
if (msg) {
// msg->dump();
if (msg->getMethodName() == "_result") {
@@ -655,7 +654,7 @@
// If it's not a Notify, Audio, or Video message, then
we're still processing
// responses from the NetStream::play() messages. We get
several before the
// the video starts.
- RTMPMsg *msg = client.decodeMsgBody(ptr->reference() +
rthead->head_size, rthead->bodysize);
+ boost::shared_ptr<RTMPMsg> msg =
client.decodeMsgBody(ptr->reference() + rthead->head_size, rthead->bodysize);
if (msg) {
// msg->dump();
if (msg->getMethodName() == "onStatus") {
@@ -685,7 +684,6 @@
// msg->at(0)->dump();
}
}
- delete msg;
} else {
log_error("Couldn't decode RTMP message Body");
continue;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/rtmp r10098: decodeMsgBody() now returns a boost:shared_ptr instead of a real pointer.,
rob <=