refine the type of RTMP from int to char. add srs_parse_timestamp(), 2.0.19
正在显示
10 个修改的文件
包含
180 行增加
和
55 行删除
| @@ -35,9 +35,10 @@ int main(int argc, char** argv) | @@ -35,9 +35,10 @@ int main(int argc, char** argv) | ||
| 35 | srs_rtmp_t rtmp; | 35 | srs_rtmp_t rtmp; |
| 36 | 36 | ||
| 37 | // packet data | 37 | // packet data |
| 38 | - int type, size; | ||
| 39 | - u_int32_t timestamp = 0; | 38 | + int size; |
| 39 | + char type; | ||
| 40 | char* data; | 40 | char* data; |
| 41 | + u_int32_t timestamp; | ||
| 41 | 42 | ||
| 42 | // srs debug info. | 43 | // srs debug info. |
| 43 | char srs_server_ip[128]; | 44 | char srs_server_ip[128]; |
| @@ -49,10 +49,11 @@ int main(int argc, char** argv) | @@ -49,10 +49,11 @@ int main(int argc, char** argv) | ||
| 49 | int64_t bytes_nrecv = 0; | 49 | int64_t bytes_nrecv = 0; |
| 50 | 50 | ||
| 51 | // packet data | 51 | // packet data |
| 52 | - int type, size; | ||
| 53 | - u_int32_t basetime = 0; | ||
| 54 | - u_int32_t timestamp = 0; | 52 | + int size; |
| 53 | + char type; | ||
| 55 | char* data; | 54 | char* data; |
| 55 | + u_int32_t timestamp; | ||
| 56 | + u_int32_t basetime = 0; | ||
| 56 | 57 | ||
| 57 | // user options | 58 | // user options |
| 58 | const char* rtmp_url = NULL; | 59 | const char* rtmp_url = NULL; |
| @@ -125,7 +125,7 @@ int parse_bytes(char* data, int size, char* hbuf, int hsize, char* tbuf, int tsi | @@ -125,7 +125,7 @@ int parse_bytes(char* data, int size, char* hbuf, int hsize, char* tbuf, int tsi | ||
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | #define FLV_HEADER_SIZE 11 | 127 | #define FLV_HEADER_SIZE 11 |
| 128 | -int parse_script_data(u_int32_t timestamp, char* data, int size, int64_t offset) | 128 | +int parse_script_data(u_int32_t timestamp, u_int32_t pts, char* data, int size, int64_t offset) |
| 129 | { | 129 | { |
| 130 | int ret = 0; | 130 | int ret = 0; |
| 131 | 131 | ||
| @@ -152,10 +152,10 @@ int parse_script_data(u_int32_t timestamp, char* data, int size, int64_t offset) | @@ -152,10 +152,10 @@ int parse_script_data(u_int32_t timestamp, char* data, int size, int64_t offset) | ||
| 152 | } | 152 | } |
| 153 | amf0_data = srs_amf0_parse(data + nparsed, size - nparsed, &nparsed); | 153 | amf0_data = srs_amf0_parse(data + nparsed, size - nparsed, &nparsed); |
| 154 | 154 | ||
| 155 | - srs_lib_trace("packet type=%s, time=%d, size=%d, data-size=%d, \n" | 155 | + srs_lib_trace("packet type=%s, dts=%d, pts=%d, size=%d, data-size=%d, \n" |
| 156 | "offset=%d\n[+00, +15] %s\n[-15, EOF] %s\n%s%s", | 156 | "offset=%d\n[+00, +15] %s\n[-15, EOF] %s\n%s%s", |
| 157 | - srs_type2string(SRS_RTMP_TYPE_SCRIPT), timestamp, size + FLV_HEADER_SIZE, size, | ||
| 158 | - (int)offset, hbuf, tbuf, | 157 | + srs_type2string(SRS_RTMP_TYPE_SCRIPT), timestamp, pts, |
| 158 | + size + FLV_HEADER_SIZE, size, (int)offset, hbuf, tbuf, | ||
| 159 | srs_amf0_human_print(amf0_name, &amf0_name_str, &amf0_size), | 159 | srs_amf0_human_print(amf0_name, &amf0_name_str, &amf0_size), |
| 160 | srs_amf0_human_print(amf0_data, &amf0_data_str, &amf0_size)); | 160 | srs_amf0_human_print(amf0_data, &amf0_data_str, &amf0_size)); |
| 161 | 161 | ||
| @@ -168,7 +168,7 @@ int parse_script_data(u_int32_t timestamp, char* data, int size, int64_t offset) | @@ -168,7 +168,7 @@ int parse_script_data(u_int32_t timestamp, char* data, int size, int64_t offset) | ||
| 168 | return ret; | 168 | return ret; |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | -int parse_audio_data(u_int32_t timestamp, char* data, int size, int64_t offset) | 171 | +int parse_audio_data(u_int32_t timestamp, u_int32_t pts, char* data, int size, int64_t offset) |
| 172 | { | 172 | { |
| 173 | int ret = 0; | 173 | int ret = 0; |
| 174 | 174 | ||
| @@ -178,15 +178,15 @@ int parse_audio_data(u_int32_t timestamp, char* data, int size, int64_t offset) | @@ -178,15 +178,15 @@ int parse_audio_data(u_int32_t timestamp, char* data, int size, int64_t offset) | ||
| 178 | // bytes | 178 | // bytes |
| 179 | parse_bytes(data, size, hbuf, sizeof(hbuf), tbuf, sizeof(tbuf), 16); | 179 | parse_bytes(data, size, hbuf, sizeof(hbuf), tbuf, sizeof(tbuf), 16); |
| 180 | 180 | ||
| 181 | - srs_lib_trace("packet type=%s, time=%d, size=%d, data-size=%d, \n" | 181 | + srs_lib_trace("packet type=%s, dts=%d, pts=%d, size=%d, data-size=%d, \n" |
| 182 | "offset=%d\n[+00, +15] %s\n[-15, EOF] %s\n", | 182 | "offset=%d\n[+00, +15] %s\n[-15, EOF] %s\n", |
| 183 | - srs_type2string(SRS_RTMP_TYPE_AUDIO), timestamp, size + FLV_HEADER_SIZE, size, | ||
| 184 | - (int)offset, hbuf, tbuf); | 183 | + srs_type2string(SRS_RTMP_TYPE_AUDIO), timestamp, pts, |
| 184 | + size + FLV_HEADER_SIZE, size, (int)offset, hbuf, tbuf); | ||
| 185 | 185 | ||
| 186 | return ret; | 186 | return ret; |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | -int parse_video_data(u_int32_t timestamp, char* data, int size, int64_t offset) | 189 | +int parse_video_data(u_int32_t timestamp, u_int32_t pts, char* data, int size, int64_t offset) |
| 190 | { | 190 | { |
| 191 | int ret = 0; | 191 | int ret = 0; |
| 192 | 192 | ||
| @@ -196,10 +196,10 @@ int parse_video_data(u_int32_t timestamp, char* data, int size, int64_t offset) | @@ -196,10 +196,10 @@ int parse_video_data(u_int32_t timestamp, char* data, int size, int64_t offset) | ||
| 196 | // bytes | 196 | // bytes |
| 197 | parse_bytes(data, size, hbuf, sizeof(hbuf), tbuf, sizeof(tbuf), 16); | 197 | parse_bytes(data, size, hbuf, sizeof(hbuf), tbuf, sizeof(tbuf), 16); |
| 198 | 198 | ||
| 199 | - srs_lib_trace("packet type=%s, time=%d, size=%d, data-size=%d, \n" | 199 | + srs_lib_trace("packet type=%s, dts=%d, pts=%d, size=%d, data-size=%d, \n" |
| 200 | "offset=%d\n[+00, +15] %s\n[-15, EOF] %s\n", | 200 | "offset=%d\n[+00, +15] %s\n[-15, EOF] %s\n", |
| 201 | - srs_type2string(SRS_RTMP_TYPE_VIDEO), timestamp, size + FLV_HEADER_SIZE, size, | ||
| 202 | - (int)offset, hbuf, tbuf); | 201 | + srs_type2string(SRS_RTMP_TYPE_VIDEO), timestamp, pts, |
| 202 | + size + FLV_HEADER_SIZE, size, (int)offset, hbuf, tbuf); | ||
| 203 | 203 | ||
| 204 | return ret; | 204 | return ret; |
| 205 | } | 205 | } |
| @@ -240,27 +240,27 @@ int parse_flv(srs_flv_t flv) | @@ -240,27 +240,27 @@ int parse_flv(srs_flv_t flv) | ||
| 240 | break; | 240 | break; |
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | + u_int32_t pts = 0; | ||
| 243 | data = (char*)malloc(size); | 244 | data = (char*)malloc(size); |
| 244 | - if ((ret = srs_flv_read_tag_data(flv, data, size)) != 0) { | ||
| 245 | - return ret; | ||
| 246 | - } | ||
| 247 | 245 | ||
| 248 | - // data tag | ||
| 249 | - if (type == SRS_RTMP_TYPE_AUDIO) { | ||
| 250 | - if ((ret = parse_audio_data(timestamp, data, size, offset)) != 0) { | ||
| 251 | - return ret; | ||
| 252 | - } | ||
| 253 | - } else if (type == SRS_RTMP_TYPE_VIDEO) { | ||
| 254 | - if ((ret = parse_video_data(timestamp, data, size, offset)) != 0) { | ||
| 255 | - return ret; | ||
| 256 | - } | ||
| 257 | - } else { | ||
| 258 | - if ((ret = parse_script_data(timestamp, data, size, offset)) != 0) { | ||
| 259 | - return ret; | 246 | + if ((ret = srs_flv_read_tag_data(flv, data, size)) == 0 |
| 247 | + && (ret = srs_parse_timestamp(timestamp, type, data, size, &pts)) == 0 | ||
| 248 | + ) { | ||
| 249 | + if (type == SRS_RTMP_TYPE_AUDIO) { | ||
| 250 | + ret = parse_audio_data(timestamp, pts, data, size, offset); | ||
| 251 | + } else if (type == SRS_RTMP_TYPE_VIDEO) { | ||
| 252 | + ret = parse_video_data(timestamp, pts, data, size, offset); | ||
| 253 | + } else { | ||
| 254 | + ret = parse_script_data(timestamp, pts, data, size, offset); | ||
| 260 | } | 255 | } |
| 261 | } | 256 | } |
| 262 | 257 | ||
| 263 | free(data); | 258 | free(data); |
| 259 | + | ||
| 260 | + if (ret != 0) { | ||
| 261 | + srs_lib_trace("parse failed, ret=%d", ret); | ||
| 262 | + return ret; | ||
| 263 | + } | ||
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | return ret; | 266 | return ret; |
| @@ -94,9 +94,10 @@ int proxy(srs_rtmp_t irtmp, srs_rtmp_t ortmp) | @@ -94,9 +94,10 @@ int proxy(srs_rtmp_t irtmp, srs_rtmp_t ortmp) | ||
| 94 | int ret = 0; | 94 | int ret = 0; |
| 95 | 95 | ||
| 96 | // packet data | 96 | // packet data |
| 97 | - int type, size; | ||
| 98 | - u_int32_t timestamp = 0; | ||
| 99 | - char* data = NULL; | 97 | + int size; |
| 98 | + char type; | ||
| 99 | + char* data; | ||
| 100 | + u_int32_t timestamp; | ||
| 100 | 101 | ||
| 101 | if ((ret = connect_ic(irtmp)) != 0) { | 102 | if ((ret = connect_ic(irtmp)) != 0) { |
| 102 | return ret; | 103 | return ret; |
| @@ -66,15 +66,19 @@ int main(int argc, char** argv) | @@ -66,15 +66,19 @@ int main(int argc, char** argv) | ||
| 66 | srs_lib_trace("play stream success"); | 66 | srs_lib_trace("play stream success"); |
| 67 | 67 | ||
| 68 | for (;;) { | 68 | for (;;) { |
| 69 | - int type, size; | ||
| 70 | - u_int32_t timestamp = 0; | 69 | + int size; |
| 70 | + char type; | ||
| 71 | char* data; | 71 | char* data; |
| 72 | + u_int32_t timestamp, pts; | ||
| 72 | 73 | ||
| 73 | if (srs_read_packet(rtmp, &type, ×tamp, &data, &size) != 0) { | 74 | if (srs_read_packet(rtmp, &type, ×tamp, &data, &size) != 0) { |
| 74 | goto rtmp_destroy; | 75 | goto rtmp_destroy; |
| 75 | } | 76 | } |
| 76 | - srs_lib_trace("got packet: type=%s, time=%d, size=%d", | ||
| 77 | - srs_type2string(type), timestamp, size); | 77 | + if (srs_parse_timestamp(timestamp, type, data, size, &pts) != 0) { |
| 78 | + goto rtmp_destroy; | ||
| 79 | + } | ||
| 80 | + srs_lib_trace("got packet: type=%s, dts=%d, pts=%d, size=%d", | ||
| 81 | + srs_type2string(type), timestamp, pts, size); | ||
| 78 | 82 | ||
| 79 | free(data); | 83 | free(data); |
| 80 | } | 84 | } |
| @@ -75,7 +75,7 @@ int main(int argc, char** argv) | @@ -75,7 +75,7 @@ int main(int argc, char** argv) | ||
| 75 | 75 | ||
| 76 | u_int32_t timestamp = 0; | 76 | u_int32_t timestamp = 0; |
| 77 | for (;;) { | 77 | for (;;) { |
| 78 | - int type = SRS_RTMP_TYPE_VIDEO; | 78 | + char type = SRS_RTMP_TYPE_VIDEO; |
| 79 | int size = 4096; | 79 | int size = 4096; |
| 80 | char* data = (char*)malloc(4096); | 80 | char* data = (char*)malloc(4096); |
| 81 | 81 |
| @@ -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 2 | 32 | #define VERSION_MAJOR 2 |
| 33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
| 34 | -#define VERSION_REVISION 18 | 34 | +#define VERSION_REVISION 19 |
| 35 | // server info. | 35 | // server info. |
| 36 | #define RTMP_SIG_SRS_KEY "SRS" | 36 | #define RTMP_SIG_SRS_KEY "SRS" |
| 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" | 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" |
| @@ -185,6 +185,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -185,6 +185,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 185 | #define ERROR_EDGE_VHOST_REMOVED 3039 | 185 | #define ERROR_EDGE_VHOST_REMOVED 3039 |
| 186 | #define ERROR_HLS_AVC_TRY_OTHERS 3040 | 186 | #define ERROR_HLS_AVC_TRY_OTHERS 3040 |
| 187 | #define ERROR_H264_API_NO_PREFIXED 3041 | 187 | #define ERROR_H264_API_NO_PREFIXED 3041 |
| 188 | +#define ERROR_FLV_INVALID_VIDEO_TAG 3042 | ||
| 188 | 189 | ||
| 189 | /** | 190 | /** |
| 190 | * whether the error code is an system control error. | 191 | * whether the error code is an system control error. |
| @@ -337,7 +337,7 @@ int srs_publish_stream(srs_rtmp_t rtmp) | @@ -337,7 +337,7 @@ int srs_publish_stream(srs_rtmp_t rtmp) | ||
| 337 | return ret; | 337 | return ret; |
| 338 | } | 338 | } |
| 339 | 339 | ||
| 340 | -const char* srs_type2string(int type) | 340 | +const char* srs_type2string(char type) |
| 341 | { | 341 | { |
| 342 | static const char* audio = "Audio"; | 342 | static const char* audio = "Audio"; |
| 343 | static const char* video = "Video"; | 343 | static const char* video = "Video"; |
| @@ -390,7 +390,7 @@ int srs_bandwidth_check(srs_rtmp_t rtmp, | @@ -390,7 +390,7 @@ int srs_bandwidth_check(srs_rtmp_t rtmp, | ||
| 390 | return ret; | 390 | return ret; |
| 391 | } | 391 | } |
| 392 | 392 | ||
| 393 | -int srs_read_packet(srs_rtmp_t rtmp, int* type, u_int32_t* timestamp, char** data, int* size) | 393 | +int srs_read_packet(srs_rtmp_t rtmp, char* type, u_int32_t* timestamp, char** data, int* size) |
| 394 | { | 394 | { |
| 395 | *type = 0; | 395 | *type = 0; |
| 396 | *timestamp = 0; | 396 | *timestamp = 0; |
| @@ -445,7 +445,7 @@ int srs_read_packet(srs_rtmp_t rtmp, int* type, u_int32_t* timestamp, char** dat | @@ -445,7 +445,7 @@ int srs_read_packet(srs_rtmp_t rtmp, int* type, u_int32_t* timestamp, char** dat | ||
| 445 | return ret; | 445 | return ret; |
| 446 | } | 446 | } |
| 447 | 447 | ||
| 448 | -int srs_write_packet(srs_rtmp_t rtmp, int type, u_int32_t timestamp, char* data, int size) | 448 | +int srs_write_packet(srs_rtmp_t rtmp, char type, u_int32_t timestamp, char* data, int size) |
| 449 | { | 449 | { |
| 450 | int ret = ERROR_SUCCESS; | 450 | int ret = ERROR_SUCCESS; |
| 451 | 451 | ||
| @@ -531,6 +531,47 @@ int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp) | @@ -531,6 +531,47 @@ int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp) | ||
| 531 | return context->rtmp->get_recv_bytes(); | 531 | return context->rtmp->get_recv_bytes(); |
| 532 | } | 532 | } |
| 533 | 533 | ||
| 534 | +int srs_parse_timestamp( | ||
| 535 | + u_int32_t time, char type, char* data, int size, | ||
| 536 | + u_int32_t* ppts | ||
| 537 | +) { | ||
| 538 | + int ret = ERROR_SUCCESS; | ||
| 539 | + | ||
| 540 | + if (type != SRS_RTMP_TYPE_VIDEO) { | ||
| 541 | + *ppts = time; | ||
| 542 | + return ret; | ||
| 543 | + } | ||
| 544 | + | ||
| 545 | + if (!SrsFlvCodec::video_is_h264(data, size)) { | ||
| 546 | + return ERROR_FLV_INVALID_VIDEO_TAG; | ||
| 547 | + } | ||
| 548 | + | ||
| 549 | + if (SrsFlvCodec::video_is_sequence_header(data, size)) { | ||
| 550 | + *ppts = time; | ||
| 551 | + return ret; | ||
| 552 | + } | ||
| 553 | + | ||
| 554 | + // 1bytes, frame type and codec id. | ||
| 555 | + // 1bytes, avc packet type. | ||
| 556 | + // 3bytes, cts, composition time, | ||
| 557 | + // pts = dts + cts, or | ||
| 558 | + // cts = pts - dts. | ||
| 559 | + if (size < 5) { | ||
| 560 | + return ERROR_FLV_INVALID_VIDEO_TAG; | ||
| 561 | + } | ||
| 562 | + | ||
| 563 | + u_int32_t cts = 0; | ||
| 564 | + char* p = data + 2; | ||
| 565 | + char* pp = (char*)&cts; | ||
| 566 | + pp[2] = *p++; | ||
| 567 | + pp[1] = *p++; | ||
| 568 | + pp[0] = *p++; | ||
| 569 | + | ||
| 570 | + *ppts = time + cts; | ||
| 571 | + | ||
| 572 | + return ret; | ||
| 573 | +} | ||
| 574 | + | ||
| 534 | const char* srs_format_time() | 575 | const char* srs_format_time() |
| 535 | { | 576 | { |
| 536 | struct timeval tv; | 577 | struct timeval tv; |
| @@ -192,7 +192,7 @@ extern int srs_bandwidth_check(srs_rtmp_t rtmp, | @@ -192,7 +192,7 @@ extern int srs_bandwidth_check(srs_rtmp_t rtmp, | ||
| 192 | * @remark user never free the return char*, | 192 | * @remark user never free the return char*, |
| 193 | * it's static shared const string. | 193 | * it's static shared const string. |
| 194 | */ | 194 | */ |
| 195 | -extern const char* srs_type2string(int type); | 195 | +extern const char* srs_type2string(char type); |
| 196 | /** | 196 | /** |
| 197 | * read a audio/video/script-data packet from rtmp stream. | 197 | * read a audio/video/script-data packet from rtmp stream. |
| 198 | * @param type, output the packet type, macros: | 198 | * @param type, output the packet type, macros: |
| @@ -215,10 +215,10 @@ extern const char* srs_type2string(int type); | @@ -215,10 +215,10 @@ extern const char* srs_type2string(int type); | ||
| 215 | * @return 0, success; otherswise, failed. | 215 | * @return 0, success; otherswise, failed. |
| 216 | */ | 216 | */ |
| 217 | extern int srs_read_packet(srs_rtmp_t rtmp, | 217 | extern int srs_read_packet(srs_rtmp_t rtmp, |
| 218 | - int* type, u_int32_t* timestamp, char** data, int* size | 218 | + char* type, u_int32_t* timestamp, char** data, int* size |
| 219 | ); | 219 | ); |
| 220 | extern int srs_write_packet(srs_rtmp_t rtmp, | 220 | extern int srs_write_packet(srs_rtmp_t rtmp, |
| 221 | - int type, u_int32_t timestamp, char* data, int size | 221 | + char type, u_int32_t timestamp, char* data, int size |
| 222 | ); | 222 | ); |
| 223 | 223 | ||
| 224 | // get protocol stack version | 224 | // get protocol stack version |
| @@ -234,6 +234,25 @@ extern int srs_version_revision(); | @@ -234,6 +234,25 @@ extern int srs_version_revision(); | ||
| 234 | extern int64_t srs_get_time_ms(); | 234 | extern int64_t srs_get_time_ms(); |
| 235 | extern int64_t srs_get_nsend_bytes(srs_rtmp_t rtmp); | 235 | extern int64_t srs_get_nsend_bytes(srs_rtmp_t rtmp); |
| 236 | extern int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp); | 236 | extern int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp); |
| 237 | +/** | ||
| 238 | +* parse the dts and pts by time in header and data in tag, | ||
| 239 | +* or to parse the RTMP packet by srs_read_packet(). | ||
| 240 | +* | ||
| 241 | +* @param time, the timestamp of tag, read by srs_flv_read_tag_header(). | ||
| 242 | +* @param type, the type of tag, read by srs_flv_read_tag_header(). | ||
| 243 | +* @param data, the data of tag, read by srs_flv_read_tag_data(). | ||
| 244 | +* @param size, the size of tag, read by srs_flv_read_tag_header(). | ||
| 245 | +* @param ppts, output the pts in ms, | ||
| 246 | +* | ||
| 247 | +* @return 0, success; otherswise, failed. | ||
| 248 | +* @remark, the dts always equals to @param time. | ||
| 249 | +* @remark, the pts=dts for audio or data. | ||
| 250 | +* @remark, video only support h.264. | ||
| 251 | +*/ | ||
| 252 | +extern int srs_parse_timestamp( | ||
| 253 | + u_int32_t time, char type, char* data, int size, | ||
| 254 | + u_int32_t* ppts | ||
| 255 | +); | ||
| 237 | 256 | ||
| 238 | // log to console, for use srs-librtmp application. | 257 | // log to console, for use srs-librtmp application. |
| 239 | extern const char* srs_format_time(); | 258 | extern const char* srs_format_time(); |
| @@ -255,19 +274,68 @@ typedef int flv_bool; | @@ -255,19 +274,68 @@ typedef int flv_bool; | ||
| 255 | extern srs_flv_t srs_flv_open_read(const char* file); | 274 | extern srs_flv_t srs_flv_open_read(const char* file); |
| 256 | extern srs_flv_t srs_flv_open_write(const char* file); | 275 | extern srs_flv_t srs_flv_open_write(const char* file); |
| 257 | extern void srs_flv_close(srs_flv_t flv); | 276 | extern void srs_flv_close(srs_flv_t flv); |
| 258 | -/* read the flv header. 9bytes header. drop the 4bytes zero previous tag size */ | 277 | +/** |
| 278 | +* read the flv header. 9bytes header. | ||
| 279 | +* @param header, @see E.2 The FLV header, flv_v10_1.pdf in SRS doc. | ||
| 280 | +* 3bytes, signature, "FLV", | ||
| 281 | +* 1bytes, version, 0x01, | ||
| 282 | +* 1bytes, flags, UB[5] 0, UB[1] audio present, UB[1] 0, UB[1] video present. | ||
| 283 | +* 4bytes, dataoffset, 0x09, The length of this header in bytes | ||
| 284 | +* | ||
| 285 | +* @return 0, success; otherswise, failed. | ||
| 286 | +* @remark, drop the 4bytes zero previous tag size. | ||
| 287 | +*/ | ||
| 259 | extern int srs_flv_read_header(srs_flv_t flv, char header[9]); | 288 | extern int srs_flv_read_header(srs_flv_t flv, char header[9]); |
| 260 | -/* read the flv tag header, 1bytes tag, 3bytes data_size, 4bytes time, 3bytes stream id. */ | 289 | +/** |
| 290 | +* read the flv tag header, 1bytes tag, 3bytes data_size, | ||
| 291 | +* 4bytes time, 3bytes stream id. | ||
| 292 | +* @param ptype, output the type of tag, macros: | ||
| 293 | +* SRS_RTMP_TYPE_AUDIO, FlvTagAudio | ||
| 294 | +* SRS_RTMP_TYPE_VIDEO, FlvTagVideo | ||
| 295 | +* SRS_RTMP_TYPE_SCRIPT, FlvTagScript | ||
| 296 | +* @param pdata_size, output the size of tag data. | ||
| 297 | +* @param ptime, output the time of tag, the dts in ms. | ||
| 298 | +* | ||
| 299 | +* @return 0, success; otherswise, failed. | ||
| 300 | +* @remark, user must ensure the next is a tag, srs never check it. | ||
| 301 | +*/ | ||
| 261 | extern int srs_flv_read_tag_header(srs_flv_t flv, | 302 | extern int srs_flv_read_tag_header(srs_flv_t flv, |
| 262 | char* ptype, int32_t* pdata_size, u_int32_t* ptime | 303 | char* ptype, int32_t* pdata_size, u_int32_t* ptime |
| 263 | ); | 304 | ); |
| 264 | -/* read the tag data. drop the 4bytes previous tag size */ | 305 | +/** |
| 306 | +* read the tag data. drop the 4bytes previous tag size | ||
| 307 | +* @param data, the data to read, user alloc and free it. | ||
| 308 | +* @param size, the size of data to read, get by srs_flv_read_tag_header(). | ||
| 309 | +* @remark, srs will ignore and drop the 4bytes previous tag size. | ||
| 310 | +*/ | ||
| 265 | extern int srs_flv_read_tag_data(srs_flv_t flv, char* data, int32_t size); | 311 | extern int srs_flv_read_tag_data(srs_flv_t flv, char* data, int32_t size); |
| 266 | -/* write flv header to file, auto write the 4bytes zero previous tag size. */ | 312 | +/** |
| 313 | +* write the flv header. 9bytes header. | ||
| 314 | +* @param header, @see E.2 The FLV header, flv_v10_1.pdf in SRS doc. | ||
| 315 | +* 3bytes, signature, "FLV", | ||
| 316 | +* 1bytes, version, 0x01, | ||
| 317 | +* 1bytes, flags, UB[5] 0, UB[1] audio present, UB[1] 0, UB[1] video present. | ||
| 318 | +* 4bytes, dataoffset, 0x09, The length of this header in bytes | ||
| 319 | +* | ||
| 320 | +* @return 0, success; otherswise, failed. | ||
| 321 | +* @remark, auto write the 4bytes zero previous tag size. | ||
| 322 | +*/ | ||
| 267 | extern int srs_flv_write_header(srs_flv_t flv, char header[9]); | 323 | extern int srs_flv_write_header(srs_flv_t flv, char header[9]); |
| 324 | +/** | ||
| 325 | +* write the flv tag to file. | ||
| 326 | +* | ||
| 327 | +* @return 0, success; otherswise, failed. | ||
| 328 | +* @remark, auto write the 4bytes zero previous tag size. | ||
| 329 | +*/ | ||
| 268 | /* write flv tag to file, auto write the 4bytes previous tag size */ | 330 | /* write flv tag to file, auto write the 4bytes previous tag size */ |
| 269 | -extern int srs_flv_write_tag(srs_flv_t flv, char type, int32_t time, char* data, int size); | ||
| 270 | -/* get the tag size, for flv injecter to adjust offset, size=tag_header+data+previous_tag */ | 331 | +extern int srs_flv_write_tag(srs_flv_t flv, |
| 332 | + char type, int32_t time, char* data, int size | ||
| 333 | +); | ||
| 334 | +/** | ||
| 335 | +* get the tag size, for flv injecter to adjust offset, | ||
| 336 | +* size = tag_header(11B) + data_size + previous_tag(4B) | ||
| 337 | +* @return the size of tag. | ||
| 338 | +*/ | ||
| 271 | extern int srs_flv_size_tag(int data_size); | 339 | extern int srs_flv_size_tag(int data_size); |
| 272 | /* file stream */ | 340 | /* file stream */ |
| 273 | /* file stream tellg to get offset */ | 341 | /* file stream tellg to get offset */ |
| @@ -278,9 +346,17 @@ extern void srs_flv_lseek(srs_flv_t flv, int64_t offset); | @@ -278,9 +346,17 @@ extern void srs_flv_lseek(srs_flv_t flv, int64_t offset); | ||
| 278 | /* whether the error code indicates EOF */ | 346 | /* whether the error code indicates EOF */ |
| 279 | extern flv_bool srs_flv_is_eof(int error_code); | 347 | extern flv_bool srs_flv_is_eof(int error_code); |
| 280 | /* media codec */ | 348 | /* media codec */ |
| 281 | -/* whether the video body is sequence header */ | 349 | +/** |
| 350 | +* whether the video body is sequence header | ||
| 351 | +* @param data, the data of tag, read by srs_flv_read_tag_data(). | ||
| 352 | +* @param size, the size of tag, read by srs_flv_read_tag_data(). | ||
| 353 | +*/ | ||
| 282 | extern flv_bool srs_flv_is_sequence_header(char* data, int32_t size); | 354 | extern flv_bool srs_flv_is_sequence_header(char* data, int32_t size); |
| 283 | -/* whether the video body is keyframe */ | 355 | +/** |
| 356 | +* whether the video body is keyframe | ||
| 357 | +* @param data, the data of tag, read by srs_flv_read_tag_data(). | ||
| 358 | +* @param size, the size of tag, read by srs_flv_read_tag_data(). | ||
| 359 | +*/ | ||
| 284 | extern flv_bool srs_flv_is_keyframe(char* data, int32_t size); | 360 | extern flv_bool srs_flv_is_keyframe(char* data, int32_t size); |
| 285 | 361 | ||
| 286 | /************************************************************* | 362 | /************************************************************* |
-
请 注册 或 登录 后发表评论