OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/rtc_video_encoder.h" | 5 #include "content/renderer/media/rtc_video_encoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 int32 bitstream_buffer_id, | 641 int32 bitstream_buffer_id, |
642 uint16 picture_id) { | 642 uint16 picture_id) { |
643 DCHECK(thread_checker_.CalledOnValidThread()); | 643 DCHECK(thread_checker_.CalledOnValidThread()); |
644 DVLOG(3) << "ReturnEncodedImage(): " | 644 DVLOG(3) << "ReturnEncodedImage(): " |
645 << "bitstream_buffer_id=" << bitstream_buffer_id | 645 << "bitstream_buffer_id=" << bitstream_buffer_id |
646 << ", picture_id=" << picture_id; | 646 << ", picture_id=" << picture_id; |
647 | 647 |
648 if (!encoded_image_callback_) | 648 if (!encoded_image_callback_) |
649 return; | 649 return; |
650 | 650 |
651 std::vector<int> offsets; | |
652 size_t i; | |
653 uint32 acc = 0; | |
654 for (i = 0; i < image->_length; ++i) { | |
655 acc = (acc << 8) | image->_buffer[i]; | |
656 if ((acc & 0xffffff00) == 0x100) | |
657 offsets.push_back(i - 3); | |
658 } | |
659 | |
660 // Generate a header describing a single fragment. | |
661 webrtc::RTPFragmentationHeader header; | |
662 memset(&header, 0, sizeof(header)); | |
663 header.VerifyAndAllocateFragmentationHeader(offsets.size()); | |
664 | |
651 webrtc::CodecSpecificInfo info; | 665 webrtc::CodecSpecificInfo info; |
652 memset(&info, 0, sizeof(info)); | 666 memset(&info, 0, sizeof(info)); |
653 info.codecType = video_codec_type_; | 667 info.codecType = video_codec_type_; |
654 if (video_codec_type_ == webrtc::kVideoCodecVP8) { | 668 if (video_codec_type_ == webrtc::kVideoCodecVP8) { |
655 info.codecSpecific.VP8.pictureId = picture_id; | 669 info.codecSpecific.VP8.pictureId = picture_id; |
656 info.codecSpecific.VP8.tl0PicIdx = -1; | 670 info.codecSpecific.VP8.tl0PicIdx = -1; |
657 info.codecSpecific.VP8.keyIdx = -1; | 671 info.codecSpecific.VP8.keyIdx = -1; |
658 } | 672 } |
659 | 673 |
660 // Generate a header describing a single fragment. | 674 for (i = 0; i < offsets.size(); ++i) { |
661 webrtc::RTPFragmentationHeader header; | 675 uint32_t length = (i == offsets.size() - 1) ? |
662 memset(&header, 0, sizeof(header)); | 676 (image->_length - offsets[i]) : (offsets[i + 1] - offsets[i]); |
663 header.VerifyAndAllocateFragmentationHeader(1); | 677 |
664 header.fragmentationOffset[0] = 0; | 678 header.fragmentationOffset[i] = offsets[i] + 3; |
665 header.fragmentationLength[0] = image->_length; | 679 header.fragmentationLength[0] = length - 3; |
Stefan
2014/08/07 19:17:27
Shouldn't this be header.fragmentationLength[i]
hshi1
2014/08/07 19:32:10
sorry for the typo, yes this should be [i] not [0]
| |
666 header.fragmentationPlType[0] = 0; | 680 header.fragmentationPlType[0] = 0; |
667 header.fragmentationTimeDiff[0] = 0; | 681 header.fragmentationTimeDiff[0] = 0; |
682 } | |
668 | 683 |
669 int32_t retval = encoded_image_callback_->Encoded(*image, &info, &header); | 684 int32_t retval = encoded_image_callback_->Encoded(*image, &info, &header); |
670 if (retval < 0) { | 685 if (retval < 0) { |
671 DVLOG(2) << "ReturnEncodedImage(): encoded_image_callback_ returned " | 686 DVLOG(2) << "ReturnEncodedImage(): encoded_image_callback_ returned " |
672 << retval; | 687 << retval; |
673 } | 688 } |
674 | 689 |
675 // The call through webrtc::EncodedImageCallback is synchronous, so we can | 690 // The call through webrtc::EncodedImageCallback is synchronous, so we can |
676 // immediately recycle the output buffer back to the Impl. | 691 // immediately recycle the output buffer back to the Impl. |
677 gpu_factories_->GetTaskRunner()->PostTask( | 692 gpu_factories_->GetTaskRunner()->PostTask( |
(...skipping 17 matching lines...) Expand all Loading... | |
695 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", | 710 UMA_HISTOGRAM_BOOLEAN("Media.RTCVideoEncoderInitEncodeSuccess", |
696 init_retval == WEBRTC_VIDEO_CODEC_OK); | 711 init_retval == WEBRTC_VIDEO_CODEC_OK); |
697 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { | 712 if (init_retval == WEBRTC_VIDEO_CODEC_OK) { |
698 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", | 713 UMA_HISTOGRAM_ENUMERATION("Media.RTCVideoEncoderProfile", |
699 video_codec_profile_, | 714 video_codec_profile_, |
700 media::VIDEO_CODEC_PROFILE_MAX + 1); | 715 media::VIDEO_CODEC_PROFILE_MAX + 1); |
701 } | 716 } |
702 } | 717 } |
703 | 718 |
704 } // namespace content | 719 } // namespace content |
OLD | NEW |