LCOV - code coverage report
Current view: top level - libavcodec - cbs_mpeg2_syntax_template.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 179 208 86.1 %
Date: 2017-12-16 13:57:32 Functions: 22 22 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          12 : static int FUNC(sequence_header)(CodedBitstreamContext *ctx, RWContext *rw,
      20             :                                  MPEG2RawSequenceHeader *current)
      21             : {
      22          12 :     CodedBitstreamMPEG2Context *mpeg2 = ctx->priv_data;
      23             :     int err, i;
      24             : 
      25          12 :     HEADER("Sequence Header");
      26             : 
      27          12 :     ui(8,  sequence_header_code);
      28             : 
      29          12 :     ui(12, horizontal_size_value);
      30          12 :     ui(12, vertical_size_value);
      31             : 
      32          12 :     mpeg2->horizontal_size = current->horizontal_size_value;
      33          12 :     mpeg2->vertical_size   = current->vertical_size_value;
      34             : 
      35          12 :     ui(4,  aspect_ratio_information);
      36          12 :     ui(4,  frame_rate_code);
      37          12 :     ui(18, bit_rate_value);
      38             : 
      39          12 :     marker_bit();
      40             : 
      41          12 :     ui(10, vbv_buffer_size_value);
      42          12 :     ui(1,  constrained_parameters_flag);
      43             : 
      44          12 :     ui(1, load_intra_quantiser_matrix);
      45          12 :     if (current->load_intra_quantiser_matrix) {
      46         520 :         for (i = 0; i < 64; i++)
      47         512 :             ui(8, intra_quantiser_matrix[i]);
      48             :     }
      49             : 
      50          12 :     ui(1, load_non_intra_quantiser_matrix);
      51          12 :     if (current->load_non_intra_quantiser_matrix) {
      52         520 :         for (i = 0; i < 64; i++)
      53         512 :             ui(8, non_intra_quantiser_matrix[i]);
      54             :     }
      55             : 
      56          12 :     return 0;
      57             : }
      58             : 
      59          28 : static int FUNC(user_data)(CodedBitstreamContext *ctx, RWContext *rw,
      60             :                            MPEG2RawUserData *current)
      61             : {
      62             :     size_t k;
      63             :     int err;
      64             : 
      65          28 :     HEADER("User Data");
      66             : 
      67          28 :     ui(8, user_data_start_code);
      68             : 
      69             : #ifdef READ
      70          14 :     k = get_bits_left(rw);
      71          14 :     av_assert0(k % 8 == 0);
      72          14 :     current->user_data_length = k /= 8;
      73          14 :     if (k > 0) {
      74          14 :         current->user_data = av_malloc(k);
      75          14 :         if (!current->user_data)
      76           0 :             return AVERROR(ENOMEM);
      77             :     }
      78             : #endif
      79             : 
      80         678 :     for (k = 0; k < current->user_data_length; k++)
      81         650 :         xui(8, user_data, current->user_data[k]);
      82             : 
      83          28 :     return 0;
      84             : }
      85             : 
      86          12 : static int FUNC(sequence_extension)(CodedBitstreamContext *ctx, RWContext *rw,
      87             :                                     MPEG2RawSequenceExtension *current)
      88             : {
      89          12 :     CodedBitstreamMPEG2Context *mpeg2 = ctx->priv_data;
      90             :     int err;
      91             : 
      92          12 :     HEADER("Sequence Extension");
      93             : 
      94          12 :     ui(8,  profile_and_level_indication);
      95          12 :     ui(1,  progressive_sequence);
      96          12 :     ui(2,  chroma_format);
      97          12 :     ui(2,  horizontal_size_extension);
      98          12 :     ui(2,  vertical_size_extension);
      99             : 
     100          24 :     mpeg2->horizontal_size = (mpeg2->horizontal_size & 0xfff) |
     101          12 :         current->horizontal_size_extension << 12;
     102          24 :     mpeg2->vertical_size = (mpeg2->vertical_size & 0xfff) |
     103          12 :         current->vertical_size_extension << 12;
     104          12 :     mpeg2->progressive_sequence = current->progressive_sequence;
     105             : 
     106          12 :     ui(12, bit_rate_extension);
     107          12 :     marker_bit();
     108          12 :     ui(8,  vbv_buffer_size_extension);
     109          12 :     ui(1,  low_delay);
     110          12 :     ui(2,  frame_rate_extension_n);
     111          12 :     ui(5,  frame_rate_extension_d);
     112             : 
     113          12 :     return 0;
     114             : }
     115             : 
     116           6 : static int FUNC(sequence_display_extension)(CodedBitstreamContext *ctx, RWContext *rw,
     117             :                                             MPEG2RawSequenceDisplayExtension *current)
     118             : {
     119             :     int err;
     120             : 
     121           6 :     HEADER("Sequence Display Extension");
     122             : 
     123           6 :     ui(3, video_format);
     124             : 
     125           6 :     ui(1, colour_description);
     126           6 :     if (current->colour_description) {
     127           2 :         ui(8, colour_primaries);
     128           2 :         ui(8, transfer_characteristics);
     129           2 :         ui(8, matrix_coefficients);
     130             :     }
     131             : 
     132           6 :     ui(14, display_horizontal_size);
     133           6 :     marker_bit();
     134           6 :     ui(14, display_vertical_size);
     135             : 
     136           6 :     return 0;
     137             : }
     138             : 
     139           4 : static int FUNC(group_of_pictures_header)(CodedBitstreamContext *ctx, RWContext *rw,
     140             :                                           MPEG2RawGroupOfPicturesHeader *current)
     141             : {
     142             :     int err;
     143             : 
     144           4 :     HEADER("Group of Pictures Header");
     145             : 
     146           4 :     ui(8,  group_start_code);
     147             : 
     148           4 :     ui(25, time_code);
     149           4 :     ui(1,  closed_gop);
     150           4 :     ui(1,  broken_link);
     151             : 
     152           4 :     return 0;
     153             : }
     154             : 
     155          38 : static int FUNC(picture_header)(CodedBitstreamContext *ctx, RWContext *rw,
     156             :                                 MPEG2RawPictureHeader *current)
     157             : {
     158             :     int err;
     159             : 
     160          38 :     HEADER("Picture Header");
     161             : 
     162          38 :     ui(8,  picture_start_code);
     163             : 
     164          38 :     ui(10, temporal_reference);
     165          38 :     ui(3,  picture_coding_type);
     166          38 :     ui(16, vbv_delay);
     167             : 
     168          64 :     if (current->picture_coding_type == 2 ||
     169          26 :         current->picture_coding_type == 3) {
     170          30 :         ui(1, full_pel_forward_vector);
     171          30 :         ui(3, forward_f_code);
     172             :     }
     173             : 
     174          38 :     if (current->picture_coding_type == 3) {
     175          18 :         ui(1, full_pel_backward_vector);
     176          18 :         ui(3, backward_f_code);
     177             :     }
     178             : 
     179          38 :     ui(1, extra_bit_picture);
     180             : 
     181          38 :     return 0;
     182             : }
     183             : 
     184          38 : static int FUNC(picture_coding_extension)(CodedBitstreamContext *ctx, RWContext *rw,
     185             :                                           MPEG2RawPictureCodingExtension *current)
     186             : {
     187          38 :     CodedBitstreamMPEG2Context *mpeg2 = ctx->priv_data;
     188             :     int err;
     189             : 
     190          38 :     HEADER("Picture Coding Extension");
     191             : 
     192          38 :     ui(4, f_code[0][0]);
     193          38 :     ui(4, f_code[0][1]);
     194          38 :     ui(4, f_code[1][0]);
     195          38 :     ui(4, f_code[1][1]);
     196             : 
     197          38 :     ui(2, intra_dc_precision);
     198          38 :     ui(2, picture_structure);
     199          38 :     ui(1, top_field_first);
     200          38 :     ui(1, frame_pred_frame_dct);
     201          38 :     ui(1, concealment_motion_vectors);
     202          38 :     ui(1, q_scale_type);
     203          38 :     ui(1, intra_vlc_format);
     204          38 :     ui(1, alternate_scan);
     205          38 :     ui(1, repeat_first_field);
     206          38 :     ui(1, chroma_420_type);
     207          38 :     ui(1, progressive_frame);
     208             : 
     209          38 :     if (mpeg2->progressive_sequence) {
     210           0 :         if (current->repeat_first_field) {
     211           0 :             if (current->top_field_first)
     212           0 :                 mpeg2->number_of_frame_centre_offsets = 3;
     213             :             else
     214           0 :                 mpeg2->number_of_frame_centre_offsets = 2;
     215             :         } else {
     216           0 :             mpeg2->number_of_frame_centre_offsets = 1;
     217             :         }
     218             :     } else {
     219          68 :         if (current->picture_structure == 1 || // Top field.
     220          30 :             current->picture_structure == 2) { // Bottom field.
     221          16 :             mpeg2->number_of_frame_centre_offsets = 1;
     222             :         } else {
     223          22 :             if (current->repeat_first_field)
     224           6 :                 mpeg2->number_of_frame_centre_offsets = 3;
     225             :             else
     226          16 :                 mpeg2->number_of_frame_centre_offsets = 2;
     227             :         }
     228             :     }
     229             : 
     230          38 :     ui(1, composite_display_flag);
     231          38 :     if (current->composite_display_flag) {
     232           0 :         ui(1, v_axis);
     233           0 :         ui(3, field_sequence);
     234           0 :         ui(1, sub_carrier);
     235           0 :         ui(7, burst_amplitude);
     236           0 :         ui(8, sub_carrier_phase);
     237             :     }
     238             : 
     239          38 :     return 0;
     240             : }
     241             : 
     242          22 : static int FUNC(quant_matrix_extension)(CodedBitstreamContext *ctx, RWContext *rw,
     243             :                                         MPEG2RawQuantMatrixExtension *current)
     244             : {
     245             :     int err, i;
     246             : 
     247          22 :     HEADER("Quant Matrix Extension");
     248             : 
     249          22 :     ui(1, load_intra_quantiser_matrix);
     250          22 :     if (current->load_intra_quantiser_matrix) {
     251        1300 :         for (i = 0; i < 64; i++)
     252        1280 :             ui(8, intra_quantiser_matrix[i]);
     253             :     }
     254             : 
     255          22 :     ui(1, load_non_intra_quantiser_matrix);
     256          22 :     if (current->load_non_intra_quantiser_matrix) {
     257        1430 :         for (i = 0; i < 64; i++)
     258        1408 :             ui(8, non_intra_quantiser_matrix[i]);
     259             :     }
     260             : 
     261          22 :     ui(1, load_chroma_intra_quantiser_matrix);
     262          22 :     if (current->load_chroma_intra_quantiser_matrix) {
     263         130 :         for (i = 0; i < 64; i++)
     264         128 :             ui(8, intra_quantiser_matrix[i]);
     265             :     }
     266             : 
     267          22 :     ui(1, load_chroma_non_intra_quantiser_matrix);
     268          22 :     if (current->load_chroma_non_intra_quantiser_matrix) {
     269         130 :         for (i = 0; i < 64; i++)
     270         128 :             ui(8, chroma_non_intra_quantiser_matrix[i]);
     271             :     }
     272             : 
     273          22 :     return 0;
     274             : }
     275             : 
     276          28 : static int FUNC(picture_display_extension)(CodedBitstreamContext *ctx, RWContext *rw,
     277             :                                            MPEG2RawPictureDisplayExtension *current)
     278             : {
     279          28 :     CodedBitstreamMPEG2Context *mpeg2 = ctx->priv_data;
     280             :     int err, i;
     281             : 
     282          28 :     HEADER("Picture Display Extension");
     283             : 
     284          78 :     for (i = 0; i < mpeg2->number_of_frame_centre_offsets; i++) {
     285          50 :         ui(16, frame_centre_horizontal_offset[i]);
     286          50 :         marker_bit();
     287          50 :         ui(16, frame_centre_vertical_offset[i]);
     288          50 :         marker_bit();
     289             :     }
     290             : 
     291          28 :     return 0;
     292             : }
     293             : 
     294         106 : static int FUNC(extension_data)(CodedBitstreamContext *ctx, RWContext *rw,
     295             :                                 MPEG2RawExtensionData *current)
     296             : {
     297             :     int err;
     298             : 
     299         106 :     HEADER("Extension Data");
     300             : 
     301         106 :     ui(8, extension_start_code);
     302         106 :     ui(4, extension_start_code_identifier);
     303             : 
     304         106 :     switch (current->extension_start_code_identifier) {
     305          12 :     case 1:
     306          12 :         return FUNC(sequence_extension)
     307             :             (ctx, rw, &current->data.sequence);
     308           6 :     case 2:
     309           6 :         return FUNC(sequence_display_extension)
     310             :             (ctx, rw, &current->data.sequence_display);
     311          22 :     case 3:
     312          22 :         return FUNC(quant_matrix_extension)
     313             :             (ctx, rw, &current->data.quant_matrix);
     314          28 :     case 7:
     315          28 :         return FUNC(picture_display_extension)
     316             :             (ctx, rw, &current->data.picture_display);
     317          38 :     case 8:
     318          38 :         return FUNC(picture_coding_extension)
     319             :             (ctx, rw, &current->data.picture_coding);
     320           0 :     default:
     321           0 :         av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid extension ID %d.\n",
     322           0 :                current->extension_start_code_identifier);
     323           0 :         return AVERROR_INVALIDDATA;
     324             :     }
     325             : }
     326             : 
     327       17492 : static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw,
     328             :                               MPEG2RawSliceHeader *current)
     329             : {
     330       17492 :     CodedBitstreamMPEG2Context *mpeg2 = ctx->priv_data;
     331             :     int err;
     332             : 
     333       17492 :     HEADER("Slice Header");
     334             : 
     335       17492 :     ui(8, slice_vertical_position);
     336             : 
     337       17492 :     if (mpeg2->vertical_size > 2800)
     338           0 :         ui(3, slice_vertical_position_extension);
     339       17492 :     if (mpeg2->scalable) {
     340           0 :         if (mpeg2->scalable_mode == 0)
     341           0 :             ui(7, priority_breakpoint);
     342             :     }
     343             : 
     344       17492 :     ui(5, quantiser_scale_code);
     345             : 
     346       17492 :     if (nextbits(1, 1, current->slice_extension_flag)) {
     347       13914 :         ui(1, slice_extension_flag);
     348       13914 :         ui(1, intra_slice);
     349       13914 :         ui(1, slice_picture_id_enable);
     350       13914 :         ui(6, slice_picture_id);
     351             : 
     352             :         {
     353             :             size_t k;
     354             : #ifdef READ
     355             :             GetBitContext start;
     356             :             uint8_t bit;
     357        6957 :             start = *rw;
     358        6957 :             for (k = 0; nextbits(1, 1, bit); k++)
     359           0 :                 skip_bits(rw, 8);
     360        6957 :             current->extra_information_length = k;
     361        6957 :             if (k > 0) {
     362           0 :                 *rw = start;
     363           0 :                 current->extra_information =
     364           0 :                     av_malloc(current->extra_information_length);
     365           0 :                 if (!current->extra_information)
     366           0 :                     return AVERROR(ENOMEM);
     367           0 :                 for (k = 0; k < current->extra_information_length; k++) {
     368           0 :                     xui(1, extra_bit_slice, bit);
     369           0 :                     xui(8, extra_information_slice,
     370             :                         current->extra_information[k]);
     371             :                 }
     372             :             }
     373             : #else
     374        6957 :             for (k = 0; k < current->extra_information_length; k++) {
     375           0 :                 xui(1, extra_bit_slice, 1);
     376           0 :                 xui(8, extra_information_slice, current->extra_information[k]);
     377             :             }
     378             : #endif
     379             :         }
     380             :     }
     381       17492 :     ui(1, extra_bit_slice);
     382             : 
     383       17492 :     return 0;
     384             : }

Generated by: LCOV version 1.13