int coda_h264_profile(int profile_idc)
{ switch (profile_idc) { case 66: return V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE; case 77: return V4L2_MPEG_VIDEO_H264_PROFILE_MAIN; case 88: return V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED; case 100: return V4L2_MPEG_VIDEO_H264_PROFILE_HIGH; default: return -EINVAL;
}
}
int coda_h264_level(int level_idc)
{ switch (level_idc) { case 10: return V4L2_MPEG_VIDEO_H264_LEVEL_1_0; case 9: return V4L2_MPEG_VIDEO_H264_LEVEL_1B; case 11: return V4L2_MPEG_VIDEO_H264_LEVEL_1_1; case 12: return V4L2_MPEG_VIDEO_H264_LEVEL_1_2; case 13: return V4L2_MPEG_VIDEO_H264_LEVEL_1_3; case 20: return V4L2_MPEG_VIDEO_H264_LEVEL_2_0; case 21: return V4L2_MPEG_VIDEO_H264_LEVEL_2_1; case 22: return V4L2_MPEG_VIDEO_H264_LEVEL_2_2; case 30: return V4L2_MPEG_VIDEO_H264_LEVEL_3_0; case 31: return V4L2_MPEG_VIDEO_H264_LEVEL_3_1; case 32: return V4L2_MPEG_VIDEO_H264_LEVEL_3_2; case 40: return V4L2_MPEG_VIDEO_H264_LEVEL_4_0; case 41: return V4L2_MPEG_VIDEO_H264_LEVEL_4_1; case 42: return V4L2_MPEG_VIDEO_H264_LEVEL_4_2; case 50: return V4L2_MPEG_VIDEO_H264_LEVEL_5_0; case 51: return V4L2_MPEG_VIDEO_H264_LEVEL_5_1; default: return -EINVAL;
}
}
struct rbsp { char *buf; int size; int pos;
};
staticinlineint rbsp_read_bit(struct rbsp *rbsp)
{ int shift = 7 - (rbsp->pos % 8); int ofs = rbsp->pos++ / 8;
if (ofs >= rbsp->size) return -EINVAL;
return (rbsp->buf[ofs] >> shift) & 1;
}
staticinlineint rbsp_write_bit(struct rbsp *rbsp, int bit)
{ int shift = 7 - (rbsp->pos % 8); int ofs = rbsp->pos++ / 8;
if (ofs >= rbsp->size) return -EINVAL;
rbsp->buf[ofs] &= ~(1 << shift);
rbsp->buf[ofs] |= bit << shift;
return 0;
}
staticinlineint rbsp_read_bits(struct rbsp *rbsp, int num, int *val)
{ int i, ret; int tmp = 0;
if (num > 32) return -EINVAL;
for (i = 0; i < num; i++) {
ret = rbsp_read_bit(rbsp); if (ret < 0) return ret;
tmp |= ret << (num - i - 1);
}
if (val)
*val = tmp;
return 0;
}
staticint rbsp_write_bits(struct rbsp *rbsp, int num, int value)
{ int ret;
while (num--) {
ret = rbsp_write_bit(rbsp, (value >> num) & 1); if (ret) return ret;
}
return 0;
}
staticint rbsp_read_uev(struct rbsp *rbsp, unsignedint *val)
{ int leading_zero_bits = 0; unsignedint tmp = 0; int ret;
while ((ret = rbsp_read_bit(rbsp)) == 0)
leading_zero_bits++; if (ret < 0) return ret;
if (leading_zero_bits > 0) {
ret = rbsp_read_bits(rbsp, leading_zero_bits, &tmp); if (ret) return ret;
}
/** * coda_h264_sps_fixup - fixes frame cropping values in h.264 SPS * @ctx: encoder context * @width: visible width * @height: visible height * @buf: buffer containing h.264 SPS RBSP, starting with NAL header * @size: modified RBSP size return value * @max_size: available size in buf * * Rewrites the frame cropping values in an h.264 SPS RBSP correctly for the * given visible width and height.
*/ int coda_h264_sps_fixup(struct coda_ctx *ctx, int width, int height, char *buf, int *size, int max_size)
{ int profile_idc; unsignedint pic_order_cnt_type; int pic_width_in_mbs_minus1, pic_height_in_map_units_minus1; int frame_mbs_only_flag, frame_cropping_flag; int vui_parameters_present_flag; unsignedint crop_right, crop_bottom; struct rbsp sps; int pos; int ret;
if (*size < 8 || *size >= max_size) return -EINVAL;
/* log2_max_frame_num_minus4 */
ret = rbsp_read_uev(&sps, NULL); if (ret) return ret;
ret = rbsp_read_uev(&sps, &pic_order_cnt_type); if (ret) return ret;
if (pic_order_cnt_type == 0) { /* log2_max_pic_order_cnt_lsb_minus4 */
ret = rbsp_read_uev(&sps, NULL); if (ret) return ret;
} elseif (pic_order_cnt_type == 1) { unsignedint i, num_ref_frames_in_pic_order_cnt_cycle;
/* delta_pic_order_always_zero_flag */
ret = rbsp_read_bit(&sps); if (ret < 0) return ret; /* offset_for_non_ref_pic */
ret = rbsp_read_sev(&sps, NULL); if (ret) return ret; /* offset_for_top_to_bottom_field */
ret = rbsp_read_sev(&sps, NULL); if (ret) return ret;
ret = rbsp_read_uev(&sps,
&num_ref_frames_in_pic_order_cnt_cycle); if (ret) return ret; for (i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; i++) { /* offset_for_ref_frame */
ret = rbsp_read_sev(&sps, NULL); if (ret) return ret;
}
}
/* max_num_ref_frames */
ret = rbsp_read_uev(&sps, NULL); if (ret) return ret;
/* gaps_in_frame_num_value_allowed_flag */
ret = rbsp_read_bit(&sps); if (ret < 0) return ret;
ret = rbsp_read_uev(&sps, &pic_width_in_mbs_minus1); if (ret) return ret;
ret = rbsp_read_uev(&sps, &pic_height_in_map_units_minus1); if (ret) return ret;
frame_mbs_only_flag = ret = rbsp_read_bit(&sps); if (ret < 0) return ret; if (!frame_mbs_only_flag) { /* mb_adaptive_frame_field_flag */
ret = rbsp_read_bit(&sps); if (ret < 0) return ret;
} /* direct_8x8_inference_flag */
ret = rbsp_read_bit(&sps); if (ret < 0) return ret;
/* Mark position of the frame cropping flag */
pos = sps.pos;
frame_cropping_flag = ret = rbsp_read_bit(&sps); if (ret < 0) return ret; if (frame_cropping_flag) { unsignedint crop_left, crop_top;
ret = rbsp_read_uev(&sps, &crop_left); if (ret) return ret;
ret = rbsp_read_uev(&sps, &crop_right); if (ret) return ret;
ret = rbsp_read_uev(&sps, &crop_top); if (ret) return ret;
ret = rbsp_read_uev(&sps, &crop_bottom); if (ret) return ret;
}
vui_parameters_present_flag = ret = rbsp_read_bit(&sps); if (ret < 0) return ret; if (vui_parameters_present_flag) {
dev_err(ctx->fh.vdev->dev_parent, "%s: Handling vui_parameters not implemented\n",
__func__); return -EINVAL;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.