diff --git a/libavcodec/cbs_mpeg2.h b/libavcodec/cbs_mpeg2.h index 32c4d4e2b10a97f2f663846a68fe49da2769e984..0b6cb998dcd012e8b4f7976f73da22b73deeb4f6 100644 --- a/libavcodec/cbs_mpeg2.h +++ b/libavcodec/cbs_mpeg2.h @@ -160,6 +160,11 @@ typedef struct MPEG2RawQuantMatrixExtension { uint8_t chroma_non_intra_quantiser_matrix[64]; } MPEG2RawQuantMatrixExtension; +typedef struct MPEG2RawPictureDisplayExtension { + uint16_t frame_centre_horizontal_offset[3]; + uint16_t frame_centre_vertical_offset[3]; +} MPEG2RawPictureDisplayExtension; + typedef struct MPEG2RawExtensionData { uint8_t extension_start_code; uint8_t extension_start_code_identifier; @@ -169,6 +174,7 @@ typedef struct MPEG2RawExtensionData { MPEG2RawSequenceDisplayExtension sequence_display; MPEG2RawQuantMatrixExtension quant_matrix; MPEG2RawPictureCodingExtension picture_coding; + MPEG2RawPictureDisplayExtension picture_display; } data; } MPEG2RawExtensionData; @@ -206,6 +212,8 @@ typedef struct CodedBitstreamMPEG2Context { uint16_t vertical_size; uint8_t scalable; uint8_t scalable_mode; + uint8_t progressive_sequence; + uint8_t number_of_frame_centre_offsets; // Write buffer. uint8_t *write_buffer; diff --git a/libavcodec/cbs_mpeg2_syntax_template.c b/libavcodec/cbs_mpeg2_syntax_template.c index b6dd42d2eebeed0ecec4080c9fa3e1afb9ad5603..4aa1eb3c062c29b8a1ccb721175d0e11e535b8cc 100644 --- a/libavcodec/cbs_mpeg2_syntax_template.c +++ b/libavcodec/cbs_mpeg2_syntax_template.c @@ -101,6 +101,7 @@ static int FUNC(sequence_extension)(CodedBitstreamContext *ctx, RWContext *rw, current->horizontal_size_extension << 12; mpeg2->vertical_size = (mpeg2->vertical_size & 0xfff) | current->vertical_size_extension << 12; + mpeg2->progressive_sequence = current->progressive_sequence; ui(12, bit_rate_extension); marker_bit(); @@ -183,6 +184,7 @@ static int FUNC(picture_header)(CodedBitstreamContext *ctx, RWContext *rw, static int FUNC(picture_coding_extension)(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawPictureCodingExtension *current) { + CodedBitstreamMPEG2Context *mpeg2 = ctx->priv_data; int err; HEADER("Picture Coding Extension"); @@ -204,6 +206,27 @@ static int FUNC(picture_coding_extension)(CodedBitstreamContext *ctx, RWContext ui(1, chroma_420_type); ui(1, progressive_frame); + if (mpeg2->progressive_sequence) { + if (current->repeat_first_field) { + if (current->top_field_first) + mpeg2->number_of_frame_centre_offsets = 3; + else + mpeg2->number_of_frame_centre_offsets = 2; + } else { + mpeg2->number_of_frame_centre_offsets = 1; + } + } else { + if (current->picture_structure == 1 || // Top field. + current->picture_structure == 2) { // Bottom field. + mpeg2->number_of_frame_centre_offsets = 1; + } else { + if (current->repeat_first_field) + mpeg2->number_of_frame_centre_offsets = 3; + else + mpeg2->number_of_frame_centre_offsets = 2; + } + } + ui(1, composite_display_flag); if (current->composite_display_flag) { ui(1, v_axis); @@ -250,6 +273,24 @@ static int FUNC(quant_matrix_extension)(CodedBitstreamContext *ctx, RWContext *r return 0; } +static int FUNC(picture_display_extension)(CodedBitstreamContext *ctx, RWContext *rw, + MPEG2RawPictureDisplayExtension *current) +{ + CodedBitstreamMPEG2Context *mpeg2 = ctx->priv_data; + int err, i; + + HEADER("Picture Display Extension"); + + for (i = 0; i < mpeg2->number_of_frame_centre_offsets; i++) { + ui(16, frame_centre_horizontal_offset[i]); + marker_bit(); + ui(16, frame_centre_vertical_offset[i]); + marker_bit(); + } + + return 0; +} + static int FUNC(extension_data)(CodedBitstreamContext *ctx, RWContext *rw, MPEG2RawExtensionData *current) { @@ -270,6 +311,9 @@ static int FUNC(extension_data)(CodedBitstreamContext *ctx, RWContext *rw, case 3: return FUNC(quant_matrix_extension) (ctx, rw, ¤t->data.quant_matrix); + case 7: + return FUNC(picture_display_extension) + (ctx, rw, ¤t->data.picture_display); case 8: return FUNC(picture_coding_extension) (ctx, rw, ¤t->data.picture_coding);