exit(1); \
}
-#define INTRA_PERIOD 30
-
static int const picture_type_patter[][2] = {{VAEncPictureTypeIntra, 1},
{VAEncPictureTypePredictive, 3}, {VAEncPictureTypePredictive, 3},{VAEncPictureTypePredictive, 3},
{VAEncPictureTypePredictive, 3}, {VAEncPictureTypePredictive, 3},{VAEncPictureTypePredictive, 3},
/* args */
int rate_control_mode;
int fps;
+ int mode; /* 0:I, 1:I/P, 2:I/P/B */
int width;
int height;
int frame_size;
bitstream_put_ui(bs, seq_param->sequence_extension.bits.frame_rate_extension_d, 5);
bitstream_byte_aligning(bs, 0);
-
- bitstream_put_ui(bs, START_CODE_GOP, 32);
- bitstream_put_ui(bs, seq_param->gop_header.bits.time_code, 25);
- bitstream_put_ui(bs, seq_param->gop_header.bits.closed_gop, 1);
- bitstream_put_ui(bs, seq_param->gop_header.bits.broken_link, 1);
-
- bitstream_byte_aligning(bs, 0);
}
static void
int i;
int chroma_420_type;
+ if (pic_param->temporal_reference == 0) {
+ bitstream_put_ui(bs, START_CODE_GOP, 32);
+ bitstream_put_ui(bs, seq_param->gop_header.bits.time_code, 25);
+ bitstream_put_ui(bs, seq_param->gop_header.bits.closed_gop, 1);
+ bitstream_put_ui(bs, seq_param->gop_header.bits.broken_link, 1);
+
+ bitstream_byte_aligning(bs, 0);
+ }
+
if (seq_param->sequence_extension.bits.chroma_format == CHROMA_FORMAT_420)
chroma_420_type = pic_param->picture_coding_extension.bits.progressive_frame;
else
fprintf(stderr, "where options include:\n");
fprintf(stderr, "\t--cqp <QP> const qp mode with specified <QP>\n");
fprintf(stderr, "\t--fps <FPS> specify the frame rate\n");
+ fprintf(stderr, "\t--mode <MODE> specify the mode 0 (I), 1 (I/P) and 2 (I/P/B)\n");
}
static void
{"help", no_argument, 0, 'h'},
{"cqp", required_argument, 0, 'c'},
{"fps", required_argument, 0, 'f'},
+ {"mode", required_argument, 0, 'm'},
{ NULL, 0, NULL, 0 }
};
ctx->fps = 30;
ctx->qp = 28;
ctx->rate_control_mode = VA_RC_CQP;
+ ctx->mode = 1;
optind = 5;
break;
+ case 'm':
+ tmp = atoi(optarg);
+
+ if (tmp < 0 || tmp > 2)
+ fprintf(stderr, "Waning: MODE must be 0, 1, or 2\n");
+ else
+ ctx->mode = tmp;
+
+ break;
+
case '?':
fprintf(stderr, "Error: unkown command options\n");
ctx->codedbuf_buf_id = VA_INVALID_ID;
ctx->codedbuf_i_size = ctx->frame_size;
ctx->codedbuf_pb_size = 0;
- ctx->intra_period = INTRA_PERIOD;
+
+ if (ctx->mode == 0)
+ ctx->intra_period = 1;
+ else
+ ctx->intra_period = 16;
+
ctx->bit_rate = -1;
for (i = 0; i < MAX_SLICES; i++) {
ctx);
}
+static int
+mpeg2enc_time_code(VAEncSequenceParameterBufferMPEG2 *seq_param,
+ int num_frames)
+{
+ int fps = (int)(seq_param->frame_rate + 0.5);
+ int time_code = 0;
+ int time_code_pictures, time_code_seconds, time_code_minutes, time_code_hours;
+ int drop_frame_flag = 0;
+
+ assert(fps <= 60);
+
+ time_code_seconds = num_frames / fps;
+ time_code_pictures = num_frames % fps;
+ time_code |= time_code_pictures;
+
+ time_code_minutes = time_code_minutes / 60;
+ time_code_seconds = time_code_minutes % 60;
+ time_code |= (time_code_seconds << 6);
+
+ time_code_hours = time_code_minutes / 60;
+ time_code_minutes = time_code_minutes % 60;
+
+ time_code |= (1 << 12); /* marker_bit */
+ time_code |= (time_code_minutes << 13);
+
+ time_code_hours = time_code_hours % 24;
+ time_code |= (time_code_hours << 19);
+
+ time_code |= (drop_frame_flag << 24);
+
+ return time_code;
+}
+
/*
* run
*/
-static void
+static void
+mpeg2enc_update_sequence_parameter(struct mpeg2enc_context *ctx,
+ VAEncPictureType picture_type,
+ int coded_order,
+ int display_order)
+{
+ VAEncSequenceParameterBufferMPEG2 *seq_param = &ctx->seq_param;
+
+ /* update the GOP info for the new GOP */
+ if (display_order % ctx->intra_period == 0) {
+ seq_param->gop_header.bits.time_code = mpeg2enc_time_code(seq_param, display_order);
+ }
+}
+
+static void
mpeg2enc_update_picture_parameter(struct mpeg2enc_context *ctx,
- VAEncPictureType picture_type,
- int coded_order,
- int display_order)
+ VAEncPictureType picture_type,
+ int coded_order,
+ int display_order)
{
- VAEncPictureParameterBufferMPEG2 *pic_param;
- VAStatus va_status;
+ VAEncPictureParameterBufferMPEG2 *pic_param = &ctx->pic_param;
- // Picture level
- pic_param = &ctx->pic_param;
pic_param->picture_type = picture_type;
- pic_param->temporal_reference = display_order;
+ pic_param->temporal_reference = display_order % ctx->intra_period;
pic_param->reconstructed_picture = surface_ids[SID_RECON_PICTURE];
pic_param->forward_reference_picture = surface_ids[SID_REFERENCE_PICTURE_L0];
pic_param->backward_reference_picture = surface_ids[SID_REFERENCE_PICTURE_L1];
- pic_param->coded_buf = ctx->codedbuf_buf_id;
+}
+
+static void
+mpeg2enc_update_picture_parameter_buffer(struct mpeg2enc_context *ctx,
+ VAEncPictureType picture_type,
+ int coded_order,
+ int display_order)
+{
+ VAEncPictureParameterBufferMPEG2 *pic_param = &ctx->pic_param;
+ VAStatus va_status;
+ /* update the coded buffer id */
+ pic_param->coded_buf = ctx->codedbuf_buf_id;
va_status = vaCreateBuffer(ctx->va_dpy,
ctx->context_id,
VAEncPictureParameterBufferType,
ctx->current_input_surface = ctx->current_upload_surface;
ctx->current_upload_surface = tmp;
+ mpeg2enc_update_sequence_parameter(ctx, picture_type, coded_order, display_order);
+ mpeg2enc_update_picture_parameter(ctx, picture_type, coded_order, display_order);
+
if (coded_order == 0) {
assert(picture_type == VAEncPictureTypeIntra);
length_in_bits = build_packed_seq_buffer(&ctx->seq_param, &packed_seq_buffer);
CHECK_VASTATUS(va_status,"vaCreateBuffer");
/* picture parameter set */
- mpeg2enc_update_picture_parameter(ctx, picture_type, coded_order, display_order);
+ mpeg2enc_update_picture_parameter_buffer(ctx, picture_type, coded_order, display_order);
mpeg2enc_render_picture(ctx);
mpeg2enc_run(struct mpeg2enc_context *ctx)
{
int display_order = 0, coded_order = 0;
- int i_frame_only = 1, i_p_frame_only = 1;
for (display_order = 0; display_order < ctx->num_pictures;) {
- if (i_frame_only) {
+ if (ctx->mode == 0) {
encode_picture(ctx,
coded_order,
display_order,
display_order + 1);
display_order++;
coded_order++;
- } else if (i_p_frame_only) {
+ } else if (ctx->mode == 1) {
+ assert(0);
if ((display_order % ctx->intra_period) == 0) {
encode_picture(ctx,
coded_order,
} else { // follow the i,p,b pattern
static int fcurrent = 0;
int fnext;
+
+ assert(0);
fcurrent = fcurrent % (sizeof(picture_type_patter)/sizeof(int[2]));
fnext = (fcurrent+1) % (sizeof(picture_type_patter)/sizeof(int[2]));