OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 RTC_DCHECK_EQ(frame.width(), codec_.width); | 641 RTC_DCHECK_EQ(frame.width(), codec_.width); |
642 RTC_DCHECK_EQ(frame.height(), codec_.height); | 642 RTC_DCHECK_EQ(frame.height(), codec_.height); |
643 | 643 |
644 if (!inited_) | 644 if (!inited_) |
645 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 645 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
646 if (encoded_complete_callback_ == NULL) | 646 if (encoded_complete_callback_ == NULL) |
647 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 647 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
648 | 648 |
649 rtc::scoped_refptr<VideoFrameBuffer> input_image = frame.video_frame_buffer(); | 649 rtc::scoped_refptr<VideoFrameBuffer> input_image = frame.video_frame_buffer(); |
650 // Since we are extracting raw pointers from |input_image| to | 650 // Since we are extracting raw pointers from |input_image| to |
651 // |raw_images_[0]|, the resolution of these frames must match. Note that | 651 // |raw_images_[0]|, the resolution of these frames must match. |
652 // |input_image| might be scaled from |frame|. In that case, the resolution of | |
653 // |raw_images_[0]| should have been updated in UpdateCodecFrameSize. | |
654 RTC_DCHECK_EQ(input_image->width(), raw_images_[0].d_w); | 652 RTC_DCHECK_EQ(input_image->width(), raw_images_[0].d_w); |
655 RTC_DCHECK_EQ(input_image->height(), raw_images_[0].d_h); | 653 RTC_DCHECK_EQ(input_image->height(), raw_images_[0].d_h); |
656 | 654 |
657 // Image in vpx_image_t format. | 655 // Image in vpx_image_t format. |
658 // Input image is const. VP8's raw image is not defined as const. | 656 // Input image is const. VP8's raw image is not defined as const. |
659 raw_images_[0].planes[VPX_PLANE_Y] = | 657 raw_images_[0].planes[VPX_PLANE_Y] = |
660 const_cast<uint8_t*>(input_image->DataY()); | 658 const_cast<uint8_t*>(input_image->DataY()); |
661 raw_images_[0].planes[VPX_PLANE_U] = | 659 raw_images_[0].planes[VPX_PLANE_U] = |
662 const_cast<uint8_t*>(input_image->DataU()); | 660 const_cast<uint8_t*>(input_image->DataU()); |
663 raw_images_[0].planes[VPX_PLANE_V] = | 661 raw_images_[0].planes[VPX_PLANE_V] = |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 vpx_codec_control(&(encoders_[0]), VP8E_SET_MAX_INTRA_BITRATE_PCT, | 760 vpx_codec_control(&(encoders_[0]), VP8E_SET_MAX_INTRA_BITRATE_PCT, |
763 rc_max_intra_target_); | 761 rc_max_intra_target_); |
764 } | 762 } |
765 if (error) | 763 if (error) |
766 return WEBRTC_VIDEO_CODEC_ERROR; | 764 return WEBRTC_VIDEO_CODEC_ERROR; |
767 timestamp_ += duration; | 765 timestamp_ += duration; |
768 // Examines frame timestamps only. | 766 // Examines frame timestamps only. |
769 return GetEncodedPartitions(frame); | 767 return GetEncodedPartitions(frame); |
770 } | 768 } |
771 | 769 |
772 // TODO(pbos): Make sure this works for properly for >1 encoders. | |
773 int VP8EncoderImpl::UpdateCodecFrameSize(int width, int height) { | |
774 codec_.width = width; | |
775 codec_.height = height; | |
776 if (codec_.numberOfSimulcastStreams <= 1) { | |
777 // For now scaling is only used for single-layer streams. | |
778 codec_.simulcastStream[0].width = width; | |
779 codec_.simulcastStream[0].height = height; | |
780 } | |
781 // Update the cpu_speed setting for resolution change. | |
782 vpx_codec_control(&(encoders_[0]), VP8E_SET_CPUUSED, | |
783 SetCpuSpeed(codec_.width, codec_.height)); | |
784 raw_images_[0].w = codec_.width; | |
785 raw_images_[0].h = codec_.height; | |
786 raw_images_[0].d_w = codec_.width; | |
787 raw_images_[0].d_h = codec_.height; | |
788 vpx_img_set_rect(&raw_images_[0], 0, 0, codec_.width, codec_.height); | |
789 | |
790 // Update encoder context for new frame size. | |
791 // Change of frame size will automatically trigger a key frame. | |
792 configurations_[0].g_w = codec_.width; | |
793 configurations_[0].g_h = codec_.height; | |
794 if (vpx_codec_enc_config_set(&encoders_[0], &configurations_[0])) { | |
795 return WEBRTC_VIDEO_CODEC_ERROR; | |
796 } | |
797 return WEBRTC_VIDEO_CODEC_OK; | |
798 } | |
799 | |
800 void VP8EncoderImpl::PopulateCodecSpecific( | 770 void VP8EncoderImpl::PopulateCodecSpecific( |
801 CodecSpecificInfo* codec_specific, | 771 CodecSpecificInfo* codec_specific, |
802 const vpx_codec_cx_pkt_t& pkt, | 772 const vpx_codec_cx_pkt_t& pkt, |
803 int stream_idx, | 773 int stream_idx, |
804 uint32_t timestamp) { | 774 uint32_t timestamp) { |
805 assert(codec_specific != NULL); | 775 assert(codec_specific != NULL); |
806 codec_specific->codecType = kVideoCodecVP8; | 776 codec_specific->codecType = kVideoCodecVP8; |
807 codec_specific->codec_name = ImplementationName(); | 777 codec_specific->codec_name = ImplementationName(); |
808 CodecSpecificInfoVP8* vp8Info = &(codec_specific->codecSpecific.VP8); | 778 CodecSpecificInfoVP8* vp8Info = &(codec_specific->codecSpecific.VP8); |
809 vp8Info->pictureId = picture_id_[stream_idx]; | 779 vp8Info->pictureId = picture_id_[stream_idx]; |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 buffer_pool_.Release(); | 1122 buffer_pool_.Release(); |
1153 inited_ = false; | 1123 inited_ = false; |
1154 return WEBRTC_VIDEO_CODEC_OK; | 1124 return WEBRTC_VIDEO_CODEC_OK; |
1155 } | 1125 } |
1156 | 1126 |
1157 const char* VP8DecoderImpl::ImplementationName() const { | 1127 const char* VP8DecoderImpl::ImplementationName() const { |
1158 return "libvpx"; | 1128 return "libvpx"; |
1159 } | 1129 } |
1160 | 1130 |
1161 } // namespace webrtc | 1131 } // namespace webrtc |
OLD | NEW |