Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(840)

Side by Side Diff: content/renderer/media/rtc_video_encoder.cc

Issue 304593004: H264 decoder for webRTC. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix off-by-one error in fragmentation offsets. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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);
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] - 4 - offsets[i]);
663 header.VerifyAndAllocateFragmentationHeader(1); 677
664 header.fragmentationOffset[0] = 0; 678 header.fragmentationOffset[i] = offsets[i];
665 header.fragmentationLength[0] = image->_length; 679 header.fragmentationLength[i] = length;
666 header.fragmentationPlType[0] = 0; 680 header.fragmentationPlType[i] = 0;
667 header.fragmentationTimeDiff[0] = 0; 681 header.fragmentationTimeDiff[i] = 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
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
OLDNEW
« no previous file with comments | « content/renderer/media/rtc_video_decoder.cc ('k') | content/renderer/media/rtc_video_encoder_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698