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