Changeset 29884 for lang/c/librtmp
- Timestamp:
- 02/11/09 02:19:25 (4 years ago)
- Location:
- lang/c/librtmp
- Files:
-
- 7 modified
-
amf_packet.c (modified) (7 diffs)
-
amf_packet.h (modified) (1 diff)
-
main.c (modified) (7 diffs)
-
rtmp.c (modified) (7 diffs)
-
rtmp.h (modified) (1 diff)
-
rtmp_packet.c (modified) (9 diffs)
-
rtmp_packet.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/librtmp/amf_packet.c
r28982 r29884 566 566 output_buffer[0] = AMF_DATATYPE_NUMBER; 567 567 write_be64double(output_buffer + 1, amf->number.value); 568 #ifdef DEBUG 569 printf("AMF serialize number: %f: ", amf->number.value); 570 { 571 int i; 572 for (i = 0; i < 9; ++i) { 573 printf("%02x, ", output_buffer[i]); 574 } 575 } 576 printf("\n"); 577 #endif 568 578 569 579 return 9; … … 580 590 output_buffer[0] = AMF_DATATYPE_BOOLEAN; 581 591 memmove(output_buffer + 1, &amf->boolean.value, 1); 592 #ifdef DEBUG 593 printf("AMF serialize boolean: %d\n", amf->boolean.value); 594 #endif 582 595 583 596 return 2; … … 598 611 write_be16int(output_buffer + 1, length); 599 612 memmove(output_buffer + 3 , amf->string.value, length); 613 #ifdef DEBUG 614 printf("AMF serialize string: %d: '%s': ", length, amf->string.value); 615 { 616 int i; 617 for (i = 0; i < 3 + length; ++i) { 618 printf("%02x, ", output_buffer[i]); 619 } 620 } 621 printf("\n"); 622 #endif 600 623 601 624 return 3 + length; … … 615 638 } 616 639 640 #ifdef DEBUG 641 printf("AMF serialize object start\n"); 642 #endif 617 643 output_buffer[0] = AMF_DATATYPE_OBJECT; 618 644 outputed_size = 1; … … 627 653 output_buffer + outputed_size + 2, 628 654 property->key, key_length); 655 #ifdef DEBUG 656 printf("key serialize: %d: '%s': ", key_length, property->key); 657 { 658 int i; 659 for (i = 0; i < 2 + key_length; ++i) { 660 printf("%02x, ", output_buffer[outputed_size + i]); 661 } 662 } 663 printf("\n"); 664 #endif 629 665 outputed_size += 2 + key_length; 630 666 serialized_value_size = amf_packet_serialize( … … 645 681 output_buffer[outputed_size] = 0x09; 646 682 outputed_size += 1; 683 #ifdef DEBUG 684 printf("AMF serialize object end\n"); 685 #endif 647 686 648 687 return outputed_size; … … 671 710 672 711 output_buffer[0] = AMF_DATATYPE_UNDEFINED; 712 #ifdef DEBUG 713 printf("AMF serialize undefined\n"); 714 #endif 673 715 674 716 return 1; -
lang/c/librtmp/amf_packet.h
r28791 r29884 127 127 extern amf_packet_t *amf_packet_create_boolean(int boolean); 128 128 extern amf_packet_t *amf_packet_create_string(char *string); 129 extern amf_packet_t *amf_packet_create_undefined(void); 129 130 extern amf_packet_t *amf_packet_create_object(void); 130 131 extern rtmp_result_t amf_packet_add_property_to_object( -
lang/c/librtmp/main.c
r29007 r29884 19 19 20 20 { 21 /* 21 22 rtmp_packet_t *rtmp_packet; 22 23 amf_packet_t *amf; … … 62 63 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 63 64 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3, 0x09}; 65 */ 64 66 /* 65 67 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD1, 0x14, … … 92 94 0x00, 0x00, 0x00, 0x00, 0x09}; 93 95 */ 96 /* 94 97 printf("sample RTMP data size: %d\n", sizeof(rtmp_packet_temp)); 95 98 for (i = 0; i < sizeof(rtmp_packet_temp); ++i) { … … 106 109 printf("analyzed size: %d\n", outputed_size); 107 110 rtmp_packet_serialize( 108 rtmp_packet, output_buffer, 1024, 4096, &outputed_size);111 rtmp_packet, output_buffer, 1024, AMF_CHANK_SIZE, &outputed_size); 109 112 printf("serialized size: %d\n", outputed_size); 110 113 for (i = 0; i < outputed_size; ++i) { … … 116 119 rtmp_packet, 117 120 output_buffer, outputed_size, 118 4096,121 AMF_CHANK_SIZE, 119 122 &outputed_size); 120 123 printf("analyzed size: %d\n", outputed_size); 121 124 rtmp_packet_serialize( 122 rtmp_packet, output_buffer, 1024, 4096, &outputed_size);125 rtmp_packet, output_buffer, 1024, AMF_CHANK_SIZE, &outputed_size); 123 126 printf("serialized size: %d\n", outputed_size); 124 127 for (i = 0; i < outputed_size; ++i) { … … 214 217 printf("\n%d\n", outputed_size); 215 218 amf_packet_free(amf); 219 */ 216 220 } 217 return 0;221 // return 0; 218 222 219 223 rc = rtmp_client_create("192.168.157.128", 1935); … … 225 229 printf("created.\n"); 226 230 227 count = 20000 ;231 count = 200000; 228 232 while (count--) { 229 233 rtmp_client_process_message(rc); -
lang/c/librtmp/rtmp.c
r28892 r29884 57 57 #include "rtmp.h" 58 58 #include "rtmp_packet.h" 59 #include "amf_packet.h" 59 60 #include "handshake.h" 60 61 … … 196 197 static void rtmp_client_handshake_first(rtmp_client_t *client); 197 198 static void rtmp_client_handshake_second(rtmp_client_t *client); 198 static void rtmp_client_get_ server_bandwidth(rtmp_client_t *client);199 static void rtmp_client_ get_client_bandwidth(rtmp_client_t *client);200 static void rtmp_client_test(rtmp_client_t *client);199 static void rtmp_client_get_packet(rtmp_client_t *client); 200 static void rtmp_client_proces_packet( 201 rtmp_client_t *client, rtmp_packet_t *packet); 201 202 202 203 static int rtmp_client_set_will_send_buffer( … … 204 205 static void rtmp_client_delete_received_buffer( 205 206 rtmp_client_t *client, int size); 207 static rtmp_result_t rtmp_client_send_packet( 208 rtmp_client_t *client, rtmp_packet_t *packet); 206 209 207 210 … … 292 295 (void*)(client->received_buffer + client->received_size), 293 296 RTMP_BUFFER_SIZE - client->received_size, 0); 297 #ifdef DEBUG 294 298 if (received_size > 0) { 295 printf("::%d:%x\n", received_size, client->received_buffer[client->received_size + 1]); 296 } 299 printf("received: %d\n", received_size); 300 } 301 #endif 297 302 client->received_size += received_size; 298 303 } … … 311 316 (const void*)client->will_send_buffer, 312 317 client->will_send_size, 0); 318 #ifdef DEBUG 319 if (sent_size > 0) { 320 printf("sent: %d\n", sent_size); 321 } 322 #endif 313 323 if (client->will_send_size - sent_size > 0) { 314 324 memmove( … … 372 382 client, 1 + sizeof(HandshakePacket) * 2); 373 383 printf("handshake 2\n"); 374 client->process_message = rtmp_client_get_server_bandwidth;375 384 client->data = rtmp_packet_create(); 376 } 377 } 378 379 static void rtmp_client_get_server_bandwidth(rtmp_client_t *client) 385 client->process_message = rtmp_client_get_packet; 386 rtmp_client_connect(client); 387 } 388 } 389 390 static void rtmp_client_get_packet(rtmp_client_t *client) 380 391 { 381 392 rtmp_result_t ret; … … 391 402 if (ret != RTMP_ERROR_UNKNOWN) printf("aofieoiea: %d\n", ret); 392 403 if (ret == RTMP_SUCCESS) { 404 printf("kuso\n"); 393 405 rtmp_client_delete_received_buffer(client, packet_size); 394 client->process_message = rtmp_client_get_client_bandwidth; 395 } 396 } 397 398 static void rtmp_client_get_client_bandwidth(rtmp_client_t *client) 399 { 400 rtmp_result_t ret; 406 rtmp_client_proces_packet(client, packet); 407 } 408 } 409 410 411 void rtmp_client_proces_packet( 412 rtmp_client_t *client, rtmp_packet_t *packet) 413 { 414 switch (packet->data_type) { 415 case RTMP_DATATYPE_CHUNK_SIZE: 416 break; 417 case RTMP_DATATYPE_BYTES_READ: 418 break; 419 case RTMP_DATATYPE_PING: 420 break; 421 case RTMP_DATATYPE_SERVER_BW: 422 break; 423 case RTMP_DATATYPE_CLIENT_BW: 424 break; 425 case RTMP_DATATYPE_AUDIO_DATA: 426 break; 427 case RTMP_DATATYPE_VIDEO_DATA: 428 break; 429 case RTMP_DATATYPE_MESSAGE: 430 break; 431 case RTMP_DATATYPE_NOTIFY: 432 break; 433 case RTMP_DATATYPE_SHARED_OBJECT: 434 break; 435 case RTMP_DATATYPE_INVOKE: 436 break; 437 default: 438 break; 439 } 440 } 441 442 443 rtmp_result_t rtmp_client_send_packet( 444 rtmp_client_t *client, rtmp_packet_t *packet) 445 { 446 rtmp_result_t result; 401 447 size_t packet_size; 402 rtmp_packet_t *packet; 403 404 packet = (rtmp_packet_t*)client->data; 405 ret = rtmp_packet_analyze_data( 448 449 result = rtmp_packet_serialize( 406 450 packet, 407 client->received_buffer, client->received_size, 451 client->will_send_buffer + client->will_send_size, 452 RTMP_BUFFER_SIZE - client->will_send_size, 408 453 client->amf_chunk_size, 409 454 &packet_size); 410 if (ret == RTMP_SUCCESS) { 411 rtmp_client_delete_received_buffer(client, packet_size); 412 client->process_message = rtmp_client_test; 413 } 414 } 415 416 static void rtmp_client_test(rtmp_client_t *client) 417 { 418 rtmp_result_t ret; 419 size_t packet_size; 420 rtmp_packet_t *packet; 421 422 packet = (rtmp_packet_t*)client->data; 423 ret = rtmp_packet_analyze_data( 424 packet, 425 client->received_buffer, client->received_size, 426 client->amf_chunk_size, 427 &packet_size); 428 if (ret == RTMP_SUCCESS) { 429 rtmp_client_delete_received_buffer(client, packet_size); 430 } 431 } 432 455 if (result != RTMP_SUCCESS) { 456 return result; 457 } 458 client->will_send_size += packet_size; 459 460 return RTMP_SUCCESS; 461 } 462 463 464 void rtmp_client_connect( 465 rtmp_client_t *client 466 /* FIXME: take URL */) 467 { 468 rtmp_packet_t *rtmp_packet; 469 amf_packet_t *amf_object; 470 471 rtmp_packet = (rtmp_packet_t*)client->data; 472 rtmp_packet_cleanup(rtmp_packet); 473 rtmp_packet->object_id = 3; 474 475 rtmp_packet_add_amf( 476 rtmp_packet, 477 amf_packet_create_string("connect")); 478 rtmp_packet_add_amf( 479 rtmp_packet, 480 amf_packet_create_number(1.0)); 481 482 amf_object = amf_packet_create_object(); 483 amf_packet_add_property_to_object( 484 amf_object, "app", amf_packet_create_string("fastpaly/")); 485 amf_packet_add_property_to_object( 486 amf_object, "flashVer", amf_packet_create_string("WIN 10,0,12,36")); 487 amf_packet_add_property_to_object( 488 amf_object, "swfUrl", amf_packet_create_undefined()); 489 amf_packet_add_property_to_object( 490 amf_object, "tcUrl", 491 amf_packet_create_string("rtmp://192.168.157.128:1935/fastplay/")); 492 amf_packet_add_property_to_object( 493 amf_object, "fpad", amf_packet_create_boolean(0)); 494 amf_packet_add_property_to_object( 495 amf_object, "capabilities", amf_packet_create_number(15.0)); 496 amf_packet_add_property_to_object( 497 amf_object, "audioCodecs", amf_packet_create_number(3191.0)); 498 amf_packet_add_property_to_object( 499 amf_object, "videoCodecs", amf_packet_create_number(252.0)); 500 amf_packet_add_property_to_object( 501 amf_object, "videoFunction", amf_packet_create_number(1.0)); 502 amf_packet_add_property_to_object( 503 amf_object, "pageUrl", amf_packet_create_undefined()); 504 amf_packet_add_property_to_object( 505 amf_object, "objectEncoding", amf_packet_create_number(0.0)); 506 rtmp_packet_add_amf(rtmp_packet, amf_object); 507 508 rtmp_client_send_packet(client, rtmp_packet); 509 } 510 -
lang/c/librtmp/rtmp.h
r28892 r29884 123 123 }; 124 124 125 125 126 extern rtmp_client_t *rtmp_client_create(); 126 127 extern void rtmp_client_free(rtmp_client_t *client); 128 extern void rtmp_client_connect( 129 rtmp_client_t *client 130 /* FIXME: take URL */); 127 131 128 132 extern void rtmp_client_process_message(rtmp_client_t *client); -
lang/c/librtmp/rtmp_packet.c
r29501 r29884 31 31 32 32 33 static void rtmp_packet_cleanup(rtmp_packet_t *packet);34 33 void rtmp_packet_retrieve_body( 35 34 unsigned char *body_output_buffer, … … 39 38 rtmp_packet_t *packet, 40 39 unsigned char *amf_buffer, 41 size_t amf_ with_chunk_header_size,40 size_t amf_size, 42 41 size_t amf_chunk_size, 43 42 unsigned char *output_buffer); … … 330 329 header_size = 12; 331 330 331 #ifdef DEBUG 332 printf("RTMP packet serialize start\n"); 333 #endif 332 334 if (header_size > output_buffer_size) { 333 335 *packet_size = 0; … … 359 361 amf_buffer = (unsigned char*)malloc(amf_size); 360 362 363 #ifdef DEBUG 364 printf("AMF serialize start\n"); 365 #endif 361 366 total_serialized_amf_size = 0; 362 367 inner_amf = packet->inner_amf_packets; … … 368 373 if (serialized_amf_size == 0) { 369 374 #ifdef DEBUG 370 printf("AMF serialize derror!\n");375 printf("AMF serialize error!\n"); 371 376 #endif 372 377 } … … 374 379 inner_amf = inner_amf->next; 375 380 } 381 #ifdef DEBUG 382 printf("AMF serialize end\n"); 383 #endif 376 384 377 385 total_serialized_size += rtmp_packet_insert_amf_chunk_header( 378 packet, amf_buffer, amf_ with_chunk_header_size,386 packet, amf_buffer, amf_size, 379 387 amf_chunk_size, 380 388 output_buffer + total_serialized_size); … … 383 391 384 392 *packet_size = total_serialized_size; 393 #ifdef DEBUG 394 printf("RTMP packet serialize end\n"); 395 #endif 385 396 386 397 return RTMP_SUCCESS; … … 391 402 rtmp_packet_t *packet, 392 403 unsigned char *amf_buffer, 393 size_t amf_ with_chunk_header_size,404 size_t amf_size, 394 405 size_t amf_chunk_size, 395 406 unsigned char *output_buffer) … … 401 412 total_serialized_size = 0; 402 413 amf_buffer_count = 0; 403 while (total_serialized_size < amf_with_chunk_header_size) { 404 remaining_chunk_size = amf_with_chunk_header_size - amf_buffer_count; 414 remaining_chunk_size = amf_size - amf_buffer_count; 415 while (remaining_chunk_size > 0) { 416 remaining_chunk_size = amf_size - amf_buffer_count; 405 417 if (remaining_chunk_size > amf_chunk_size) { 406 418 memmove( -
lang/c/librtmp/rtmp_packet.h
r29501 r29884 87 87 rtmp_packet_t *packet, 88 88 amf_packet_t *amf); 89 extern void rtmp_packet_cleanup(rtmp_packet_t *packet); 89 90 90 91 extern rtmp_result_t rtmp_packet_analyze_data(
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)