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