gboolean mpeg4_util_parse_VOP (GstBuffer * buf, Mpeg4VideoObjectLayer * vol, Mpeg4VideoObjectPlane * vop) { GstBitReader reader = GST_BIT_READER_INIT_FROM_BUFFER (buf); guint8 vop_start_code; guint8 modulo_time_base; /* set default values */ vop->modulo_time_base = 0; vop->rounding_type = 0; vop->top_field_first = 1; vop->alternate_vertical_scan_flag = 0; vop->fcode_forward = 1; vop->fcode_backward = 1; /* start code prefix */ SKIP (&reader, 24); READ_UINT8 (&reader, vop_start_code, 8); if (vop_start_code != MPEG4_PACKET_VOP) goto wrong_start_code; READ_UINT8 (&reader, vop->coding_type, 2); READ_UINT8 (&reader, modulo_time_base, 1); while (modulo_time_base) { vop->modulo_time_base++; READ_UINT8 (&reader, modulo_time_base, 1); } /* marker bit */ SKIP (&reader, 1); READ_UINT16 (&reader, vop->time_increment, vol->vop_time_increment_bits); /* marker bit */ SKIP (&reader, 1); READ_UINT8 (&reader, vop->coded, 1); if (!vop->coded) return TRUE; if (vop->coding_type == P_VOP) READ_UINT8 (&reader, vop->rounding_type, 1); READ_UINT8 (&reader, vop->intra_dc_vlc_thr, 3); if (vol->interlaced) { READ_UINT8 (&reader, vop->top_field_first, 1); READ_UINT8 (&reader, vop->alternate_vertical_scan_flag, 1); } READ_UINT16 (&reader, vop->quant, vol->quant_precision); if (vop->coding_type != I_VOP) { READ_UINT8 (&reader, vop->fcode_forward, 3); CHECK_ALLOWED (vop->fcode_forward, 1, 7); } if (vop->coding_type == B_VOP) { READ_UINT8 (&reader, vop->fcode_backward, 3); CHECK_ALLOWED (vop->fcode_backward, 1, 7); } return TRUE; error: GST_WARNING ("error parsing \"Video Object Plane\""); return FALSE; wrong_start_code: GST_WARNING ("got buffer with wrong start code"); goto error; }
gboolean mpeg4_util_parse_VOL (GstBuffer * buf, Mpeg4VisualObject * vo, Mpeg4VideoObjectLayer * vol) { GstBitReader reader = GST_BIT_READER_INIT_FROM_BUFFER (buf); guint8 video_object_layer_start_code; guint8 aspect_ratio_info; guint8 control_parameters; guint8 not_8_bit; /* set default values */ vol->verid = vo->verid; vol->priority = vo->priority; vol->low_delay = FALSE; vol->chroma_format = 1; vol->vbv_parameters = FALSE; vol->quant_precision = 5; vol->bits_per_pixel = 8; vol->quarter_sample = FALSE; /* start code prefix */ SKIP (&reader, 24); READ_UINT8 (&reader, video_object_layer_start_code, 8); if (!(video_object_layer_start_code >= MPEG4_PACKET_VOL_MIN && video_object_layer_start_code <= MPEG4_PACKET_VOL_MAX)) goto wrong_start_code; READ_UINT8 (&reader, vol->random_accesible_vol, 1); READ_UINT8 (&reader, vol->video_object_type_indication, 8); READ_UINT8 (&reader, vol->is_object_layer_identifier, 1); if (vol->is_object_layer_identifier) { READ_UINT8 (&reader, vol->verid, 4); READ_UINT8 (&reader, vol->priority, 3); } READ_UINT8 (&reader, aspect_ratio_info, 4); if (aspect_ratio_info != 0xff) mpeg4_util_par_from_info (aspect_ratio_info, &vol->par_n, &vol->par_d); else { READ_UINT8 (&reader, vol->par_n, 8); CHECK_ALLOWED (vol->par_n, 1, 255); READ_UINT8 (&reader, vol->par_d, 8); CHECK_ALLOWED (vol->par_d, 1, 255); } READ_UINT8 (&reader, control_parameters, 1); if (control_parameters) { READ_UINT8 (&reader, vol->chroma_format, 2); READ_UINT8 (&reader, vol->low_delay, 1); READ_UINT8 (&reader, vol->vbv_parameters, 1); if (vol->vbv_parameters) { guint16 first_half, latter_half; guint8 latter_part; READ_UINT16 (&reader, first_half, 15); SKIP (&reader, 1); READ_UINT16 (&reader, latter_half, 15); SKIP (&reader, 1); vol->bit_rate = (first_half << 15) | latter_half; READ_UINT16 (&reader, first_half, 15); SKIP (&reader, 1); READ_UINT8 (&reader, latter_part, 3); SKIP (&reader, 1); vol->vbv_buffer_size = (first_half << 15) | latter_part; } } READ_UINT8 (&reader, vol->shape, 2); if (vol->shape != 0x0) goto invalid_shape; /* marker_bit */ SKIP (&reader, 1); READ_UINT16 (&reader, vol->vop_time_increment_resolution, 16); CHECK_ALLOWED (vol->vop_time_increment_resolution, 1, G_MAXUINT16); vol->vop_time_increment_bits = g_bit_storage (vol->vop_time_increment_resolution); /* marker_bit */ SKIP (&reader, 1); READ_UINT8 (&reader, vol->fixed_vop_rate, 1); if (vol->fixed_vop_rate) READ_UINT16 (&reader, vol->fixed_vop_time_increment, vol->vop_time_increment_bits); /* marker bit */ SKIP (&reader, 1); READ_UINT16 (&reader, vol->width, 13); /* marker bit */ SKIP (&reader, 1); READ_UINT16 (&reader, vol->height, 13); /* marker bit */ SKIP (&reader, 1); READ_UINT8 (&reader, vol->interlaced, 1); READ_UINT8 (&reader, vol->obmc_disable, 1); if (vol->verid == 0x1) { READ_UINT8 (&reader, vol->sprite_enable, 1); } else READ_UINT8 (&reader, vol->sprite_enable, 2); if (vol->sprite_enable != 0x0) goto invalid_sprite_enable; READ_UINT8 (&reader, not_8_bit, 1); if (not_8_bit) { READ_UINT8 (&reader, vol->quant_precision, 4); CHECK_ALLOWED (vol->quant_precision, 3, 9); READ_UINT8 (&reader, vol->bits_per_pixel, 4); CHECK_ALLOWED (vol->bits_per_pixel, 4, 12); } READ_UINT8 (&reader, vol->quant_type, 1); if (vol->quant_type) { if (!mpeg4_util_parse_quant (&reader, vol->intra_quant_mat, default_intra_quant_mat)) goto error; if (!mpeg4_util_parse_quant (&reader, vol->non_intra_quant_mat, default_non_intra_quant_mat)) goto error; } else { memset (&vol->intra_quant_mat, 0, 64); memset (&vol->non_intra_quant_mat, 0, 64); } if (vol->verid != 0x1) READ_UINT8 (&reader, vol->quarter_sample, 1); READ_UINT8 (&reader, vol->complexity_estimation_disable, 1); if (!vol->complexity_estimation_disable) goto complexity_estimation_error; READ_UINT8 (&reader, vol->resync_marker_disable, 1); return TRUE; error: GST_WARNING ("error parsing \"Video Object Layer\""); return FALSE; wrong_start_code: GST_WARNING ("got buffer with wrong start code"); goto error; invalid_shape: GST_WARNING ("we only support rectangular shape"); goto error; invalid_sprite_enable: GST_WARNING ("we only support sprite_enable == 0"); goto error; complexity_estimation_error: GST_WARNING ("don't support complexity estimation"); goto error; }
/** * gst_mpeg4_parse_video_packet_header: * @videopackethdr: The #GstMpeg4VideoPacketHdr structure to fill * @vol: The last parsed #GstMpeg4VideoObjectLayer, will be updated * with the informations found during the parsing * @vop: The last parsed #GstMpeg4VideoObjectPlane, will be updated * with the informations found during the parsing * @sprite_trajectory: A #GstMpeg4SpriteTrajectory to fill or %NULL * with the informations found during the parsing * @data: The data to parse, should be set after the resync marker. * @size: The size of the data to parse * * Parsers @data containing the video packet header * and fills the @videopackethdr structure */ GstMpeg4ParseResult gst_mpeg4_parse_video_packet_header (GstMpeg4VideoPacketHdr * videopackethdr, GstMpeg4VideoObjectLayer * vol, GstMpeg4VideoObjectPlane * vop, GstMpeg4SpriteTrajectory * sprite_trajectory, const guint8 * data, gsize size) { guint8 markersize; GstBitReader br = GST_BIT_READER_INIT (data, size); g_return_val_if_fail (videopackethdr != NULL, GST_MPEG4_PARSER_ERROR); g_return_val_if_fail (vol != NULL, GST_MPEG4_PARSER_ERROR); markersize = compute_resync_marker_size (vop, NULL, NULL); CHECK_REMAINING (&br, markersize); if (gst_bit_reader_get_bits_uint32_unchecked (&br, markersize) != 0x01) goto failed; if (vol->shape != GST_MPEG4_RECTANGULAR) { READ_UINT8 (&br, videopackethdr->header_extension_code, 1); if (vol->sprite_enable == GST_MPEG4_SPRITE_STATIC && vop->coding_type == GST_MPEG4_I_VOP) { CHECK_REMAINING (&br, 56); U_READ_UINT16 (&br, vop->width, 13); CHECK_MARKER (&br); U_READ_UINT16 (&br, vop->height, 13); CHECK_MARKER (&br); U_READ_UINT16 (&br, vop->horizontal_mc_spatial_ref, 13); CHECK_MARKER (&br); U_READ_UINT16 (&br, vop->vertical_mc_spatial_ref, 13); CHECK_MARKER (&br); /* Update macroblock infirmations */ vop->mb_height = (vop->height + 15) / 16; vop->mb_width = (vop->width + 15) / 16; vop->mb_num = vop->mb_height * vop->mb_width; } } READ_UINT16 (&br, videopackethdr->macroblock_number, g_bit_storage (vop->mb_num - 1)); if (vol->shape != GST_MPEG4_BINARY_ONLY) READ_UINT16 (&br, videopackethdr->quant_scale, vol->quant_precision); if (vol->shape == GST_MPEG4_RECTANGULAR) READ_UINT8 (&br, videopackethdr->header_extension_code, 1); if (videopackethdr->header_extension_code) { guint timeincr = 0; guint8 bit = 0, coding_type; do { READ_UINT8 (&br, bit, 1); timeincr++; } while (bit); vol->vop_time_increment_bits = timeincr; CHECK_MARKER (&br); READ_UINT16 (&br, vop->time_increment, timeincr); CHECK_MARKER (&br); READ_UINT8 (&br, coding_type, 2); vop->coding_type = coding_type; if (vol->shape != GST_MPEG4_RECTANGULAR) { READ_UINT8 (&br, vop->change_conv_ratio_disable, 1); if (vop->coding_type != GST_MPEG4_I_VOP) READ_UINT8 (&br, vop->shape_coding_type, 1); } if (vol->shape != GST_MPEG4_BINARY_ONLY) { READ_UINT8 (&br, vop->intra_dc_vlc_thr, 3); if (sprite_trajectory && vol->sprite_enable == GST_MPEG4_SPRITE_GMG && vop->coding_type == GST_MPEG4_S_VOP && vol->no_of_sprite_warping_points > 0) { parse_sprite_trajectory (&br, sprite_trajectory, vol->no_of_sprite_warping_points); } if (vol->reduced_resolution_vop_enable && vol->shape == GST_MPEG4_RECTANGULAR && (vop->coding_type == GST_MPEG4_P_VOP || vop->coding_type == GST_MPEG4_I_VOP)) READ_UINT8 (&br, vop->reduced_resolution, 1); if (vop->coding_type != GST_MPEG4_I_VOP) { READ_UINT8 (&br, vop->fcode_forward, 3); CHECK_ALLOWED (vop->fcode_forward, 1, 7); } if (vop->coding_type == GST_MPEG4_B_VOP) { READ_UINT8 (&br, vop->fcode_backward, 3); CHECK_ALLOWED (vop->fcode_backward, 1, 7); } } } if (vol->newpred_enable) { guint16 nbbits = vol->vop_time_increment_bits + 3 < 15 ? vop->time_increment + 3 : 15; READ_UINT16 (&br, vop->id, nbbits); READ_UINT8 (&br, vop->id_for_prediction_indication, 1); if (vop->id_for_prediction_indication) { /* Would be nice if the standard actually told us... */ READ_UINT16 (&br, vop->id, nbbits); CHECK_MARKER (&br); } } videopackethdr->size = gst_bit_reader_get_pos (&br); failed: GST_DEBUG ("Failed to parse video packet header"); return GST_MPEG4_PARSER_NO_PACKET; }
/** * gst_mpeg4_parse_video_object_layer: * @vol: The #GstMpeg4VideoObjectLayer structure to fill * @vo: The #GstMpeg4VisualObject currently being parsed or %NULL * @data: The data to parse * @size: The size of the @data to parse * * Parses @data containing the video object layer packet, and fills * the @vol structure. * * Returns: a #GstMpeg4ParseResult */ GstMpeg4ParseResult gst_mpeg4_parse_video_object_layer (GstMpeg4VideoObjectLayer * vol, GstMpeg4VisualObject * vo, const guint8 * data, gsize size) { guint8 video_object_layer_start_code; /* Used for enums types */ guint8 tmp; GstBitReader br = GST_BIT_READER_INIT (data, size); g_return_val_if_fail (vol != NULL, GST_MPEG4_PARSER_ERROR); GST_DEBUG ("Parsing video object layer"); READ_UINT8 (&br, video_object_layer_start_code, 8); if (!(video_object_layer_start_code >= GST_MPEG4_VIDEO_LAYER_FIRST && video_object_layer_start_code <= GST_MPEG4_VIDEO_LAYER_LAST)) goto wrong_start_code; /* set default values */ if (vo) { vol->verid = vo->verid; vol->priority = vo->priority; } else { vol->verid = 1; vol->priority = 0; } vol->low_delay = FALSE; vol->chroma_format = 1; vol->vbv_parameters = FALSE; vol->quant_precision = 5; vol->bits_per_pixel = 8; vol->quarter_sample = FALSE; vol->newpred_enable = FALSE; vol->interlaced = 0; vol->width = 0; vol->height = 0; READ_UINT8 (&br, vol->random_accessible_vol, 1); READ_UINT8 (&br, vol->video_object_type_indication, 8); READ_UINT8 (&br, vol->is_object_layer_identifier, 1); if (vol->is_object_layer_identifier) { READ_UINT8 (&br, vol->verid, 4); READ_UINT8 (&br, vol->priority, 3); } READ_UINT8 (&br, tmp, 4); vol->aspect_ratio_info = tmp; if (vol->aspect_ratio_info != GST_MPEG4_EXTENDED_PAR) { mpeg4_util_par_from_info (vol->aspect_ratio_info, &vol->par_width, &vol->par_height); } else { gint v; READ_UINT8 (&br, vol->par_width, 8); v = vol->par_width; CHECK_ALLOWED (v, 1, 255); READ_UINT8 (&br, vol->par_height, 8); v = vol->par_height; CHECK_ALLOWED (v, 1, 255); } GST_DEBUG ("Pixel aspect ratio %d/%d", vol->par_width, vol->par_width); READ_UINT8 (&br, vol->control_parameters, 1); if (vol->control_parameters) { guint8 chroma_format; READ_UINT8 (&br, chroma_format, 2); vol->chroma_format = chroma_format; READ_UINT8 (&br, vol->low_delay, 1); READ_UINT8 (&br, vol->vbv_parameters, 1); if (vol->vbv_parameters) { CHECK_REMAINING (&br, 79); vol->first_half_bitrate = gst_bit_reader_get_bits_uint16_unchecked (&br, 15); MARKER_UNCHECKED (&br); vol->latter_half_bitrate = gst_bit_reader_get_bits_uint16_unchecked (&br, 15); MARKER_UNCHECKED (&br); vol->bit_rate = (vol->first_half_bitrate << 15) | vol->latter_half_bitrate; vol->first_half_vbv_buffer_size = gst_bit_reader_get_bits_uint16_unchecked (&br, 15); MARKER_UNCHECKED (&br); vol->latter_half_vbv_buffer_size = gst_bit_reader_get_bits_uint8_unchecked (&br, 3); vol->vbv_buffer_size = (vol->first_half_vbv_buffer_size << 15) | vol->latter_half_vbv_buffer_size; vol->first_half_vbv_occupancy = gst_bit_reader_get_bits_uint16_unchecked (&br, 11); MARKER_UNCHECKED (&br); vol->latter_half_vbv_occupancy = gst_bit_reader_get_bits_uint16_unchecked (&br, 15); MARKER_UNCHECKED (&br); } } READ_UINT8 (&br, tmp, 2); vol->shape = tmp; if (vol->shape == GST_MPEG4_GRAYSCALE) { /* TODO support grayscale shapes, for now we just pass */ /* Something the standard starts to define... */ GST_WARNING ("Grayscale shaped not supported"); goto failed; } if (vol->shape == GST_MPEG4_GRAYSCALE && vol->verid != 0x01) READ_UINT8 (&br, vol->shape_extension, 4); CHECK_REMAINING (&br, 19); MARKER_UNCHECKED (&br); vol->vop_time_increment_resolution = gst_bit_reader_get_bits_uint16_unchecked (&br, 16); if (vol->vop_time_increment_resolution < 1) { GST_WARNING ("value not in allowed range. value: %d, range %d-%d", vol->vop_time_increment_resolution, 1, G_MAXUINT16); goto failed; } vol->vop_time_increment_bits = g_bit_storage (vol->vop_time_increment_resolution); MARKER_UNCHECKED (&br); vol->fixed_vop_rate = gst_bit_reader_get_bits_uint8_unchecked (&br, 1); if (vol->fixed_vop_rate) READ_UINT16 (&br, vol->fixed_vop_time_increment, vol->vop_time_increment_bits); if (vol->shape != GST_MPEG4_BINARY_ONLY) { if (vol->shape == GST_MPEG4_RECTANGULAR) { CHECK_REMAINING (&br, 29); MARKER_UNCHECKED (&br); vol->width = gst_bit_reader_get_bits_uint16_unchecked (&br, 13); MARKER_UNCHECKED (&br); vol->height = gst_bit_reader_get_bits_uint16_unchecked (&br, 13); MARKER_UNCHECKED (&br); } READ_UINT8 (&br, vol->interlaced, 1); READ_UINT8 (&br, vol->obmc_disable, 1); if (vol->verid == 0x1) READ_UINT8 (&br, tmp, 1); else READ_UINT8 (&br, tmp, 2); vol->sprite_enable = tmp; if (vol->sprite_enable == GST_MPEG4_SPRITE_STATIC || vol->sprite_enable == GST_MPEG4_SPRITE_GMG) { if (vol->sprite_enable == GST_MPEG4_SPRITE_GMG) CHECK_REMAINING (&br, 9); else { CHECK_REMAINING (&br, 65); vol->sprite_width = gst_bit_reader_get_bits_uint16_unchecked (&br, 13); MARKER_UNCHECKED (&br); vol->sprite_height = gst_bit_reader_get_bits_uint16_unchecked (&br, 13); MARKER_UNCHECKED (&br); vol->sprite_left_coordinate = gst_bit_reader_get_bits_uint16_unchecked (&br, 13); MARKER_UNCHECKED (&br); vol->sprite_top_coordinate = gst_bit_reader_get_bits_uint16_unchecked (&br, 13); MARKER_UNCHECKED (&br); } vol->no_of_sprite_warping_points = gst_bit_reader_get_bits_uint8_unchecked (&br, 6); vol->sprite_warping_accuracy = gst_bit_reader_get_bits_uint8_unchecked (&br, 2); vol->sprite_brightness_change = gst_bit_reader_get_bits_uint8_unchecked (&br, 1); if (vol->sprite_enable != GST_MPEG4_SPRITE_GMG) vol->low_latency_sprite_enable = gst_bit_reader_get_bits_uint8_unchecked (&br, 1); } if (vol->verid != 0x1 && vol->shape != GST_MPEG4_RECTANGULAR) READ_UINT8 (&br, vol->sadct_disable, 1); READ_UINT8 (&br, vol->not_8_bit, 1); if (vol->not_8_bit) { READ_UINT8 (&br, vol->quant_precision, 4); CHECK_ALLOWED (vol->quant_precision, 3, 9); READ_UINT8 (&br, vol->bits_per_pixel, 4); CHECK_ALLOWED (vol->bits_per_pixel, 4, 12); } if (vol->shape == GST_MPEG4_GRAYSCALE) { /* We don't actually support it */ READ_UINT8 (&br, vol->no_gray_quant_update, 1); READ_UINT8 (&br, vol->composition_method, 1); READ_UINT8 (&br, vol->linear_composition, 1); } READ_UINT8 (&br, vol->quant_type, 1); if (vol->quant_type) { if (!parse_quant (&br, vol->intra_quant_mat, default_intra_quant_mat, &vol->load_intra_quant_mat)) goto failed; if (!parse_quant (&br, vol->non_intra_quant_mat, default_non_intra_quant_mat, &vol->load_non_intra_quant_mat)) goto failed; if (vol->shape == GST_MPEG4_GRAYSCALE) { /* Something the standard starts to define... */ GST_WARNING ("Grayscale shaped not supported"); goto failed; } } else { memset (&vol->intra_quant_mat, 0, 64); memset (&vol->non_intra_quant_mat, 0, 64); } if (vol->verid != 0x1) READ_UINT8 (&br, vol->quarter_sample, 1); READ_UINT8 (&br, vol->complexity_estimation_disable, 1); if (!vol->complexity_estimation_disable) { guint8 estimation_method; guint8 estimation_disable; /* skip unneeded properties */ READ_UINT8 (&br, estimation_method, 2); if (estimation_method < 2) { READ_UINT8 (&br, estimation_disable, 1); if (!estimation_disable) SKIP (&br, 6); READ_UINT8 (&br, estimation_disable, 1); if (!estimation_disable) SKIP (&br, 4); CHECK_MARKER (&br); READ_UINT8 (&br, estimation_disable, 1); if (!estimation_disable) SKIP (&br, 4); READ_UINT8 (&br, estimation_disable, 1); if (!estimation_disable) SKIP (&br, 6); CHECK_MARKER (&br); if (estimation_method == 1) { READ_UINT8 (&br, estimation_disable, 1); if (!estimation_disable) SKIP (&br, 2); } } } READ_UINT8 (&br, vol->resync_marker_disable, 1); READ_UINT8 (&br, vol->data_partitioned, 1); if (vol->data_partitioned) READ_UINT8 (&br, vol->reversible_vlc, 1); if (vol->verid != 0x01) { READ_UINT8 (&br, vol->newpred_enable, 1); if (vol->newpred_enable) /* requested_upstream_message_type and newpred_segment_type */ SKIP (&br, 3); READ_UINT8 (&br, vol->reduced_resolution_vop_enable, 1); } READ_UINT8 (&br, vol->scalability, 1); if (vol->scalability) { SKIP (&br, 26); /* Few not needed props */ READ_UINT8 (&br, vol->enhancement_type, 1); } /* More unused infos */ } else if (vol->verid != 0x01) { GST_WARNING ("Binary only shapes not fully supported"); goto failed; } /* ... */ return GST_MPEG4_PARSER_OK; failed: GST_WARNING ("failed parsing \"Video Object Layer\""); return GST_MPEG4_PARSER_ERROR; wrong_start_code: GST_WARNING ("got buffer with wrong start code"); goto failed; }
/** * gst_mpeg4_parse_video_object_plane: * @vop: The #GstMpeg4VideoObjectPlane currently being parsed * @sprite_trajectory: A #GstMpeg4SpriteTrajectory to fill or %NULL * @vol: The #GstMpeg4VideoObjectLayer structure to fill * @data: The data to parse * @size: The size of the @data to parse * * Parses @data containing the video object plane packet, and fills the @vol * structure. * * Returns: a #GstMpeg4ParseResult */ GstMpeg4ParseResult gst_mpeg4_parse_video_object_plane (GstMpeg4VideoObjectPlane * vop, GstMpeg4SpriteTrajectory * sprite_trajectory, GstMpeg4VideoObjectLayer * vol, const guint8 * data, gsize size) { guint8 vop_start_code, coding_type, modulo_time_base; GstBitReader br = GST_BIT_READER_INIT (data, size); g_return_val_if_fail (vop != NULL, GST_MPEG4_PARSER_ERROR); if (vol->shape == GST_MPEG4_BINARY_ONLY) { /* TODO: implement binary only shapes */ GST_WARNING ("Binary only shapes not supported"); goto failed; } READ_UINT8 (&br, vop_start_code, 8); if (vop_start_code != GST_MPEG4_VIDEO_OBJ_PLANE) goto wrong_start_code; /* set default values */ vop->modulo_time_base = 0; vop->rounding_type = 0; vop->top_field_first = 1; vop->alternate_vertical_scan_flag = 0; vop->fcode_forward = 1; vop->fcode_backward = 1; /* Compute macroblock informations */ if (vol->interlaced) vop->mb_height = (2 * (vol->height + 31) / 32); else vop->mb_height = (vol->height + 15) / 16; vop->mb_width = (vol->width + 15) / 16; vop->mb_num = vop->mb_height * vop->mb_width; READ_UINT8 (&br, coding_type, 2); vop->coding_type = coding_type; READ_UINT8 (&br, modulo_time_base, 1); while (modulo_time_base) { vop->modulo_time_base++; READ_UINT8 (&br, modulo_time_base, 1); } CHECK_REMAINING (&br, vol->vop_time_increment_bits + 3); MARKER_UNCHECKED (&br); vop->time_increment = gst_bit_reader_get_bits_uint16_unchecked (&br, vol->vop_time_increment_bits); MARKER_UNCHECKED (&br); vop->coded = gst_bit_reader_get_bits_uint8_unchecked (&br, 1); if (!vop->coded) return GST_MPEG4_PARSER_OK; if (vol->newpred_enable) { guint16 nbbits = vop->time_increment + 3 < 15 ? vop->time_increment + 3 : 15; READ_UINT16 (&br, vop->id, nbbits); READ_UINT8 (&br, vop->id_for_prediction_indication, 1); if (vop->id_for_prediction_indication) { /* Would be nice if the standard actually told us... */ READ_UINT16 (&br, vop->id, nbbits); CHECK_MARKER (&br); } } if (vol->shape != GST_MPEG4_BINARY_ONLY && (vop->coding_type == GST_MPEG4_P_VOP || (vop->coding_type == GST_MPEG4_S_VOP && vol->sprite_enable == GST_MPEG4_SPRITE_GMG))) READ_UINT8 (&br, vop->rounding_type, 1); if ((vol->reduced_resolution_vop_enable) && (vol->shape == GST_MPEG4_RECTANGULAR || (vop->coding_type = GST_MPEG4_P_VOP || vop->coding_type == GST_MPEG4_I_VOP))) READ_UINT8 (&br, vop->reduced_resolution, 1); if (vol->shape != GST_MPEG4_RECTANGULAR) { if (vol->sprite_enable == GST_MPEG4_SPRITE_STATIC && vop->coding_type == GST_MPEG4_I_VOP) { CHECK_REMAINING (&br, 55); vop->width = gst_bit_reader_get_bits_uint16_unchecked (&br, 13); MARKER_UNCHECKED (&br); vop->height = gst_bit_reader_get_bits_uint16_unchecked (&br, 13); MARKER_UNCHECKED (&br); vop->horizontal_mc_spatial_ref = gst_bit_reader_get_bits_uint16_unchecked (&br, 13); MARKER_UNCHECKED (&br); vop->vertical_mc_spatial_ref = gst_bit_reader_get_bits_uint16_unchecked (&br, 13); MARKER_UNCHECKED (&br); /* Recompute the Macroblock informations * accordingly to the new values */ if (vol->interlaced) vop->mb_height = (2 * (vol->height + 31) / 32); else vop->mb_height = (vol->height + 15) / 16; vop->mb_width = (vol->width + 15) / 16; vop->mb_num = vop->mb_height * vop->mb_width; } if ((vol->shape != GST_MPEG4_BINARY_ONLY) && vol->scalability && vol->enhancement_type) READ_UINT8 (&br, vop->background_composition, 1); READ_UINT8 (&br, vop->change_conv_ratio_disable, 1); READ_UINT8 (&br, vop->constant_alpha, 1); if (vop->constant_alpha) READ_UINT8 (&br, vop->constant_alpha_value, 1); } if (vol->shape != GST_MPEG4_BINARY_ONLY) { if (!vol->complexity_estimation_disable) { GST_WARNING ("Complexity estimation not supported"); goto failed; } READ_UINT8 (&br, vop->intra_dc_vlc_thr, 3); if (vol->interlaced) { READ_UINT8 (&br, vop->top_field_first, 1); READ_UINT8 (&br, vop->alternate_vertical_scan_flag, 1); } } if ((vol->sprite_enable == GST_MPEG4_SPRITE_STATIC || vol->sprite_enable == GST_MPEG4_SPRITE_GMG) && vop->coding_type == GST_MPEG4_S_VOP) { /* only if @sprite_trajectory is not NULL we parse it */ if (sprite_trajectory && vol->no_of_sprite_warping_points) parse_sprite_trajectory (&br, sprite_trajectory, vol->no_of_sprite_warping_points); if (vol->sprite_brightness_change) { GST_WARNING ("sprite_brightness_change not supported"); goto failed; } if (vol->sprite_enable == GST_MPEG4_SPRITE_STATIC) { GST_WARNING ("sprite enable static not supported"); goto failed; } } if (vol->shape != GST_MPEG4_BINARY_ONLY) { READ_UINT16 (&br, vop->quant, vol->quant_precision); if (vol->shape == GST_MPEG4_GRAYSCALE) { /* TODO implement grayscale support */ GST_WARNING ("Grayscale shapes no supported"); /* TODO implement me */ goto failed; } if (vop->coding_type != GST_MPEG4_I_VOP) { READ_UINT8 (&br, vop->fcode_forward, 3); CHECK_ALLOWED (vop->fcode_forward, 1, 7); } if (vop->coding_type == GST_MPEG4_B_VOP) { READ_UINT8 (&br, vop->fcode_backward, 3); CHECK_ALLOWED (vop->fcode_backward, 1, 7); } } if (!vol->scalability) { if (vol->shape != GST_MPEG4_RECTANGULAR) READ_UINT8 (&br, vop->shape_coding_type, 1); } else { if (vol->enhancement_type) { READ_UINT8 (&br, vop->load_backward_shape, 1); if (vop->load_backward_shape) { GST_WARNING ("Load backward shape not supported"); goto failed; } READ_UINT8 (&br, vop->ref_select_code, 2); } } vop->size = gst_bit_reader_get_pos (&br); /* More things to possibly parse ... */ return GST_MPEG4_PARSER_OK; failed: GST_WARNING ("failed parsing \"Video Object Plane\""); return GST_MPEG4_PARSER_ERROR; wrong_start_code: GST_WARNING ("got buffer with wrong start code"); goto failed; }