Merge "Fix: check cx_data buffer prior to write"
[profile/ivi/libvpx.git] / vp8 / encoder / onyx_int.h
1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11
12 #ifndef __INC_VP8_INT_H
13 #define __INC_VP8_INT_H
14
15 #include <stdio.h>
16 #include "vpx_config.h"
17 #include "vp8/common/onyx.h"
18 #include "treewriter.h"
19 #include "tokenize.h"
20 #include "vp8/common/onyxc_int.h"
21 #include "variance.h"
22 #include "dct.h"
23 #include "encodemb.h"
24 #include "quantize.h"
25 #include "vp8/common/entropy.h"
26 #include "vp8/common/threading.h"
27 #include "vpx_ports/mem.h"
28 #include "vpx/internal/vpx_codec_internal.h"
29 #include "mcomp.h"
30 #include "temporal_filter.h"
31 #include "vp8/common/findnearmv.h"
32 #include "lookahead.h"
33
34 //#define SPEEDSTATS 1
35 #define MIN_GF_INTERVAL             4
36 #define DEFAULT_GF_INTERVAL         7
37
38 #define KEY_FRAME_CONTEXT 5
39
40 #define MAX_LAG_BUFFERS (CONFIG_REALTIME_ONLY? 1 : 25)
41
42 #define AF_THRESH   25
43 #define AF_THRESH2  100
44 #define ARF_DECAY_THRESH 12
45 #define MAX_MODES 20
46
47 #define MIN_THRESHMULT  32
48 #define MAX_THRESHMULT  512
49
50 #define GF_ZEROMV_ZBIN_BOOST 12
51 #define LF_ZEROMV_ZBIN_BOOST 6
52 #define MV_ZBIN_BOOST        4
53 #define ZBIN_OQ_MAX 192
54
55 #if !(CONFIG_REALTIME_ONLY)
56 #define VP8_TEMPORAL_ALT_REF 1
57 #endif
58
59 #define MAX_PERIODICITY 16
60
61 typedef struct
62 {
63     int kf_indicated;
64     unsigned int frames_since_key;
65     unsigned int frames_since_golden;
66     int filter_level;
67     int frames_till_gf_update_due;
68     int recent_ref_frame_usage[MAX_REF_FRAMES];
69
70     MV_CONTEXT mvc[2];
71     int mvcosts[2][MVvals+1];
72
73 #ifdef MODE_STATS
74     // Stats
75     int y_modes[5];
76     int uv_modes[4];
77     int b_modes[10];
78     int inter_y_modes[10];
79     int inter_uv_modes[4];
80     int inter_b_modes[10];
81 #endif
82
83     vp8_prob ymode_prob[4], uv_mode_prob[3];   /* interframe intra mode probs */
84     vp8_prob kf_ymode_prob[4], kf_uv_mode_prob[3];   /* keyframe "" */
85
86     int ymode_count[5], uv_mode_count[4];  /* intra MB type cts this frame */
87
88     int count_mb_ref_frame_usage[MAX_REF_FRAMES];
89
90     int this_frame_percent_intra;
91     int last_frame_percent_intra;
92
93
94 } CODING_CONTEXT;
95
96 typedef struct
97 {
98     double frame;
99     double intra_error;
100     double coded_error;
101     double ssim_weighted_pred_err;
102     double pcnt_inter;
103     double pcnt_motion;
104     double pcnt_second_ref;
105     double pcnt_neutral;
106     double MVr;
107     double mvr_abs;
108     double MVc;
109     double mvc_abs;
110     double MVrv;
111     double MVcv;
112     double mv_in_out_count;
113     double new_mv_count;
114     double duration;
115     double count;
116 }
117 FIRSTPASS_STATS;
118
119 typedef struct
120 {
121     int frames_so_far;
122     double frame_intra_error;
123     double frame_coded_error;
124     double frame_pcnt_inter;
125     double frame_pcnt_motion;
126     double frame_mvr;
127     double frame_mvr_abs;
128     double frame_mvc;
129     double frame_mvc_abs;
130
131 } ONEPASS_FRAMESTATS;
132
133
134 typedef enum
135 {
136     THR_ZEROMV         = 0,
137     THR_DC             = 1,
138
139     THR_NEARESTMV      = 2,
140     THR_NEARMV         = 3,
141
142     THR_ZEROG          = 4,
143     THR_NEARESTG       = 5,
144
145     THR_ZEROA          = 6,
146     THR_NEARESTA       = 7,
147
148     THR_NEARG          = 8,
149     THR_NEARA          = 9,
150
151     THR_V_PRED         = 10,
152     THR_H_PRED         = 11,
153     THR_TM             = 12,
154
155     THR_NEWMV          = 13,
156     THR_NEWG           = 14,
157     THR_NEWA           = 15,
158
159     THR_SPLITMV        = 16,
160     THR_SPLITG         = 17,
161     THR_SPLITA         = 18,
162
163     THR_B_PRED         = 19,
164 }
165 THR_MODES;
166
167 typedef enum
168 {
169     DIAMOND = 0,
170     NSTEP = 1,
171     HEX = 2
172 } SEARCH_METHODS;
173
174 typedef struct
175 {
176     int RD;
177     SEARCH_METHODS search_method;
178     int improved_quant;
179     int improved_dct;
180     int auto_filter;
181     int recode_loop;
182     int iterative_sub_pixel;
183     int half_pixel_search;
184     int quarter_pixel_search;
185     int thresh_mult[MAX_MODES];
186     int max_step_search_steps;
187     int first_step;
188     int optimize_coefficients;
189
190     int use_fastquant_for_pick;
191     int no_skip_block4x4_search;
192     int improved_mv_pred;
193
194 } SPEED_FEATURES;
195
196 typedef struct
197 {
198     MACROBLOCK  mb;
199     int segment_counts[MAX_MB_SEGMENTS];
200     int totalrate;
201 } MB_ROW_COMP;
202
203 typedef struct
204 {
205     TOKENEXTRA *start;
206     TOKENEXTRA *stop;
207 } TOKENLIST;
208
209 typedef struct
210 {
211     int ithread;
212     void *ptr1;
213     void *ptr2;
214 } ENCODETHREAD_DATA;
215 typedef struct
216 {
217     int ithread;
218     void *ptr1;
219 } LPFTHREAD_DATA;
220
221
222 typedef struct VP8_ENCODER_RTCD
223 {
224     VP8_COMMON_RTCD            *common;
225     vp8_variance_rtcd_vtable_t  variance;
226     vp8_fdct_rtcd_vtable_t      fdct;
227     vp8_encodemb_rtcd_vtable_t  encodemb;
228     vp8_quantize_rtcd_vtable_t  quantize;
229     vp8_search_rtcd_vtable_t    search;
230     vp8_temporal_rtcd_vtable_t  temporal;
231 } VP8_ENCODER_RTCD;
232
233 enum
234 {
235     BLOCK_16X8,
236     BLOCK_8X16,
237     BLOCK_8X8,
238     BLOCK_4X4,
239     BLOCK_16X16,
240     BLOCK_MAX_SEGMENTS
241 };
242
243 typedef struct
244 {
245     // Layer configuration
246     double frame_rate;
247     int target_bandwidth;
248
249     // Layer specific coding parameters
250     int starting_buffer_level;
251     int optimal_buffer_level;
252     int maximum_buffer_size;
253
254     int avg_frame_size_for_layer;
255
256     int buffer_level;
257     int bits_off_target;
258
259     long long total_actual_bits;
260     int total_target_vs_actual;
261
262     int worst_quality;
263     int active_worst_quality;
264     int best_quality;
265     int active_best_quality;
266
267     int ni_av_qi;
268     int ni_tot_qi;
269     int ni_frames;
270     int avg_frame_qindex;
271
272     double rate_correction_factor;
273     double key_frame_rate_correction_factor;
274     double gf_rate_correction_factor;
275
276     int zbin_over_quant;
277
278     int inter_frame_target;
279     INT64 total_byte_count;
280
281     int filter_level;
282
283     int last_frame_percent_intra;
284
285     int count_mb_ref_frame_usage[MAX_REF_FRAMES];
286
287 } LAYER_CONTEXT;
288
289 typedef struct VP8_COMP
290 {
291
292     DECLARE_ALIGNED(16, short, Y1quant[QINDEX_RANGE][16]);
293     DECLARE_ALIGNED(16, unsigned char, Y1quant_shift[QINDEX_RANGE][16]);
294     DECLARE_ALIGNED(16, short, Y1zbin[QINDEX_RANGE][16]);
295     DECLARE_ALIGNED(16, short, Y1round[QINDEX_RANGE][16]);
296
297     DECLARE_ALIGNED(16, short, Y2quant[QINDEX_RANGE][16]);
298     DECLARE_ALIGNED(16, unsigned char, Y2quant_shift[QINDEX_RANGE][16]);
299     DECLARE_ALIGNED(16, short, Y2zbin[QINDEX_RANGE][16]);
300     DECLARE_ALIGNED(16, short, Y2round[QINDEX_RANGE][16]);
301
302     DECLARE_ALIGNED(16, short, UVquant[QINDEX_RANGE][16]);
303     DECLARE_ALIGNED(16, unsigned char, UVquant_shift[QINDEX_RANGE][16]);
304     DECLARE_ALIGNED(16, short, UVzbin[QINDEX_RANGE][16]);
305     DECLARE_ALIGNED(16, short, UVround[QINDEX_RANGE][16]);
306
307     DECLARE_ALIGNED(16, short, zrun_zbin_boost_y1[QINDEX_RANGE][16]);
308     DECLARE_ALIGNED(16, short, zrun_zbin_boost_y2[QINDEX_RANGE][16]);
309     DECLARE_ALIGNED(16, short, zrun_zbin_boost_uv[QINDEX_RANGE][16]);
310     DECLARE_ALIGNED(16, short, Y1quant_fast[QINDEX_RANGE][16]);
311     DECLARE_ALIGNED(16, short, Y2quant_fast[QINDEX_RANGE][16]);
312     DECLARE_ALIGNED(16, short, UVquant_fast[QINDEX_RANGE][16]);
313
314
315     MACROBLOCK mb;
316     VP8_COMMON common;
317     vp8_writer bc, bc2;
318     // bool_writer *bc2;
319
320     VP8_CONFIG oxcf;
321
322     struct lookahead_ctx    *lookahead;
323     struct lookahead_entry  *source;
324     struct lookahead_entry  *alt_ref_source;
325
326     YV12_BUFFER_CONFIG *Source;
327     YV12_BUFFER_CONFIG *un_scaled_source;
328     YV12_BUFFER_CONFIG scaled_source;
329
330     int source_alt_ref_pending; // frame in src_buffers has been identified to be encoded as an alt ref
331     int source_alt_ref_active;  // an alt ref frame has been encoded and is usable
332
333     int is_src_frame_alt_ref;   // source of frame to encode is an exact copy of an alt ref frame
334
335     int gold_is_last; // golden frame same as last frame ( short circuit gold searches)
336     int alt_is_last;  // Alt reference frame same as last ( short circuit altref search)
337     int gold_is_alt;  // don't do both alt and gold search ( just do gold).
338
339     //int refresh_alt_ref_frame;
340     YV12_BUFFER_CONFIG last_frame_uf;
341
342     TOKENEXTRA *tok;
343     unsigned int tok_count;
344
345
346     unsigned int frames_since_key;
347     unsigned int key_frame_frequency;
348     unsigned int this_key_frame_forced;
349     unsigned int next_key_frame_forced;
350
351     // Ambient reconstruction err target for force key frames
352     int ambient_err;
353
354     unsigned int mode_check_freq[MAX_MODES];
355     unsigned int mode_test_hit_counts[MAX_MODES];
356     unsigned int mode_chosen_counts[MAX_MODES];
357     unsigned int mbs_tested_so_far;
358
359     int rd_thresh_mult[MAX_MODES];
360     int rd_baseline_thresh[MAX_MODES];
361     int rd_threshes[MAX_MODES];
362
363     int RDMULT;
364     int RDDIV ;
365
366     CODING_CONTEXT coding_context;
367
368     // Rate targetting variables
369     int64_t prediction_error;
370     int64_t last_prediction_error;
371     int64_t intra_error;
372     int64_t last_intra_error;
373
374     int this_frame_target;
375     int projected_frame_size;
376     int last_q[2];                   // Separate values for Intra/Inter
377
378     double rate_correction_factor;
379     double key_frame_rate_correction_factor;
380     double gf_rate_correction_factor;
381
382     int frames_till_gf_update_due;      // Count down till next GF
383     int current_gf_interval;          // GF interval chosen when we coded the last GF
384
385     int gf_overspend_bits;            // Total bits overspent becasue of GF boost (cumulative)
386
387     int non_gf_bitrate_adjustment;     // Used in the few frames following a GF to recover the extra bits spent in that GF
388
389     int kf_overspend_bits;            // Extra bits spent on key frames that need to be recovered on inter frames
390     int kf_bitrate_adjustment;        // Current number of bit s to try and recover on each inter frame.
391     int max_gf_interval;
392     int baseline_gf_interval;
393     int active_arnr_frames;           // <= cpi->oxcf.arnr_max_frames
394
395     int64_t key_frame_count;
396     int prior_key_frame_distance[KEY_FRAME_CONTEXT];
397     int per_frame_bandwidth;          // Current section per frame bandwidth target
398     int av_per_frame_bandwidth;        // Average frame size target for clip
399     int min_frame_bandwidth;          // Minimum allocation that should be used for any frame
400     int inter_frame_target;
401     double output_frame_rate;
402     int64_t last_time_stamp_seen;
403     int64_t last_end_time_stamp_seen;
404     int64_t first_time_stamp_ever;
405
406     int ni_av_qi;
407     int ni_tot_qi;
408     int ni_frames;
409     int avg_frame_qindex;
410
411     int zbin_over_quant;
412     int zbin_mode_boost;
413     int zbin_mode_boost_enabled;
414
415     int64_t total_byte_count;
416
417     int buffered_mode;
418
419     int64_t buffer_level;
420     int bits_off_target;
421
422     int rolling_target_bits;
423     int rolling_actual_bits;
424
425     int long_rolling_target_bits;
426     int long_rolling_actual_bits;
427
428     int64_t total_actual_bits;
429     int total_target_vs_actual;        // debug stats
430
431     int worst_quality;
432     int active_worst_quality;
433     int best_quality;
434     int active_best_quality;
435
436     int cq_target_quality;
437
438     int drop_frames_allowed;          // Are we permitted to drop frames?
439     int drop_frame;                  // Drop this frame?
440     int drop_count;                  // How many frames have we dropped?
441     int max_drop_count;               // How many frames should we drop?
442     int max_consec_dropped_frames;     // Limit number of consecutive frames that can be dropped.
443
444
445     int ymode_count [VP8_YMODES];        /* intra MB type cts this frame */
446     int uv_mode_count[VP8_UV_MODES];       /* intra MB type cts this frame */
447
448     unsigned int MVcount [2] [MVvals];  /* (row,col) MV cts this frame */
449
450     unsigned int coef_counts [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];  /* for this frame */
451     //DECLARE_ALIGNED(16, int, coef_counts_backup [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS]);   //not used any more
452     //save vp8_tree_probs_from_distribution result for each frame to avoid repeat calculation
453     vp8_prob frame_coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
454     unsigned int frame_branch_ct [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES][2];
455
456     int gfu_boost;
457     int kf_boost;
458     int last_boost;
459
460     int target_bandwidth;
461     struct vpx_codec_pkt_list  *output_pkt_list;
462
463 #if 0
464     // Experimental code for lagged and one pass
465     ONEPASS_FRAMESTATS one_pass_frame_stats[MAX_LAG_BUFFERS];
466     int one_pass_frame_index;
467 #endif
468
469     int decimation_factor;
470     int decimation_count;
471
472     // for real time encoding
473     int avg_encode_time;              //microsecond
474     int avg_pick_mode_time;            //microsecond
475     int Speed;
476     unsigned int cpu_freq;           //Mhz
477     int compressor_speed;
478
479     int interquantizer;
480     int auto_gold;
481     int auto_adjust_gold_quantizer;
482     int goldfreq;
483     int auto_worst_q;
484     int cpu_used;
485     int horiz_scale;
486     int vert_scale;
487     int pass;
488
489
490     int prob_intra_coded;
491     int prob_last_coded;
492     int prob_gf_coded;
493     int prob_skip_false;
494     int last_skip_false_probs[3];
495     int last_skip_probs_q[3];
496     int recent_ref_frame_usage[MAX_REF_FRAMES];
497
498     int count_mb_ref_frame_usage[MAX_REF_FRAMES];
499     int this_frame_percent_intra;
500     int last_frame_percent_intra;
501
502     int ref_frame_flags;
503
504     SPEED_FEATURES sf;
505     int error_bins[1024];
506
507     // Data used for real time conferencing mode to help determine if it would be good to update the gf
508     int inter_zz_count;
509     int gf_bad_count;
510     int gf_update_recommended;
511     int skip_true_count;
512     int skip_false_count;
513
514     unsigned char *segmentation_map;
515     signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];            // Segment data (can be deltas or absolute values)
516     int  segment_encode_breakout[MAX_MB_SEGMENTS];                    // segment threashold for encode breakout
517
518     unsigned char *active_map;
519     unsigned int active_map_enabled;
520     // Video conferencing cyclic refresh mode flags etc
521     // This is a mode designed to clean up the background over time in live encoding scenarious. It uses segmentation
522     int cyclic_refresh_mode_enabled;
523     int cyclic_refresh_mode_max_mbs_perframe;
524     int cyclic_refresh_mode_index;
525     int cyclic_refresh_q;
526     signed char *cyclic_refresh_map;
527
528 #if CONFIG_MULTITHREAD
529     // multithread data
530     int * mt_current_mb_col;
531     int mt_sync_range;
532     int b_multi_threaded;
533     int encoding_thread_count;
534
535     pthread_t *h_encoding_thread;
536     pthread_t h_filter_thread;
537
538     MB_ROW_COMP *mb_row_ei;
539     ENCODETHREAD_DATA *en_thread_data;
540     LPFTHREAD_DATA lpf_thread_data;
541
542     //events
543     sem_t *h_event_start_encoding;
544     sem_t h_event_end_encoding;
545     sem_t h_event_start_lpf;
546     sem_t h_event_end_lpf;
547 #endif
548
549     TOKENLIST *tplist;
550     unsigned int partition_sz[MAX_PARTITIONS];
551     // end of multithread data
552
553
554     fractional_mv_step_fp *find_fractional_mv_step;
555     vp8_full_search_fn_t full_search_sad;
556     vp8_refining_search_fn_t refining_search_sad;
557     vp8_diamond_search_fn_t diamond_search_sad;
558     vp8_variance_fn_ptr_t fn_ptr[BLOCK_MAX_SEGMENTS];
559     unsigned int time_receive_data;
560     unsigned int time_compress_data;
561     unsigned int time_pick_lpf;
562     unsigned int time_encode_mb_row;
563
564     int base_skip_false_prob[128];
565
566     struct twopass_rc
567     {
568         unsigned int section_intra_rating;
569         double section_max_qfactor;
570         unsigned int next_iiratio;
571         unsigned int this_iiratio;
572         FIRSTPASS_STATS *total_stats;
573         FIRSTPASS_STATS *this_frame_stats;
574         FIRSTPASS_STATS *stats_in, *stats_in_end, *stats_in_start;
575         FIRSTPASS_STATS *total_left_stats;
576         int first_pass_done;
577         int64_t bits_left;
578         int64_t clip_bits_total;
579         double avg_iiratio;
580         double modified_error_total;
581         double modified_error_used;
582         double modified_error_left;
583         double kf_intra_err_min;
584         double gf_intra_err_min;
585         int frames_to_key;
586         int maxq_max_limit;
587         int maxq_min_limit;
588         int gf_decay_rate;
589         int static_scene_max_gf_interval;
590         int kf_bits;
591         int gf_group_error_left;           // Remaining error from uncoded frames in a gf group. Two pass use only
592
593         // Projected total bits available for a key frame group of frames
594         int64_t kf_group_bits;
595
596         // Error score of frames still to be coded in kf group
597         int64_t kf_group_error_left;
598
599         int gf_group_bits;                // Projected Bits available for a group of frames including 1 GF or ARF
600         int gf_bits;                     // Bits for the golden frame or ARF - 2 pass only
601         int alt_extra_bits;
602         double est_max_qcorrection_factor;
603     } twopass;
604
605 #if CONFIG_RUNTIME_CPU_DETECT
606     VP8_ENCODER_RTCD            rtcd;
607 #endif
608 #if VP8_TEMPORAL_ALT_REF
609     YV12_BUFFER_CONFIG alt_ref_buffer;
610     YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS];
611     int fixed_divide[512];
612 #endif
613
614 #if CONFIG_INTERNAL_STATS
615     int    count;
616     double total_y;
617     double total_u;
618     double total_v;
619     double total ;
620     double total_sq_error;
621     double totalp_y;
622     double totalp_u;
623     double totalp_v;
624     double totalp;
625     double total_sq_error2;
626     int    bytes;
627     double summed_quality;
628     double summed_weights;
629     unsigned int tot_recode_hits;
630
631
632     double total_ssimg_y;
633     double total_ssimg_u;
634     double total_ssimg_v;
635     double total_ssimg_all;
636
637     int b_calculate_ssimg;
638 #endif
639     int b_calculate_psnr;
640
641     // Per MB activity measurement
642     unsigned int activity_avg;
643     unsigned int * mb_activity_map;
644     int * mb_norm_activity_map;
645
646     // Record of which MBs still refer to last golden frame either
647     // directly or through 0,0
648     unsigned char *gf_active_flags;
649     int gf_active_count;
650
651     int output_partition;
652
653     //Store last frame's MV info for next frame MV prediction
654     int_mv *lfmv;
655     int *lf_ref_frame_sign_bias;
656     int *lf_ref_frame;
657
658     int force_next_frame_intra; /* force next frame to intra when kf_auto says so */
659
660     int droppable;
661
662     // Coding layer state variables
663     unsigned int current_layer;
664     LAYER_CONTEXT layer_context[MAX_LAYERS];
665
666     long long frames_in_layer[MAX_LAYERS];
667     long long bytes_in_layer[MAX_LAYERS];
668     double sum_psnr[MAX_LAYERS];
669     double sum_psnr_p[MAX_LAYERS];
670     double total_error2[MAX_LAYERS];
671     double total_error2_p[MAX_LAYERS];
672     double sum_ssim[MAX_LAYERS];
673     double sum_weights[MAX_LAYERS];
674
675     double total_ssimg_y_in_layer[MAX_LAYERS];
676     double total_ssimg_u_in_layer[MAX_LAYERS];
677     double total_ssimg_v_in_layer[MAX_LAYERS];
678     double total_ssimg_all_in_layer[MAX_LAYERS];
679
680 } VP8_COMP;
681
682 void control_data_rate(VP8_COMP *cpi);
683
684 void vp8_encode_frame(VP8_COMP *cpi);
685
686 void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned char *dest_end, unsigned long *size);
687
688 void vp8_activity_masking(VP8_COMP *cpi, MACROBLOCK *x);
689
690 int rd_cost_intra_mb(MACROBLOCKD *x);
691
692 void vp8_tokenize_mb(VP8_COMP *, MACROBLOCKD *, TOKENEXTRA **);
693
694 void vp8_set_speed_features(VP8_COMP *cpi);
695
696 #if CONFIG_DEBUG
697 #define CHECK_MEM_ERROR(lval,expr) do {\
698         lval = (expr); \
699         if(!lval) \
700             vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,\
701                                "Failed to allocate "#lval" at %s:%d", \
702                                __FILE__,__LINE__);\
703     } while(0)
704 #else
705 #define CHECK_MEM_ERROR(lval,expr) do {\
706         lval = (expr); \
707         if(!lval) \
708             vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,\
709                                "Failed to allocate "#lval);\
710     } while(0)
711 #endif
712 #endif