LCOV - code coverage report
Current view: top level - libavcodec - cbs_vp9_syntax_template.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 178 197 90.4 %
Date: 2018-05-20 11:54:08 Functions: 28 28 100.0 %

          Line data    Source code
       1             : /*
       2             :  * This file is part of FFmpeg.
       3             :  *
       4             :  * FFmpeg is free software; you can redistribute it and/or
       5             :  * modify it under the terms of the GNU Lesser General Public
       6             :  * License as published by the Free Software Foundation; either
       7             :  * version 2.1 of the License, or (at your option) any later version.
       8             :  *
       9             :  * FFmpeg is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             :  * Lesser General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public
      15             :  * License along with FFmpeg; if not, write to the Free Software
      16             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      17             :  */
      18             : 
      19          28 : static int FUNC(frame_sync_code)(CodedBitstreamContext *ctx, RWContext *rw,
      20             :                                  VP9RawFrameHeader *current)
      21             : {
      22          28 :     uint8_t frame_sync_byte_0 = VP9_FRAME_SYNC_0;
      23          28 :     uint8_t frame_sync_byte_1 = VP9_FRAME_SYNC_1;
      24          28 :     uint8_t frame_sync_byte_2 = VP9_FRAME_SYNC_2;
      25             :     int err;
      26             : 
      27          28 :     xf(8, frame_sync_byte_0, frame_sync_byte_0, 0);
      28          28 :     xf(8, frame_sync_byte_1, frame_sync_byte_1, 0);
      29          28 :     xf(8, frame_sync_byte_2, frame_sync_byte_2, 0);
      30             : 
      31          28 :     if (frame_sync_byte_0 != VP9_FRAME_SYNC_0 ||
      32          28 :         frame_sync_byte_1 != VP9_FRAME_SYNC_1 ||
      33             :         frame_sync_byte_2 != VP9_FRAME_SYNC_2) {
      34           0 :         av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid frame sync code: "
      35             :                "%02x %02x %02x.\n", frame_sync_byte_0,
      36             :                frame_sync_byte_1, frame_sync_byte_2);
      37           0 :         return AVERROR_INVALIDDATA;
      38             :     }
      39             : 
      40          28 :     return 0;
      41             : }
      42             : 
      43          28 : static int FUNC(color_config)(CodedBitstreamContext *ctx, RWContext *rw,
      44             :                               VP9RawFrameHeader *current, int profile)
      45             : {
      46             :     int err;
      47             : 
      48          28 :     if (profile >= 2)
      49           6 :         f(1, ten_or_twelve_bit);
      50             : 
      51          28 :     f(3, color_space);
      52             : 
      53          28 :     if (current->color_space != VP9_CS_RGB) {
      54          28 :         f(1, color_range);
      55          28 :         if (profile == 1 || profile == 3) {
      56           8 :             f(1, subsampling_x);
      57           8 :             f(1, subsampling_y);
      58           8 :             f(1, color_config_reserved_zero);
      59             :         } else {
      60          20 :             infer(subsampling_x, 1);
      61          20 :             infer(subsampling_y, 1);
      62             :         }
      63             :     } else {
      64           0 :         infer(color_range, 1);
      65           0 :         if (profile == 1 || profile == 3) {
      66           0 :             infer(subsampling_x, 0);
      67           0 :             infer(subsampling_y, 0);
      68             :         }
      69             :     }
      70             : 
      71          28 :     return 0;
      72             : }
      73             : 
      74          30 : static int FUNC(frame_size)(CodedBitstreamContext *ctx, RWContext *rw,
      75             :                             VP9RawFrameHeader *current)
      76             : {
      77          30 :     CodedBitstreamVP9Context *vp9 = ctx->priv_data;
      78             :     int err;
      79             : 
      80          30 :     f(16, frame_width_minus_1);
      81          30 :     f(16, frame_height_minus_1);
      82             : 
      83          30 :     vp9->mi_cols = (current->frame_width_minus_1  + 8) >> 3;
      84          30 :     vp9->mi_rows = (current->frame_height_minus_1 + 8) >> 3;
      85          30 :     vp9->sb64_cols = (vp9->mi_cols + 7) >> 3;
      86          30 :     vp9->sb64_rows = (vp9->mi_rows + 7) >> 3;
      87             : 
      88          30 :     return 0;
      89             : }
      90             : 
      91         362 : static int FUNC(render_size)(CodedBitstreamContext *ctx, RWContext *rw,
      92             :                              VP9RawFrameHeader *current)
      93             : {
      94             :     int err;
      95             : 
      96         362 :     f(1, render_and_frame_size_different);
      97             : 
      98         362 :     if (current->render_and_frame_size_different) {
      99           6 :         f(16, render_width_minus_1);
     100           6 :         f(16, render_height_minus_1);
     101             :     }
     102             : 
     103         362 :     return 0;
     104             : }
     105             : 
     106         334 : static int FUNC(frame_size_with_refs)(CodedBitstreamContext *ctx, RWContext *rw,
     107             :                                       VP9RawFrameHeader *current)
     108             : {
     109             :     int err, i;
     110             : 
     111         342 :     for (i = 0; i < VP9_REFS_PER_FRAME; i++) {
     112         340 :         fs(1, found_ref[i], 1, i);
     113         340 :         if (current->found_ref[i])
     114         332 :             break;
     115             :     }
     116         334 :     if (i >= VP9_REFS_PER_FRAME)
     117           2 :         CHECK(FUNC(frame_size)(ctx, rw, current));
     118         334 :     CHECK(FUNC(render_size)(ctx, rw, current));
     119             : 
     120         334 :     return 0;
     121             : }
     122             : 
     123         334 : static int FUNC(interpolation_filter)(CodedBitstreamContext *ctx, RWContext *rw,
     124             :                                       VP9RawFrameHeader *current)
     125             : {
     126             :     int err;
     127             : 
     128         334 :     f(1, is_filter_switchable);
     129         334 :     if (!current->is_filter_switchable)
     130         160 :         f(2, raw_interpolation_filter_type);
     131             : 
     132         334 :     return 0;
     133             : }
     134             : 
     135         362 : static int FUNC(loop_filter_params)(CodedBitstreamContext *ctx, RWContext *rw,
     136             :                                     VP9RawFrameHeader *current)
     137             : {
     138             :     int err, i;
     139             : 
     140         362 :     f(6, loop_filter_level);
     141         362 :     f(3, loop_filter_sharpness);
     142             : 
     143         362 :     f(1, loop_filter_delta_enabled);
     144         362 :     if (current->loop_filter_delta_enabled) {
     145         332 :         f(1, loop_filter_delta_update);
     146         332 :         if (current->loop_filter_delta_update) {
     147         280 :             for (i = 0; i < VP9_MAX_REF_FRAMES; i++) {
     148         224 :                 fs(1, update_ref_delta[i], 1, i);
     149         224 :                 if (current->update_ref_delta[i])
     150          90 :                     ss(6, loop_filter_ref_deltas[i], 1, i);
     151             :             }
     152         168 :             for (i = 0; i < 2; i++) {
     153         112 :                 fs(1, update_mode_delta[i], 1, i);
     154         112 :                 if (current->update_mode_delta[i])
     155           4 :                     ss(6, loop_filter_mode_deltas[i], 1, i);
     156             :             }
     157             :         }
     158             :     }
     159             : 
     160         362 :     return 0;
     161             : }
     162             : 
     163         362 : static int FUNC(quantization_params)(CodedBitstreamContext *ctx, RWContext *rw,
     164             :                                      VP9RawFrameHeader *current)
     165             : {
     166             :     int err;
     167             : 
     168         362 :     f(8, base_q_idx);
     169             : 
     170         362 :     delta_q(delta_q_y_dc);
     171         362 :     delta_q(delta_q_uv_dc);
     172         362 :     delta_q(delta_q_uv_ac);
     173             : 
     174         362 :     return 0;
     175             : }
     176             : 
     177         362 : static int FUNC(segmentation_params)(CodedBitstreamContext *ctx, RWContext *rw,
     178             :                                      VP9RawFrameHeader *current)
     179             : {
     180             :     static const int segmentation_feature_bits[VP9_SEG_LVL_MAX]   = { 8, 6, 2, 0 };
     181             :     static const int segmentation_feature_signed[VP9_SEG_LVL_MAX] = { 1, 1, 0, 0 };
     182             : 
     183             :     int err, i, j;
     184             : 
     185         362 :     f(1, segmentation_enabled);
     186             : 
     187         362 :     if (current->segmentation_enabled) {
     188          86 :         f(1, segmentation_update_map);
     189          86 :         if (current->segmentation_update_map) {
     190         432 :             for (i = 0; i < 7; i++)
     191         378 :                 prob(segmentation_tree_probs[i], 1, i);
     192          54 :             f(1, segmentation_temporal_update);
     193         216 :             for (i = 0; i < 3; i++) {
     194         162 :                 if (current->segmentation_temporal_update)
     195         156 :                     prob(segmentation_pred_prob[i], 1, i);
     196             :                 else
     197           6 :                     infer(segmentation_pred_prob[i], 255);
     198             :             }
     199             :         }
     200             : 
     201          86 :         f(1, segmentation_update_data);
     202          86 :         if (current->segmentation_update_data) {
     203          58 :             f(1, segmentation_abs_or_delta_update);
     204         522 :             for (i = 0; i < VP9_MAX_SEGMENTS; i++) {
     205        2320 :                 for (j = 0; j < VP9_SEG_LVL_MAX; j++) {
     206        1856 :                     fs(1, feature_enabled[i][j], 2, i, j);
     207        2192 :                     if (current->feature_enabled[i][j] &&
     208         336 :                         segmentation_feature_bits[j]) {
     209         330 :                         fs(segmentation_feature_bits[j],
     210             :                            feature_value[i][j], 2, i, j);
     211         660 :                         if (segmentation_feature_signed[j])
     212         324 :                             fs(1, feature_sign[i][j], 2, i, j);
     213             :                         else
     214           6 :                             infer(feature_sign[i][j], 0);
     215             :                     } else {
     216        1526 :                         infer(feature_value[i][j], 0);
     217        1526 :                         infer(feature_sign[i][j],  0);
     218             :                     }
     219             :                 }
     220             :             }
     221             :         }
     222             :     }
     223             : 
     224         362 :     return 0;
     225             : }
     226             : 
     227         362 : static int FUNC(tile_info)(CodedBitstreamContext *ctx, RWContext *rw,
     228             :                            VP9RawFrameHeader *current)
     229             : {
     230         362 :     CodedBitstreamVP9Context *vp9 = ctx->priv_data;
     231             :     int min_log2_tile_cols, max_log2_tile_cols;
     232             :     int err;
     233             : 
     234         362 :     min_log2_tile_cols = 0;
     235         724 :     while ((VP9_MAX_TILE_WIDTH_B64 << min_log2_tile_cols) < vp9->sb64_cols)
     236           0 :         ++min_log2_tile_cols;
     237         362 :     max_log2_tile_cols = 0;
     238         732 :     while ((vp9->sb64_cols >> (max_log2_tile_cols + 1)) >= VP9_MIN_TILE_WIDTH_B64)
     239           8 :         ++max_log2_tile_cols;
     240             : 
     241         362 :     increment(tile_cols_log2, min_log2_tile_cols, max_log2_tile_cols);
     242             : 
     243         362 :     increment(tile_rows_log2, 0, 2);
     244             : 
     245         362 :     return 0;
     246             : }
     247             : 
     248         394 : static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw,
     249             :                                      VP9RawFrameHeader *current)
     250             : {
     251             :     int profile, i;
     252             :     int err;
     253             : 
     254         394 :     f(2, frame_marker);
     255             : 
     256         394 :     f(1, profile_low_bit);
     257         394 :     f(1, profile_high_bit);
     258         394 :     profile = (current->profile_high_bit << 1) + current->profile_low_bit;
     259         394 :     if (profile == 3)
     260          44 :         f(1, profile_reserved_zero);
     261             : 
     262         394 :     f(1, show_existing_frame);
     263         394 :     if (current->show_existing_frame) {
     264          32 :         f(3, frame_to_show_map_idx);
     265          32 :         infer(header_size_in_bytes, 0);
     266          32 :         infer(refresh_frame_flags,  0x00);
     267          32 :         infer(loop_filter_level,    0);
     268          32 :         return 0;
     269             :     }
     270             : 
     271         362 :     f(1, frame_type);
     272         362 :     f(1, show_frame);
     273         362 :     f(1, error_resilient_mode);
     274             : 
     275         362 :     if (current->frame_type == VP9_KEY_FRAME) {
     276          28 :         CHECK(FUNC(frame_sync_code)(ctx, rw, current));
     277          28 :         CHECK(FUNC(color_config)(ctx, rw, current, profile));
     278          28 :         CHECK(FUNC(frame_size)(ctx, rw, current));
     279          28 :         CHECK(FUNC(render_size)(ctx, rw, current));
     280             : 
     281          28 :         infer(refresh_frame_flags, 0xff);
     282             : 
     283             :     } else {
     284         334 :          if (current->show_frame == 0)
     285          28 :              f(1, intra_only);
     286             :          else
     287         306 :              infer(intra_only, 0);
     288             : 
     289         334 :          if (current->error_resilient_mode == 0)
     290         334 :              f(2, reset_frame_context);
     291             :          else
     292           0 :              infer(reset_frame_context, 0);
     293             : 
     294         334 :          if (current->intra_only == 1) {
     295           0 :              CHECK(FUNC(frame_sync_code)(ctx, rw, current));
     296             : 
     297           0 :              if (profile > 0) {
     298           0 :                  CHECK(FUNC(color_config)(ctx, rw, current, profile));
     299             :              } else {
     300           0 :                  infer(color_space,   1);
     301           0 :                  infer(subsampling_x, 1);
     302           0 :                  infer(subsampling_y, 1);
     303             :              }
     304             : 
     305           0 :              f(8, refresh_frame_flags);
     306             : 
     307           0 :              CHECK(FUNC(frame_size)(ctx, rw, current));
     308           0 :              CHECK(FUNC(render_size)(ctx, rw, current));
     309             :          } else {
     310         334 :              f(8, refresh_frame_flags);
     311             : 
     312        1336 :              for (i = 0; i < VP9_REFS_PER_FRAME; i++) {
     313        1002 :                  fs(3, ref_frame_idx[i], 1, i);
     314        1002 :                  fs(1, ref_frame_sign_bias[VP9_LAST_FRAME + i],
     315             :                     1, VP9_LAST_FRAME + i);
     316             :              }
     317             : 
     318         334 :              CHECK(FUNC(frame_size_with_refs)(ctx, rw, current));
     319         334 :              f(1, allow_high_precision_mv);
     320         334 :              CHECK(FUNC(interpolation_filter)(ctx, rw, current));
     321             :          }
     322             :     }
     323             : 
     324         362 :     if (current->error_resilient_mode == 0) {
     325         362 :         f(1, refresh_frame_context);
     326         362 :         f(1, frame_parallel_decoding_mode);
     327             :     } else {
     328           0 :         infer(refresh_frame_context,        0);
     329           0 :         infer(frame_parallel_decoding_mode, 1);
     330             :     }
     331             : 
     332         362 :     f(2, frame_context_idx);
     333             : 
     334         362 :     CHECK(FUNC(loop_filter_params)(ctx, rw, current));
     335         362 :     CHECK(FUNC(quantization_params)(ctx, rw, current));
     336         362 :     CHECK(FUNC(segmentation_params)(ctx, rw, current));
     337         362 :     CHECK(FUNC(tile_info)(ctx, rw, current));
     338             : 
     339         362 :     f(16, header_size_in_bytes);
     340             : 
     341         362 :     return 0;
     342             : }
     343             : 
     344         394 : static int FUNC(trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
     345             : {
     346             :     int err;
     347         394 :     av_unused int zero = 0;
     348        1700 :     while (byte_alignment(rw) != 0)
     349         912 :         xf(1, zero_bit, zero, 0);
     350             : 
     351         394 :     return 0;
     352             : }
     353             : 
     354         394 : static int FUNC(frame)(CodedBitstreamContext *ctx, RWContext *rw,
     355             :                        VP9RawFrame *current)
     356             : {
     357             :     int err;
     358             : 
     359         394 :     HEADER("Frame");
     360             : 
     361         394 :     CHECK(FUNC(uncompressed_header)(ctx, rw, &current->header));
     362             : 
     363         394 :     CHECK(FUNC(trailing_bits)(ctx, rw));
     364             : 
     365         394 :     return 0;
     366             : }
     367             : 
     368          26 : static int FUNC(superframe_index)(CodedBitstreamContext *ctx, RWContext *rw,
     369             :                                   VP9RawSuperframeIndex *current)
     370             : {
     371             :     int err, i;
     372             : 
     373          26 :     HEADER("Superframe Index");
     374             : 
     375          26 :     f(3, superframe_marker);
     376          26 :     f(2, bytes_per_framesize_minus_1);
     377          26 :     f(3, frames_in_superframe_minus_1);
     378             : 
     379          80 :     for (i = 0; i <= current->frames_in_superframe_minus_1; i++) {
     380             :         // Surprise little-endian!
     381          54 :         fle(8 * (current->bytes_per_framesize_minus_1 + 1),
     382             :             frame_sizes[i], 1, i);
     383             :     }
     384             : 
     385          26 :     f(3, superframe_marker);
     386          26 :     f(2, bytes_per_framesize_minus_1);
     387          26 :     f(3, frames_in_superframe_minus_1);
     388             : 
     389          26 :     return 0;
     390             : }

Generated by: LCOV version 1.13