Changeset 29007
- Timestamp:
- 01/25/09 16:37:56 (4 years ago)
- Location:
- lang/c/librtmp
- Files:
-
- 2 modified
-
main.c (modified) (3 diffs)
-
rtmp_packet.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/c/librtmp/main.c
r28982 r29007 71 71 0x2C, 0x30, 0x2C, 0x31, 0x2C, 0x31, 0x32, 0x33, 72 72 0x00, 0x0C, 0x63, 0x61, 0x70, 0x61, 0x62, 0x69, 73 0x6C, 0x69, 0x74, 0x69, 0x65, 0x73, 0x00, 0x40, //73 0x6C, 0x69, 0x74, 0x69, 0x65, 0x73, 0x00, 0x40, 74 74 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 75 75 0x00, 0x09, 0x03, 0x00, 0x05, 0x6C, 0x65, 0x76, … … 80 80 0x6E, 0x2E, 0x43, 0x6F, 0x6E, 0x6E, 0x65, 0x63, 81 81 0x74, 0x2E, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 82 0x73, 0x00, 0x0B, 0x64, 0x65, 0x73, 0x63, 0x72, //82 0x73, 0x00, 0x0B, 0x64, 0x65, 0x73, 0x63, 0x72, 83 83 0x69, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x02, 0x00, 84 84 0x15, 0x43, 0x6F, 0x6E, 0x6E, 0x65, 0x63, 0x74, … … 102 102 rtmp_packet, 103 103 rtmp_packet_temp, sizeof(rtmp_packet_temp), 104 4096,104 AMF_CHANK_SIZE, 105 105 &outputed_size); 106 106 printf("analyzed size: %d\n", outputed_size); -
lang/c/librtmp/rtmp_packet.c
r28982 r29007 32 32 33 33 static void rtmp_packet_cleanup(rtmp_packet_t *packet); 34 static unsigned char *rtmp_packet_retrieve_amf( 35 unsigned char *amf_chunks, size_t amf_with_chunk_header_size, 36 size_t amf_chunk_size, 37 size_t *return_amf_size); 34 static unsigned char *rtmp_packet_retrieve_body( 35 unsigned char *amf_chunks, size_t rtmp_body_size, 36 size_t amf_chunk_size, int chunk_delimiter_num); 38 37 static size_t rtmp_packet_insert_amf_chunk_header( 39 38 rtmp_packet_t *packet, … … 44 43 static rtmp_result_t rtmp_packet_amf_analyze( 45 44 rtmp_packet_t *packet, 46 unsigned char *amf_packets_buffer, size_t amf_size);45 unsigned char *amf_packets_buffer, size_t rtmp_body_size); 47 46 48 47 … … 79 78 80 79 81 unsigned char *rtmp_packet_retrieve_amf( 82 unsigned char *amf_chunks, size_t amf_with_chunk_header_size, 83 size_t amf_chunk_size, 84 size_t *return_amf_size) 85 { 86 int chunk_delimiter_num; 80 unsigned char *rtmp_packet_retrieve_body( 81 unsigned char *amf_chunks, size_t rtmp_body_size, 82 size_t amf_chunk_size, int chunk_delimiter_num) 83 { 87 84 int amf_size_count; 88 85 size_t amf_moved_size; 89 size_t amf_size;90 86 unsigned char *amf_output_buffer; 91 92 chunk_delimiter_num = 0; 93 amf_size_count = amf_with_chunk_header_size - amf_chunk_size; 94 while (amf_size_count > 0) { 95 chunk_delimiter_num++; 96 amf_size_count -= amf_chunk_size + 1; /* 1 is delimiter(0xC3) */ 97 } 98 amf_size = amf_with_chunk_header_size - chunk_delimiter_num; 99 amf_output_buffer = (unsigned char*)malloc(amf_size); 87 size_t rtmp_body_with_chunk_delimiter_size; 88 89 amf_output_buffer = (unsigned char*)malloc(rtmp_body_size); 100 90 if (amf_output_buffer == NULL) { 101 *return_amf_size = 0;102 91 return NULL; 103 92 } 104 93 amf_size_count = 0; 105 94 amf_moved_size = 0; 106 while (amf_size_count < amf_with_chunk_header_size) { 107 int rest = amf_with_chunk_header_size - amf_size_count; 95 rtmp_body_with_chunk_delimiter_size = 96 rtmp_body_size + chunk_delimiter_num; 97 while (amf_size_count < rtmp_body_with_chunk_delimiter_size) { 98 int rest = rtmp_body_with_chunk_delimiter_size - amf_size_count; 108 99 if (rest < amf_chunk_size) { 109 100 memmove( … … 120 111 amf_size_count += amf_chunk_size + 1; /* 1 is delimiter(0xC3) */ 121 112 } 122 *return_amf_size = amf_size;123 113 return amf_output_buffer; 124 114 } … … 133 123 int header_size_magic; 134 124 int header_size; 135 size_t amf_with_chunk_header_size;125 size_t rtmp_body_size; 136 126 unsigned char *amf_chunks; 137 127 unsigned char *amf_buffer; 138 size_t amf_size;139 128 rtmp_result_t amf_ret; 129 int chunk_delimiter_num; 130 int amf_size_count; 140 131 141 132 if (data_size == 0) { … … 172 163 packet->timer = read_be24int(data + 1); 173 164 #ifdef DEBUG 174 printf("timer: % d\n", packet->timer);165 printf("timer: %ld\n", packet->timer); 175 166 #endif 176 167 if (header_size_magic == HEADER_MAGIC_04) { … … 183 174 return RTMP_ERROR_DIVIDED_PACKET; 184 175 } 185 amf_with_chunk_header_size = read_be24int(data + 4); 186 #ifdef DEBUG 187 printf("amf_with_chunk_header_size: %d\n", amf_with_chunk_header_size); 176 rtmp_body_size = read_be24int(data + 4); 177 #ifdef DEBUG 178 printf("rtmp_body_size: %d\n", rtmp_body_size); 179 #endif 180 chunk_delimiter_num = 0; 181 amf_size_count = amf_chunk_size; 182 while (amf_size_count < rtmp_body_size) { 183 chunk_delimiter_num++; 184 amf_size_count -= amf_chunk_size; 185 } 186 #ifdef DEBUG 187 printf("chunk_delimiter_num: %d\n", chunk_delimiter_num); 188 188 #endif 189 189 packet->data_type = data[7]; … … 193 193 if (header_size_magic == HEADER_MAGIC_08) { 194 194 header_size = 8; 195 if ( amf_with_chunk_header_size == 0) {195 if (rtmp_body_size == 0) { 196 196 *packet_size = 8; 197 197 return RTMP_SUCCESS; … … 205 205 header_size = 12; 206 206 packet->stream_id = read_le32int(data + 8); 207 if ( amf_with_chunk_header_size == 0) {207 if (rtmp_body_size == 0) { 208 208 *packet_size = 12; 209 209 return RTMP_SUCCESS; … … 211 211 amf_chunks = data + 12; 212 212 } 213 if (header_size + amf_with_chunk_header_size > data_size) {213 if (header_size + rtmp_body_size > data_size) { 214 214 *packet_size = 0; 215 215 return RTMP_ERROR_BROKEN_PACKET; 216 216 } 217 *packet_size = header_size + amf_with_chunk_header_size;218 219 amf_buffer = rtmp_packet_retrieve_ amf(220 amf_chunks, amf_with_chunk_header_size, amf_chunk_size, &amf_size);221 amf_ret = rtmp_packet_amf_analyze(packet, amf_buffer, amf_size);217 *packet_size = header_size + rtmp_body_size; 218 219 amf_buffer = rtmp_packet_retrieve_body( 220 amf_chunks, rtmp_body_size, amf_chunk_size, chunk_delimiter_num); 221 amf_ret = rtmp_packet_amf_analyze(packet, amf_buffer, rtmp_body_size); 222 222 free(amf_buffer); 223 223 … … 326 326 amf_size - total_serialized_amf_size); 327 327 if (serialized_amf_size == 0) { 328 #ifdef DEBUG 328 329 printf("AMF serialized error!\n"); 330 #endif 329 331 } 330 332 total_serialized_amf_size += serialized_amf_size;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)