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 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 tl_configs[i].encoder_layer_id); | 820 tl_configs[i].encoder_layer_id); |
821 } | 821 } |
822 // TODO(holmer): Ideally the duration should be the timestamp diff of this | 822 // TODO(holmer): Ideally the duration should be the timestamp diff of this |
823 // frame and the next frame to be encoded, which we don't have. Instead we | 823 // frame and the next frame to be encoded, which we don't have. Instead we |
824 // would like to use the duration of the previous frame. Unfortunately the | 824 // would like to use the duration of the previous frame. Unfortunately the |
825 // rate control seems to be off with that setup. Using the average input | 825 // rate control seems to be off with that setup. Using the average input |
826 // frame rate to calculate an average duration for now. | 826 // frame rate to calculate an average duration for now. |
827 assert(codec_.maxFramerate > 0); | 827 assert(codec_.maxFramerate > 0); |
828 uint32_t duration = 90000 / codec_.maxFramerate; | 828 uint32_t duration = 90000 / codec_.maxFramerate; |
829 | 829 |
830 // Note we must pass 0 for |flags| field in encode call below since they are | 830 int error = WEBRTC_VIDEO_CODEC_OK; |
831 // set above in |vpx_codec_control| function for each encoder/spatial layer. | 831 int num_tries = 0; |
832 int error = vpx_codec_encode(&encoders_[0], &raw_images_[0], timestamp_, | 832 // If the first try returns WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT |
833 duration, 0, VPX_DL_REALTIME); | 833 // the frame must be reencoded with the same parameters again because |
834 // Reset specific intra frame thresholds, following the key frame. | 834 // target bitrate is exceeded and encoder state has been reset. |
835 if (send_key_frame) { | 835 while (num_tries == 0 || |
836 vpx_codec_control(&(encoders_[0]), VP8E_SET_MAX_INTRA_BITRATE_PCT, | 836 (num_tries == 1 && |
837 rc_max_intra_target_); | 837 error == WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT)) { |
| 838 ++num_tries; |
| 839 // Note we must pass 0 for |flags| field in encode call below since they are |
| 840 // set above in |vpx_codec_control| function for each encoder/spatial layer. |
| 841 error = vpx_codec_encode(&encoders_[0], &raw_images_[0], timestamp_, |
| 842 duration, 0, VPX_DL_REALTIME); |
| 843 // Reset specific intra frame thresholds, following the key frame. |
| 844 if (send_key_frame) { |
| 845 vpx_codec_control(&(encoders_[0]), VP8E_SET_MAX_INTRA_BITRATE_PCT, |
| 846 rc_max_intra_target_); |
| 847 } |
| 848 if (error) |
| 849 return WEBRTC_VIDEO_CODEC_ERROR; |
| 850 timestamp_ += duration; |
| 851 // Examines frame timestamps only. |
| 852 error = GetEncodedPartitions(tl_configs, frame); |
838 } | 853 } |
839 if (error) | 854 return error; |
840 return WEBRTC_VIDEO_CODEC_ERROR; | |
841 timestamp_ += duration; | |
842 // Examines frame timestamps only. | |
843 return GetEncodedPartitions(tl_configs, frame); | |
844 } | 855 } |
845 | 856 |
846 void VP8EncoderImpl::PopulateCodecSpecific( | 857 void VP8EncoderImpl::PopulateCodecSpecific( |
847 CodecSpecificInfo* codec_specific, | 858 CodecSpecificInfo* codec_specific, |
848 const TemporalLayers::FrameConfig& tl_config, | 859 const TemporalLayers::FrameConfig& tl_config, |
849 const vpx_codec_cx_pkt_t& pkt, | 860 const vpx_codec_cx_pkt_t& pkt, |
850 int stream_idx, | 861 int stream_idx, |
851 uint32_t timestamp) { | 862 uint32_t timestamp) { |
852 assert(codec_specific != NULL); | 863 assert(codec_specific != NULL); |
853 codec_specific->codecType = kVideoCodecVP8; | 864 codec_specific->codecType = kVideoCodecVP8; |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1250 buffer_pool_.Release(); | 1261 buffer_pool_.Release(); |
1251 inited_ = false; | 1262 inited_ = false; |
1252 return WEBRTC_VIDEO_CODEC_OK; | 1263 return WEBRTC_VIDEO_CODEC_OK; |
1253 } | 1264 } |
1254 | 1265 |
1255 const char* VP8DecoderImpl::ImplementationName() const { | 1266 const char* VP8DecoderImpl::ImplementationName() const { |
1256 return "libvpx"; | 1267 return "libvpx"; |
1257 } | 1268 } |
1258 | 1269 |
1259 } // namespace webrtc | 1270 } // namespace webrtc |
OLD | NEW |