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

Side by Side Diff: source/libvpx/vpx/src/svc_encodeframe.c

Issue 341293003: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 6 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
« no previous file with comments | « source/libvpx/vpx/internal/vpx_codec_internal.h ('k') | source/libvpx/vpx/src/vpx_codec.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebM 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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 return VPX_CODEC_INVALID_PARAM; 489 return VPX_CODEC_INVALID_PARAM;
490 } 490 }
491 strncpy(si->scale_factors, scale_factors, sizeof(si->scale_factors)); 491 strncpy(si->scale_factors, scale_factors, sizeof(si->scale_factors));
492 si->scale_factors[sizeof(si->scale_factors) - 1] = '\0'; 492 si->scale_factors[sizeof(si->scale_factors) - 1] = '\0';
493 return VPX_CODEC_OK; 493 return VPX_CODEC_OK;
494 } 494 }
495 495
496 vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx, 496 vpx_codec_err_t vpx_svc_init(SvcContext *svc_ctx, vpx_codec_ctx_t *codec_ctx,
497 vpx_codec_iface_t *iface, 497 vpx_codec_iface_t *iface,
498 vpx_codec_enc_cfg_t *enc_cfg) { 498 vpx_codec_enc_cfg_t *enc_cfg) {
499 int max_intra_size_pct;
500 vpx_codec_err_t res; 499 vpx_codec_err_t res;
501 SvcInternal *const si = get_svc_internal(svc_ctx); 500 SvcInternal *const si = get_svc_internal(svc_ctx);
502 if (svc_ctx == NULL || codec_ctx == NULL || iface == NULL || 501 if (svc_ctx == NULL || codec_ctx == NULL || iface == NULL ||
503 enc_cfg == NULL) { 502 enc_cfg == NULL) {
504 return VPX_CODEC_INVALID_PARAM; 503 return VPX_CODEC_INVALID_PARAM;
505 } 504 }
506 if (si == NULL) return VPX_CODEC_MEM_ERROR; 505 if (si == NULL) return VPX_CODEC_MEM_ERROR;
507 506
508 si->codec_ctx = codec_ctx; 507 si->codec_ctx = codec_ctx;
509 508
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 if (total > 0) { 567 if (total > 0) {
569 enc_cfg->ss_target_bitrate[i] = (unsigned int) 568 enc_cfg->ss_target_bitrate[i] = (unsigned int)
570 (enc_cfg->rc_target_bitrate * alloc_ratio[i] / total); 569 (enc_cfg->rc_target_bitrate * alloc_ratio[i] / total);
571 } 570 }
572 } 571 }
573 } 572 }
574 573
575 // modify encoder configuration 574 // modify encoder configuration
576 enc_cfg->ss_number_layers = si->layers; 575 enc_cfg->ss_number_layers = si->layers;
577 enc_cfg->ts_number_layers = 1; // Temporal layers not used in this encoder. 576 enc_cfg->ts_number_layers = 1; // Temporal layers not used in this encoder.
578 enc_cfg->kf_mode = VPX_KF_DISABLED;
579 // Lag in frames not currently supported 577 // Lag in frames not currently supported
580 enc_cfg->g_lag_in_frames = 0; 578 enc_cfg->g_lag_in_frames = 0;
581 579
582 // TODO(ivanmaltz): determine if these values need to be set explicitly for 580 // TODO(ivanmaltz): determine if these values need to be set explicitly for
583 // svc, or if the normal default/override mechanism can be used 581 // svc, or if the normal default/override mechanism can be used
584 enc_cfg->rc_dropframe_thresh = 0; 582 enc_cfg->rc_dropframe_thresh = 0;
585 enc_cfg->rc_end_usage = VPX_CBR;
586 enc_cfg->rc_resize_allowed = 0; 583 enc_cfg->rc_resize_allowed = 0;
587 584
588 if (enc_cfg->g_pass == VPX_RC_ONE_PASS) { 585 if (enc_cfg->g_pass == VPX_RC_ONE_PASS) {
589 enc_cfg->rc_min_quantizer = 33; 586 enc_cfg->rc_min_quantizer = 33;
590 enc_cfg->rc_max_quantizer = 33; 587 enc_cfg->rc_max_quantizer = 33;
591 } 588 }
592 589
593 enc_cfg->rc_undershoot_pct = 100; 590 enc_cfg->rc_undershoot_pct = 100;
594 enc_cfg->rc_overshoot_pct = 15; 591 enc_cfg->rc_overshoot_pct = 15;
595 enc_cfg->rc_buf_initial_sz = 500; 592 enc_cfg->rc_buf_initial_sz = 500;
596 enc_cfg->rc_buf_optimal_sz = 600; 593 enc_cfg->rc_buf_optimal_sz = 600;
597 enc_cfg->rc_buf_sz = 1000; 594 enc_cfg->rc_buf_sz = 1000;
598 enc_cfg->g_error_resilient = 1; 595 enc_cfg->g_error_resilient = 1;
599 596
600 // Initialize codec 597 // Initialize codec
601 res = vpx_codec_enc_init(codec_ctx, iface, enc_cfg, VPX_CODEC_USE_PSNR); 598 res = vpx_codec_enc_init(codec_ctx, iface, enc_cfg, VPX_CODEC_USE_PSNR);
602 if (res != VPX_CODEC_OK) { 599 if (res != VPX_CODEC_OK) {
603 svc_log(svc_ctx, SVC_LOG_ERROR, "svc_enc_init error\n"); 600 svc_log(svc_ctx, SVC_LOG_ERROR, "svc_enc_init error\n");
604 return res; 601 return res;
605 } 602 }
606 603
607 vpx_codec_control(codec_ctx, VP9E_SET_SVC, 1); 604 vpx_codec_control(codec_ctx, VP9E_SET_SVC, 1);
608 vpx_codec_control(codec_ctx, VP8E_SET_CPUUSED, 1);
609 vpx_codec_control(codec_ctx, VP8E_SET_STATIC_THRESHOLD, 1);
610 vpx_codec_control(codec_ctx, VP8E_SET_NOISE_SENSITIVITY, 1);
611 vpx_codec_control(codec_ctx, VP8E_SET_TOKEN_PARTITIONS, 1); 605 vpx_codec_control(codec_ctx, VP8E_SET_TOKEN_PARTITIONS, 1);
606 vpx_codec_control(codec_ctx, VP8E_SET_ENABLEAUTOALTREF, 0);
612 607
613 max_intra_size_pct =
614 (int)(((double)enc_cfg->rc_buf_optimal_sz * 0.5) *
615 ((double)enc_cfg->g_timebase.den / enc_cfg->g_timebase.num) / 10.0);
616 vpx_codec_control(codec_ctx, VP8E_SET_MAX_INTRA_BITRATE_PCT,
617 max_intra_size_pct);
618 return VPX_CODEC_OK; 608 return VPX_CODEC_OK;
619 } 609 }
620 610
621 // SVC Algorithm flags - these get mapped to VP8_EFLAG_* defined in vp8cx.h 611 // SVC Algorithm flags - these get mapped to VP8_EFLAG_* defined in vp8cx.h
622 612
623 // encoder should reference the last frame 613 // encoder should reference the last frame
624 #define USE_LAST (1 << 0) 614 #define USE_LAST (1 << 0)
625 615
626 // encoder should reference the alt ref frame 616 // encoder should reference the alt ref frame
627 #define USE_ARF (1 << 1) 617 #define USE_ARF (1 << 1)
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 SvcInternal *const si = get_svc_internal(svc_ctx); 852 SvcInternal *const si = get_svc_internal(svc_ctx);
863 if (svc_ctx == NULL || codec_ctx == NULL || si == NULL) { 853 if (svc_ctx == NULL || codec_ctx == NULL || si == NULL) {
864 return VPX_CODEC_INVALID_PARAM; 854 return VPX_CODEC_INVALID_PARAM;
865 } 855 }
866 856
867 memset(&superframe, 0, sizeof(superframe)); 857 memset(&superframe, 0, sizeof(superframe));
868 svc_log_reset(svc_ctx); 858 svc_log_reset(svc_ctx);
869 si->rc_stats_buf_used = 0; 859 si->rc_stats_buf_used = 0;
870 860
871 si->layers = svc_ctx->spatial_layers; 861 si->layers = svc_ctx->spatial_layers;
872 if (si->frame_within_gop >= si->kf_dist || 862 if (si->encode_frame_count == 0) {
873 si->encode_frame_count == 0) {
874 si->frame_within_gop = 0; 863 si->frame_within_gop = 0;
875 } 864 }
876 si->is_keyframe = (si->frame_within_gop == 0); 865 si->is_keyframe = (si->frame_within_gop == 0);
877 si->frame_size = 0; 866 si->frame_size = 0;
878 867
879 if (rawimg != NULL) { 868 if (rawimg != NULL) {
880 svc_log(svc_ctx, SVC_LOG_DEBUG, 869 svc_log(svc_ctx, SVC_LOG_DEBUG,
881 "vpx_svc_encode layers: %d, frame_count: %d, " 870 "vpx_svc_encode layers: %d, frame_count: %d, "
882 "frame_within_gop: %d\n", si->layers, si->encode_frame_count, 871 "frame_within_gop: %d\n", si->layers, si->encode_frame_count,
883 si->frame_within_gop); 872 si->frame_within_gop);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 return si->rc_stats_buf_used; 1127 return si->rc_stats_buf_used;
1139 } 1128 }
1140 1129
1141 char *vpx_svc_get_rc_stats_buffer(const SvcContext *svc_ctx) { 1130 char *vpx_svc_get_rc_stats_buffer(const SvcContext *svc_ctx) {
1142 const SvcInternal *const si = get_const_svc_internal(svc_ctx); 1131 const SvcInternal *const si = get_const_svc_internal(svc_ctx);
1143 if (svc_ctx == NULL || si == NULL) return NULL; 1132 if (svc_ctx == NULL || si == NULL) return NULL;
1144 return si->rc_stats_buf; 1133 return si->rc_stats_buf;
1145 } 1134 }
1146 1135
1147 1136
OLDNEW
« no previous file with comments | « source/libvpx/vpx/internal/vpx_codec_internal.h ('k') | source/libvpx/vpx/src/vpx_codec.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698