00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "avcodec.h"
00022
00023
00024 typedef struct DVDSubParseContext {
00025 uint8_t *packet;
00026 int packet_len;
00027 int packet_index;
00028 } DVDSubParseContext;
00029
00030 static int dvdsub_parse_init(AVCodecParserContext *s)
00031 {
00032 return 0;
00033 }
00034
00035 static int dvdsub_parse(AVCodecParserContext *s,
00036 AVCodecContext *avctx,
00037 const uint8_t **poutbuf, int *poutbuf_size,
00038 const uint8_t *buf, int buf_size)
00039 {
00040 DVDSubParseContext *pc = s->priv_data;
00041
00042 if (pc->packet_index == 0) {
00043 if (buf_size < 2)
00044 return 0;
00045 pc->packet_len = AV_RB16(buf);
00046 if (pc->packet_len == 0)
00047 pc->packet_len = AV_RB32(buf+2);
00048 av_freep(&pc->packet);
00049 pc->packet = av_malloc(pc->packet_len);
00050 }
00051 if (pc->packet) {
00052 if (pc->packet_index + buf_size <= pc->packet_len) {
00053 memcpy(pc->packet + pc->packet_index, buf, buf_size);
00054 pc->packet_index += buf_size;
00055 if (pc->packet_index >= pc->packet_len) {
00056 *poutbuf = pc->packet;
00057 *poutbuf_size = pc->packet_len;
00058 pc->packet_index = 0;
00059 return buf_size;
00060 }
00061 } else {
00062
00063 pc->packet_index = 0;
00064 }
00065 }
00066 *poutbuf = NULL;
00067 *poutbuf_size = 0;
00068 return buf_size;
00069 }
00070
00071 static void dvdsub_parse_close(AVCodecParserContext *s)
00072 {
00073 DVDSubParseContext *pc = s->priv_data;
00074 av_freep(&pc->packet);
00075 }
00076
00077 AVCodecParser dvdsub_parser = {
00078 { CODEC_ID_DVD_SUBTITLE },
00079 sizeof(DVDSubParseContext),
00080 dvdsub_parse_init,
00081 dvdsub_parse,
00082 dvdsub_parse_close,
00083 };