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

Side by Side Diff: source/libvpx/vp9/vp9_cx_iface.c

Issue 478033002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: 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
« no previous file with comments | « source/libvpx/vp9/vp9_common.mk ('k') | source/libvpx/vp9/vp9_dx_iface.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) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 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 22 matching lines...) Expand all
33 unsigned int arnr_strength; 33 unsigned int arnr_strength;
34 unsigned int arnr_type; 34 unsigned int arnr_type;
35 vp8e_tuning tuning; 35 vp8e_tuning tuning;
36 unsigned int cq_level; // constrained quality level 36 unsigned int cq_level; // constrained quality level
37 unsigned int rc_max_intra_bitrate_pct; 37 unsigned int rc_max_intra_bitrate_pct;
38 unsigned int lossless; 38 unsigned int lossless;
39 unsigned int frame_parallel_decoding_mode; 39 unsigned int frame_parallel_decoding_mode;
40 AQ_MODE aq_mode; 40 AQ_MODE aq_mode;
41 unsigned int frame_periodic_boost; 41 unsigned int frame_periodic_boost;
42 BIT_DEPTH bit_depth; 42 BIT_DEPTH bit_depth;
43 vp9e_tune_content content;
43 }; 44 };
44 45
45 struct extraconfig_map { 46 struct extraconfig_map {
46 unsigned int usage; 47 unsigned int usage;
47 struct vp9_extracfg cfg; 48 struct vp9_extracfg cfg;
48 }; 49 };
49 50
50 static const struct extraconfig_map extracfg_map[] = { 51 static const struct extraconfig_map extracfg_map[] = {
51 { 52 {
52 0, 53 0,
(...skipping 10 matching lines...) Expand all
63 5, // arnr_strength 64 5, // arnr_strength
64 3, // arnr_type 65 3, // arnr_type
65 VP8_TUNE_PSNR, // tuning 66 VP8_TUNE_PSNR, // tuning
66 10, // cq_level 67 10, // cq_level
67 0, // rc_max_intra_bitrate_pct 68 0, // rc_max_intra_bitrate_pct
68 0, // lossless 69 0, // lossless
69 0, // frame_parallel_decoding_mode 70 0, // frame_parallel_decoding_mode
70 NO_AQ, // aq_mode 71 NO_AQ, // aq_mode
71 0, // frame_periodic_delta_q 72 0, // frame_periodic_delta_q
72 BITS_8, // Bit depth 73 BITS_8, // Bit depth
74 VP9E_CONTENT_DEFAULT // content
73 } 75 }
74 } 76 }
75 }; 77 };
76 78
77 struct vpx_codec_alg_priv { 79 struct vpx_codec_alg_priv {
78 vpx_codec_priv_t base; 80 vpx_codec_priv_t base;
79 vpx_codec_enc_cfg_t cfg; 81 vpx_codec_enc_cfg_t cfg;
80 struct vp9_extracfg extra_cfg; 82 struct vp9_extracfg extra_cfg;
81 VP9EncoderConfig oxcf; 83 VP9EncoderConfig oxcf;
82 VP9_COMP *cpi; 84 VP9_COMP *cpi;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 RANGE_CHECK_BOOL(extra_cfg, enable_auto_alt_ref); 214 RANGE_CHECK_BOOL(extra_cfg, enable_auto_alt_ref);
213 RANGE_CHECK(extra_cfg, cpu_used, -16, 16); 215 RANGE_CHECK(extra_cfg, cpu_used, -16, 16);
214 RANGE_CHECK_HI(extra_cfg, noise_sensitivity, 6); 216 RANGE_CHECK_HI(extra_cfg, noise_sensitivity, 6);
215 RANGE_CHECK(extra_cfg, tile_columns, 0, 6); 217 RANGE_CHECK(extra_cfg, tile_columns, 0, 6);
216 RANGE_CHECK(extra_cfg, tile_rows, 0, 2); 218 RANGE_CHECK(extra_cfg, tile_rows, 0, 2);
217 RANGE_CHECK_HI(extra_cfg, sharpness, 7); 219 RANGE_CHECK_HI(extra_cfg, sharpness, 7);
218 RANGE_CHECK(extra_cfg, arnr_max_frames, 0, 15); 220 RANGE_CHECK(extra_cfg, arnr_max_frames, 0, 15);
219 RANGE_CHECK_HI(extra_cfg, arnr_strength, 6); 221 RANGE_CHECK_HI(extra_cfg, arnr_strength, 6);
220 RANGE_CHECK(extra_cfg, arnr_type, 1, 3); 222 RANGE_CHECK(extra_cfg, arnr_type, 1, 3);
221 RANGE_CHECK(extra_cfg, cq_level, 0, 63); 223 RANGE_CHECK(extra_cfg, cq_level, 0, 63);
224 RANGE_CHECK(extra_cfg, content,
225 VP9E_CONTENT_DEFAULT, VP9E_CONTENT_INVALID - 1);
222 226
223 // TODO(yaowu): remove this when ssim tuning is implemented for vp9 227 // TODO(yaowu): remove this when ssim tuning is implemented for vp9
224 if (extra_cfg->tuning == VP8_TUNE_SSIM) 228 if (extra_cfg->tuning == VP8_TUNE_SSIM)
225 ERROR("Option --tune=ssim is not currently supported in VP9."); 229 ERROR("Option --tune=ssim is not currently supported in VP9.");
226 230
227 if (cfg->g_pass == VPX_RC_LAST_PASS) { 231 if (cfg->g_pass == VPX_RC_LAST_PASS) {
228 const size_t packet_sz = sizeof(FIRSTPASS_STATS); 232 const size_t packet_sz = sizeof(FIRSTPASS_STATS);
229 const int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz); 233 const int n_packets = (int)(cfg->rc_twopass_stats_in.sz / packet_sz);
230 const FIRSTPASS_STATS *stats; 234 const FIRSTPASS_STATS *stats;
231 235
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 const vpx_image_t *img) { 294 const vpx_image_t *img) {
291 switch (img->fmt) { 295 switch (img->fmt) {
292 case VPX_IMG_FMT_YV12: 296 case VPX_IMG_FMT_YV12:
293 case VPX_IMG_FMT_I420: 297 case VPX_IMG_FMT_I420:
294 case VPX_IMG_FMT_I422: 298 case VPX_IMG_FMT_I422:
295 case VPX_IMG_FMT_I444: 299 case VPX_IMG_FMT_I444:
296 break; 300 break;
297 default: 301 default:
298 ERROR("Invalid image format. Only YV12, I420, I422, I444 images are " 302 ERROR("Invalid image format. Only YV12, I420, I422, I444 images are "
299 "supported."); 303 "supported.");
304 break;
300 } 305 }
301 306
302 if (img->d_w != ctx->cfg.g_w || img->d_h != ctx->cfg.g_h) 307 if (img->d_w != ctx->cfg.g_w || img->d_h != ctx->cfg.g_h)
303 ERROR("Image size must match encoder init configuration size"); 308 ERROR("Image size must match encoder init configuration size");
304 309
305 return VPX_CODEC_OK; 310 return VPX_CODEC_OK;
306 } 311 }
307 312
313 static int get_image_bps(const vpx_image_t *img) {
314 switch (img->fmt) {
315 case VPX_IMG_FMT_YV12:
316 case VPX_IMG_FMT_I420: return 12;
317 case VPX_IMG_FMT_I422: return 16;
318 case VPX_IMG_FMT_I444: return 24;
319 default: assert(0 && "Invalid image format"); break;
320 }
321 return 0;
322 }
308 323
309 static vpx_codec_err_t set_encoder_config( 324 static vpx_codec_err_t set_encoder_config(
310 VP9EncoderConfig *oxcf, 325 VP9EncoderConfig *oxcf,
311 const vpx_codec_enc_cfg_t *cfg, 326 const vpx_codec_enc_cfg_t *cfg,
312 const struct vp9_extracfg *extra_cfg) { 327 const struct vp9_extracfg *extra_cfg) {
313 oxcf->profile = cfg->g_profile; 328 oxcf->profile = cfg->g_profile;
314 oxcf->width = cfg->g_w; 329 oxcf->width = cfg->g_w;
315 oxcf->height = cfg->g_h; 330 oxcf->height = cfg->g_h;
316 oxcf->bit_depth = extra_cfg->bit_depth; 331 oxcf->bit_depth = extra_cfg->bit_depth;
317 // guess a frame rate if out of whack, use 30 332 // guess a frame rate if out of whack, use 30
318 oxcf->framerate = (double)cfg->g_timebase.den / cfg->g_timebase.num; 333 oxcf->init_framerate = (double)cfg->g_timebase.den / cfg->g_timebase.num;
319 if (oxcf->framerate > 180) 334 if (oxcf->init_framerate > 180)
320 oxcf->framerate = 30; 335 oxcf->init_framerate = 30;
321 336
322 switch (cfg->g_pass) { 337 switch (cfg->g_pass) {
323 case VPX_RC_ONE_PASS: 338 case VPX_RC_ONE_PASS:
324 oxcf->mode = ONE_PASS_GOOD; 339 oxcf->mode = ONE_PASS_GOOD;
340 oxcf->pass = 0;
325 break; 341 break;
326 case VPX_RC_FIRST_PASS: 342 case VPX_RC_FIRST_PASS:
327 oxcf->mode = TWO_PASS_FIRST; 343 oxcf->mode = TWO_PASS_FIRST;
344 oxcf->pass = 1;
328 break; 345 break;
329 case VPX_RC_LAST_PASS: 346 case VPX_RC_LAST_PASS:
330 oxcf->mode = TWO_PASS_SECOND_BEST; 347 oxcf->mode = TWO_PASS_SECOND_BEST;
348 oxcf->pass = 2;
331 break; 349 break;
332 } 350 }
333 351
334 oxcf->lag_in_frames = cfg->g_pass == VPX_RC_FIRST_PASS ? 0 352 oxcf->lag_in_frames = cfg->g_pass == VPX_RC_FIRST_PASS ? 0
335 : cfg->g_lag_in_frames; 353 : cfg->g_lag_in_frames;
336 oxcf->rc_mode = cfg->rc_end_usage; 354 oxcf->rc_mode = cfg->rc_end_usage;
337 355
338 // Convert target bandwidth from Kbit/s to Bit/s 356 // Convert target bandwidth from Kbit/s to Bit/s
339 oxcf->target_bandwidth = 1000 * cfg->rc_target_bitrate; 357 oxcf->target_bandwidth = 1000 * cfg->rc_target_bitrate;
340 oxcf->rc_max_intra_bitrate_pct = extra_cfg->rc_max_intra_bitrate_pct; 358 oxcf->rc_max_intra_bitrate_pct = extra_cfg->rc_max_intra_bitrate_pct;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 397
380 #if CONFIG_FP_MB_STATS 398 #if CONFIG_FP_MB_STATS
381 oxcf->firstpass_mb_stats_in = cfg->rc_firstpass_mb_stats_in; 399 oxcf->firstpass_mb_stats_in = cfg->rc_firstpass_mb_stats_in;
382 #endif 400 #endif
383 401
384 oxcf->arnr_max_frames = extra_cfg->arnr_max_frames; 402 oxcf->arnr_max_frames = extra_cfg->arnr_max_frames;
385 oxcf->arnr_strength = extra_cfg->arnr_strength; 403 oxcf->arnr_strength = extra_cfg->arnr_strength;
386 oxcf->arnr_type = extra_cfg->arnr_type; 404 oxcf->arnr_type = extra_cfg->arnr_type;
387 405
388 oxcf->tuning = extra_cfg->tuning; 406 oxcf->tuning = extra_cfg->tuning;
407 oxcf->content = extra_cfg->content;
389 408
390 oxcf->tile_columns = extra_cfg->tile_columns; 409 oxcf->tile_columns = extra_cfg->tile_columns;
391 oxcf->tile_rows = extra_cfg->tile_rows; 410 oxcf->tile_rows = extra_cfg->tile_rows;
392 411
393 oxcf->error_resilient_mode = cfg->g_error_resilient; 412 oxcf->error_resilient_mode = cfg->g_error_resilient;
394 oxcf->frame_parallel_decoding_mode = extra_cfg->frame_parallel_decoding_mode; 413 oxcf->frame_parallel_decoding_mode = extra_cfg->frame_parallel_decoding_mode;
395 414
396 oxcf->aq_mode = extra_cfg->aq_mode; 415 oxcf->aq_mode = extra_cfg->aq_mode;
397 416
398 oxcf->frame_periodic_boost = extra_cfg->frame_periodic_boost; 417 oxcf->frame_periodic_boost = extra_cfg->frame_periodic_boost;
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 // Select the extra vp6 configuration table based on the current 684 // Select the extra vp6 configuration table based on the current
666 // usage value. If the current usage value isn't found, use the 685 // usage value. If the current usage value isn't found, use the
667 // values for usage case 0. 686 // values for usage case 0.
668 for (i = 0; 687 for (i = 0;
669 extracfg_map[i].usage && extracfg_map[i].usage != cfg->g_usage; 688 extracfg_map[i].usage && extracfg_map[i].usage != cfg->g_usage;
670 ++i) {} 689 ++i) {}
671 690
672 priv->extra_cfg = extracfg_map[i].cfg; 691 priv->extra_cfg = extracfg_map[i].cfg;
673 priv->extra_cfg.pkt_list = &priv->pkt_list.head; 692 priv->extra_cfg.pkt_list = &priv->pkt_list.head;
674 693
675 // Maximum buffer size approximated based on having multiple ARF.
676 priv->cx_data_sz = priv->cfg.g_w * priv->cfg.g_h * 3 / 2 * 8;
677
678 if (priv->cx_data_sz < 4096)
679 priv->cx_data_sz = 4096;
680
681 priv->cx_data = (unsigned char *)malloc(priv->cx_data_sz);
682 if (priv->cx_data == NULL)
683 return VPX_CODEC_MEM_ERROR;
684
685 vp9_initialize_enc(); 694 vp9_initialize_enc();
686 695
687 res = validate_config(priv, &priv->cfg, &priv->extra_cfg); 696 res = validate_config(priv, &priv->cfg, &priv->extra_cfg);
688 697
689 if (res == VPX_CODEC_OK) { 698 if (res == VPX_CODEC_OK) {
690 VP9_COMP *cpi; 699 VP9_COMP *cpi;
691 set_encoder_config(&ctx->priv->alg_priv->oxcf, 700 set_encoder_config(&ctx->priv->alg_priv->oxcf,
692 &ctx->priv->alg_priv->cfg, 701 &ctx->priv->alg_priv->cfg,
693 &ctx->priv->alg_priv->extra_cfg); 702 &ctx->priv->alg_priv->extra_cfg);
694 cpi = vp9_create_compressor(&ctx->priv->alg_priv->oxcf); 703 cpi = vp9_create_compressor(&ctx->priv->alg_priv->oxcf);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 } 800 }
792 *x++ = marker; 801 *x++ = marker;
793 ctx->pending_cx_data_sz += index_sz; 802 ctx->pending_cx_data_sz += index_sz;
794 #ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA 803 #ifdef TEST_SUPPLEMENTAL_SUPERFRAME_DATA
795 index_sz += index_sz_test; 804 index_sz += index_sz_test;
796 #endif 805 #endif
797 } 806 }
798 return index_sz; 807 return index_sz;
799 } 808 }
800 809
810 // vp9 uses 10,000,000 ticks/second as time stamp
811 #define TICKS_PER_SEC 10000000LL
812
813 static int64_t timebase_units_to_ticks(const vpx_rational_t *timebase,
814 int64_t n) {
815 return n * TICKS_PER_SEC * timebase->num / timebase->den;
816 }
817
818 static int64_t ticks_to_timebase_units(const vpx_rational_t *timebase,
819 int64_t n) {
820 const int64_t round = TICKS_PER_SEC * timebase->num / 2 - 1;
821 return (n * timebase->den + round) / timebase->num / TICKS_PER_SEC;
822 }
823
801 static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx, 824 static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
802 const vpx_image_t *img, 825 const vpx_image_t *img,
803 vpx_codec_pts_t pts, 826 vpx_codec_pts_t pts,
804 unsigned long duration, 827 unsigned long duration,
805 vpx_enc_frame_flags_t flags, 828 vpx_enc_frame_flags_t flags,
806 unsigned long deadline) { 829 unsigned long deadline) {
807 vpx_codec_err_t res = VPX_CODEC_OK; 830 vpx_codec_err_t res = VPX_CODEC_OK;
831 const vpx_rational_t *const timebase = &ctx->cfg.g_timebase;
808 832
809 if (img) 833 if (img != NULL) {
810 res = validate_img(ctx, img); 834 res = validate_img(ctx, img);
835 // TODO(jzern) the checks related to cpi's validity should be treated as a
836 // failure condition, encoder setup is done fully in init() currently.
837 if (res == VPX_CODEC_OK && ctx->cpi != NULL && ctx->cx_data == NULL) {
838 // There's no codec control for multiple alt-refs so check the encoder
839 // instance for its status to determine the compressed data size.
840 ctx->cx_data_sz = ctx->cfg.g_w * ctx->cfg.g_h *
841 get_image_bps(img) / 8 *
842 (ctx->cpi->multi_arf_allowed ? 8 : 2);
843 if (ctx->cx_data_sz < 4096) ctx->cx_data_sz = 4096;
844
845 ctx->cx_data = (unsigned char *)malloc(ctx->cx_data_sz);
846 if (ctx->cx_data == NULL) {
847 return VPX_CODEC_MEM_ERROR;
848 }
849 }
850 }
811 851
812 pick_quickcompress_mode(ctx, duration, deadline); 852 pick_quickcompress_mode(ctx, duration, deadline);
813 vpx_codec_pkt_list_init(&ctx->pkt_list); 853 vpx_codec_pkt_list_init(&ctx->pkt_list);
814 854
815 // Handle Flags 855 // Handle Flags
816 if (((flags & VP8_EFLAG_NO_UPD_GF) && (flags & VP8_EFLAG_FORCE_GF)) || 856 if (((flags & VP8_EFLAG_NO_UPD_GF) && (flags & VP8_EFLAG_FORCE_GF)) ||
817 ((flags & VP8_EFLAG_NO_UPD_ARF) && (flags & VP8_EFLAG_FORCE_ARF))) { 857 ((flags & VP8_EFLAG_NO_UPD_ARF) && (flags & VP8_EFLAG_FORCE_ARF))) {
818 ctx->base.err_detail = "Conflicting flags."; 858 ctx->base.err_detail = "Conflicting flags.";
819 return VPX_CODEC_INVALID_PARAM; 859 return VPX_CODEC_INVALID_PARAM;
820 } 860 }
821 861
822 vp9_apply_encoding_flags(ctx->cpi, flags); 862 vp9_apply_encoding_flags(ctx->cpi, flags);
823 863
824 // Handle fixed keyframe intervals 864 // Handle fixed keyframe intervals
825 if (ctx->cfg.kf_mode == VPX_KF_AUTO && 865 if (ctx->cfg.kf_mode == VPX_KF_AUTO &&
826 ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist) { 866 ctx->cfg.kf_min_dist == ctx->cfg.kf_max_dist) {
827 if (++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist) { 867 if (++ctx->fixed_kf_cntr > ctx->cfg.kf_min_dist) {
828 flags |= VPX_EFLAG_FORCE_KF; 868 flags |= VPX_EFLAG_FORCE_KF;
829 ctx->fixed_kf_cntr = 1; 869 ctx->fixed_kf_cntr = 1;
830 } 870 }
831 } 871 }
832 872
833 // Initialize the encoder instance on the first frame. 873 // Initialize the encoder instance on the first frame.
834 if (res == VPX_CODEC_OK && ctx->cpi != NULL) { 874 if (res == VPX_CODEC_OK && ctx->cpi != NULL) {
835 unsigned int lib_flags = 0; 875 unsigned int lib_flags = 0;
836 YV12_BUFFER_CONFIG sd; 876 YV12_BUFFER_CONFIG sd;
837 int64_t dst_time_stamp, dst_end_time_stamp; 877 int64_t dst_time_stamp = timebase_units_to_ticks(timebase, pts);
878 int64_t dst_end_time_stamp =
879 timebase_units_to_ticks(timebase, pts + duration);
838 size_t size, cx_data_sz; 880 size_t size, cx_data_sz;
839 unsigned char *cx_data; 881 unsigned char *cx_data;
840 882
841 // Set up internal flags 883 // Set up internal flags
842 if (ctx->base.init_flags & VPX_CODEC_USE_PSNR) 884 if (ctx->base.init_flags & VPX_CODEC_USE_PSNR)
843 ((VP9_COMP *)ctx->cpi)->b_calculate_psnr = 1; 885 ((VP9_COMP *)ctx->cpi)->b_calculate_psnr = 1;
844 886
845 /* vp9 use 10,000,000 ticks/second as time stamp */
846 dst_time_stamp = (pts * 10000000 * ctx->cfg.g_timebase.num)
847 / ctx->cfg.g_timebase.den;
848 dst_end_time_stamp = (pts + duration) * 10000000 * ctx->cfg.g_timebase.num /
849 ctx->cfg.g_timebase.den;
850
851 if (img != NULL) { 887 if (img != NULL) {
852 res = image2yuvconfig(img, &sd); 888 res = image2yuvconfig(img, &sd);
853 889
854 // Store the original flags in to the frame buffer. Will extract the 890 // Store the original flags in to the frame buffer. Will extract the
855 // key frame flag when we actually encode this frame. 891 // key frame flag when we actually encode this frame.
856 if (vp9_receive_raw_frame(ctx->cpi, flags, 892 if (vp9_receive_raw_frame(ctx->cpi, flags,
857 &sd, dst_time_stamp, dst_end_time_stamp)) { 893 &sd, dst_time_stamp, dst_end_time_stamp)) {
858 VP9_COMP *cpi = (VP9_COMP *)ctx->cpi; 894 VP9_COMP *cpi = (VP9_COMP *)ctx->cpi;
859 res = update_error_state(ctx, &cpi->common.error); 895 res = update_error_state(ctx, &cpi->common.error);
860 } 896 }
(...skipping 16 matching lines...) Expand all
877 ctx->base.err_detail = "Compressed data buffer too small"; 913 ctx->base.err_detail = "Compressed data buffer too small";
878 return VPX_CODEC_ERROR; 914 return VPX_CODEC_ERROR;
879 } 915 }
880 } 916 }
881 917
882 while (cx_data_sz >= ctx->cx_data_sz / 2 && 918 while (cx_data_sz >= ctx->cx_data_sz / 2 &&
883 -1 != vp9_get_compressed_data(ctx->cpi, &lib_flags, &size, 919 -1 != vp9_get_compressed_data(ctx->cpi, &lib_flags, &size,
884 cx_data, &dst_time_stamp, 920 cx_data, &dst_time_stamp,
885 &dst_end_time_stamp, !img)) { 921 &dst_end_time_stamp, !img)) {
886 if (size) { 922 if (size) {
887 vpx_codec_pts_t round, delta; 923 VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi;
888 vpx_codec_cx_pkt_t pkt; 924 vpx_codec_cx_pkt_t pkt;
889 VP9_COMP *const cpi = (VP9_COMP *)ctx->cpi;
890 925
891 #if CONFIG_SPATIAL_SVC 926 #if CONFIG_SPATIAL_SVC
892 if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) 927 if (is_spatial_svc(cpi))
893 cpi->svc.layer_context[cpi->svc.spatial_layer_id].layer_size += size; 928 cpi->svc.layer_context[cpi->svc.spatial_layer_id].layer_size += size;
894 #endif 929 #endif
895 930
896 // Pack invisible frames with the next visible frame 931 // Pack invisible frames with the next visible frame
897 if (cpi->common.show_frame == 0 932 if (cpi->common.show_frame == 0
898 #if CONFIG_SPATIAL_SVC 933 #if CONFIG_SPATIAL_SVC
899 || (cpi->use_svc && cpi->svc.number_temporal_layers == 1 && 934 || (is_spatial_svc(cpi) &&
900 cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1) 935 cpi->svc.spatial_layer_id < cpi->svc.number_spatial_layers - 1)
901 #endif 936 #endif
902 ) { 937 ) {
903 if (ctx->pending_cx_data == 0) 938 if (ctx->pending_cx_data == 0)
904 ctx->pending_cx_data = cx_data; 939 ctx->pending_cx_data = cx_data;
905 ctx->pending_cx_data_sz += size; 940 ctx->pending_cx_data_sz += size;
906 ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; 941 ctx->pending_frame_sizes[ctx->pending_frame_count++] = size;
907 ctx->pending_frame_magnitude |= size; 942 ctx->pending_frame_magnitude |= size;
908 cx_data += size; 943 cx_data += size;
909 cx_data_sz -= size; 944 cx_data_sz -= size;
910 continue; 945 continue;
911 } 946 }
912 947
913 // Add the frame packet to the list of returned packets. 948 // Add the frame packet to the list of returned packets.
914 round = (vpx_codec_pts_t)10000000 * ctx->cfg.g_timebase.num / 2 - 1;
915 delta = (dst_end_time_stamp - dst_time_stamp);
916 pkt.kind = VPX_CODEC_CX_FRAME_PKT; 949 pkt.kind = VPX_CODEC_CX_FRAME_PKT;
917 pkt.data.frame.pts = 950 pkt.data.frame.pts = ticks_to_timebase_units(timebase, dst_time_stamp);
918 (dst_time_stamp * ctx->cfg.g_timebase.den + round) 951 pkt.data.frame.duration =
919 / ctx->cfg.g_timebase.num / 10000000; 952 (unsigned long)ticks_to_timebase_units(timebase,
920 pkt.data.frame.duration = (unsigned long) 953 dst_end_time_stamp - dst_time_stamp);
921 ((delta * ctx->cfg.g_timebase.den + round)
922 / ctx->cfg.g_timebase.num / 10000000);
923 pkt.data.frame.flags = lib_flags << 16; 954 pkt.data.frame.flags = lib_flags << 16;
924 955
925 if (lib_flags & FRAMEFLAGS_KEY 956 if (lib_flags & FRAMEFLAGS_KEY
926 #if CONFIG_SPATIAL_SVC 957 #if CONFIG_SPATIAL_SVC
927 || (cpi->use_svc && cpi->svc.number_temporal_layers == 1 && 958 || (is_spatial_svc(cpi) &&
928 cpi->svc.layer_context[0].is_key_frame) 959 cpi->svc.layer_context[0].is_key_frame)
929 #endif 960 #endif
930 ) 961 )
931 pkt.data.frame.flags |= VPX_FRAME_IS_KEY; 962 pkt.data.frame.flags |= VPX_FRAME_IS_KEY;
932 963
933 if (cpi->common.show_frame == 0) { 964 if (cpi->common.show_frame == 0) {
934 pkt.data.frame.flags |= VPX_FRAME_IS_INVISIBLE; 965 pkt.data.frame.flags |= VPX_FRAME_IS_INVISIBLE;
935 966
936 // This timestamp should be as close as possible to the 967 // This timestamp should be as close as possible to the
937 // prior PTS so that if a decoder uses pts to schedule when 968 // prior PTS so that if a decoder uses pts to schedule when
938 // to do this, we start right after last frame was decoded. 969 // to do this, we start right after last frame was decoded.
939 // Invisible frames have no duration. 970 // Invisible frames have no duration.
940 pkt.data.frame.pts = ((cpi->last_time_stamp_seen 971 pkt.data.frame.pts =
941 * ctx->cfg.g_timebase.den + round) 972 ticks_to_timebase_units(timebase, cpi->last_time_stamp_seen) + 1;
942 / ctx->cfg.g_timebase.num / 10000000) + 1;
943 pkt.data.frame.duration = 0; 973 pkt.data.frame.duration = 0;
944 } 974 }
945 975
946 if (cpi->droppable) 976 if (cpi->droppable)
947 pkt.data.frame.flags |= VPX_FRAME_IS_DROPPABLE; 977 pkt.data.frame.flags |= VPX_FRAME_IS_DROPPABLE;
948 978
949 if (ctx->pending_cx_data) { 979 if (ctx->pending_cx_data) {
950 ctx->pending_frame_sizes[ctx->pending_frame_count++] = size; 980 ctx->pending_frame_sizes[ctx->pending_frame_count++] = size;
951 ctx->pending_frame_magnitude |= size; 981 ctx->pending_frame_magnitude |= size;
952 ctx->pending_cx_data_sz += size; 982 ctx->pending_cx_data_sz += size;
953 size += write_superframe_index(ctx); 983 size += write_superframe_index(ctx);
954 pkt.data.frame.buf = ctx->pending_cx_data; 984 pkt.data.frame.buf = ctx->pending_cx_data;
955 pkt.data.frame.sz = ctx->pending_cx_data_sz; 985 pkt.data.frame.sz = ctx->pending_cx_data_sz;
956 ctx->pending_cx_data = NULL; 986 ctx->pending_cx_data = NULL;
957 ctx->pending_cx_data_sz = 0; 987 ctx->pending_cx_data_sz = 0;
958 ctx->pending_frame_count = 0; 988 ctx->pending_frame_count = 0;
959 ctx->pending_frame_magnitude = 0; 989 ctx->pending_frame_magnitude = 0;
960 } else { 990 } else {
961 pkt.data.frame.buf = cx_data; 991 pkt.data.frame.buf = cx_data;
962 pkt.data.frame.sz = size; 992 pkt.data.frame.sz = size;
963 } 993 }
964 pkt.data.frame.partition_id = -1; 994 pkt.data.frame.partition_id = -1;
965 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); 995 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt);
966 cx_data += size; 996 cx_data += size;
967 cx_data_sz -= size; 997 cx_data_sz -= size;
968 #if CONFIG_SPATIAL_SVC 998 #if CONFIG_SPATIAL_SVC
969 if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) { 999 if (is_spatial_svc(cpi)) {
970 vpx_codec_cx_pkt_t pkt = {0}; 1000 vpx_codec_cx_pkt_t pkt = {0};
971 int i; 1001 int i;
972 pkt.kind = VPX_CODEC_SPATIAL_SVC_LAYER_SIZES; 1002 pkt.kind = VPX_CODEC_SPATIAL_SVC_LAYER_SIZES;
973 for (i = 0; i < cpi->svc.number_spatial_layers; ++i) { 1003 for (i = 0; i < cpi->svc.number_spatial_layers; ++i) {
974 pkt.data.layer_sizes[i] = cpi->svc.layer_context[i].layer_size; 1004 pkt.data.layer_sizes[i] = cpi->svc.layer_context[i].layer_size;
975 cpi->svc.layer_context[i].layer_size = 0; 1005 cpi->svc.layer_context[i].layer_size = 0;
976 } 1006 }
977 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt); 1007 vpx_codec_pkt_list_add(&ctx->pkt_list.head, &pkt);
978 } 1008 }
979 #endif 1009 #endif
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 } else { 1049 } else {
1020 return VPX_CODEC_INVALID_PARAM; 1050 return VPX_CODEC_INVALID_PARAM;
1021 } 1051 }
1022 } 1052 }
1023 1053
1024 static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx, 1054 static vpx_codec_err_t ctrl_get_reference(vpx_codec_alg_priv_t *ctx,
1025 va_list args) { 1055 va_list args) {
1026 vp9_ref_frame_t *const frame = va_arg(args, vp9_ref_frame_t *); 1056 vp9_ref_frame_t *const frame = va_arg(args, vp9_ref_frame_t *);
1027 1057
1028 if (frame != NULL) { 1058 if (frame != NULL) {
1029 YV12_BUFFER_CONFIG *fb; 1059 YV12_BUFFER_CONFIG *fb = get_ref_frame(&ctx->cpi->common, frame->idx);
1060 if (fb == NULL) return VPX_CODEC_ERROR;
1030 1061
1031 vp9_get_reference_enc(ctx->cpi, frame->idx, &fb);
1032 yuvconfig2image(&frame->img, fb, NULL); 1062 yuvconfig2image(&frame->img, fb, NULL);
1033 return VPX_CODEC_OK; 1063 return VPX_CODEC_OK;
1034 } else { 1064 } else {
1035 return VPX_CODEC_INVALID_PARAM; 1065 return VPX_CODEC_INVALID_PARAM;
1036 } 1066 }
1037 } 1067 }
1038 1068
1039 static vpx_codec_err_t ctrl_set_previewpp(vpx_codec_alg_priv_t *ctx, 1069 static vpx_codec_err_t ctrl_set_previewpp(vpx_codec_alg_priv_t *ctx,
1040 va_list args) { 1070 va_list args) {
1041 #if CONFIG_VP9_POSTPROC 1071 #if CONFIG_VP9_POSTPROC
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 cpi->svc.layer_context[i].svc_params_received.spatial_layer = -1; 1219 cpi->svc.layer_context[i].svc_params_received.spatial_layer = -1;
1190 } 1220 }
1191 } 1221 }
1192 1222
1193 cpi->svc.layer_context[params->spatial_layer].svc_params_received = 1223 cpi->svc.layer_context[params->spatial_layer].svc_params_received =
1194 *params; 1224 *params;
1195 1225
1196 return VPX_CODEC_OK; 1226 return VPX_CODEC_OK;
1197 } 1227 }
1198 1228
1229 static vpx_codec_err_t ctrl_set_tune_content(vpx_codec_alg_priv_t *ctx,
1230 va_list args) {
1231 struct vp9_extracfg extra_cfg = ctx->extra_cfg;
1232 extra_cfg.content = CAST(VP9E_SET_TUNE_CONTENT, args);
1233 return update_extra_cfg(ctx, &extra_cfg);
1234 }
1235
1199 static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = { 1236 static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = {
1200 {VP8_COPY_REFERENCE, ctrl_copy_reference}, 1237 {VP8_COPY_REFERENCE, ctrl_copy_reference},
1201 {VP8E_UPD_ENTROPY, ctrl_update_entropy}, 1238 {VP8E_UPD_ENTROPY, ctrl_update_entropy},
1202 {VP8E_UPD_REFERENCE, ctrl_update_reference}, 1239 {VP8E_UPD_REFERENCE, ctrl_update_reference},
1203 {VP8E_USE_REFERENCE, ctrl_use_reference}, 1240 {VP8E_USE_REFERENCE, ctrl_use_reference},
1204 1241
1205 // Setters 1242 // Setters
1206 {VP8_SET_REFERENCE, ctrl_set_reference}, 1243 {VP8_SET_REFERENCE, ctrl_set_reference},
1207 {VP8_SET_POSTPROC, ctrl_set_previewpp}, 1244 {VP8_SET_POSTPROC, ctrl_set_previewpp},
1208 {VP8E_SET_ROI_MAP, ctrl_set_roi_map}, 1245 {VP8E_SET_ROI_MAP, ctrl_set_roi_map},
(...skipping 12 matching lines...) Expand all
1221 {VP8E_SET_TUNING, ctrl_set_tuning}, 1258 {VP8E_SET_TUNING, ctrl_set_tuning},
1222 {VP8E_SET_CQ_LEVEL, ctrl_set_cq_level}, 1259 {VP8E_SET_CQ_LEVEL, ctrl_set_cq_level},
1223 {VP8E_SET_MAX_INTRA_BITRATE_PCT, ctrl_set_rc_max_intra_bitrate_pct}, 1260 {VP8E_SET_MAX_INTRA_BITRATE_PCT, ctrl_set_rc_max_intra_bitrate_pct},
1224 {VP9E_SET_LOSSLESS, ctrl_set_lossless}, 1261 {VP9E_SET_LOSSLESS, ctrl_set_lossless},
1225 {VP9E_SET_FRAME_PARALLEL_DECODING, ctrl_set_frame_parallel_decoding_mode}, 1262 {VP9E_SET_FRAME_PARALLEL_DECODING, ctrl_set_frame_parallel_decoding_mode},
1226 {VP9E_SET_AQ_MODE, ctrl_set_aq_mode}, 1263 {VP9E_SET_AQ_MODE, ctrl_set_aq_mode},
1227 {VP9E_SET_FRAME_PERIODIC_BOOST, ctrl_set_frame_periodic_boost}, 1264 {VP9E_SET_FRAME_PERIODIC_BOOST, ctrl_set_frame_periodic_boost},
1228 {VP9E_SET_SVC, ctrl_set_svc}, 1265 {VP9E_SET_SVC, ctrl_set_svc},
1229 {VP9E_SET_SVC_PARAMETERS, ctrl_set_svc_parameters}, 1266 {VP9E_SET_SVC_PARAMETERS, ctrl_set_svc_parameters},
1230 {VP9E_SET_SVC_LAYER_ID, ctrl_set_svc_layer_id}, 1267 {VP9E_SET_SVC_LAYER_ID, ctrl_set_svc_layer_id},
1268 {VP9E_SET_TUNE_CONTENT, ctrl_set_tune_content},
1231 1269
1232 // Getters 1270 // Getters
1233 {VP8E_GET_LAST_QUANTIZER, ctrl_get_quantizer}, 1271 {VP8E_GET_LAST_QUANTIZER, ctrl_get_quantizer},
1234 {VP8E_GET_LAST_QUANTIZER_64, ctrl_get_quantizer64}, 1272 {VP8E_GET_LAST_QUANTIZER_64, ctrl_get_quantizer64},
1235 {VP9_GET_REFERENCE, ctrl_get_reference}, 1273 {VP9_GET_REFERENCE, ctrl_get_reference},
1236 1274
1237 { -1, NULL}, 1275 { -1, NULL},
1238 }; 1276 };
1239 1277
1240 static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = { 1278 static vpx_codec_enc_cfg_map_t encoder_usage_cfg_map[] = {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 50, // rc_two_pass_vbrbias 1318 50, // rc_two_pass_vbrbias
1281 0, // rc_two_pass_vbrmin_section 1319 0, // rc_two_pass_vbrmin_section
1282 2000, // rc_two_pass_vbrmax_section 1320 2000, // rc_two_pass_vbrmax_section
1283 1321
1284 // keyframing settings (kf) 1322 // keyframing settings (kf)
1285 VPX_KF_AUTO, // g_kfmode 1323 VPX_KF_AUTO, // g_kfmode
1286 0, // kf_min_dist 1324 0, // kf_min_dist
1287 9999, // kf_max_dist 1325 9999, // kf_max_dist
1288 1326
1289 VPX_SS_DEFAULT_LAYERS, // ss_number_layers 1327 VPX_SS_DEFAULT_LAYERS, // ss_number_layers
1290 #if CONFIG_SPATIAL_SVC
1291 {0}, 1328 {0},
1292 #endif
1293 {0}, // ss_target_bitrate 1329 {0}, // ss_target_bitrate
1294 1, // ts_number_layers 1330 1, // ts_number_layers
1295 {0}, // ts_target_bitrate 1331 {0}, // ts_target_bitrate
1296 {0}, // ts_rate_decimator 1332 {0}, // ts_rate_decimator
1297 0, // ts_periodicity 1333 0, // ts_periodicity
1298 {0}, // ts_layer_id 1334 {0}, // ts_layer_id
1299 #if VPX_ENCODER_ABI_VERSION == (1 + VPX_CODEC_ABI_VERSION) 1335 #if VPX_ENCODER_ABI_VERSION == (1 + VPX_CODEC_ABI_VERSION)
1300 "vp8.fpf" // first pass filename 1336 "vp8.fpf" // first pass filename
1301 #endif 1337 #endif
1302 } 1338 }
1303 }, 1339 },
1304 { -1, {NOT_IMPLEMENTED}}
1305 }; 1340 };
1306 1341
1307 #ifndef VERSION_STRING 1342 #ifndef VERSION_STRING
1308 #define VERSION_STRING 1343 #define VERSION_STRING
1309 #endif 1344 #endif
1310 CODEC_INTERFACE(vpx_codec_vp9_cx) = { 1345 CODEC_INTERFACE(vpx_codec_vp9_cx) = {
1311 "WebM Project VP9 Encoder" VERSION_STRING, 1346 "WebM Project VP9 Encoder" VERSION_STRING,
1312 VPX_CODEC_INTERNAL_ABI_VERSION, 1347 VPX_CODEC_INTERNAL_ABI_VERSION,
1313 VPX_CODEC_CAP_ENCODER | VPX_CODEC_CAP_PSNR, // vpx_codec_caps_t 1348 VPX_CODEC_CAP_ENCODER | VPX_CODEC_CAP_PSNR, // vpx_codec_caps_t
1314 encoder_init, // vpx_codec_init_fn_t 1349 encoder_init, // vpx_codec_init_fn_t
1315 encoder_destroy, // vpx_codec_destroy_fn_t 1350 encoder_destroy, // vpx_codec_destroy_fn_t
1316 encoder_ctrl_maps, // vpx_codec_ctrl_fn_map_t 1351 encoder_ctrl_maps, // vpx_codec_ctrl_fn_map_t
1317 NOT_IMPLEMENTED, // vpx_codec_get_mmap_fn_t
1318 NOT_IMPLEMENTED, // vpx_codec_set_mmap_fn_t
1319 { // NOLINT 1352 { // NOLINT
1320 NOT_IMPLEMENTED, // vpx_codec_peek_si_fn_t 1353 NOT_IMPLEMENTED, // vpx_codec_peek_si_fn_t
1321 NOT_IMPLEMENTED, // vpx_codec_get_si_fn_t 1354 NOT_IMPLEMENTED, // vpx_codec_get_si_fn_t
1322 NOT_IMPLEMENTED, // vpx_codec_decode_fn_t 1355 NOT_IMPLEMENTED, // vpx_codec_decode_fn_t
1323 NOT_IMPLEMENTED, // vpx_codec_frame_get_fn_t 1356 NOT_IMPLEMENTED, // vpx_codec_frame_get_fn_t
1324 NOT_IMPLEMENTED // vpx_codec_set_fb_fn_t 1357 NOT_IMPLEMENTED // vpx_codec_set_fb_fn_t
1325 }, 1358 },
1326 { // NOLINT 1359 { // NOLINT
1360 1, // 1 cfg map
1327 encoder_usage_cfg_map, // vpx_codec_enc_cfg_map_t 1361 encoder_usage_cfg_map, // vpx_codec_enc_cfg_map_t
1328 encoder_encode, // vpx_codec_encode_fn_t 1362 encoder_encode, // vpx_codec_encode_fn_t
1329 encoder_get_cxdata, // vpx_codec_get_cx_data_fn_t 1363 encoder_get_cxdata, // vpx_codec_get_cx_data_fn_t
1330 encoder_set_config, // vpx_codec_enc_config_set_fn_t 1364 encoder_set_config, // vpx_codec_enc_config_set_fn_t
1331 NOT_IMPLEMENTED, // vpx_codec_get_global_headers_fn_t 1365 NOT_IMPLEMENTED, // vpx_codec_get_global_headers_fn_t
1332 encoder_get_preview, // vpx_codec_get_preview_frame_fn_t 1366 encoder_get_preview, // vpx_codec_get_preview_frame_fn_t
1333 NOT_IMPLEMENTED // vpx_codec_enc_mr_get_mem_loc_fn_t 1367 NOT_IMPLEMENTED // vpx_codec_enc_mr_get_mem_loc_fn_t
1334 } 1368 }
1335 }; 1369 };
OLDNEW
« no previous file with comments | « source/libvpx/vp9/vp9_common.mk ('k') | source/libvpx/vp9/vp9_dx_iface.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698