- format = p_schro_params->format;
-
- while (go) {
- /* Parse data and process result. */
- state = schro_decoder_wait (decoder);
- switch (state)
- {
- case SCHRO_DECODER_FIRST_ACCESS_UNIT:
- libschroedinger_handle_first_access_unit (avccontext);
- break;
-
- case SCHRO_DECODER_NEED_BITS:
- /* Need more input data - stop iterating over what we have. */
- go = 0;
- break;
-
- case SCHRO_DECODER_NEED_FRAME:
- /* Decoder needs a frame - create one and push it in. */
-
- frame = schro_frame_new_and_alloc(NULL,
- p_schro_params->frame_format,
- format->width,
- format->height);
- schro_decoder_add_output_picture (decoder, frame);
- break;
-
- case SCHRO_DECODER_OK:
- /* Pull a frame out of the decoder. */
- frame = schro_decoder_pull (decoder);
-
- if (frame) {
- ff_dirac_schro_queue_push_back(
- &p_schro_params->dec_frame_queue,
- frame);
+ /* Loop through all the individual parse units in the input buffer */
+ do {
+ if ((enc_buf = find_next_parse_unit(&parse_ctx))) {
+ /* Set Schrotag with the pts to be recovered after decoding*/
+ enc_buf->tag = schro_tag_new(av_malloc(sizeof(int64_t)), av_free);
+ if (!enc_buf->tag->value) {
+ av_log(avccontext, AV_LOG_ERROR, "Unable to allocate SchroTag\n");
+ return AVERROR(ENOMEM);
+ }
+ AV_WN(64, enc_buf->tag->value, pts);
+ /* Push buffer into decoder. */
+ if (SCHRO_PARSE_CODE_IS_PICTURE(enc_buf->data[4]) &&
+ SCHRO_PARSE_CODE_NUM_REFS(enc_buf->data[4]) > 0)
+ avccontext->has_b_frames = 1;
+ state = schro_decoder_push(decoder, enc_buf);
+ if (state == SCHRO_DECODER_FIRST_ACCESS_UNIT)
+ libschroedinger_handle_first_access_unit(avccontext);
+ go = 1;
+ } else
+ outer = 0;
+
+ while (go) {
+ /* Parse data and process result. */
+ state = schro_decoder_wait(decoder);
+ switch (state) {
+ case SCHRO_DECODER_FIRST_ACCESS_UNIT:
+ libschroedinger_handle_first_access_unit(avccontext);
+ break;
+
+ case SCHRO_DECODER_NEED_BITS:
+ /* Need more input data - stop iterating over what we have. */
+ go = 0;
+ break;
+
+ case SCHRO_DECODER_NEED_FRAME:
+ /* Decoder needs a frame - create one and push it in. */
+ frame = ff_create_schro_frame(avccontext,
+ p_schro_params->frame_format);
+ schro_decoder_add_output_picture(decoder, frame);
+ break;
+
+ case SCHRO_DECODER_OK:
+ /* Pull a frame out of the decoder. */
+ tag = schro_decoder_get_picture_tag(decoder);
+ frame = schro_decoder_pull(decoder);
+
+ if (frame) {
+ /* Add relation between schroframe and pts. */
+ framewithpts = av_malloc(sizeof(LibSchroFrameContext));
+ if (!framewithpts) {
+ av_log(avccontext, AV_LOG_ERROR, "Unable to allocate FrameWithPts\n");
+ return AVERROR(ENOMEM);
+ }
+ framewithpts->frame = frame;
+ framewithpts->pts = AV_RN64(tag->value);
+ ff_schro_queue_push_back(&p_schro_params->dec_frame_queue,
+ framewithpts);
+ }
+ break;
+ case SCHRO_DECODER_EOS:
+ go = 0;
+ p_schro_params->eos_pulled = 1;
+ schro_decoder_reset(decoder);
+ outer = 0;
+ break;
+
+ case SCHRO_DECODER_ERROR:
+ return -1;
+ break;