dirac_parser.c

Go to the documentation of this file.
00001 /*
00002  * Dirac parser
00003  *
00004  * Copyright (c) 2007 Marco Gerards <marco@gnu.org>
00005  *
00006  * This file is part of FFmpeg.
00007  *
00008  * FFmpeg is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * FFmpeg is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with FFmpeg; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 /**
00024  * @file dirac_parser.c
00025  * Dirac Parser
00026  * @author Marco Gerards <marco@gnu.org>
00027  */
00028 
00029 #include "parser.h"
00030 
00031 #define DIRAC_PARSE_INFO_PREFIX 0x42424344
00032 
00033 /**
00034  * Finds the end of the current frame in the bitstream.
00035  * @return the position of the first byte of the next frame or -1
00036  */
00037 static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
00038 {
00039     uint32_t state = pc->state;
00040     int i;
00041 
00042     for (i = 0; i < buf_size; i++) {
00043         state = (state << 8) | buf[i];
00044         if (state == DIRAC_PARSE_INFO_PREFIX) {
00045             pc->frame_start_found ^= 1;
00046             if (!pc->frame_start_found) {
00047                 pc->state = -1;
00048                 return i - 3;
00049             }
00050         }
00051     }
00052 
00053     pc->state = state;
00054 
00055     return END_NOT_FOUND;
00056 }
00057 
00058 static int dirac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
00059                        const uint8_t **poutbuf, int *poutbuf_size,
00060                        const uint8_t *buf, int buf_size)
00061 {
00062     ParseContext *pc = s->priv_data;
00063     int next;
00064 
00065     if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
00066         next = buf_size;
00067     }else{
00068         next = find_frame_end(pc, buf, buf_size);
00069 
00070         if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
00071             *poutbuf = NULL;
00072             *poutbuf_size = 0;
00073             return buf_size;
00074         }
00075     }
00076 
00077     *poutbuf = buf;
00078     *poutbuf_size = buf_size;
00079     return next;
00080 }
00081 
00082 AVCodecParser dirac_parser = {
00083     { CODEC_ID_DIRAC },
00084     sizeof(ParseContext),
00085     NULL,
00086     dirac_parse,
00087     ff_parse_close,
00088 };

Generated on Fri Jan 9 16:44:26 2009 for libextractor by  doxygen 1.5.1