*/
/**
-* @file libschroedingerenc.c
+* @file libavcodec/libschroedingerenc.c
* Dirac encoder support via libschroedinger-1.0 libraries. More details about
* the Schroedinger project can be found at http://www.diracvideo.org/.
* The library implements Dirac Specification Version 2.2
/** Schroedinger encoder handle*/
SchroEncoder* encoder;
+ /** buffer to store encoder output before writing it to the frame queue*/
+ unsigned char *enc_buf;
+
+ /** Size of encoder buffer*/
+ int enc_buf_size;
+
/** queue storing encoded frames */
FfmpegDiracSchroQueue enc_frame_queue;
schro_encoder_setting_set_double (p_schro_params->encoder,
"gop_structure",
SCHRO_ENCODER_GOP_INTRA_ONLY);
+
+ if (avccontext->coder_type == FF_CODER_TYPE_VLC) {
+ schro_encoder_setting_set_double (p_schro_params->encoder,
+ "enable_noarith", 1);
+ }
}
else {
schro_encoder_setting_set_double (p_schro_params->encoder,
schro_video_format_set_std_signal_range(p_schro_params->format,
SCHRO_SIGNAL_RANGE_8BIT_VIDEO);
-
- /* Hardcode motion vector precision to quarter pixel. */
- schro_encoder_setting_set_double (p_schro_params->encoder,
- "mv_precision", 2);
-
/* Set the encoder format. */
schro_encoder_set_video_format(p_schro_params->encoder,
p_schro_params->format);
SchroBuffer *enc_buf;
int presentation_frame;
int parse_code;
+ int last_frame_in_sequence = 0;
if(data == NULL) {
/* Push end of sequence if not already signalled. */
&presentation_frame);
assert (enc_buf->length > 0);
assert (enc_buf->length <= buf_size);
+ parse_code = enc_buf->data[4];
+
+ /* All non-frame data is prepended to actual frame data to
+ * be able to set the pts correctly. So we don't write data
+ * to the frame output queue until we actually have a frame
+ */
+ p_schro_params->enc_buf = av_realloc (
+ p_schro_params->enc_buf,
+ p_schro_params->enc_buf_size + enc_buf->length
+ );
+
+ memcpy(p_schro_params->enc_buf+p_schro_params->enc_buf_size,
+ enc_buf->data, enc_buf->length);
+ p_schro_params->enc_buf_size += enc_buf->length;
+
+
+ if (state == SCHRO_STATE_END_OF_STREAM) {
+ p_schro_params->eos_pulled = 1;
+ go = 0;
+ }
+
+ if (!SCHRO_PARSE_CODE_IS_PICTURE(parse_code)) {
+ schro_buffer_unref (enc_buf);
+ break;
+ }
/* Create output frame. */
p_frame_output = av_mallocz(sizeof(FfmpegDiracSchroEncodedFrame));
/* Set output data. */
- p_frame_output->size = enc_buf->length;
- p_frame_output->p_encbuf = av_malloc(enc_buf->length);
- memcpy(p_frame_output->p_encbuf, enc_buf->data, enc_buf->length);
-
- parse_code = enc_buf->data[4];
+ p_frame_output->size = p_schro_params->enc_buf_size;
+ p_frame_output->p_encbuf = p_schro_params->enc_buf;
if (SCHRO_PARSE_CODE_IS_INTRA(parse_code) &&
SCHRO_PARSE_CODE_IS_REFERENCE(parse_code)) {
p_frame_output->key_frame = 1;
/* Parse the coded frame number from the bitstream. Bytes 14
* through 17 represesent the frame number. */
- if (SCHRO_PARSE_CODE_IS_PICTURE(parse_code))
- {
- assert (enc_buf->length >= 17);
p_frame_output->frame_num = (enc_buf->data[13] << 24) +
(enc_buf->data[14] << 16) +
(enc_buf->data[15] << 8) +
enc_buf->data[16];
- }
ff_dirac_schro_queue_push_back (&p_schro_params->enc_frame_queue,
p_frame_output);
+ p_schro_params->enc_buf_size = 0;
+ p_schro_params->enc_buf = NULL;
+
schro_buffer_unref (enc_buf);
- if (state == SCHRO_STATE_END_OF_STREAM) {
- p_schro_params->eos_pulled = 1;
- go = 0;
- }
break;
case SCHRO_STATE_NEED_FRAME:
}
/* Copy 'next' frame in queue. */
+
+ if (p_schro_params->enc_frame_queue.size == 1 &&
+ p_schro_params->eos_pulled)
+ last_frame_in_sequence = 1;
+
p_frame_output =
ff_dirac_schro_queue_pop (&p_schro_params->enc_frame_queue);
avccontext->coded_frame->pts = p_frame_output->frame_num;
enc_size = p_frame_output->size;
+ /* Append the end of sequence information to the last frame in the
+ * sequence. */
+ if (last_frame_in_sequence && p_schro_params->enc_buf_size > 0)
+ {
+ memcpy (frame + enc_size, p_schro_params->enc_buf,
+ p_schro_params->enc_buf_size);
+ enc_size += p_schro_params->enc_buf_size;
+ av_freep (&p_schro_params->enc_buf);
+ p_schro_params->enc_buf_size = 0;
+ }
+
/* free frame */
SchroedingerFreeFrame (p_frame_output);
ff_dirac_schro_queue_free (&p_schro_params->enc_frame_queue,
SchroedingerFreeFrame);
+
+ /* Free the encoder buffer. */
+ if (p_schro_params->enc_buf_size)
+ av_freep(&p_schro_params->enc_buf);
+
/* Free the video format structure. */
av_freep(&p_schro_params->format);
libschroedinger_encode_frame,
libschroedinger_encode_close,
.capabilities= CODEC_CAP_DELAY,
- .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, -1},
+ .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_NONE},
+ .long_name= NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"),
};