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

Generated by: LCOV version 1.13