fix bug #36: never directly use *(int32_t*) to convert, for arm may not support
正在显示
5 个修改的文件
包含
70 行增加
和
18 行删除
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
31 | // current release version | 31 | // current release version |
32 | #define VERSION_MAJOR "0" | 32 | #define VERSION_MAJOR "0" |
33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
34 | -#define VERSION_REVISION "91" | 34 | +#define VERSION_REVISION "92" |
35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
36 | // server info. | 36 | // server info. |
37 | #define RTMP_SIG_SRS_KEY "srs" | 37 | #define RTMP_SIG_SRS_KEY "srs" |
@@ -232,3 +232,11 @@ void SrsStream::write_string(std::string value) | @@ -232,3 +232,11 @@ void SrsStream::write_string(std::string value) | ||
232 | p += value.length(); | 232 | p += value.length(); |
233 | } | 233 | } |
234 | 234 | ||
235 | +void SrsStream::write_bytes(char* data, int size) | ||
236 | +{ | ||
237 | + srs_assert(require(size)); | ||
238 | + | ||
239 | + memcpy(p, data, size); | ||
240 | + p += size; | ||
241 | +} | ||
242 | + |
@@ -129,6 +129,10 @@ public: | @@ -129,6 +129,10 @@ public: | ||
129 | * write string to stream | 129 | * write string to stream |
130 | */ | 130 | */ |
131 | virtual void write_string(std::string value); | 131 | virtual void write_string(std::string value); |
132 | + /** | ||
133 | + * write bytes to stream | ||
134 | + */ | ||
135 | + virtual void write_bytes(char* data, int size); | ||
132 | }; | 136 | }; |
133 | 137 | ||
134 | #endif | 138 | #endif |
@@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
31 | #include <srs_protocol_io.hpp> | 31 | #include <srs_protocol_io.hpp> |
32 | #include <srs_protocol_utility.hpp> | 32 | #include <srs_protocol_utility.hpp> |
33 | #include <srs_protocol_rtmp.hpp> | 33 | #include <srs_protocol_rtmp.hpp> |
34 | +#include <srs_kernel_stream.hpp> | ||
34 | 35 | ||
35 | #ifdef SRS_AUTO_SSL | 36 | #ifdef SRS_AUTO_SSL |
36 | 37 | ||
@@ -230,6 +231,26 @@ namespace srs | @@ -230,6 +231,26 @@ namespace srs | ||
230 | return ret; | 231 | return ret; |
231 | } | 232 | } |
232 | 233 | ||
234 | + // read/write stream using SrsStream. | ||
235 | + void __srs_stream_write_4bytes(char* pp, int32_t value) | ||
236 | + { | ||
237 | + static SrsStream stream; | ||
238 | + | ||
239 | + int ret = stream.initialize(pp, 4); | ||
240 | + srs_assert(ret == ERROR_SUCCESS); | ||
241 | + | ||
242 | + stream.write_4bytes(value); | ||
243 | + } | ||
244 | + int32_t __srs_stream_read_4bytes(char* pp) | ||
245 | + { | ||
246 | + static SrsStream stream; | ||
247 | + | ||
248 | + int ret = stream.initialize(pp, 4); | ||
249 | + srs_assert(ret == ERROR_SUCCESS); | ||
250 | + | ||
251 | + return stream.read_4bytes(); | ||
252 | + } | ||
253 | + | ||
233 | // calc the offset of key, | 254 | // calc the offset of key, |
234 | // the key->offset cannot be used as the offset of key. | 255 | // the key->offset cannot be used as the offset of key. |
235 | int srs_key_block_get_offset(key_block* key) | 256 | int srs_key_block_get_offset(key_block* key) |
@@ -282,7 +303,7 @@ namespace srs | @@ -282,7 +303,7 @@ namespace srs | ||
282 | char* pp = c1s1_key_bytes + 764; | 303 | char* pp = c1s1_key_bytes + 764; |
283 | 304 | ||
284 | pp -= sizeof(int32_t); | 305 | pp -= sizeof(int32_t); |
285 | - key->offset = *(int32_t*)pp; | 306 | + key->offset = __srs_stream_read_4bytes(pp); |
286 | 307 | ||
287 | key->random0 = NULL; | 308 | key->random0 = NULL; |
288 | key->random1 = NULL; | 309 | key->random1 = NULL; |
@@ -373,7 +394,7 @@ namespace srs | @@ -373,7 +394,7 @@ namespace srs | ||
373 | 394 | ||
374 | char* pp = c1s1_digest_bytes; | 395 | char* pp = c1s1_digest_bytes; |
375 | 396 | ||
376 | - digest->offset = *(int32_t*)pp; | 397 | + digest->offset = __srs_stream_read_4bytes(pp); |
377 | pp += sizeof(int32_t); | 398 | pp += sizeof(int32_t); |
378 | 399 | ||
379 | digest->random0 = NULL; | 400 | digest->random0 = NULL; |
@@ -416,13 +437,13 @@ namespace srs | @@ -416,13 +437,13 @@ namespace srs | ||
416 | void __srs_time_copy_to(char*& pp, int32_t time) | 437 | void __srs_time_copy_to(char*& pp, int32_t time) |
417 | { | 438 | { |
418 | // 4bytes time | 439 | // 4bytes time |
419 | - *(int32_t*)pp = time; | 440 | + __srs_stream_write_4bytes(pp, time); |
420 | pp += 4; | 441 | pp += 4; |
421 | } | 442 | } |
422 | void __srs_version_copy_to(char*& pp, int32_t version) | 443 | void __srs_version_copy_to(char*& pp, int32_t version) |
423 | { | 444 | { |
424 | // 4bytes version | 445 | // 4bytes version |
425 | - *(int32_t*)pp = version; | 446 | + __srs_stream_write_4bytes(pp, version); |
426 | pp += 4; | 447 | pp += 4; |
427 | } | 448 | } |
428 | void __srs_key_copy_to(char*& pp, key_block* key) | 449 | void __srs_key_copy_to(char*& pp, key_block* key) |
@@ -441,16 +462,17 @@ namespace srs | @@ -441,16 +462,17 @@ namespace srs | ||
441 | } | 462 | } |
442 | pp += key->random1_size; | 463 | pp += key->random1_size; |
443 | 464 | ||
444 | - *(int32_t*)pp = key->offset; | 465 | + __srs_stream_write_4bytes(pp, key->offset); |
445 | pp += 4; | 466 | pp += 4; |
446 | } | 467 | } |
447 | void __srs_digest_copy_to(char*& pp, digest_block* digest, bool with_digest) | 468 | void __srs_digest_copy_to(char*& pp, digest_block* digest, bool with_digest) |
448 | { | 469 | { |
449 | // 732bytes digest block without the 32bytes digest-data | 470 | // 732bytes digest block without the 32bytes digest-data |
450 | // nbytes digest block part1 | 471 | // nbytes digest block part1 |
451 | - *(int32_t*)pp = digest->offset; | 472 | + __srs_stream_write_4bytes(pp, digest->offset); |
452 | pp += 4; | 473 | pp += 4; |
453 | 474 | ||
475 | + // digest random padding. | ||
454 | if (digest->random0_size > 0) { | 476 | if (digest->random0_size > 0) { |
455 | memcpy(pp, digest->random0, digest->random0_size); | 477 | memcpy(pp, digest->random0, digest->random0_size); |
456 | } | 478 | } |
@@ -720,8 +742,9 @@ namespace srs | @@ -720,8 +742,9 @@ namespace srs | ||
720 | 742 | ||
721 | destroy_blocks(); | 743 | destroy_blocks(); |
722 | 744 | ||
723 | - time = *(int32_t*)_c1s1; | ||
724 | - version = *(int32_t*)(_c1s1 + 4); // client c1 version | 745 | + |
746 | + time = __srs_stream_read_4bytes(_c1s1); | ||
747 | + version = __srs_stream_read_4bytes(_c1s1 + 4); // client c1 version | ||
725 | 748 | ||
726 | if (_schema == srs_schema0) { | 749 | if (_schema == srs_schema0) { |
727 | if ((ret = srs_key_block_parse(&block0.key, _c1s1 + 8)) != ERROR_SUCCESS) { | 750 | if ((ret = srs_key_block_parse(&block0.key, _c1s1 + 8)) != ERROR_SUCCESS) { |
@@ -766,9 +789,11 @@ namespace srs | @@ -766,9 +789,11 @@ namespace srs | ||
766 | 789 | ||
767 | destroy_blocks(); | 790 | destroy_blocks(); |
768 | 791 | ||
792 | + // client c1 time and version | ||
769 | time = ::time(NULL); | 793 | time = ::time(NULL); |
770 | - version = 0x00000000; // client c1 version | 794 | + version = 0x80000702; // client c1 version |
771 | 795 | ||
796 | + // generate signature by schema | ||
772 | if (_schema == srs_schema0) { | 797 | if (_schema == srs_schema0) { |
773 | srs_key_block_init(&block0.key); | 798 | srs_key_block_init(&block0.key); |
774 | srs_digest_block_init(&block1.digest); | 799 | srs_digest_block_init(&block1.digest); |
@@ -779,6 +804,7 @@ namespace srs | @@ -779,6 +804,7 @@ namespace srs | ||
779 | 804 | ||
780 | schema = _schema; | 805 | schema = _schema; |
781 | 806 | ||
807 | + // generate digest | ||
782 | char* digest = NULL; | 808 | char* digest = NULL; |
783 | 809 | ||
784 | if ((ret = calc_c1_digest(digest)) != ERROR_SUCCESS) { | 810 | if ((ret = calc_c1_digest(digest)) != ERROR_SUCCESS) { |
@@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
31 | #include <srs_protocol_handshake.hpp> | 31 | #include <srs_protocol_handshake.hpp> |
32 | #include <srs_protocol_rtmp_stack.hpp> | 32 | #include <srs_protocol_rtmp_stack.hpp> |
33 | #include <srs_protocol_utility.hpp> | 33 | #include <srs_protocol_utility.hpp> |
34 | +#include <srs_kernel_stream.hpp> | ||
34 | 35 | ||
35 | using namespace std; | 36 | using namespace std; |
36 | 37 | ||
@@ -268,9 +269,13 @@ int SrsHandshakeBytes::create_c0c1() | @@ -268,9 +269,13 @@ int SrsHandshakeBytes::create_c0c1() | ||
268 | srs_random_generate(c0c1, 1537); | 269 | srs_random_generate(c0c1, 1537); |
269 | 270 | ||
270 | // plain text required. | 271 | // plain text required. |
271 | - c0c1[0] = 0x03; | ||
272 | - *(int32_t*)(c0c1 + 1) = ::time(NULL); | ||
273 | - *(int32_t*)(c0c1 + 1 + 4) = 0x00; | 272 | + static SrsStream stream; |
273 | + if ((ret = stream.initialize(c0c1, 9)) != ERROR_SUCCESS) { | ||
274 | + return ret; | ||
275 | + } | ||
276 | + stream.write_1bytes(0x03); | ||
277 | + stream.write_4bytes(::time(NULL)); | ||
278 | + stream.write_4bytes(0x00); | ||
274 | 279 | ||
275 | return ret; | 280 | return ret; |
276 | } | 281 | } |
@@ -287,11 +292,15 @@ int SrsHandshakeBytes::create_s0s1s2(const char* c1) | @@ -287,11 +292,15 @@ int SrsHandshakeBytes::create_s0s1s2(const char* c1) | ||
287 | srs_random_generate(s0s1s2, 3073); | 292 | srs_random_generate(s0s1s2, 3073); |
288 | 293 | ||
289 | // plain text required. | 294 | // plain text required. |
290 | - s0s1s2[0] = 0x03; | ||
291 | - *(int32_t*)(s0s1s2 + 1) = ::time(NULL); | 295 | + SrsStream stream; |
296 | + if ((ret = stream.initialize(s0s1s2, 9)) != ERROR_SUCCESS) { | ||
297 | + return ret; | ||
298 | + } | ||
299 | + stream.write_1bytes(0x03); | ||
300 | + stream.write_4bytes(::time(NULL)); | ||
292 | // s2 time2 copy from c1 | 301 | // s2 time2 copy from c1 |
293 | if (c0c1) { | 302 | if (c0c1) { |
294 | - *(int32_t*)(s0s1s2 + 1 + 4) = *(int32_t*)(c0c1 + 1); | 303 | + stream.write_bytes(c0c1 + 1, 4); |
295 | } | 304 | } |
296 | 305 | ||
297 | // if c1 specified, copy c1 to s2. | 306 | // if c1 specified, copy c1 to s2. |
@@ -315,10 +324,14 @@ int SrsHandshakeBytes::create_c2() | @@ -315,10 +324,14 @@ int SrsHandshakeBytes::create_c2() | ||
315 | srs_random_generate(c2, 1536); | 324 | srs_random_generate(c2, 1536); |
316 | 325 | ||
317 | // time | 326 | // time |
318 | - *(int32_t*)(c2) = ::time(NULL); | 327 | + SrsStream stream; |
328 | + if ((ret = stream.initialize(c2, 8)) != ERROR_SUCCESS) { | ||
329 | + return ret; | ||
330 | + } | ||
331 | + stream.write_4bytes(::time(NULL)); | ||
319 | // c2 time2 copy from s1 | 332 | // c2 time2 copy from s1 |
320 | if (s0s1s2) { | 333 | if (s0s1s2) { |
321 | - *(int32_t*)(c2 + 4) = *(int32_t*)(s0s1s2 + 1); | 334 | + stream.write_bytes(s0s1s2 + 1, 4); |
322 | } | 335 | } |
323 | 336 | ||
324 | return ret; | 337 | return ret; |
@@ -455,6 +468,7 @@ int SrsRtmpClient::connect_app(string app, string tc_url) | @@ -455,6 +468,7 @@ int SrsRtmpClient::connect_app(string app, string tc_url) | ||
455 | SrsConnectAppPacket* pkt = new SrsConnectAppPacket(); | 468 | SrsConnectAppPacket* pkt = new SrsConnectAppPacket(); |
456 | 469 | ||
457 | pkt->command_object->set("app", SrsAmf0Any::str(app.c_str())); | 470 | pkt->command_object->set("app", SrsAmf0Any::str(app.c_str())); |
471 | + pkt->command_object->set("flashVer", SrsAmf0Any::str("WIN 12,0,0,41")); | ||
458 | pkt->command_object->set("swfUrl", SrsAmf0Any::str()); | 472 | pkt->command_object->set("swfUrl", SrsAmf0Any::str()); |
459 | pkt->command_object->set("tcUrl", SrsAmf0Any::str(tc_url.c_str())); | 473 | pkt->command_object->set("tcUrl", SrsAmf0Any::str(tc_url.c_str())); |
460 | pkt->command_object->set("fpad", SrsAmf0Any::boolean(false)); | 474 | pkt->command_object->set("fpad", SrsAmf0Any::boolean(false)); |
-
请 注册 或 登录 后发表评论