正在显示
7 个修改的文件
包含
286 行增加
和
115 行删除
| @@ -201,8 +201,9 @@ Supported operating systems and hardware: | @@ -201,8 +201,9 @@ Supported operating systems and hardware: | ||
| 201 | * 2013-10-17, Created.<br/> | 201 | * 2013-10-17, Created.<br/> |
| 202 | 202 | ||
| 203 | ## History | 203 | ## History |
| 204 | -* v1.0, 2014-10-18, remove supports for OSX(darwin). 2.0.1. | ||
| 205 | -* v1.0, 2014-10-16, revert github srs README to English. 2.0.0. | 204 | +* v2.0, 2014-10-19, fix [#184](https://github.com/winlinvip/simple-rtmp-server/issues/184), support AnnexB in RTMP body for HLS. 2.0.2 |
| 205 | +* v2.0, 2014-10-18, remove supports for OSX(darwin). 2.0.1. | ||
| 206 | +* v2.0, 2014-10-16, revert github srs README to English. 2.0.0. | ||
| 206 | * <strong>v1.0, 2014-10-09, [1.0 beta(1.0.0)](https://github.com/winlinvip/simple-rtmp-server/releases/tag/1.0.beta) released. 59316 lines.</strong> | 207 | * <strong>v1.0, 2014-10-09, [1.0 beta(1.0.0)](https://github.com/winlinvip/simple-rtmp-server/releases/tag/1.0.beta) released. 59316 lines.</strong> |
| 207 | * v1.0, 2014-10-08, fix [#151](https://github.com/winlinvip/simple-rtmp-server/issues/151), always reap ts whatever audio or video packet. 0.9.223. | 208 | * v1.0, 2014-10-08, fix [#151](https://github.com/winlinvip/simple-rtmp-server/issues/151), always reap ts whatever audio or video packet. 0.9.223. |
| 208 | * v1.0, 2014-10-08, fix [#162](https://github.com/winlinvip/simple-rtmp-server/issues/162), failed if no epoll. 0.9.222. | 209 | * v1.0, 2014-10-08, fix [#162](https://github.com/winlinvip/simple-rtmp-server/issues/162), failed if no epoll. 0.9.222. |
| @@ -27,6 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -27,6 +27,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 27 | #include <srs_kernel_log.hpp> | 27 | #include <srs_kernel_log.hpp> |
| 28 | #include <srs_kernel_stream.hpp> | 28 | #include <srs_kernel_stream.hpp> |
| 29 | #include <srs_protocol_amf0.hpp> | 29 | #include <srs_protocol_amf0.hpp> |
| 30 | +#include <srs_app_utility.hpp> | ||
| 30 | 31 | ||
| 31 | SrsCodecSampleUnit::SrsCodecSampleUnit() | 32 | SrsCodecSampleUnit::SrsCodecSampleUnit() |
| 32 | { | 33 | { |
| @@ -358,143 +359,255 @@ int SrsAvcAacCodec::video_avc_demux(char* data, int size, SrsCodecSample* sample | @@ -358,143 +359,255 @@ int SrsAvcAacCodec::video_avc_demux(char* data, int size, SrsCodecSample* sample | ||
| 358 | sample->avc_packet_type = (SrsCodecVideoAVCType)avc_packet_type; | 359 | sample->avc_packet_type = (SrsCodecVideoAVCType)avc_packet_type; |
| 359 | 360 | ||
| 360 | if (avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader) { | 361 | if (avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader) { |
| 361 | - // AVCDecoderConfigurationRecord | ||
| 362 | - // 5.2.4.1.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 16 | ||
| 363 | - avc_extra_size = stream->size() - stream->pos(); | ||
| 364 | - if (avc_extra_size > 0) { | ||
| 365 | - srs_freep(avc_extra_data); | ||
| 366 | - avc_extra_data = new char[avc_extra_size]; | ||
| 367 | - memcpy(avc_extra_data, stream->data() + stream->pos(), avc_extra_size); | 362 | + if ((ret = avc_demux_sps_pps(stream)) != ERROR_SUCCESS) { |
| 363 | + return ret; | ||
| 368 | } | 364 | } |
| 369 | - | ||
| 370 | - if (!stream->require(6)) { | 365 | + } else if (avc_packet_type == SrsCodecVideoAVCTypeNALU){ |
| 366 | + // ensure the sequence header demuxed | ||
| 367 | + if (avc_extra_size <= 0 || !avc_extra_data) { | ||
| 371 | ret = ERROR_HLS_DECODE_ERROR; | 368 | ret = ERROR_HLS_DECODE_ERROR; |
| 372 | - srs_error("hls decode video avc sequenc header failed. ret=%d", ret); | 369 | + srs_error("hls decode video avc failed, sequence header not found. ret=%d", ret); |
| 373 | return ret; | 370 | return ret; |
| 374 | } | 371 | } |
| 375 | - //int8_t configurationVersion = stream->read_1bytes(); | ||
| 376 | - stream->read_1bytes(); | ||
| 377 | - //int8_t AVCProfileIndication = stream->read_1bytes(); | ||
| 378 | - avc_profile = stream->read_1bytes(); | ||
| 379 | - //int8_t profile_compatibility = stream->read_1bytes(); | ||
| 380 | - stream->read_1bytes(); | ||
| 381 | - //int8_t AVCLevelIndication = stream->read_1bytes(); | ||
| 382 | - avc_level = stream->read_1bytes(); | ||
| 383 | 372 | ||
| 384 | - // parse the NALU size. | ||
| 385 | - int8_t lengthSizeMinusOne = stream->read_1bytes(); | ||
| 386 | - lengthSizeMinusOne &= 0x03; | ||
| 387 | - NAL_unit_length = lengthSizeMinusOne; | ||
| 388 | - | ||
| 389 | - // 1 sps | ||
| 390 | - if (!stream->require(1)) { | ||
| 391 | - ret = ERROR_HLS_DECODE_ERROR; | ||
| 392 | - srs_error("hls decode video avc sequenc header sps failed. ret=%d", ret); | ||
| 393 | - return ret; | 373 | + // One or more NALUs (Full frames are required) |
| 374 | + // try "AnnexB" from H.264-AVC-ISO_IEC_14496-10.pdf, page 211. | ||
| 375 | + if ((ret = avc_demux_annexb_format(stream, sample)) != ERROR_SUCCESS) { | ||
| 376 | + // stop try when system error. | ||
| 377 | + if (ret != ERROR_HLS_AVC_TRY_OTHERS) { | ||
| 378 | + srs_error("avc demux for annexb failed. ret=%d", ret); | ||
| 379 | + return ret; | ||
| 380 | + } | ||
| 381 | + | ||
| 382 | + // try "ISO Base Media File Format" from H.264-AVC-ISO_IEC_14496-15.pdf, page 20 | ||
| 383 | + if ((ret = avc_demux_ibmf_format(stream, sample)) != ERROR_SUCCESS) { | ||
| 384 | + return ret; | ||
| 385 | + } | ||
| 394 | } | 386 | } |
| 395 | - int8_t numOfSequenceParameterSets = stream->read_1bytes(); | ||
| 396 | - numOfSequenceParameterSets &= 0x1f; | ||
| 397 | - if (numOfSequenceParameterSets != 1) { | ||
| 398 | - ret = ERROR_HLS_DECODE_ERROR; | ||
| 399 | - srs_error("hls decode video avc sequenc header sps failed. ret=%d", ret); | 387 | + } else { |
| 388 | + // ignored. | ||
| 389 | + } | ||
| 390 | + | ||
| 391 | + srs_info("video decoded, type=%d, codec=%d, avc=%d, time=%d, size=%d", | ||
| 392 | + frame_type, video_codec_id, avc_packet_type, composition_time, size); | ||
| 393 | + | ||
| 394 | + return ret; | ||
| 395 | +} | ||
| 396 | + | ||
| 397 | +int SrsAvcAacCodec::avc_demux_sps_pps(SrsStream* stream) | ||
| 398 | +{ | ||
| 399 | + int ret = ERROR_SUCCESS; | ||
| 400 | + | ||
| 401 | + // AVCDecoderConfigurationRecord | ||
| 402 | + // 5.2.4.1.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 16 | ||
| 403 | + avc_extra_size = stream->size() - stream->pos(); | ||
| 404 | + if (avc_extra_size > 0) { | ||
| 405 | + srs_freep(avc_extra_data); | ||
| 406 | + avc_extra_data = new char[avc_extra_size]; | ||
| 407 | + memcpy(avc_extra_data, stream->data() + stream->pos(), avc_extra_size); | ||
| 408 | + } | ||
| 409 | + | ||
| 410 | + if (!stream->require(6)) { | ||
| 411 | + ret = ERROR_HLS_DECODE_ERROR; | ||
| 412 | + srs_error("hls decode video avc sequenc header failed. ret=%d", ret); | ||
| 413 | + return ret; | ||
| 414 | + } | ||
| 415 | + //int8_t configurationVersion = stream->read_1bytes(); | ||
| 416 | + stream->read_1bytes(); | ||
| 417 | + //int8_t AVCProfileIndication = stream->read_1bytes(); | ||
| 418 | + avc_profile = stream->read_1bytes(); | ||
| 419 | + //int8_t profile_compatibility = stream->read_1bytes(); | ||
| 420 | + stream->read_1bytes(); | ||
| 421 | + //int8_t AVCLevelIndication = stream->read_1bytes(); | ||
| 422 | + avc_level = stream->read_1bytes(); | ||
| 423 | + | ||
| 424 | + // parse the NALU size. | ||
| 425 | + int8_t lengthSizeMinusOne = stream->read_1bytes(); | ||
| 426 | + lengthSizeMinusOne &= 0x03; | ||
| 427 | + NAL_unit_length = lengthSizeMinusOne; | ||
| 428 | + | ||
| 429 | + // 5.3.4.2.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 16 | ||
| 430 | + // 5.2.4.1 AVC decoder configuration record | ||
| 431 | + // 5.2.4.1.2 Semantics | ||
| 432 | + // The value of this field shall be one of 0, 1, or 3 corresponding to a | ||
| 433 | + // length encoded with 1, 2, or 4 bytes, respectively. | ||
| 434 | + if (NAL_unit_length == 2) { | ||
| 435 | + ret = ERROR_HLS_DECODE_ERROR; | ||
| 436 | + srs_error("sps lengthSizeMinusOne should never be 2. ret=%d", ret); | ||
| 437 | + return ret; | ||
| 438 | + } | ||
| 439 | + | ||
| 440 | + // 1 sps | ||
| 441 | + if (!stream->require(1)) { | ||
| 442 | + ret = ERROR_HLS_DECODE_ERROR; | ||
| 443 | + srs_error("hls decode video avc sequenc header sps failed. ret=%d", ret); | ||
| 444 | + return ret; | ||
| 445 | + } | ||
| 446 | + int8_t numOfSequenceParameterSets = stream->read_1bytes(); | ||
| 447 | + numOfSequenceParameterSets &= 0x1f; | ||
| 448 | + if (numOfSequenceParameterSets != 1) { | ||
| 449 | + ret = ERROR_HLS_DECODE_ERROR; | ||
| 450 | + srs_error("hls decode video avc sequenc header sps failed. ret=%d", ret); | ||
| 451 | + return ret; | ||
| 452 | + } | ||
| 453 | + if (!stream->require(2)) { | ||
| 454 | + ret = ERROR_HLS_DECODE_ERROR; | ||
| 455 | + srs_error("hls decode video avc sequenc header sps size failed. ret=%d", ret); | ||
| 456 | + return ret; | ||
| 457 | + } | ||
| 458 | + sequenceParameterSetLength = stream->read_2bytes(); | ||
| 459 | + if (!stream->require(sequenceParameterSetLength)) { | ||
| 460 | + ret = ERROR_HLS_DECODE_ERROR; | ||
| 461 | + srs_error("hls decode video avc sequenc header sps data failed. ret=%d", ret); | ||
| 462 | + return ret; | ||
| 463 | + } | ||
| 464 | + if (sequenceParameterSetLength > 0) { | ||
| 465 | + srs_freep(sequenceParameterSetNALUnit); | ||
| 466 | + sequenceParameterSetNALUnit = new char[sequenceParameterSetLength]; | ||
| 467 | + memcpy(sequenceParameterSetNALUnit, stream->data() + stream->pos(), sequenceParameterSetLength); | ||
| 468 | + stream->skip(sequenceParameterSetLength); | ||
| 469 | + } | ||
| 470 | + // 1 pps | ||
| 471 | + if (!stream->require(1)) { | ||
| 472 | + ret = ERROR_HLS_DECODE_ERROR; | ||
| 473 | + srs_error("hls decode video avc sequenc header pps failed. ret=%d", ret); | ||
| 474 | + return ret; | ||
| 475 | + } | ||
| 476 | + int8_t numOfPictureParameterSets = stream->read_1bytes(); | ||
| 477 | + numOfPictureParameterSets &= 0x1f; | ||
| 478 | + if (numOfPictureParameterSets != 1) { | ||
| 479 | + ret = ERROR_HLS_DECODE_ERROR; | ||
| 480 | + srs_error("hls decode video avc sequenc header pps failed. ret=%d", ret); | ||
| 481 | + return ret; | ||
| 482 | + } | ||
| 483 | + if (!stream->require(2)) { | ||
| 484 | + ret = ERROR_HLS_DECODE_ERROR; | ||
| 485 | + srs_error("hls decode video avc sequenc header pps size failed. ret=%d", ret); | ||
| 486 | + return ret; | ||
| 487 | + } | ||
| 488 | + pictureParameterSetLength = stream->read_2bytes(); | ||
| 489 | + if (!stream->require(pictureParameterSetLength)) { | ||
| 490 | + ret = ERROR_HLS_DECODE_ERROR; | ||
| 491 | + srs_error("hls decode video avc sequenc header pps data failed. ret=%d", ret); | ||
| 492 | + return ret; | ||
| 493 | + } | ||
| 494 | + if (pictureParameterSetLength > 0) { | ||
| 495 | + srs_freep(pictureParameterSetNALUnit); | ||
| 496 | + pictureParameterSetNALUnit = new char[pictureParameterSetLength]; | ||
| 497 | + memcpy(pictureParameterSetNALUnit, stream->data() + stream->pos(), pictureParameterSetLength); | ||
| 498 | + stream->skip(pictureParameterSetLength); | ||
| 499 | + } | ||
| 500 | + | ||
| 501 | + return ret; | ||
| 502 | +} | ||
| 503 | + | ||
| 504 | +int SrsAvcAacCodec::avc_demux_annexb_format(SrsStream* stream, SrsCodecSample* sample) | ||
| 505 | +{ | ||
| 506 | + int ret = ERROR_SUCCESS; | ||
| 507 | + | ||
| 508 | + // not annexb, try others | ||
| 509 | + if (!srs_avc_startswith_annexb(stream, NULL)) { | ||
| 510 | + return ERROR_HLS_AVC_TRY_OTHERS; | ||
| 511 | + } | ||
| 512 | + | ||
| 513 | + // AnnexB | ||
| 514 | + // B.1.1 Byte stream NAL unit syntax, | ||
| 515 | + // H.264-AVC-ISO_IEC_14496-10.pdf, page 211. | ||
| 516 | + while (!stream->empty()) { | ||
| 517 | + // find start code | ||
| 518 | + int nb_start_code = 0; | ||
| 519 | + if (!srs_avc_startswith_annexb(stream, &nb_start_code)) { | ||
| 400 | return ret; | 520 | return ret; |
| 401 | } | 521 | } |
| 402 | - if (!stream->require(2)) { | ||
| 403 | - ret = ERROR_HLS_DECODE_ERROR; | ||
| 404 | - srs_error("hls decode video avc sequenc header sps size failed. ret=%d", ret); | ||
| 405 | - return ret; | 522 | + |
| 523 | + // skip the start code. | ||
| 524 | + if (nb_start_code > 0) { | ||
| 525 | + stream->skip(nb_start_code); | ||
| 406 | } | 526 | } |
| 407 | - sequenceParameterSetLength = stream->read_2bytes(); | ||
| 408 | - if (!stream->require(sequenceParameterSetLength)) { | ||
| 409 | - ret = ERROR_HLS_DECODE_ERROR; | ||
| 410 | - srs_error("hls decode video avc sequenc header sps data failed. ret=%d", ret); | ||
| 411 | - return ret; | 527 | + |
| 528 | + // the NALU start bytes. | ||
| 529 | + char* p = stream->data() + stream->pos(); | ||
| 530 | + | ||
| 531 | + // get the last matched NALU | ||
| 532 | + while (!stream->empty()) { | ||
| 533 | + if (srs_avc_startswith_annexb(stream, &nb_start_code)) { | ||
| 534 | + break; | ||
| 535 | + } | ||
| 536 | + | ||
| 537 | + stream->skip(1); | ||
| 412 | } | 538 | } |
| 413 | - if (sequenceParameterSetLength > 0) { | ||
| 414 | - srs_freep(sequenceParameterSetNALUnit); | ||
| 415 | - sequenceParameterSetNALUnit = new char[sequenceParameterSetLength]; | ||
| 416 | - memcpy(sequenceParameterSetNALUnit, stream->data() + stream->pos(), sequenceParameterSetLength); | ||
| 417 | - stream->skip(sequenceParameterSetLength); | 539 | + |
| 540 | + char* pp = stream->data() + stream->pos(); | ||
| 541 | + | ||
| 542 | + // skip the empty. | ||
| 543 | + if (pp - p <= 0) { | ||
| 544 | + continue; | ||
| 418 | } | 545 | } |
| 419 | - // 1 pps | ||
| 420 | - if (!stream->require(1)) { | ||
| 421 | - ret = ERROR_HLS_DECODE_ERROR; | ||
| 422 | - srs_error("hls decode video avc sequenc header pps failed. ret=%d", ret); | 546 | + |
| 547 | + // got the NALU. | ||
| 548 | + if ((ret = sample->add_sample_unit(p, pp - p)) != ERROR_SUCCESS) { | ||
| 549 | + srs_error("annexb add video sample failed. ret=%d", ret); | ||
| 423 | return ret; | 550 | return ret; |
| 424 | } | 551 | } |
| 425 | - int8_t numOfPictureParameterSets = stream->read_1bytes(); | ||
| 426 | - numOfPictureParameterSets &= 0x1f; | ||
| 427 | - if (numOfPictureParameterSets != 1) { | 552 | + } |
| 553 | + | ||
| 554 | + return ret; | ||
| 555 | +} | ||
| 556 | + | ||
| 557 | +int SrsAvcAacCodec::avc_demux_ibmf_format(SrsStream* stream, SrsCodecSample* sample) | ||
| 558 | +{ | ||
| 559 | + int ret = ERROR_SUCCESS; | ||
| 560 | + | ||
| 561 | + int PictureLength = stream->size() - stream->pos(); | ||
| 562 | + | ||
| 563 | + // 5.3.4.2.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 16 | ||
| 564 | + // 5.2.4.1 AVC decoder configuration record | ||
| 565 | + // 5.2.4.1.2 Semantics | ||
| 566 | + // The value of this field shall be one of 0, 1, or 3 corresponding to a | ||
| 567 | + // length encoded with 1, 2, or 4 bytes, respectively. | ||
| 568 | + srs_assert(NAL_unit_length != 2); | ||
| 569 | + | ||
| 570 | + // 5.3.4.2.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 20 | ||
| 571 | + for (int i = 0; i < PictureLength;) { | ||
| 572 | + // unsigned int((NAL_unit_length+1)*8) NALUnitLength; | ||
| 573 | + if (!stream->require(NAL_unit_length + 1)) { | ||
| 428 | ret = ERROR_HLS_DECODE_ERROR; | 574 | ret = ERROR_HLS_DECODE_ERROR; |
| 429 | - srs_error("hls decode video avc sequenc header pps failed. ret=%d", ret); | 575 | + srs_error("hls decode video avc NALU size failed. ret=%d", ret); |
| 430 | return ret; | 576 | return ret; |
| 431 | } | 577 | } |
| 432 | - if (!stream->require(2)) { | 578 | + int32_t NALUnitLength = 0; |
| 579 | + if (NAL_unit_length == 3) { | ||
| 580 | + NALUnitLength = stream->read_4bytes(); | ||
| 581 | + } else if (NAL_unit_length == 1) { | ||
| 582 | + NALUnitLength = stream->read_2bytes(); | ||
| 583 | + } else { | ||
| 584 | + NALUnitLength = stream->read_1bytes(); | ||
| 585 | + } | ||
| 586 | + | ||
| 587 | + // maybe stream is invalid format. | ||
| 588 | + // see: https://github.com/winlinvip/simple-rtmp-server/issues/183 | ||
| 589 | + if (NALUnitLength < 0) { | ||
| 433 | ret = ERROR_HLS_DECODE_ERROR; | 590 | ret = ERROR_HLS_DECODE_ERROR; |
| 434 | - srs_error("hls decode video avc sequenc header pps size failed. ret=%d", ret); | 591 | + srs_error("maybe stream is AnnexB format. ret=%d", ret); |
| 435 | return ret; | 592 | return ret; |
| 436 | } | 593 | } |
| 437 | - pictureParameterSetLength = stream->read_2bytes(); | ||
| 438 | - if (!stream->require(pictureParameterSetLength)) { | 594 | + |
| 595 | + // NALUnit | ||
| 596 | + if (!stream->require(NALUnitLength)) { | ||
| 439 | ret = ERROR_HLS_DECODE_ERROR; | 597 | ret = ERROR_HLS_DECODE_ERROR; |
| 440 | - srs_error("hls decode video avc sequenc header pps data failed. ret=%d", ret); | 598 | + srs_error("hls decode video avc NALU data failed. ret=%d", ret); |
| 441 | return ret; | 599 | return ret; |
| 442 | } | 600 | } |
| 443 | - if (pictureParameterSetLength > 0) { | ||
| 444 | - srs_freep(pictureParameterSetNALUnit); | ||
| 445 | - pictureParameterSetNALUnit = new char[pictureParameterSetLength]; | ||
| 446 | - memcpy(pictureParameterSetNALUnit, stream->data() + stream->pos(), pictureParameterSetLength); | ||
| 447 | - stream->skip(pictureParameterSetLength); | ||
| 448 | - } | ||
| 449 | - } else if (avc_packet_type == SrsCodecVideoAVCTypeNALU){ | ||
| 450 | - // ensure the sequence header demuxed | ||
| 451 | - if (avc_extra_size <= 0 || !avc_extra_data) { | ||
| 452 | - ret = ERROR_HLS_DECODE_ERROR; | ||
| 453 | - srs_error("hls decode video avc failed, sequence header not found. ret=%d", ret); | 601 | + // 7.3.1 NAL unit syntax, H.264-AVC-ISO_IEC_14496-10.pdf, page 44. |
| 602 | + if ((ret = sample->add_sample_unit(stream->data() + stream->pos(), NALUnitLength)) != ERROR_SUCCESS) { | ||
| 603 | + srs_error("hls add video sample failed. ret=%d", ret); | ||
| 454 | return ret; | 604 | return ret; |
| 455 | } | 605 | } |
| 606 | + stream->skip(NALUnitLength); | ||
| 456 | 607 | ||
| 457 | - // One or more NALUs (Full frames are required) | ||
| 458 | - // 5.3.4.2.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 20 | ||
| 459 | - int PictureLength = stream->size() - stream->pos(); | ||
| 460 | - for (int i = 0; i < PictureLength;) { | ||
| 461 | - if (!stream->require(NAL_unit_length + 1)) { | ||
| 462 | - ret = ERROR_HLS_DECODE_ERROR; | ||
| 463 | - srs_error("hls decode video avc NALU size failed. ret=%d", ret); | ||
| 464 | - return ret; | ||
| 465 | - } | ||
| 466 | - int32_t NALUnitLength = 0; | ||
| 467 | - if (NAL_unit_length == 3) { | ||
| 468 | - NALUnitLength = stream->read_4bytes(); | ||
| 469 | - } else if (NAL_unit_length == 2) { | ||
| 470 | - NALUnitLength = stream->read_3bytes(); | ||
| 471 | - } else if (NAL_unit_length == 1) { | ||
| 472 | - NALUnitLength = stream->read_2bytes(); | ||
| 473 | - } else { | ||
| 474 | - NALUnitLength = stream->read_1bytes(); | ||
| 475 | - } | ||
| 476 | - // NALUnit | ||
| 477 | - if (!stream->require(NALUnitLength)) { | ||
| 478 | - ret = ERROR_HLS_DECODE_ERROR; | ||
| 479 | - srs_error("hls decode video avc NALU data failed. ret=%d", ret); | ||
| 480 | - return ret; | ||
| 481 | - } | ||
| 482 | - // 7.3.1 NAL unit syntax, H.264-AVC-ISO_IEC_14496-10.pdf, page 44. | ||
| 483 | - if ((ret = sample->add_sample_unit(stream->data() + stream->pos(), NALUnitLength)) != ERROR_SUCCESS) { | ||
| 484 | - srs_error("hls add video sample failed. ret=%d", ret); | ||
| 485 | - return ret; | ||
| 486 | - } | ||
| 487 | - stream->skip(NALUnitLength); | ||
| 488 | - | ||
| 489 | - i += NAL_unit_length + 1 + NALUnitLength; | ||
| 490 | - } | ||
| 491 | - } else { | ||
| 492 | - // ignored. | 608 | + i += NAL_unit_length + 1 + NALUnitLength; |
| 493 | } | 609 | } |
| 494 | 610 | ||
| 495 | - srs_info("video decoded, type=%d, codec=%d, avc=%d, time=%d, size=%d", | ||
| 496 | - frame_type, video_codec_id, avc_packet_type, composition_time, size); | ||
| 497 | - | ||
| 498 | return ret; | 611 | return ret; |
| 499 | } | 612 | } |
| 500 | 613 |
| @@ -278,6 +278,22 @@ public: | @@ -278,6 +278,22 @@ public: | ||
| 278 | * demux the h.264 NALUs to sampe units. | 278 | * demux the h.264 NALUs to sampe units. |
| 279 | */ | 279 | */ |
| 280 | virtual int video_avc_demux(char* data, int size, SrsCodecSample* sample); | 280 | virtual int video_avc_demux(char* data, int size, SrsCodecSample* sample); |
| 281 | +private: | ||
| 282 | + /** | ||
| 283 | + * when avc packet type is SrsCodecVideoAVCTypeSequenceHeader, | ||
| 284 | + * decode the sps and pps. | ||
| 285 | + */ | ||
| 286 | + virtual int avc_demux_sps_pps(SrsStream* stream); | ||
| 287 | + /** | ||
| 288 | + * demux the avc NALU in "AnnexB" | ||
| 289 | + * from H.264-AVC-ISO_IEC_14496-10.pdf, page 211. | ||
| 290 | + */ | ||
| 291 | + virtual int avc_demux_annexb_format(SrsStream* stream, SrsCodecSample* sample); | ||
| 292 | + /** | ||
| 293 | + * demux the avc NALU in "ISO Base Media File Format" | ||
| 294 | + * from H.264-AVC-ISO_IEC_14496-15.pdf, page 20 | ||
| 295 | + */ | ||
| 296 | + virtual int avc_demux_ibmf_format(SrsStream* stream, SrsCodecSample* sample); | ||
| 281 | }; | 297 | }; |
| 282 | 298 | ||
| 283 | #endif | 299 | #endif |
| @@ -36,8 +36,9 @@ using namespace std; | @@ -36,8 +36,9 @@ using namespace std; | ||
| 36 | #include <srs_kernel_error.hpp> | 36 | #include <srs_kernel_error.hpp> |
| 37 | #include <srs_app_kbps.hpp> | 37 | #include <srs_app_kbps.hpp> |
| 38 | #include <srs_app_json.hpp> | 38 | #include <srs_app_json.hpp> |
| 39 | +#include <srs_kernel_stream.hpp> | ||
| 39 | 40 | ||
| 40 | -int srs_socket_connect(std::string server, int port, int64_t timeout, st_netfd_t* pstfd) | 41 | +int srs_socket_connect(string server, int port, int64_t timeout, st_netfd_t* pstfd) |
| 41 | { | 42 | { |
| 42 | int ret = ERROR_SUCCESS; | 43 | int ret = ERROR_SUCCESS; |
| 43 | 44 | ||
| @@ -89,7 +90,7 @@ failed: | @@ -89,7 +90,7 @@ failed: | ||
| 89 | return ret; | 90 | return ret; |
| 90 | } | 91 | } |
| 91 | 92 | ||
| 92 | -int srs_get_log_level(std::string level) | 93 | +int srs_get_log_level(string level) |
| 93 | { | 94 | { |
| 94 | if ("verbose" == level) { | 95 | if ("verbose" == level) { |
| 95 | return SrsLogLevel::Verbose; | 96 | return SrsLogLevel::Verbose; |
| @@ -106,6 +107,35 @@ int srs_get_log_level(std::string level) | @@ -106,6 +107,35 @@ int srs_get_log_level(std::string level) | ||
| 106 | } | 107 | } |
| 107 | } | 108 | } |
| 108 | 109 | ||
| 110 | +bool srs_avc_startswith_annexb(SrsStream* stream, int* pnb_start_code) | ||
| 111 | +{ | ||
| 112 | + char* bytes = stream->data() + stream->pos(); | ||
| 113 | + char* p = bytes; | ||
| 114 | + | ||
| 115 | + for (;;) { | ||
| 116 | + if (!stream->require(p - bytes + 3)) { | ||
| 117 | + return false; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + // not match | ||
| 121 | + if (p[0] != 0x00 || p[1] != 0x00) { | ||
| 122 | + return false; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + // match N[00] 00 00 01, where N>=0 | ||
| 126 | + if (p[2] == 0x01) { | ||
| 127 | + if (pnb_start_code) { | ||
| 128 | + *pnb_start_code = (int)(p - bytes) + 3; | ||
| 129 | + } | ||
| 130 | + return true; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + p++; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + return false; | ||
| 137 | +} | ||
| 138 | + | ||
| 109 | static SrsRusage _srs_system_rusage; | 139 | static SrsRusage _srs_system_rusage; |
| 110 | 140 | ||
| 111 | SrsRusage::SrsRusage() | 141 | SrsRusage::SrsRusage() |
| @@ -39,6 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -39,6 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 39 | #include <srs_app_st.hpp> | 39 | #include <srs_app_st.hpp> |
| 40 | 40 | ||
| 41 | class SrsKbps; | 41 | class SrsKbps; |
| 42 | +class SrsStream; | ||
| 42 | 43 | ||
| 43 | // client open socket and connect to server. | 44 | // client open socket and connect to server. |
| 44 | extern int srs_socket_connect(std::string server, int port, int64_t timeout, st_netfd_t* pstfd); | 45 | extern int srs_socket_connect(std::string server, int port, int64_t timeout, st_netfd_t* pstfd); |
| @@ -49,6 +50,15 @@ extern int srs_socket_connect(std::string server, int port, int64_t timeout, st_ | @@ -49,6 +50,15 @@ extern int srs_socket_connect(std::string server, int port, int64_t timeout, st_ | ||
| 49 | */ | 50 | */ |
| 50 | extern int srs_get_log_level(std::string level); | 51 | extern int srs_get_log_level(std::string level); |
| 51 | 52 | ||
| 53 | +/** | ||
| 54 | +* whether stream starts with the avc NALU in "AnnexB" | ||
| 55 | +* from H.264-AVC-ISO_IEC_14496-10.pdf, page 211. | ||
| 56 | +* start code must be "N[00] 00 00 01" where N>=0 | ||
| 57 | +* @param pnb_start_code output the size of start code, must >=3. | ||
| 58 | +* NULL to ignore. | ||
| 59 | +*/ | ||
| 60 | +extern bool srs_avc_startswith_annexb(SrsStream* stream, int* pnb_start_code = NULL); | ||
| 61 | + | ||
| 52 | // current process resouce usage. | 62 | // current process resouce usage. |
| 53 | // @see: man getrusage | 63 | // @see: man getrusage |
| 54 | class SrsRusage | 64 | class SrsRusage |
| @@ -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 "1" | 34 | +#define VERSION_REVISION "2" |
| 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" |
| @@ -183,6 +183,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -183,6 +183,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 183 | #define ERROR_KERNEL_FLV_STREAM_CLOSED 3037 | 183 | #define ERROR_KERNEL_FLV_STREAM_CLOSED 3037 |
| 184 | #define ERROR_KERNEL_STREAM_INIT 3038 | 184 | #define ERROR_KERNEL_STREAM_INIT 3038 |
| 185 | #define ERROR_EDGE_VHOST_REMOVED 3039 | 185 | #define ERROR_EDGE_VHOST_REMOVED 3039 |
| 186 | +#define ERROR_HLS_AVC_TRY_OTHERS 3040 | ||
| 186 | 187 | ||
| 187 | /** | 188 | /** |
| 188 | * whether the error code is an system control error. | 189 | * whether the error code is an system control error. |
-
请 注册 或 登录 后发表评论