Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * DPX parser
  3.  * Copyright (c) 2013 Paul B Mahol
  4.  *
  5.  * This file is part of FFmpeg.
  6.  *
  7.  * FFmpeg is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * FFmpeg is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with FFmpeg; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20.  */
  21.  
  22. /**
  23.  * @file
  24.  * DPX parser
  25.  */
  26.  
  27. #include "libavutil/bswap.h"
  28. #include "parser.h"
  29.  
  30. typedef struct DPXParseContext {
  31.     ParseContext pc;
  32.     uint32_t index;
  33.     uint32_t fsize;
  34.     uint32_t remaining_size;
  35.     int is_be;
  36. } DPXParseContext;
  37.  
  38. static int dpx_parse(AVCodecParserContext *s, AVCodecContext *avctx,
  39.                      const uint8_t **poutbuf, int *poutbuf_size,
  40.                      const uint8_t *buf, int buf_size)
  41. {
  42.     DPXParseContext *d = s->priv_data;
  43.     uint32_t state = d->pc.state;
  44.     int next = END_NOT_FOUND;
  45.     int i = 0;
  46.  
  47.     s->pict_type = AV_PICTURE_TYPE_I;
  48.  
  49.     *poutbuf_size = 0;
  50.     if (buf_size == 0)
  51.         return 0;
  52.  
  53.     if (!d->pc.frame_start_found) {
  54.         for (; i < buf_size; i++) {
  55.             state = (state << 8) | buf[i];
  56.             if (state == MKBETAG('S','D','P','X') ||
  57.                 state == MKTAG('S','D','P','X')) {
  58.                 d->pc.frame_start_found = 1;
  59.                 d->is_be = state == MKBETAG('S','D','P','X');
  60.                 break;
  61.             }
  62.         }
  63.         d->pc.state = state;
  64.     } else {
  65.         if (d->remaining_size) {
  66.             i = FFMIN(d->remaining_size, buf_size);
  67.             d->remaining_size -= i;
  68.             if (d->remaining_size)
  69.                 goto flush;
  70.             next = i;
  71.         }
  72.     }
  73.  
  74.     for (;d->pc.frame_start_found && i < buf_size; i++) {
  75.         d->pc.state = (d->pc.state << 8) | buf[i];
  76.         if (d->index == 16) {
  77.             d->fsize = d->is_be ? d->pc.state : av_bswap32(d->pc.state);
  78.             if (d->fsize <= 1664) {
  79.                 d->index = d->pc.frame_start_found = 0;
  80.                 goto flush;
  81.             }
  82.             d->index = 0;
  83.             if (d->fsize > buf_size - i + 19)
  84.                 d->remaining_size = d->fsize - buf_size + i - 19;
  85.             else
  86.                 next = d->fsize + i - 19;
  87.             break;
  88.         }
  89.         d->index++;
  90.     }
  91.  
  92. flush:
  93.     if (ff_combine_frame(&d->pc, next, &buf, &buf_size) < 0)
  94.         return buf_size;
  95.  
  96.     d->index = d->pc.frame_start_found = 0;
  97.  
  98.     *poutbuf      = buf;
  99.     *poutbuf_size = buf_size;
  100.     return next;
  101. }
  102.  
  103. AVCodecParser ff_dpx_parser = {
  104.     .codec_ids      = { AV_CODEC_ID_DPX },
  105.     .priv_data_size = sizeof(DPXParseContext),
  106.     .parser_parse   = dpx_parse,
  107.     .parser_close   = ff_parse_close,
  108. };
  109.